NAV Navbar
C#

Trading API ver. 0.1.3

General information

The base endpoint for REST requests is:
https://api.b2bx.exchange:8443/trading

Public

Supported instruments

GET /frontoffice/api/info

Response:

{
    "serverTime": 636880696809972288,
    "pairs": {
        "btc_usdt": {
            "baseAsset": "btc",
            "quoteAsset": "usdt",
            "minPrice": 0,
            "maxPrice": 0,
            "minAmount": 0,
            "hidden": 0,
            "fee": 0,
            "makerFee": 0,
            "makerFeeLimit": 0,
            "takerFee": 0.001,
            "takerFeeLimit": 0,
            "priceScale": 6,
            "amountScale": 6,
            "createdAt": "2019-11-14T16:18:49.253354",
            "updatedAt": "2019-11-14T16:18:49.253354"
        },
        ...
        "gnt_usdt": {
            "baseAsset": "gnt",
            "quoteAsset": "usdt",
            "minPrice": 0,
            "maxPrice": 0,
            "minAmount": 0,
            "hidden": 0,
            "fee": 0,
            "makerFee": 0,
            "makerFeeLimit": 0,
            "takerFee": 0.001,
            "takerFeeLimit": 0,
            "priceScale": 5,
            "amountScale": 5,
            "createdAt": "2019-11-14T16:18:49.253354",
            "updatedAt": "2019-11-14T16:18:49.253354"
        }
    }
}

Order book snapshot

GET marketdata/instruments/{instrument}/depth

Response:

{
    "instrument": "eth_btc",
    "bids": [
        {
            "amount": 0.3092258,
            "price": 0.01734264
        },
        {
            "amount": 51.61494099,
            "price": 0.01734363
        }...
    ],
    "asks": [
        {
            "amount": 133.52370356,
            "price": 0.01739337
        },
        {
            "amount": 9.16854518,
            "price": 0.01739838
        }...
    ],
    "version": 1891724,
    "askTotalAmount": 1849.11363582,
    "bidTotalAmount": 809.23878372,
    "snapshot": true
}

Real-time order book data

Open connection with public hub:
https://api.b2bx.exchange:8443/trading/marketdata/info
Order book channel name is "Book".

Update:

{
    "type":2,
    "invocationId":"1",
    "item": {
        "instrument": "btc_usd",
        "bids": [
        {
            "amount": 1.3393,
            "price": 8348.98
        },
        ...
        ],
        "asks": [
        {
            "amount": 0.0,
            "price": 8394.84
        },
        ...
        ],
        "version": 367398,
        "askTotalAmount": 115.24421295,
        "bidTotalAmount": 108.16757362,
        "snapshot": false
    }
}

Private API

Notice

Code example:


//keys
var PublicKey = "06879020-2476-49f4-89ef-617004328120" //uuid
var PrivateKey = "ca3a03e1-fc5c-4954-99dc-876db3997d8f"

//generate payload
var orderPayload = new
            {
                Order = new Order(OrderType.Buy, "btc_usdt", 8600, 1), // see above
                ts = DateTime.UtcNow.ToString("s") //
            };
var json = JsonConvert.SerializeObject(orderPayload);
var payloadBytes = ContentEncoding.GetBytes(json);

//hashe payload
var privateKeyBytes = Encoding.UTF8.GetBytes(PrivateKey)
var hmac = new HMACSHA512(privateKeyBytes)
var signedPayload = hmac.ComputeHash(payloadBytes).ToUpperHex();

//add headers and send request
request.Headers.Add("Key", PublicKey.ToString());
request.Headers.Add("Sign", signedPayload);
HttpClient.SendAsync(request);

Place the order

POST /frontoffice/api/order

Headers

Key: 'ca3a03e1-fc5c-4954-99dc-876db3997d8f'
Sign: '61DB64474F54891C434B4AEEBB8D90584E4FE4B597BCE13BB0F8C3E3862ACB0
8658CED4A4AC819BA89FD9B0305935A2D8623D6000441E93C0F1A3899A5B401D0'

Request body:

{
    "ts": "2019-12-12T01:01:01",
    "order":{
        "instrument":"btc_usdt",
        "type":"sell",
        "amount":1,
        "price":1,
        "isLimit":true,
        "isStop":false,
        "activationPrice":0
    }
}

Response:

{
  "order": {
    "orderId": "-72057594037927935",
    "total": 0.0,
    "orderType": 0,
    "commission": 0.0,
    "createdAt": "2019-03-13T12:01:32.8880912Z",
    "unitsFilled": 0.0,
    "isPending": true,
    "status": "Working",
    "type": "sell",
    "amount": 1.0,
    "price": 1.0,
    "isLimit": true,
    "instrument": "btc_usdt"
  }
}

Cancel the order

DELETE /frontoffice/api/orders/{orderId}

The {orderId} is the one that comes with response message generated with Place order request.

Request URL: /frontoffice/api/orders/-72057594037927933?ts=2019-12-12T01:01:01

Headers

Key: 'ca3a03e1-fc5c-4954-99dc-876db3997d8f'
Sign: '61DB64474F54891C434B4AEEBB8D90584E4FE4B597BCE13BB0F8C3E3862ACB0
8658CED4A4AC819BA89FD9B0305935A2D8623D6000441E93C0F1A3899A5B401D0'

Historical orders

GET frontoffice/api/order_history

Possible URL parameters:

Request URL: /frontoffice/api/order_history?market=btc_usdt&ts=2019-12-12T01:01:01

Headers

Key: 'ca3a03e1-fc5c-4954-99dc-876db3997d8f'
Sign: '61DB64474F54891C434B4AEEBB8D90584E4FE4B597BCE13BB0F8C3E3862ACB0
8658CED4A4AC819BA89FD9B0305935A2D8623D6000441E93C0F1A3899A5B401D0'

Respose:

{
  "filters": {},
  "paging": {
    "page": 1,
    "per_page": 15,
    "total": 0
  },
  "data": [
    {
      "orderId": "-72057594037927933",
      "total": 1.0,
      "orderType": 0,
      "commission": 0.0,
      "createdAt": "2019-03-13T08:24:50.578088Z",
      "unitsFilled": 1.0,
      "isPending": false,
      "status": "Completed",
      "type": "sell",
      "amount": 1.0,
      "price": 1.0,
      "isLimit": true,
      "instrument": "btc_usdt"
    },
    ...
    {
      "orderId": "-72057594037927935",
      "total": 0.0,
      "orderType": 0,
      "commission": 0.0,
      "createdAt": "2019-03-13T07:54:06.4232625Z",
      "unitsFilled": 0.0,
      "isPending": false,
      "status": "Cancelled",
      "type": "sell",
      "amount": 1.0,
      "price": 1.0,
      "isLimit": true,
      "instrument": "btc_usdt"
    }
  ]
}

Trading history

GET frontoffice/api/trades_hitory&ts=2019-12-12T01:01:01

Possible URL parameters:

Request URL: /frontoffice/api/ttrade_history?market=btc_usdt

Headers

Key: 'ca3a03e1-fc5c-4954-99dc-876db3997d8f'
Sign: '61DB64474F54891C434B4AEEBB8D90584E4FE4B597BCE13BB0F8C3E3862ACB0
8658CED4A4AC819BA89FD9B0305935A2D8623D6000441E93C0F1A3899A5B401D0'

Response

{
  "filters": {
    "market": "btc_usdt"
  },
  "paging": {
    "page": 1,
    "per_page": 15,
    "total": 0
  },
  "data": [
    {
      "tradeSeq": 0,
      "tradeTime": "2019-12-20T06:17:03.093597",
      "amount": 0.00000001,
      "executionPrice": 0.00000001,
      "instrument": "btc_usdt",
      "side": 0,
      "commission": 0.00000000
    },
    {
      "tradeSeq": 3927,
      "tradeTime": "2019-12-20T06:17:03.093597",
      "amount": 0.00000001,
      "executionPrice": 0.00000001,
      "instrument": "btc_usdt",
      "side": 1,
      "commission": 0.00000000
    }
  ]
}

Real-time balances and orders data

Open connection with private hub:
https://api.b2bx.exchange:8443/trading/ws/account

Open orders channel name is "OpenOrders".
Balance updates channel name is "Balance".

Headers

Key: '06879020-2476-49f4-89ef-617004328120'
Sign: '61DB64474F54891C434B4AEEBB8D90584E4FE4B597BCE13BB0F8C3E3862ACB0
8658CED4A4AC819BA89FD9B0305935A2D8623D6000441E93C0F1A3899A5B401D0'
Payload: '2019-12-12T01:01:01'

How to subscribe on private channel using SignalR:

//keys
var PublicKey = "06879020-2476-49f4-89ef-617004328120" //uuid
var PrivateKey = "ca3a03e1-fc5c-4954-99dc-876db3997d8f"

//generate payload
var payload = DateTime.UtcNow.ToString();
var payloadBytes = ContentEncoding.GetBytes(payload);

//hashe payload
var privateKeyBytes = Encoding.UTF8.GetBytes(PrivateKey)
var hmac = new HMACSHA512(privateKeyBytes)
var hash= hmac.ComputeHash(payloadBytes).ToUpperHex();

//create SignalR HubConnection
var hubConnection = new HubConnectionBuilder()
                   .WithUrl(new Uri(WssEndpoint, "/ws/account"), HttpTransportType.WebSockets,  options =>
                   {
                       options.Headers = new Dictionary<string, string>() {
                                { "Key", PublicKey},
                                { "Sign", hash},
                                { "Payload", payload}
                        };
                   })
                   .Build()

Errors

1. Requests with a time (ts field) different from the current time by more than 5 seconds will be returned with an error -

reject_request = DateTime.UTCNow () - ts >= TimeTpan.FromSeconds(5)

2. No stop orders are supported so far. In response to the request the message will arrive:

500 Internal Server Error

{
  "errors": [
    {
      "code": "unexpected",
      "message": "Stop orders are not supported.",
    }
  ]
}

3. If the system is overloaded you will receive:

503 (Sevice Unavailable)

{
  "errors": [
    {
      "code": "",
      "message": "System is currently overloaded"
    }
  ]
}

API rate limits

/frontoffice/* - 1 req/sec
/marketdata/* - 2 req/sec

Changes

ver. 0.1.2 Retrieve order book snapshot by rest method.
ver. 0.1.3 Changed URL endpoints. Added API rate limits.

C#