Skip to content
This repository has been archived by the owner on Aug 23, 2022. It is now read-only.
/ BitMax.Net Public archive

Open Source .Net Wrapper for the @bitmax-exchange Rest Api and Websockets Api

License

Notifications You must be signed in to change notification settings

burakoner/BitMax.Net

Repository files navigation

Icon BitMax.Net

A .Net wrapper for the BitMax API as described on BitMax, including all features the API provides using clear and readable objects.

If you think something is broken, something is missing or have any questions, please open an Issue

CryptoExchange.Net

Implementation is build upon the CryptoExchange.Net library, make sure to also check out the documentation on that: docs

My CryptoExchange.Net implementations:


OKEx

Chiliz

BitMax

BtcTurk

Paribu

Thodex

Coinzo

Tatum

JKorf CryptoExchange.Net implementations:


Binance

Bitfinex

Bittrex

CoinEx

Huobi

Kraken

Kucoin

Implementations from third parties:


Bitmex

Exante

HitBTC

Liquid

LiveCoin

Switcheo

Donations

Donations are greatly appreciated and a motivation to keep improving.

BTC: 33WbRKqt7wXARVdAJSu1G1x3QnbyPtZ2bH
ETH: 0x65b02db9b67b73f5f1e983ae10796f91ded57b64

Installation

Nuget version Nuget downloads Available on Nuget.

PM> Install-Package BitMax.Net

To get started with BitMax.Net first you will need to get the library itself. The easiest way to do this is to install the package into your project using NuGet. Using Visual Studio this can be done in two ways.

Using the package manager

In Visual Studio right click on your solution and select 'Manage NuGet Packages for solution...'. A screen will appear which initially shows the currently installed packages. In the top bit select 'Browse'. This will let you download net package from the NuGet server. In the search box type 'BitMax.Net' and hit enter. The BitMax.Net package should come up in the results. After selecting the package you can then on the right hand side select in which projects in your solution the package should install. After you've selected all project you wish to install and use BitMax.Net in hit 'Install' and the package will be downloaded and added to you projects.

Using the package manager console

In Visual Studio in the top menu select 'Tools' -> 'NuGet Package Manager' -> 'Package Manager Console'. This should open up a command line interface. On top of the interface there is a dropdown menu where you can select the Default Project. This is the project that BitMax.Net will be installed in. After selecting the correct project type Install-Package BitMax.Net in the command line interface. This should install the latest version of the package in your project.

After doing either of above steps you should now be ready to actually start using BitMax.Net.

Getting started

After installing it's time to actually use it. To get started we have to add the BitMax.Net namespace: using BitMax.Net;.

BitMax.Net provides two clients to interact with the BitMax API. The BitMaxClient provides all rest API calls. The BitMaxSocketClient provides functions to interact with the websocket provided by the BitMax API. Both clients are disposable and as such can be used in a usingstatement.

Rest Api Examples

Cash (Spot) / Margin » Public Endpoints

BitMaxClient api = new BitMaxClient();
var assets = api.GetAssets();
var products = api.GetProducts();
var tickers_01 = api.GetTickers();
var tickers_02 = api.GetTickers("BTC/USDT");
var tickers_03 = api.GetTickers("BTC/USDT", "ETH/USDT", "LTC/USDT");
var tickers_04 = api.GetTickers(new List<string> { "BTC/USDT", "ETH/USDT", "LTC/USDT" });
var periods = api.GetBarPeriods();
var candles_01 = api.GetCandles("BTC/USDT", BitMaxPeriod.OneHour);
var candles_02 = api.GetCandles("BTC/USDT", BitMaxPeriod.OneMonth, 10);
var orderbook = api.GetOrderBook("BTC/USDT");
var trades_01 = api.GetTrades("BTC/USDT");
var trades_02 = api.GetTrades("BTC/USDT", 50);

Cash (Spot) / Margin » Private Endpoints

BitMaxClient api = new BitMaxClient();
api.SetApiCredentials("XXXXXXXX-API-KEY-XXXXXXXX", "XXXXXXXX-API-SECRET-XXXXXXXX");

var account_info = api.GetAccountInfo();
api.SetAccountGroup(account_info.Data.AccountGroup);

var spot_balances_01 = api.GetSpotBalances();
var spot_balances_02 = api.GetSpotBalances(showAll: true);
var spot_balances_03 = api.GetSpotBalances("BTC");
var spot_balances_04 = api.GetSpotBalances("BTC", true);
var margin_balances_01 = api.GetMarginBalances(showAll: false);
var margin_balances_02 = api.GetMarginBalances(showAll: true);
var margin_balances_03 = api.GetMarginBalances("BTC");
var margin_balances_04 = api.GetMarginBalances("BTC", true);
var margin_risk = api.GetMarginRisk();
var transfer = api.AccountTransfer(BitMaxWalletAccount.Cash, BitMaxWalletAccount.Margin, "BTC", 0.1m);
var deposit_address_01 = api.GetDepositAddresses("USDT");
var deposit_address_02 = api.GetDepositAddresses("USDT", "ERC20");
var wallet_transactions_01 = api.GetWalletTransactions();
var wallet_transactions_02 = api.GetWalletTransactions("BTC");
var wallet_transactions_03 = api.GetWalletTransactions("ETH", BitMaxTransactionType.Deposit, 1, 100);
var spot_order_01 = api.PlaceSpotOrder("ETH/USDT", 0.1m, BitMaxCashOrderType.Limit, BitMaxCashOrderSide.Buy, orderPrice: 607.90m);
var spot_order_02 = api.PlaceSpotOrder("BTC/USDT", 0.1m, BitMaxCashOrderType.Market, BitMaxCashOrderSide.Buy);
var spot_order_03 = api.PlaceSpotOrder("BTC/USDT", 0.1m, BitMaxCashOrderType.Limit, BitMaxCashOrderSide.Buy, 23000.00m);
var margin_order_01 = api.PlaceMarginOrder("ETH/USDT", 0.1m, BitMaxCashOrderType.Limit, BitMaxCashOrderSide.Buy, orderPrice: 607.90m);
var margin_order_02 = api.PlaceMarginOrder("BTC/USDT", 0.1m, BitMaxCashOrderType.Market, BitMaxCashOrderSide.Buy);
var margin_order_03 = api.PlaceMarginOrder("BTC/USDT", 0.1m, BitMaxCashOrderType.Limit, BitMaxCashOrderSide.Buy, 23000.00m);
var spot_cancel_order = api.CancelSpotOrder("BTC/USDT", "a176a4316ec6U3352487793bethuCafd");
var spot_cancel_all_orders_01 = api.CancelAllSpotOrders();
var spot_cancel_all_orders_02 = api.CancelAllSpotOrders("ETH/USDT");    
var margin_cancel_all_orders_01 = api.CancelAllMarginOrders();
var margin_cancel_all_orders_02 = api.CancelAllMarginOrders("ETH/USDT");
var spot_query = api.GetSpotOrder("a176a4316ec6U3352487793bethuCafd");
var margin_query = api.GetSpotOrder("a176a4316ec6U3352487793bethuCafd");
var spot_open_orders_01 = api.GetSpotOpenOrders();
var spot_open_orders_02 = api.GetSpotOpenOrders("ETH/USDT");
var spot_current_history_orders = api.GetSpotCurrentHistoryOrders();
var spot_history_orders = api.GetSpotHistoryOrders();

var spot_orders = new List<BitMaxCashPlaceOrder>();
spot_orders.Add(new BitMaxCashPlaceOrder
{
    Symbol = "BTC/USDT",
    Size = 0.1m,
    OrderType = BitMaxCashOrderType.Market,
    OrderSide = BitMaxOrderSide.Buy,
});
spot_orders.Add(new BitMaxCashPlaceOrder
{
    Symbol = "BTC/USDT",
    Size = 0.1m,
    OrderType = BitMaxCashOrderType.Limit,
    OrderSide = BitMaxOrderSide.Buy,
    OrderPrice = 23000.00m,
    PostOnly = false,
    TimeInForce = BitMaxCashOrderTimeInForce.GoodTillCanceled,
});
var spot_batch_orders = api.PlaceSpotBatchOrders(spot_orders);

var spot_orders_to_cancel = new List<BitMaxCashCancelOrder>();
spot_orders_to_cancel.Add(new BitMaxCashCancelOrder
{
    Symbol = "BTC/USDT",
    OrderId = "a176a4316ec6U3352487793bethuCafd",
});
spot_orders_to_cancel.Add(new BitMaxCashCancelOrder
{
    Symbol = "BTC/USDT",
    OrderId = "a176a4316ec6U3352487793bethuCafe",
});
var spot_cancel_batch_orders = api.CancelSpotBatchOrders(spot_orders_to_cancel);

Futures » Public Endpoints

BitMaxClient api = new BitMaxClient();

var futures_assets = api.GetFuturesAssets();
var futures_contracts = api.GetFuturesContracts();
var futures_refprices = api.GetFuturesReferencePrices();
var futures_marketdata_01 = api.GetFuturesMarketData();
var futures_marketdata_02 = api.GetFuturesMarketData("BTC-PERP");
var futures_fundingrates = api.GetFuturesFundingRates();

Futures » Private Endpoints

BitMaxClient api = new BitMaxClient();
api.SetApiCredentials("XXXXXXXX-API-KEY-XXXXXXXX", "XXXXXXXX-API-SECRET-XXXXXXXX");

var futures_info = api.GetAccountInfo();
api.SetAccountGroup(futures_info.Data.AccountGroup);

var futures_balances = api.GetFuturesBalances();
var futures_positions = api.GetFuturesPositions();
var futures_risk = api.GetFuturesRisk();
var futures_payments = api.GetFuturesFundingPayments();
var futures_transfer_01 = api.TransferFromCashToFutures("BTC", 0.1m);
var futures_transfer_02 = api.TransferFromFuturesToCash("BTC", 0.1m);
var futures_order_01 = api.PlaceFuturesOrder("BTC-PERP", 0.1m, BitMaxFuturesOrderType.Limit, BitMaxOrderSide.Buy, orderPrice: 23000.00m);
var futures_order_02 = api.PlaceFuturesOrder("BTC-PERP", 0.1m, BitMaxFuturesOrderType.Market, BitMaxOrderSide.Buy);
var futures_order_03 = api.PlaceFuturesOrder("BTC-PERP", 0.1m, BitMaxFuturesOrderType.Limit, BitMaxOrderSide.Buy, 23000.00m);
var futures_cancel_order = api.CancelFuturesOrder("BTC-PERP", "a176a4316ec6U3352487793bethuCafd");
var futures_cancel_all_orders_01 = api.CancelAllFuturesOrders();
var futures_cancel_all_orders_02 = api.CancelAllFuturesOrders("BTC-PERP");
var futures_place_batch_orders = api.PlaceFuturesBatchOrders(new List<BitMaxFuturesPlaceOrder> { });
var futures_cancel_batch_orders = api.CancelFuturesBatchOrders(new List<BitMaxFuturesCancelOrder> { });
var futures_query = api.GetFuturesOrder("a176a4316ec6U3352487793bethuCafd");
var futures_open_orders_01 = api.GetFuturesOpenOrders();
var futures_open_orders_02 = api.GetSpotOpenOrders("BTC-PERP");
var futures_current_history_orders = api.GetFuturesCurrentHistoryOrders();

Websocket Api Examples

The BitMax.Net socket client provides several socket endpoint to which can be subscribed.

Cash (Spot) / Margin » Public Feeds

var ws = new BitMaxSocketClient();

var sub01 = ws.SubscribeToSummary("*", (data) =>
{
    if (data != null)
    {
        Console.WriteLine($"Summary >> {data.Symbol} T:{data.Timestamp} O:{data.Open} H:{data.High} L:{data.Low} C:{data.Close} V:{data.Volume}");
    }
});

var sub02 = ws.SubscribeToBestAskBidUpdates(new List<string> { "BTC/USDT", "ETH/USDT" }, (data) =>
{
    if (data != null)
    {
        Console.WriteLine($"BBO >> {data.Symbol} T:{data.Timestamp} AP:{data.BestAsk.Price} AA:{data.BestAsk.Quantity} BP:{data.BestBid.Price} BA:{data.BestBid.Quantity}");
    }
});

var sub03 = ws.SubscribeToOrderBookUpdates(new List<string> { "BTC/USDT", "ETH/USDT" }, (data) =>
{
    if (data != null)
    {
        Console.WriteLine($"Book >> {data.Symbol} T:{data.Timestamp} AC:{data.Asks.Count()} BC:{data.Bids.Count()}");
    }
});

var sub04 = ws.SubscribeToTrades(new List<string> { "BTC/USDT", "ETH/USDT" }, (data) =>
{
    if (data != null)
    {
        Console.WriteLine($"Trades >> {data.Symbol} T:{data.Timestamp} P:{data.Price} A:{data.Amount} SN:{data.SequenceNumber} BM:{data.IsBuyerMarketMaker}");
    }
});

var sub05 = ws.SubscribeToCandles(new List<string> { "BTC/USDT", "ETH/USDT" }, BitMaxPeriod.OneHour, (data) =>
{
    if (data != null)
    {
        Console.WriteLine($"Candle >> {data.Symbol} P:{data.Period} OT:{data.OpenTime} O:{data.Open} H:{data.High} L:{data.Low} C:{data.Close} V:{data.Volume}");
    }
});

// Needs Authentication
var sub06 = ws.SubscribeToSpotBalanceAndOrders((data) =>
{
    if (data != null)
    {
        Console.WriteLine($"Balance >> {data.Asset} AB:{data.AvailableBalance} TB:{data.TotalBalance}");
    }
}, (data) =>
{
    if (data != null)
    {
        Console.WriteLine($"Order >> {data.Symbol} OT:{data.OrderType} P:{data.Price} SP:{data.StopPrice}");
    }
});
            
// Needs Authentication
var sub07 = ws.SubscribeToMarginBalanceAndOrders((data) =>
{
    if (data != null)
    {
        Console.WriteLine($"Balance >> {data.Asset} AB:{data.AvailableBalance} TB:{data.TotalBalance}");
    }
}, (data) =>
{
    if (data != null)
    {
        Console.WriteLine($"Order >> {data.Symbol} OT:{data.OrderType} P:{data.Price} SP:{data.StopPrice}");
    }
});

// Unsubscribe
_ = ws.Unsubscribe(sub05.Data);

Cash (Spot) / Margin » Private Feeds

var credentials = new CryptoExchange.Net.Authentication.ApiCredentials("XXXXXXXX-API-KEY-XXXXXXXX", "XXXXXXXX-API-SECRET-XXXXXXXX");
var ws = new BitMaxSocketClient(new BitMaxSocketClientOptions { ApiCredentials = credentials });

var auth = ws.Login();

// Needs Authentication
var sub05 = ws.SubscribeToSpotBalanceAndOrders((data) =>
{
    if (data != null)
    {
        Console.WriteLine($"Balance >> {data.Asset} AB:{data.AvailableBalance} TB:{data.TotalBalance}");
    }
}, (data) =>
{
    if (data != null)
    {
        Console.WriteLine($"Order >> {data.Symbol} OT:{data.OrderType} P:{data.Price} SP:{data.StopPrice}");
    }
});

// Needs Authentication
var sub06 = ws.SubscribeToMarginBalanceAndOrders((data) =>
{
    if (data != null)
    {
        Console.WriteLine($"Balance >> {data.Asset} AB:{data.AvailableBalance} TB:{data.TotalBalance}");
    }
}, (data) =>
{
    if (data != null)
    {
        Console.WriteLine($"Order >> {data.Symbol} OT:{data.OrderType} P:{data.Price} SP:{data.StopPrice}");
    }
});

// Unsubscribe
_ = ws.Unsubscribe(sub05.Data);

Futures » Public Feeds

var ws = new BitMaxSocketClient();

var sub01 = ws.SubscribeToFuturesMarketData("BTC-PERP", (data) =>
{
    if (data != null)
    {
        Console.WriteLine($"Market Data >> {data.Symbol} OI:{data.OpenInterest} FR:{data.FundingRate} FPF:{data.FundingPaymentFlag} IP:{data.IndexPrice} MP:{data.MarkPrice}");
    }
});

Futures » Private Feeds

var credentials = new CryptoExchange.Net.Authentication.ApiCredentials("XXXXXXXX-API-KEY-XXXXXXXX", "XXXXXXXX-API-SECRET-XXXXXXXX");
var ws = new BitMaxSocketClient(new BitMaxSocketClientOptions { ApiCredentials = credentials });

var auth = ws.Login();

// Needs Authentication
ws.SubscribeToFuturesOrders((data) =>
{
    if (data != null)
    {
        Console.WriteLine($"Order Data >> {data.Symbol} OI:{data.OrderId} OT:{data.OrderType} P:{data.Price} AP:{data.AveragePrice}");
    }
});

Release Notes

  • Version 2.5.0 - 18 Sep 2021

    • Synced with CryptoExchange.Net v4.1.0
  • Version 2.1.0 - 31 Mar 2021

    • Updated dependencies
  • Version 2.0.2 - 11 Feb 2021

    • Added SubscribeToSummary method to BitMaxSocketClient
  • Version 2.0.1 - 01 Feb 2021

    • Updated CryptoExchange.Net to 3.6.0
  • Version 2.0.0 - 17 Jan 2021

    • All methods are virtual now. You can customize methods by overriding.
    • Added TatumWalletManager Client
    • Added new TRON endpoints
    • Fixed several minor bugs
  • Version 1.3.2 - 15 Jan 2021

    • Fixed some minor bugs
  • Version 1.2.8 - 12 Jan 2021

    • Updated CryptoExchange.Net to 3.5.0
  • Version 1.1.3 - 10 Jan 2021

    • Fixed some minor bugs
  • Version 1.1.0 - 29 Dec 2020

    • Added Batch Order support
    • Added Futures Rest Api support
    • Added Futures WS Api support
  • Version 1.0.0 - 28 Dec 2020

    • First Release

About

Open Source .Net Wrapper for the @bitmax-exchange Rest Api and Websockets Api

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages