Spot Websocket API

Test connectivity to the WebSocket API

ping_connectivity(self, id=None)

Test connectivity to the WebSocket API.

Parameters:

id (str) – request id

Message sent:

{
    "id": "922bcc6e-9de8-440d-9e84-7c80933a8d0d",
    "method": "ping"
}

Response:

{
    "id": "922bcc6e-9de8-440d-9e84-7c80933a8d0d",
    "status": 200,
    "result": {},
    "rateLimits": [{
        "rateLimitType": "REQUEST_WEIGHT",
        "interval": "MINUTE",
        "intervalNum": 1,
        "limit": 1200,
        "count": 1
    }]
}

Note: You can use regular WebSocket ping frames to test connectivity as well, WebSocket API will respond with pong frames as soon as possible.

Check server time

server_time(self, id=None)

Check server time

Parameters:

id (str) – request id

Message sent:

{
    "id": "187d3cb2-942d-484c-8271-4e2141bbadb1",
    "method": "time"
}

Response:

{
    "id": "187d3cb2-942d-484c-8271-4e2141bbadb1",
    "status": 200,
    "result": {
        "serverTime": 1656400526260
    },
    "rateLimits": [{
        "rateLimitType": "REQUEST_WEIGHT",
        "interval": "MINUTE",
        "intervalNum": 1,
        "limit": 1200,
        "count": 1
    }]
}

Test connectivity to the WebSocket API and get the current server time.

Get exchange information

exchange_info(self, **kwargs)

Exchange information

Query current exchange trading rules, rate limits, and symbol information.

Note: For symbol, Upper case is required.

Keyword Arguments:
  • symbols (list) – symbols to get info

  • symbol (str) – symbol to get info

  • permissons (list) – permissions to get info

Message sent:

{
    "id": "5494febb-d167-46a2-996d-70533eb4d976",
    "method": "exchangeInfo",
    "params": {
        "symbols": [
            "BNBBTC"
        ]
    }
}

Response:

{
    "id": "5494febb-d167-46a2-996d-70533eb4d976",
    "status": 200,
    "result": {
    "timezone": "UTC",
    "serverTime": 1655969291181,
    "rateLimits": [{
        "rateLimitType": "REQUEST_WEIGHT",
        "interval": "MINUTE",
        "intervalNum": 1,
        "limit": 1200
    },
    {
        "rateLimitType": "ORDERS",
        "interval": "SECOND",
        "intervalNum": 10,
        "limit": 50
    },
    {
        "rateLimitType": "ORDERS",
        "interval": "DAY",
        "intervalNum": 1,
        "limit": 160000
    },
    {
        "rateLimitType": "RAW_REQUESTS",
        "interval": "MINUTE",
        "intervalNum": 5,
        "limit": 6100
    }],
    "exchangeFilters": [],
    "symbols": [{
        "symbol": "BNBBTC",
        "status": "TRADING",
        "baseAsset": "BNB",
        "baseAssetPrecision": 8,
        "quoteAsset": "BTC",
        "quotePrecision": 8,
        "quoteAssetPrecision": 8,
        "baseCommissionPrecision": 8,
        "quoteCommissionPrecision": 8,
        "orderTypes": [
            "LIMIT",
            "LIMIT_MAKER",
            "MARKET",
            "STOP_LOSS_LIMIT",
            "TAKE_PROFIT_LIMIT"
        ],
        "icebergAllowed": true,
        "ocoAllowed": true,
        "quoteOrderQtyMarketAllowed": true,
        "allowTrailingStop": true,
        "cancelReplaceAllowed": true,
        "isSpotTradingAllowed": true,
        "isMarginTradingAllowed": true,
        "filters": [{
            "filterType": "PRICE_FILTER",
            "minPrice": "0.00000100",
            "maxPrice": "100000.00000000",
            "tickSize": "0.00000100"
        },
        {
            "filterType": "LOT_SIZE",
            "minQty": "0.00100000",
            "maxQty": "100000.00000000",
            "stepSize": "0.00100000"
        }],
        "permissions": [
            "SPOT",
            "MARGIN",
            "TRD_GRP_004"
        ],
        "defaultSelfTradePreventionMode": "NONE",
        "allowedSelfTradePreventionModes": [
            "NONE"
        ]
    }]},
    "rateLimits": [{
        "rateLimitType": "REQUEST_WEIGHT",
        "interval": "MINUTE",
        "intervalNum": 1,
        "limit": 1200,
        "count": 10
    }]
}

Get order book

order_book(self, symbol: str, **kwargs)

Order book

Parameters:

symbol (str) – symbol to get order book

Keyword Arguments:

limit (int) – limit of order book

Message sent:

{
    "id": "5494febb-d167-46a2-996d-70533eb4d976",
    "method": "depth",
    "params": {
        "symbol": "BNBBTC",
        "limit": 10
    }
}

Response:

{
    "id": "5494febb-d167-46a2-996d-70533eb4d976",
    "status": 200,
    "result": {
        "lastUpdateId": 2731179239,
        "bids": [
            [
                "0.01379900",
                "3.43200000"
            ],
            [
                "0.01379800",
                "3.24300000"
            ],
            [
                "0.01379700",
                "10.45500000"
            ],
            [
                "0.01379600",
                "3.82100000"
            ],
            [
                "0.01379500",
                "10.26200000"
            ]
        ],
        "asks": [
            [
                "0.01380000",
                "5.91700000"
            ],
            [
                "0.01380100",
                "6.01400000"
            ],
            [
                "0.01380200",
                "0.26800000"
            ],
            [
                "0.01380300",
                "0.33800000"
            ],
            [
                "0.01380400",
                "0.26800000"
            ]
        ]
    },
    "rateLimits": [
        {
            "rateLimitType": "REQUEST_WEIGHT",
            "interval": "MINUTE",
            "intervalNum": 1,
            "limit": 1200,
            "count": 1
        }
    ]
}

Get historical trades

historical_trades(self, symbol: str, apiKey: str, **kwargs)

Historical trades

Parameters:

symbol (str) – symbol to get historical trades

Keyword Arguments:
  • symbol (str) – symbol to get historical trades

  • fromId (int) – trade id to fetch from

  • limit (int) – limit of historical trades

Message sent:

{
    "id": "5494febb-d167-46a2-996d-70533eb4d976",
    "method": "trades.historical",
    "params": {
        "symbol": "BNBBTC",
        "apiKey": "vmPUZE6mv9SD5VNHk4HlWFsOr6aKE2zvsw0MuIgwCIPy6utIco14y7Ju91duEh8A",
        "fromId": 0,
        "limit": 1
    }
}

Response:

{
    "id": "5494febb-d167-46a2-996d-70533eb4d976",
    "status": 200,
    "result": [
        {
            "id": 0,
            "price": "0.01361000",
            "qty": "0.01400000",
            "quoteQty": "0.00019054",
            "time": 1660009530807,
            "isBuyerMaker": true,
            "isBestMatch": true
        }
    ],
    "rateLimits": [
        {
            "rateLimitType": "REQUEST_WEIGHT",
            "interval": "MINUTE",
            "intervalNum": 1,
            "limit": 1200,
            "count": 1
        }
    ]
}

Get compressed, aggregate trades

aggregate_trades(self, symbol: str, **kwargs)

Aggregate trades

Parameters:

symbol (str) – symbol to get aggregate trades

Keyword Arguments:
  • symbol (str) – symbol to get aggregate trades

  • fromId (int) – trade id to fetch from

  • limit (int) – limit of aggregate trades

  • startTime (int) – start time to fetch from

  • endTime (int) – end time to fetch from

Message sent:

{
    "id": "5494febb-d167-46a2-996d-70533eb4d976",
    "method": "trades.aggregate",
    "params": {
        "symbol": "BNBBTC",
        "fromId": 0,
        "limit": 1
    }
}

Response:

{
    "id": "5494febb-d167-46a2-996d-70533eb4d976",
    "status": 200,
    "result": [
        {
            "a": 0,
            "p": "0.01361000",
            "q": "0.01400000",
            "f": 0,
            "l": 0,
            "T": 1660009530807,
            "m": true,
            "M": true
        }
    ],
    "rateLimits": [
        {
            "rateLimitType": "REQUEST_WEIGHT",
            "interval": "MINUTE",
            "intervalNum": 1,
            "limit": 1200,
            "count": 1
        }
    ]
}

klines

klines(self, symbol: str, interval: str, **kwargs)

Klines/candlesticks

Parameters:
  • symbol (str) – symbol to get klines

  • interval (str) – interval of klines

Keyword Arguments:
  • startTime (int) – start time to fetch from

  • endTime (int) – end time to fetch from

  • timeZone (str, optional) – Default: 0 (UTC)

  • limit (int) – limit of klines

Message sent:

{
    "id": "5494febb-d167-46a2-996d-70533eb4d976",
    "method": "klines",
    "params": {
        "symbol": "BNBBTC",
        "interval": "1m",
        "startTime": 1655969280000,
        "limit": 1
    }
}

Response:

{
    "id": "5494febb-d167-46a2-996d-70533eb4d976",
    "status": 200,
    "result": [
        [
            1660009530807,
            "0.01361000",
            "0.01361000",
            "0.01361000",
            "0.01361000",
            "0.01400000",
            1660009530807,
            "0.00019054",
            0,
            "0.00000000",
            "0.00000000",
            "0"
        ]
    ],
    "rateLimits": [
        {
            "rateLimitType": "REQUEST_WEIGHT",
            "interval": "MINUTE",
            "intervalNum": 1,
            "limit": 1200,
            "count": 1
        }
    ]
}

Klines/candlesticks for UI

ui_klines(self, symbol: str, interval: str, **kwargs)

Klines/candlesticks for UI

Parameters:
  • symbol (str) – symbol to get klines

  • interval (str) – interval of klines

Keyword Arguments:
  • startTime (int) – start time to fetch from

  • endTime (int) – end time to fetch from

  • timeZone (str, optional) – Default: 0 (UTC)

  • limit (int) – limit of klines

Message sent:

{
    "id": "5494febb-d167-46a2-996d-70533eb4d976",
    "method": "uiKlines",
    "params": {
        "symbol": "BNBBTC",
        "interval": "1m",
        "startTime": 1655969280000,
        "limit": 1
    }
}

Response:

{
    "id": "5494febb-d167-46a2-996d-70533eb4d976",
    "status": 200,
    "result": [
        [
            1660009530807,
            "0.01361000",
            "0.01361000",
            "0.01361000",
            "0.01361000",
            "0.01400000",
            1660009530807,
            "0.00019054",
            0,
            "0.00000000",
            "0.00000000",
            "0"
        ]
    ],
    "rateLimits": [
        {
            "rateLimitType": "REQUEST_WEIGHT",
            "interval": "MINUTE",
            "intervalNum": 1,
            "limit": 1200,
            "count": 1
        }
    ]
}

Current average price for a symbol

avg_price(self, symbol: str, **kwargs)

Current average price for a symbol

Parameters:

symbol (str) – symbol to get average price

Message sent:

{
    "id": "5494febb-d167-46a2-996d-70533eb4d976",
    "method": "avgPrice",
    "params": {
        "symbol": "BNBBTC"
    }
}

Response:

{
    "id": "5494febb-d167-46a2-996d-70533eb4d976",
    "status": 200,
    "result": {
        "mins": 5,
        "price": "0.01361000"
    },
    "rateLimits": [
        {
            "rateLimitType": "REQUEST_WEIGHT",
            "interval": "MINUTE",
            "intervalNum": 1,
            "limit": 1200,
            "count": 1
        }
    ]
}

24hr ticker price change statistics

ticker_24hr(self, **kwargs)

24 hour rolling window price change statistics

Keyword Arguments:
  • symbol (str) – symbol to get ticker 24hr

  • symbols (list) – symbols to get ticker 24hr

  • type (str) – type of ticker 24hr

Message sent:

{
    "id": "5494febb-d167-46a2-996d-70533eb4d976",
    "method": "ticker.24hr",
    "params": {
        "symbol": "BNBBTC"
    }
}

Response:

{
    "id": "5494febb-d167-46a2-996d-70533eb4d976",
    "status": 200,
    "result": {
        "symbol": "BNBBTC",
        "priceChange": "-94.99999800",
        "priceChangePercent": "-95.960",
        "weightedAvgPrice": "0.29628482",
        "prevClosePrice": "0.10002000",
        "lastPrice": "4.00000200",
        "lastQty": "200.00000000",
        "bidPrice": "4.00000000",
        "bidQty": "10.00000000",
        "askPrice": "4.00000200",
        "askQty": "10.00000000",
        "openPrice": "99.00000000",
        "highPrice": "100.00000000",
        "lowPrice": "0.10000000",
        "volume": "8913.30000000",
        "quoteVolume": "15.30000000",
        "openTime": 1499783499040,
        "closeTime": 1499869899040,
        "firstId": 28385,
        "lastId": 28460,
        "count": 76
    },
    "rateLimits": [
        {
            "rateLimitType": "REQUEST_WEIGHT",
            "interval": "MINUTE",
            "intervalNum": 1,
            "limit": 1200,
            "count": 1
        }
    ]
}

Rolling window price change statistics

ticker(self, **kwargs)

Rolling window price change statistics

Keyword Arguments:
  • symbol (str) – symbol to get ticker

  • symbols (list) – symbols to get ticker

  • type (str) – type of ticker

  • windowSize (str) – window size of ticker

Message sent:

{
    "id": "f4b3b507-c8f2-442a-81a6-b2f12daa030f",
    "method": "ticker",
    "params": {
        "symbols": [
            "BNBBTC",
            "BTCUSDT"
        ],
        "windowSize": "7d"
    }
}

Response

{
    "id": "f4b3b507-c8f2-442a-81a6-b2f12daa030f",
    "status": 200,
    "result": {
        "symbol": "BNBBTC",
        "priceChange": "0.00061500",
        "priceChangePercent": "4.735",
        "weightedAvgPrice": "0.01368242",
        "openPrice": "0.01298900",
        "highPrice": "0.01418800",
        "lowPrice": "0.01296000",
        "lastPrice": "0.01360400",
        "volume": "587179.23900000",
        "quoteVolume": "8034.03382165",
        "openTime": 1659580020000,
        "closeTime": 1660184865291,
        "firstId": 192977765,
        "lastId": 195365758,
        "count": 2387994
    },
    "rateLimits": [
        {
            "rateLimitType": "REQUEST_WEIGHT",
            "interval": "MINUTE",
            "intervalNum": 1,
            "limit": 1200,
            "count": 2
        }
    ]
}

Symbol price ticker

ticker_price(self, **kwargs)

Symbol price ticker

Keyword Arguments:
  • symbol (str) – symbol to get ticker price

  • symbols (list) – symbols to get ticker price

Message sent:

{
    "id": "5494febb-d167-46a2-996d-70533eb4d976",
    "method": "ticker.price",
    "params": {
        "symbol": "BNBBTC"
    }
}

Response:

{
    "id": "5494febb-d167-46a2-996d-70533eb4d976",
    "status": 200,
    "result": {
        "symbol": "BNBBTC",
        "price": "4.00000200"
    },
    "rateLimits": [
        {
            "rateLimitType": "REQUEST_WEIGHT",
            "interval": "MINUTE",
            "intervalNum": 1,
            "limit": 1200,
            "count": 1
        }
    ]
}

Symbol order book ticker

ticker_book(self, **kwargs)

Symbol order book ticker

Keyword Arguments:
  • symbol (str) – symbol to get ticker book

  • symbols (list) – symbols to get ticker book

Message sent:

{
    "id": "5494febb-d167-46a2-996d-70533eb4d976",
    "method": "ticker.book",
    "params": {
        "symbol": "BNBBTC"
    }
}

Response:

{
    "id": "5494febb-d167-46a2-996d-70533eb4d976",
    "status": 200,
    "result": {
        "symbol": "BNBBTC",
        "bidPrice": "4.00000000",
        "bidQty": "431.00000000",
        "askPrice": "4.00000200",
        "askQty": "9.00000000"
    },
    "rateLimits": [
        {
            "rateLimitType": "REQUEST_WEIGHT",
            "interval": "MINUTE",
            "intervalNum": 1,
            "limit": 1200,
            "count": 1
        }
    ]
}

Account information

account(self, **kwargs)

Account information (USER_DATA)

Keyword Arguments:
  • id (str, optional) – Client generated ID.

  • recvWindow (int, optional) – The value cannot be greater than 60000

Message sent:

{
    "id": "605a6d20-6588-4cb9-afa0-b0ab087507ba",
    "method": "account.status",
    "params": {
        "apiKey": "vmPUZE6mv9SD5VNHk4HlWFsOr6aKE2zvsw0MuIgwCIPy6utIco14y7Ju91duEh8A",
        "signature": "83303b4a136ac1371795f465808367242685a9e3a42b22edb4d977d0696eb45c",
        "timestamp": 1660801839480
    }
}

Response:

{
    "id": "605a6d20-6588-4cb9-afa0-b0ab087507ba",
    "status": 200,
    "result": {
        "makerCommission": 15,
        "takerCommission": 15,
        "buyerCommission": 0,
        "sellerCommission": 0,
        "canTrade": true,
        "canWithdraw": true,
        "canDeposit": true,
        "commissionRates": {
            "maker": "0.00150000",
            "taker": "0.00150000",
            "buyer": "0.00000000",
            "seller":"0.00000000"
        },
        "brokered": false,
        "requireSelfTradePrevention": false,
        "updateTime": 1660801833000,
        "accountType": "SPOT",
        "balances": [
            {
                "asset": "BNB",
                "free": "0.00000000",
                "locked": "0.00000000"
            },
            {
                "asset": "BTC",
                "free": "1.3447112",
                "locked": "0.08600000"
            },
            {
                "asset": "USDT",
                "free": "1021.21000000",
                "locked": "0.00000000"
            }
        ],
        "permissions": [
            "SPOT"
        ]
    },
    "rateLimits": [
        {
            "rateLimitType": "REQUEST_WEIGHT",
            "interval": "MINUTE",
            "intervalNum": 1,
            "limit": 1200,
            "count": 10
        }
    ]
}

Account order rate limits

order_rate_limit(self, **kwargs)

Account order rate limits (USER_DATA)

Keyword Arguments:
  • id (str, optional) – Client generated ID.

  • recvWindow (int, optional) – The value cannot be greater than 60000

Message sent:

{
    "id": "d3783d8d-f8d1-4d2c-b8a0-b7596af5a664",
    "method": "account.rateLimits.orders",
    "params": {
        "apiKey": "vmPUZE6mv9SD5VNHk4HlWFsOr6aKE2zvsw0MuIgwCIPy6utIco14y7Ju91duEh8A",
        "signature": "76289424d6e288f4dc47d167ac824e859dabf78736f4348abbbac848d719eb94",
        "timestamp": 1660801839500
    }
}

Response:

{
    "id": "d3783d8d-f8d1-4d2c-b8a0-b7596af5a664",
    "status": 200,
    "result": [{
        "rateLimitType": "ORDERS",
        "interval": "SECOND",
        "intervalNum": 1,
        "limit": 200
    },
    {
        "rateLimitType": "ORDERS",
        "interval": "DAY",
        "intervalNum": 1,
        "limit": 100000
    }],
    "rateLimits": [{
        "rateLimitType": "REQUEST_WEIGHT",
        "interval": "MINUTE",
        "intervalNum": 1,
        "limit": 1200,
        "count": 10
    }]
}

Account order history

order_history(self, **kwargs)

Account order history (USER_DATA)

Keyword Arguments:
  • id (str, optional) – Client generated ID.

  • symbol (str, optional) – Symbol

  • orderId (int, optional) – Order ID

  • startTime (int, optional) – Timestamp in ms

  • endTime (int, optional) – Timestamp in ms

  • limit (int, optional) – Default 500; max 1000.

  • recvWindow (int, optional) – The value cannot be greater than 60000

Message sent:

{
    "id": "734235c2-13d2-4574-be68-723e818c08f3",
    "method": "allOrders",
    "params": {
        "symbol": "BTCUSDT",
        "startTime": 1660780800000,
        "endTime": 1660867200000,
        "limit": 5,
        "apiKey": "vmPUZE6mv9SD5VNHk4HlWFsOr6aKE2zvsw0MuIgwCIPy6utIco14y7Ju91duEh8A",
        "signature": "f50a972ba7fad92842187643f6b930802d4e20bce1ba1e788e856e811577bd42",
        "timestamp": 1661955123341
    }
}

Response

{
    "id": "734235c2-13d2-4574-be68-723e818c08f3",
    "status": 200,
    "result": [{
        "symbol": "BTCUSDT",
        "orderId": 12569099453,
        "orderListId": -1,
        "clientOrderId": "4d96324ff9d44481926157",
        "price": "23416.10000000",
        "origQty": "0.00847000",
        "executedQty": "0.00847000",
        "cummulativeQuoteQty": "198.33521500",
        "status": "FILLED",
        "timeInForce": "GTC",
        "type": "LIMIT",
        "side": "SELL",
        "stopPrice": "0.00000000",
        "icebergQty": "0.00000000",
        "time": 1660801715639,
        "updateTime": 1660801717945,
        "isWorking": true,
        "workingTime": 1660801715639,
        "origQuoteOrderQty": "0.00000000",
        "selfTradePreventionMode": "NONE",
        "preventedMatchId": 0,
        "preventedQuantity": "1.200000"
        }],
    "rateLimits": [{
        "rateLimitType": "REQUEST_WEIGHT",
        "interval": "MINUTE",
        "intervalNum": 1,
        "limit": 1200,
        "count": 10
    }]
}

Account OCO history

oco_history(self, **kwargs)

Account OCO history (USER_DATA)

Keyword Arguments:
  • id (str, optional) – Client generated ID.

  • fromId (int, optional) – OCO ID

  • startTime (int, optional) – Timestamp in ms

  • endTime (int, optional) – Timestamp in ms

  • limit (int, optional) – Default 500; max 1000.

  • recvWindow (int, optional) – The value cannot be greater than 60000

Message sent:

{
    "id": "8617b7b3-1b3d-4dec-94cd-eefd929b8ceb",
    "method": "allOrderLists",
    "params": {
        "startTime": 1660780800000,
        "endTime": 1660867200000,
        "limit": 5,
        "apiKey": "vmPUZE6mv9SD5VNHk4HlWFsOr6aKE2zvsw0MuIgwCIPy6utIco14y7Ju91duEh8A",
        "signature": "c8e1484db4a4a02d0e84dfa627eb9b8298f07ebf12fcc4eaf86e4a565b2712c2",
        "timestamp": 1661955123341
    }
}

Response

{
    "id": "8617b7b3-1b3d-4dec-94cd-eefd929b8ceb",
    "status": 200,
    "result": [{
        "orderListId": 1274512,
        "contingencyType": "OCO",
        "listStatusType": "EXEC_STARTED",
        "listOrderStatus": "EXECUTING",
        "listClientOrderId": "08985fedd9ea2cf6b28996",
        "transactionTime": 1660801713793,
        "symbol": "BTCUSDT",
        "orders": [{
            "symbol": "BTCUSDT",
            "orderId": 12569138901,
            "clientOrderId": "BqtFCj5odMoWtSqGk2X9tU"
        },
        {
            "symbol": "BTCUSDT",
            "orderId": 12569138902,
            "clientOrderId": "jLnZpj5enfMXTuhKB1d0us"
        }]
    }],
    "rateLimits": [{
        "rateLimitType": "REQUEST_WEIGHT",
        "interval": "MINUTE",
        "intervalNum": 1,
        "limit": 1200,
        "count": 10
    }]
}

Account trade history

my_trades(self, **kwargs)

Account trade history (USER_DATA)

Keyword Arguments:
  • id (str, optional) – Client generated ID.

  • symbol (str, optional) – Symbol

  • orderId (int, optional) – order id

  • startTime (int, optional) – Timestamp in ms

  • endTime (int, optional) – Timestamp in ms

  • fromId (int, optional) – Trade id to fetch from. Default gets most recent trades.

  • limit (int, optional) – Default 500; max 1000.

  • recvWindow (int, optional) – The value cannot be greater than 60000

Message sent:

{
    "id": "f4ce6a53-a29d-4f70-823b-4ab59391d6e8",
    "method": "myTrades",
    "params": {
        "symbol": "BTCUSDT",
        "startTime": 1660780800000,
        "endTime": 1660867200000,
        "apiKey": "vmPUZE6mv9SD5VNHk4HlWFsOr6aKE2zvsw0MuIgwCIPy6utIco14y7Ju91duEh8A",
        "signature": "c5a5ffb79fd4f2e10a92f895d488943a57954edf5933bde3338dfb6ea6d6eefc",
        "timestamp": 1661955125250
    }
}

Response:

{
    "id": "f4ce6a53-a29d-4f70-823b-4ab59391d6e8",
    "status": 200,
    "result": [
        {
            "symbol": "BTCUSDT",
            "id": 12569138901,
            "orderId": 12569138901,
            "price": "0.00000000",
            "qty": "0.00000000",
            "commission": "0.00000000",
            "commissionAsset": "BTC",
            "time": 1660801715639,
            "isBuyer": true,
            "isMaker": false,
            "isBestMatch": true
        }
    ],
    "rateLimits": [{
        "rateLimitType": "REQUEST_WEIGHT",
        "interval": "MINUTE",
        "intervalNum": 1,
        "limit": 1200,
        "count": 10
    }]
}

Account prevented matches

prevented_matches(self, symbol: str, **kwargs)

Account prevented matches (USER_DATA)

Keyword Arguments:
  • id (str, optional) – Client generated ID.

  • symbol (str, optional) – Symbol

  • preventedMatchId (int, optional) – Prevented match id

  • orderId (int, optional) – order id

  • fromPrevMatchId (int, optional) – Prevented match id to fetch from.

  • limit (int, optional) – Default 500; max 1000.

  • recvWindow (int, optional) – The value cannot be greater than 60000

Combinations supported::
  • symbol + preventedMatchId

  • symbol + orderId

  • symbol + orderId + fromPreventedMatchId (limit will default to 500)

  • symbol + orderId + fromPreventedMatchId + limit

Message sent:

{
    "id": "g4ce6a53-a39d-4f71-823b-4ab5r391d6y8",
    "method": "myPreventedMatches",
    "params": {
        "symbol": "BTCUSDT",
        "orderId": 35,
        "apiKey": "vmPUZE6mv9SD5VNHk4HlWFsOr6aKE2zvsw0MuIgwCIPy6utIco14y7Ju91duEh8A",
        "signature": "c5a5ffb79fd4f2e10a92f895d488943a57954edf5933bde3338dfb6ea6d6eefc",
        "timestamp": 1673923281052
    }
}

Response

{
    "id": "g4ce6a53-a39d-4f71-823b-4ab5r391d6y8",
    "status": 200,
    "result": [{
        "symbol": "BTCUSDT",
        "preventedMatchId": 1,
        "takerOrderId": 5,
        "makerOrderId": 3,
        "tradeGroupId": 1,
        "selfTradePreventionMode": "EXPIRE_MAKER",
        "price": "1.100000",
        "makerPreventedQuantity": "1.300000",
        "transactTime": 1669101687094
    }],
    "rateLimits": [{
        "rateLimitType": "REQUEST_WEIGHT",
        "interval": "MINUTE",
        "intervalNum": 1,
        "limit": 1200,
        "count": 10
    }]
}

Create a new order

new_order(self, symbol: str, side: str, type: str, **kwargs)

Create a new order.

Parameters:
  • symbol (str) – Symbol to trade.

  • side (str) – Side of the trade.

  • type (str) – Type of the trade.

Keyword Arguments:
  • timeInForce (str) – Time in force.

  • quantity (float) – Quantity of the trade.

  • quoteOrderQty (float) – Quote order quantity.

  • price (float) – Price of the trade.

  • newClientOrderId (str) – New client order id.

  • stopPrice (float) – Stop price.

  • trailingDelta (int) – Trailing delta.

  • icebergQty (float) – Iceberg quantity.

  • strategyId (int) – Strategy id.

  • strategyType (int) – Strategy type.

  • selfTradePreventionMode (str) – Self trade prevention.

  • newOrderRespType (str) – New order response type.

  • recvWindow (int) – Recv window.

Message sent:

{
    "id": "56374a46-3061-486b-a311-99ee972eb648",
    "method": "order.place",
    "params": {
        "symbol": "BTCUSDT",
        "side": "SELL",
        "type": "LIMIT",
        "timeInForce": "GTC",
        "price": "23416.10000000",
        "quantity": "0.00847000",
        "apiKey": "vmPUZE6mv9SD5VNHk4HlWFsOr6aKE2zvsw0MuIgwCIPy6utIco14y7Ju91duEh8A",
        "signature": "15af09e41c36f3cc61378c2fbe2c33719a03dd5eba8d0f9206fbda44de717c88",
        "timestamp": 1660801715431
    }
}

Response

{
    "id": "56374a46-3061-486b-a311-99ee972eb648",
    "status": 200,
    "result": {
        "symbol": "BTCUSDT",
        "orderId": 12569099453,
        "orderListId": -1,
        "clientOrderId": "4d96324ff9d44481926157ec08158a40",
        "transactTime": 1660801715639
    },
    "rateLimits": [
        {
            "rateLimitType": "ORDERS",
            "interval": "SECOND",
            "intervalNum": 10,
            "limit": 50,
            "count": 1
        },
        {
            "rateLimitType": "ORDERS",
            "interval": "DAY",
            "intervalNum": 1,
            "limit": 160000,
            "count": 1
        },
        {
            "rateLimitType": "REQUEST_WEIGHT",
            "interval": "MINUTE",
            "intervalNum": 1,
            "limit": 1200,
            "count": 1
        }
    ]
}

Test new order

new_order_test(self, symbol: str, side: str, type: str, **kwargs)

Test new order (TRADE)

Parameters:
  • symbol (str) – Symbol to trade.

  • side (str) – Side of the trade.

  • type (str) – Type of the trade.

Keyword Arguments:
  • timeInForce (str) – Time in force.

  • quantity (float) – Quantity of the trade.

  • quoteOrderQty (float) – Quote order quantity.

  • price (float) – Price of the trade.

  • newClientOrderId (str) – New client order id.

  • stopPrice (float) – Stop price.

  • trailingDelta (int) – Trailing delta.

  • icebergQty (float) – Iceberg quantity.

  • strategyId (int) – Strategy id.

  • strategyType (int) – Strategy type.

  • selfTradePreventionMode (str) – Self trade prevention.

  • newOrderRespType (str) – New order response type.

  • recvWindow (int) – Recv window.

Message sent:

{
    "id": "56374a46-3061-486b-a311-99ee972eb648",
    "method": "order.test",
    "params": {
        "symbol": "BTCUSDT",
        "side": "SELL",
        "type": "LIMIT",
        "timeInForce": "GTC",
        "price": "23416.10000000",
        "quantity": "0.00847000",
        "apiKey": "vmPUZE6mv9SD5VNHk4HlWFsOr6aKE2zvsw0MuIgwCIPy6utIco14y7Ju91duEh8A",
        "signature": "15af09e41c36f3cc61378c2fbe2c33719a03dd5eba8d0f9206fbda44de717c88",
        "timestamp": 1660801715431
    }
}

Response

{
    "id": "6ffebe91-01d9-43ac-be99-57cf062e0e30",
    "status": 200,
    "result": {},
    "rateLimits": [
        {
            "rateLimitType": "REQUEST_WEIGHT",
            "interval": "MINUTE",
            "intervalNum": 1,
            "limit": 1200,
            "count": 1
        }
    ]
}

Get order

get_order(self, symbol: str, **kwargs)

Get order (USER_DATA)

Parameters:

symbol (str) – Symbol to trade.

Keyword Arguments:
  • orderId (int) – Order id.

  • origClientOrderId (str) – Original client order id.

  • recvWindow (int) – Recv window.

Message sent:

{
    "id": "aa62318a-5a97-4f3b-bdc7-640bbe33b291",
    "method": "order.status",
    "params": {
        "symbol": "BTCUSDT",
        "orderId": 12569099453,
        "apiKey": "vmPUZE6mv9SD5VNHk4HlWFsOr6aKE2zvsw0MuIgwCIPy6utIco14y7Ju91duEh8A",
        "signature": "2c3aab5a078ee4ea465ecd95523b77289f61476c2f238ec10c55ea6cb11a6f35",
        "timestamp": 1660801720951
    }
}

Response:

{
    "id": "aa62318a-5a97-4f3b-bdc7-640bbe33b291",
    "status": 200,
    "result": {
        "symbol": "BTCUSDT",
        "orderId": 12569099453,
        "orderListId": -1,
        "clientOrderId": "4d96324ff9d44481926157",
        "price": "23416.10000000",
        "origQty": "0.00847000",
        "executedQty": "0.00847000",
        "cummulativeQuoteQty": "198.33521500",
        "status": "FILLED",
        "timeInForce": "GTC",
        "type": "LIMIT",
        "side": "SELL",
        "stopPrice": "0.00000000",
        "trailingDelta": 10,
        "trailingTime": -1,
        "icebergQty": "0.00000000",
        "time": 1660801715639,
        "updateTime": 1660801717945,
        "isWorking": true,
        "workingTime": 1660801715639,
        "origQuoteOrderQty": "0.00000000",
        "strategyId": 37463720,
        "strategyType": 1000000,
        "selfTradePreventionMode": "NONE",
        "preventedMatchId": 0,
        "preventedQuantity": "1.200000"
    },
    "rateLimits": [
        {
            "rateLimitType": "REQUEST_WEIGHT",
            "interval": "MINUTE",
            "intervalNum": 1,
            "limit": 1200,
            "count": 2
        }
    ]
}

Cancel order

cancel_order(self, symbol: str, **kwargs)
Cancel order (USER_DATA)
Args:

symbol (str): Symbol to trade.

Keyword Args:

orderId (int): Order id. origClientOrderId (str): Original client order id. newClientOrderId (str): New client order id. recvWindow (int): Recv window.

Message sent:

{
    "id": "5633b6a2-90a9-4192-83e7-925c90b6a2fd",
    "method": "order.cancel",
    "params": {
        "symbol": "BTCUSDT",
        "origClientOrderId": "4d96324ff9d44481926157",
        "apiKey": "vmPUZE6mv9SD5VNHk4HlWFsOr6aKE2zvsw0MuIgwCIPy6utIco14y7Ju91duEh8A",
        "signature": "33d5b721f278ae17a52f004a82a6f68a70c68e7dd6776ed0be77a455ab855282",
        "timestamp": 1660801715830
    }
}

Response:

{
    "id": "5633b6a2-90a9-4192-83e7-925c90b6a2fd",
    "status": 200,
    "result": {
        "symbol": "BTCUSDT",
        "origClientOrderId": "4d96324ff9d44481926157",
        "orderId": 12569099453,
        "orderListId": -1,
        "clientOrderId": "91fe37ce9e69c90d6358c0",
        "price": "23416.10000000",
        "origQty": "0.00847000",
        "executedQty": "0.00001000",
        "cummulativeQuoteQty": "0.23416100",
        "status": "CANCELED",
        "timeInForce": "GTC",
        "type": "LIMIT",
        "side": "SELL",
        "stopPrice": "0.00000000",
        "trailingDelta": 0,
        "trailingTime": -1,
        "icebergQty": "0.00000000",
        "strategyId": 37463720,
        "strategyType": 1000000,
        "selfTradePreventionMode": "NONE"
    },
    "rateLimits": [
        {
            "rateLimitType": "REQUEST_WEIGHT",
            "interval": "MINUTE",
            "intervalNum": 1,
            "limit": 1200,
            "count": 1
        }
    ]
}

Cancel and replace order

cancel_replace_order(self, symbol: str, cancelReplaceMode: str, side: str, type: str, **kwargs)

Cancel and replace order :param symbol: Symbol to trade. :type symbol: str :param cancelReplaceMode: :type cancelReplaceMode: str :param side: SIDE :type side: str :param type: ORDER_TYPE :type type: str

Keyword Arguments:
  • cancelOrderId (int) – Cancel order by orderId

  • cancelOrigClientOrderId (int) – Cancel order by clientOrderId.

  • cancelNewClientOrderId (str) – New ID for the canceled order. Automatically generated if not sent

  • timeInForce (str) – Time in force.

  • price (float) – Price.

  • quantity (float) – Quantity.

  • quoteOrderQty (float) – Quote order quantity.

  • newClientOrderId (str) – New client order id.

  • newOrderRespType (str) – New order response type.

  • stopPrice (float) – Stop price.

  • trailingDelta (float) – Trailing delta.

  • icebergQty (float) – Iceberg quantity.

  • strategyId (int) – Strategy id.

  • strategyType (int) – Strategy type.

  • selfTradePreventionMode (str) – Self trade prevention mode.

  • recvWindow (int) – Recv window.

Message Sent:

{
    "id": "99de1036-b5e2-4e0f-9b5c-13d751c93a1a",
    "method": "order.cancelReplace",
    "params": {
        "symbol": "BTCUSDT",
        "cancelReplaceMode": "ALLOW_FAILURE",
        "cancelOrigClientOrderId": "4d96324ff9d44481926157",
        "side": "SELL",
        "type": "LIMIT",
        "timeInForce": "GTC",
        "price": "23416.10000000",
        "quantity": "0.00847000",
        "apiKey": "vmPUZE6mv9SD5VNHk4HlWFsOr6aKE2zvsw0MuIgwCIPy6utIco14y7Ju91duEh8A",
        "signature": "7028fdc187868754d25e42c37ccfa5ba2bab1d180ad55d4c3a7e2de643943dc5",
        "timestamp": 1660813156900
    }
}

Response:

{
    "id": "b220edfe-f3c4-4a3a-9d13-b35473783a25",
    "status": 409,
    "error": {
        "code": -2021,
        "msg": "Order cancel-replace partially failed.",
        "data": {
        "cancelResult": "SUCCESS",
        "newOrderResult": "FAILURE",
        "cancelResponse": {
            "symbol": "BTCUSDT",
            "origClientOrderId": "4d96324ff9d44481926157",
            "orderId": 125690984230,
            "orderListId": -1,
            "clientOrderId": "91fe37ce9e69c90d6358c0",
            "price": "23450.00000000",
            "origQty": "0.00847000",
            "executedQty": "0.00001000",
            "cummulativeQuoteQty": "0.23450000",
            "status": "CANCELED",
            "timeInForce": "GTC",
            "type": "LIMIT",
            "side": "SELL",
            "selfTradePreventionMode": "NONE"
        },
        "newOrderResponse": {
            "code": -2010,
            "msg": "Order would immediately match and take."
        }
        }
    },
    "rateLimits": [
        {
            "rateLimitType": "ORDERS",
            "interval": "SECOND",
            "intervalNum": 10,
            "limit": 50,
            "count": 1
        },
        {
            "rateLimitType": "ORDERS",
            "interval": "DAY",
            "intervalNum": 1,
            "limit": 160000,
            "count": 1
        },
        {
            "rateLimitType": "REQUEST_WEIGHT",
            "interval": "MINUTE",
            "intervalNum": 1,
            "limit": 1200,
            "count": 1
        }
    ]
}

{
    "id": "ce641763-ff74-41ac-b9f7-db7cbe5e93b1",
    "status": 409,
    "error": {
        "code": -2021,
        "msg": "Order cancel-replace partially failed.",
        "data": {
        "cancelResult": "FAILURE",
        "newOrderResult": "SUCCESS",
        "cancelResponse": {
            "code": -2011,
            "msg": "Unknown order sent."
        },
        "newOrderResponse": {
            "symbol": "BTCUSDT",
            "orderId": 12569099453,
            "orderListId": -1,
            "clientOrderId": "bX5wROblo6YeDwa9iTLeyY",
            "transactTime": 1660813156959,
            "price": "23416.10000000",
            "origQty": "0.00847000",
            "executedQty": "0.00000000",
            "cummulativeQuoteQty": "0.00000000",
            "status": "NEW",
            "timeInForce": "GTC",
            "type": "LIMIT",
            "side": "SELL",
            "workingTime": 1669693344508,
            "fills": [],
            "selfTradePreventionMode": "NONE"
        }
        }
    },
    "rateLimits": [
        {
            "rateLimitType": "ORDERS",
            "interval": "SECOND",
            "intervalNum": 10,
            "limit": 50,
            "count": 1
        },
        {
            "rateLimitType": "ORDERS",
            "interval": "DAY",
            "intervalNum": 1,
            "limit": 160000,
            "count": 1
        },
        {
            "rateLimitType": "REQUEST_WEIGHT",
            "interval": "MINUTE",
            "intervalNum": 1,
            "limit": 1200,
            "count": 1
        }
    ]
}

Current open orders

get_open_orders(self, **kwargs)

Current open orders (USER_DATA)

Keyword Arguments:
  • symbol (str) – Symbol.

  • recvWindow (int) – Recv window.

Message Sent:

{
    "id": "55f07876-4f6f-4c47-87dc-43e5fff3f2e7",
    "method": "openOrders.status",
    "params": {
        "symbol": "BTCUSDT",
        "apiKey": "vmPUZE6mv9SD5VNHk4HlWFsOr6aKE2zvsw0MuIgwCIPy6utIco14y7Ju91duEh8A",
        "signature": "d632b3fdb8a81dd44f82c7c901833309dd714fe508772a89b0a35b0ee0c48b89",
        "timestamp": 1660813156812
    }
}

Response:

{
    "id": "55f07876-4f6f-4c47-87dc-43e5fff3f2e7",
    "status": 200,
    "result": [
        {
            "symbol": "BTCUSDT",
            "orderId": 12569099453,
            "orderListId": -1,
            "clientOrderId": "4d96324ff9d44481926157",
            "price": "23416.10000000",
            "origQty": "0.00847000",
            "executedQty": "0.00720000",
            "cummulativeQuoteQty": "172.43931000",
            "status": "PARTIALLY_FILLED",
            "timeInForce": "GTC",
            "type": "LIMIT",
            "side": "SELL",
            "stopPrice": "0.00000000",
            "icebergQty": "0.00000000",
            "time": 1660801715639,
            "updateTime": 1660801717945,
            "isWorking": true,
            "workingTime": 1660801715639,
            "origQuoteOrderQty": "0.00000000",
            "selfTradePreventionMode": "NONE"
        }
    ],
    "rateLimits": [
        {
            "rateLimitType": "REQUEST_WEIGHT",
            "interval": "MINUTE",
            "intervalNum": 1,
            "limit": 1200,
            "count": 3
        }
    ]
}

Cancel all open orders on a symbol

cancel_open_orders(self, symbol: str, **kwargs)

Cancel all open orders on a symbol (USER_DATA)

Parameters:

symbol (str) – Symbol.

Keyword Arguments:

recvWindow (int) – Recv window.

Message Sent:

{
    "id": "778f938f-9041-4b88-9914-efbf64eeacc8",
    "method": "openOrders.cancelAll"
    "params": {
        "symbol": "BTCUSDT",
        "apiKey": "vmPUZE6mv9SD5VNHk4HlWFsOr6aKE2zvsw0MuIgwCIPy6utIco14y7Ju91duEh8A",
        "signature": "773f01b6e3c2c9e0c1d217bc043ce383c1ddd6f0e25f8d6070f2b66a6ceaf3a5",
        "timestamp": 1660805557200
    }
}

Response:

{
    "id": "778f938f-9041-4b88-9914-efbf64eeacc8",
    "status": 200,
    "result": [
        {
            "symbol": "BTCUSDT",
            "origClientOrderId": "4d96324ff9d44481926157",
            "orderId": 12569099453,
            "orderListId": -1,
            "clientOrderId": "91fe37ce9e69c90d6358c0",
            "price": "23416.10000000",
            "origQty": "0.00847000",
            "executedQty": "0.00001000",
            "cummulativeQuoteQty": "0.23416100",
            "status": "CANCELED",
            "timeInForce": "GTC",
            "type": "LIMIT",
            "side": "SELL",
            "stopPrice": "0.00000000",
            "trailingDelta": 0,
            "trailingTime": -1,
            "icebergQty": "0.00000000",
            "strategyId": 37463720,
            "strategyType": 1000000,
            "selfTradePreventionMode": "NONE"
        },
        {
            "orderListId": 19431,
            "contingencyType": "OCO",
            "listStatusType": "ALL_DONE",
            "listOrderStatus": "ALL_DONE",
            "listClientOrderId": "iuVNVJYYrByz6C4yGOPPK0",
            "transactionTime": 1660803702431,
            "symbol": "BTCUSDT",
            "orders": [
                {
                "symbol": "BTCUSDT",
                "orderId": 12569099453,
                "clientOrderId": "bX5wROblo6YeDwa9iTLeyY"
                },
                {
                "symbol": "BTCUSDT",
                "orderId": 12569099454,
                "clientOrderId": "Tnu2IP0J5Y4mxw3IATBfmW"
                }
            ],
            "orderReports": [
                {
                    "symbol": "BTCUSDT",
                    "origClientOrderId": "bX5wROblo6YeDwa9iTLeyY",
                    "orderId": 12569099453,
                    "orderListId": 19431,
                    "clientOrderId": "OFFXQtxVFZ6Nbcg4PgE2DA",
                    "price": "23450.50000000",
                    "origQty": "0.00850000",
                    "executedQty": "0.00000000",
                    "cummulativeQuoteQty": "0.00000000",
                    "status": "CANCELED",
                    "timeInForce": "GTC",
                    "type": "STOP_LOSS_LIMIT",
                    "side": "BUY",
                    "stopPrice": "23430.00000000",
                    "selfTradePreventionMode": "NONE"
                },
                {
                    "symbol": "BTCUSDT",
                    "origClientOrderId": "Tnu2IP0J5Y4mxw3IATBfmW",
                    "orderId": 12569099454,
                    "orderListId": 19431,
                    "clientOrderId": "OFFXQtxVFZ6Nbcg4PgE2DA",
                    "price": "23400.00000000",
                    "origQty": "0.00850000",
                    "executedQty": "0.00000000",
                    "cummulativeQuoteQty": "0.00000000",
                    "status": "CANCELED",
                    "timeInForce": "GTC",
                    "type": "LIMIT_MAKER",
                    "side": "BUY",
                    "selfTradePreventionMode": "NONE"
                }
            ]
        }
    ],
    "rateLimits": [
        {
            "rateLimitType": "REQUEST_WEIGHT",
            "interval": "MINUTE",
            "intervalNum": 1,
            "limit": 1200,
            "count": 1
        }
    ]
}

Place a new OCO Order

new_oco_order(self, symbol: str, side: str, quantity: float, aboveType: str, belowType: str, **kwargs)

Place new Order list - OCO (TRADE) :param symbol: Symbol. :type symbol: str :param side: BUY or SELL. :type side: str :param quantity: Quantity. :type quantity: float :param aboveType: Supported values : STOP_LOSS_LIMIT, STOP_LOSS, LIMIT_MAKER :type aboveType: str :param belowType: Supported values : STOP_LOSS_LIMIT, STOP_LOSS, LIMIT_MAKER. :type belowType: str

Keyword Arguments:
  • listClientOrderId (str) – A unique id for the entire order list.

  • aboveClientOrderId (str) – Arbitrary unique ID among open orders for the above leg order. Automatically generated if not sent

  • aboveIcebergQty (int) – Note that this can only be used if aboveTimeInForce is GTC.

  • abovePrice (float)

  • aboveStopPrice (float) – Can be used if aboveType is STOP_LOSS or STOP_LOSS_LIMIT. Either aboveStopPrice or aboveTrailingDelta or both, must be specified.

  • aboveTrailingDelta (int)

  • aboveTimeInForce (float) – Required if the aboveType is STOP_LOSS_LIMIT.

  • aboveStrategyId (int) – Arbitrary numeric value identifying the above leg order within an order strategy.

  • aboveStrategyType (int) – Arbitrary numeric value identifying the above leg order strategy. Values smaller than 1000000 are reserved and cannot be used.

  • belowClientOrderId (str)

  • belowIcebergQty (int) – Note that this can only be used if belowTimeInForce is GTC.

  • belowPrice (float)

  • belowStopPrice (float) – Can be used if belowType is STOP_LOSS or STOP_LOSS_LIMIT. Either belowStopPrice or belowTrailingDelta or both, must be specified.

  • belowTrailingDelta (int)

  • belowTimeInForce (str) – Required if the belowType is STOP_LOSS_LIMIT.

  • belowStrategyId (int) – Arbitrary numeric value identifying the below leg order within an order strategy.

  • belowStrategyType (int) – Arbitrary numeric value identifying the below leg order strategy. Values smaller than 1000000 are reserved and cannot be used.

  • newOrderRespType (str) – Select response format: ACK, RESULT, FULL

  • selfTradePreventionMode (str) – The allowed enums is dependent on what is configured on the symbol. The possible supported values are EXPIRE_TAKER, EXPIRE_MAKER, EXPIRE_BOTH, NONE.

  • recvWindow (int) – Recv window.

Message sent:

{
    "id": "56374a46-3261-486b-a211-99ed972eb648",
    "method": "orderList.place.oco",
    "params":
    {
        "symbol": "LTCBNB",
        "side": "BUY",
        "quantity": 1,
        "timestamp": 1711062760647,
        "aboveType": "STOP_LOSS_LIMIT",
        "abovePrice": "1.5",
        "aboveStopPrice": "1.50000001",
        "aboveTimeInForce": "GTC",
        "belowType": "LIMIT_MAKER",
        "belowPrice": "1.49999999",
        "apiKey": "duwNf97YPLqhFIk7kZF0dDdGYVAXStA7BeEz0fIT9RAhUbixJtyS6kJ3hhzJsRXC",
        "signature": "64614cfd8dd38260d4fd86d3c455dbf4b9d1c8a8170ea54f700592a986c30ddb"
    }
}

Response:

{
    "id": "56374a46-3261-486b-a211-99ed972eb648",
    "status": 200,
    "result":
    {
        "orderListId": 2,
        "contingencyType": "OCO",
        "listStatusType": "EXEC_STARTED",
        "listOrderStatus": "EXECUTING",
        "listClientOrderId": "cKPMnDCbcLQILtDYM4f4fX",
        "transactionTime": 1711062760648,
        "symbol": "LTCBNB",
        "orders": [
            {
                "symbol": "LTCBNB",
                "orderId": 2,
                "clientOrderId": "0m6I4wfxvTUrOBSMUl0OPU"
            },
            {
                "symbol": "LTCBNB",
                "orderId": 3,
                "clientOrderId": "Z2IMlR79XNY5LU0tOxrWyW"
            }
        ],
        "orderReports": [
            {
                "symbol": "LTCBNB",
                "orderId": 2,
                "orderListId": 2,
                "clientOrderId": "0m6I4wfxvTUrOBSMUl0OPU",
                "transactTime": 1711062760648,
                "price": "1.50000000",
                "origQty": "1.000000",
                "executedQty": "0.000000",
                "cummulativeQuoteQty": "0.00000000",
                "status": "NEW",
                "timeInForce": "GTC",
                "type": "STOP_LOSS_LIMIT",
                "side": "BUY",
                "stopPrice": "1.50000001",
                "workingTime": -1,
                "selfTradePreventionMode": "NONE"
            },
            {
                "symbol": "LTCBNB",
                "orderId": 3,
                "orderListId": 2,
                "clientOrderId": "Z2IMlR79XNY5LU0tOxrWyW",
                "transactTime": 1711062760648,
                "price": "1.49999999",
                "origQty": "1.000000",
                "executedQty": "0.000000",
                "cummulativeQuoteQty": "0.00000000",
                "status": "NEW",
                "timeInForce": "GTC",
                "type": "LIMIT_MAKER",
                "side": "BUY",
                "workingTime": 1711062760648,
                "selfTradePreventionMode": "NONE"
            }
        ]
    },
    "rateLimits": [
        {
            "rateLimitType": "ORDERS",
            "interval": "SECOND",
            "intervalNum": 10,
            "limit": 50,
            "count": 2
        },
        {
            "rateLimitType": "ORDERS",
            "interval": "DAY",
            "intervalNum": 1,
            "limit": 160000,
            "count": 2
        },
        {
            "rateLimitType": "REQUEST_WEIGHT",
            "interval": "MINUTE",
            "intervalNum": 1,
            "limit": 6000,
            "count": 1
        }
    ]
}

Get OCO order

get_oco_order(self, **kwargs)

Get OCO order

Keyword Arguments:
  • orderListId (int) – Order list id.

  • origClientOrderId (str) – Original client order id.

  • recvWindow (int) – Recv window.

Message sent:

{
    "id": "b53fd5ff-82c7-4a04-bd64-5f9dc42c2100",
    "method": "orderList.status",
    "params": {
        "symbol": "BTCUSDT",
        "origClientOrderId": "08985fedd9ea2cf6b28996"
        "apiKey": "vmPUZE6mv9SD5VNHk4HlWFsOr6aKE2zvsw0MuIgwCIPy6utIco14y7Ju91duEh8A",
        "signature": "d12f4e8892d46c0ddfbd43d556ff6d818581b3be22a02810c2c20cb719aed6a4",
        "timestamp": 1660801713965
    }
}

Response:

{
    "id": "b53fd5ff-82c7-4a04-bd64-5f9dc42c2100",
    "status": 200,
    "result": {
    "orderListId": 1274512,
    "contingencyType": "OCO",
    "listStatusType": "EXEC_STARTED",
    "listOrderStatus": "EXECUTING",
    "listClientOrderId": "08985fedd9ea2cf6b28996",
    "transactionTime": 1660801713793,
    "symbol": "BTCUSDT",
    "orders": [
        {
            "symbol": "BTCUSDT",
            "orderId": 12569138901,
            "clientOrderId": "BqtFCj5odMoWtSqGk2X9tU"
        },
        {
            "symbol": "BTCUSDT",
            "orderId": 12569138902,
            "clientOrderId": "jLnZpj5enfMXTuhKB1d0us"
        }
    ]
    },
    "rateLimits": [
        {
            "rateLimitType": "REQUEST_WEIGHT",
            "interval": "MINUTE",
            "intervalNum": 1,
            "limit": 1200,
            "count": 2
        }
    ]
}

Cancel OCO order

cancel_oco_order(self, symbol: str, **kwargs)

Cancel OCO order

Parameters:

symbol (str) – Symbol to place the order on.

Keyword Arguments:
  • orderListId (int) – Order list id.

  • listClientOrderId (str) – List client order id.

  • newClientOrderId (str) – New client order id.

  • recvWindow (int) – Recv window.

Message sent:

{
    "id": "c5899911-d3f4-47ae-8835-97da553d27d0",
    "method": "orderList.cancel",
    "params": {
        "symbol": "BTCUSDT",
        "orderListId": 1274512,
        "apiKey": "vmPUZE6mv9SD5VNHk4HlWFsOr6aKE2zvsw0MuIgwCIPy6utIco14y7Ju91duEh8A",
        "signature": "4973f4b2fee30bf6d45e4a973e941cc60fdd53c8dd5a25edeac96f5733c0ccee",
        "timestamp": 1660801720210
    }
}

Response:

{
    "id": "c5899911-d3f4-47ae-8835-97da553d27d0",
    "status": 200,
    "result": {
        "orderListId": 1274512,
        "contingencyType": "OCO",
        "listStatusType": "ALL_DONE",
        "listOrderStatus": "ALL_DONE",
        "listClientOrderId": "6023531d7edaad348f5aff",
        "transactionTime": 1660801720215,
        "symbol": "BTCUSDT",
        "orders": [
            {
                "symbol": "BTCUSDT",
                "orderId": 12569138901,
                "clientOrderId": "BqtFCj5odMoWtSqGk2X9tU"
            },
            {
                "symbol": "BTCUSDT",
                "orderId": 12569138902,
                "clientOrderId": "jLnZpj5enfMXTuhKB1d0us"
            }
        ],
        "orderReports": [
            {
                "symbol": "BTCUSDT",
                "orderId": 12569138901,
                "orderListId": 1274512,
                "clientOrderId": "BqtFCj5odMoWtSqGk2X9tU",
                "transactTime": 1660801720215,
                "price": "23410.00000000",
                "origQty": "0.00650000",
                "executedQty": "0.00000000",
                "cummulativeQuoteQty": "0.00000000",
                "status": "CANCELED",
                "timeInForce": "GTC",
                "type": "STOP_LOSS_LIMIT",
                "side": "SELL",
                "stopPrice": "23405.00000000",
                "selfTradePreventionMode": "NONE"
            },
            {
                "symbol": "BTCUSDT",
                "orderId": 12569138902,
                "orderListId": 1274512,
                "clientOrderId": "jLnZpj5enfMXTuhKB1d0us",
                "transactTime": 1660801720215,
                "price": "23420.00000000",
                "origQty": "0.00650000",
                "executedQty": "0.00000000",
                "cummulativeQuoteQty": "0.00000000",
                "status": "CANCELED",
                "timeInForce": "GTC",
                "type": "LIMIT_MAKER",
                "side": "SELL",
                "selfTradePreventionMode": "NONE"
            }
        ]
    },
    "rateLimits": [
        {
            "rateLimitType": "REQUEST_WEIGHT",
            "interval": "MINUTE",
            "intervalNum": 1,
            "limit": 1200,
            "count": 1
        }
    ]
}

Get all OCO orders

get_open_oco_orders(self, **kwargs)

Get open OCO orders

Keyword Arguments:

recvWindow (int) – Recv window.

Message sent:

{
    "id": "3a4437e2-41a3-4c19-897c-9cadc5dce8b6",
    "method": "openOrderLists.status",
    "params": {
        "apiKey": "vmPUZE6mv9SD5VNHk4HlWFsOr6aKE2zvsw0MuIgwCIPy6utIco14y7Ju91duEh8A",
        "signature": "1bea8b157dd78c3da30359bddcd999e4049749fe50b828e620e12f64e8b433c9",
        "timestamp": 1660801713831
    }
}

Response:

{
    "id": "3a4437e2-41a3-4c19-897c-9cadc5dce8b6",
    "status": 200,
    "result": [
        {
            "orderListId": 0,
            "contingencyType": "OCO",
            "listStatusType": "EXEC_STARTED",
            "listOrderStatus": "EXECUTING",
            "listClientOrderId": "08985fedd9ea2cf6b28996",
            "transactionTime": 1660801713793,
            "symbol": "BTCUSDT",
            "orders": [
                {
                    "symbol": "BTCUSDT",
                    "orderId": 4,
                    "clientOrderId": "CUhLgTXnX5n2c0gWiLpV4d"
                },
                {
                    "symbol": "BTCUSDT",
                    "orderId": 5,
                    "clientOrderId": "1ZqG7bBuYwaF4SU8CwnwHm"
                }
            ]
        }
    ],
    "rateLimits": [
        {
            "rateLimitType": "REQUEST_WEIGHT",
            "interval": "MINUTE",
            "intervalNum": 1,
            "limit": 1200,
            "count": 3
        }
    ]
}

Start user data stream

user_data_start(self, id=None)

Start user data stream (USER_STREAM)

Parameters:

id (str) – A unique id for the request

Message sent:

{
    "id": "d3df8a61-98ea-4fe0-8f4e-0fcea5d418b0",
    "method": "userDataStream.start",
    "params": {
        "apiKey": "vmPUZE6mv9SD5VNHk4HlWFsOr6aKE2zvsw0MuIgwCIPy6utIco14y7Ju91duEh8A"
    }
}

Response:

{
    "id": "d3df8a61-98ea-4fe0-8f4e-0fcea5d418b0",
    "status": 200,
    "result": {
        "listenKey": "xs0mRXdAKlIPDRFrlPcw0qI41Eh3ixNntmymGyhrhgqo7L6FuLaWArTD7RLP"
    },
    "rateLimits": [
        {
        "rateLimitType": "REQUEST_WEIGHT",
        "interval": "MINUTE",
        "intervalNum": 1,
        "limit": 1200,
        "count": 1
        }
    ]
}

Ping user data stream

user_data_ping(self, listenKey: str, id=None)

Keepalive a user data stream to prevent a time out.

Parameters:
  • listenKey (str) – The listen key from the user data stream

  • id (str) – A unique id for the request

Message sent:

{
    "id": "815d5fce-0880-4287-a567-80badf004c74",
    "method": "userDataStream.ping",
    "params": {
        "listenKey": "xs0mRXdAKlIPDRFrlPcw0qI41Eh3ixNntmymGyhrhgqo7L6FuLaWArTD7RLP",
        "apiKey": "vmPUZE6mv9SD5VNHk4HlWFsOr6aKE2zvsw0MuIgwCIPy6utIco14y7Ju91duEh8A"
    }
}

Response:

{
    "id": "815d5fce-0880-4287-a567-80badf004c74",
    "status": 200,
    "response": {},
    "rateLimits": [
        {
        "rateLimitType": "REQUEST_WEIGHT",
        "interval": "MINUTE",
        "intervalNum": 1,
        "limit": 1200,
        "count": 1
        }
    ]
}

Stop user data stream

user_data_stop(self, listenKey: str, id=None)

Stop user data stream

Parameters:
  • listenKey (str) – The listen key from the user data stream

  • id (str) – A unique id for the request

Message sent:

{
    "id": "819e1b1b-8c06-485b-a13e-131326c69599",
    "method": "userDataStream.stop",
    "params": {
        "listenKey": "xs0mRXdAKlIPDRFrlPcw0qI41Eh3ixNntmymGyhrhgqo7L6FuLaWArTD7RLP",
        "apiKey": "vmPUZE6mv9SD5VNHk4HlWFsOr6aKE2zvsw0MuIgwCIPy6utIco14y7Ju91duEh8A"
    }
}

Response:

{
    "id": "819e1b1b-8c06-485b-a13e-131326c69599",
    "status": 200,
    "response": {},
    "rateLimits": [
        {
        "rateLimitType": "REQUEST_WEIGHT",
        "interval": "MINUTE",
        "intervalNum": 1,
        "limit": 1200,
        "count": 1
        }
    ]
}