TradeGate
- class TradeGate.TradeGate(configDict, sandbox=False)
Bases:
object- cancelAllSymbolOpenOrders(symbol, futures=False)
Cancel all active orders of a symbol
- Parameters
- Returns
Order datas of the cancelled orders
- Return type
- Output
[ { 'symbol': 'BTCUSDT', 'orderId': 3051990476, 'clientOrderId': 'sDAclHSkWaO5R3fHYwI9IQ', 'transactTime': 1656335835113, 'price': 20000.0, 'origQty': 0.002, 'executedQty': 0.0, 'cummulativeQuoteQty': 0.0, 'status': 'CANCELED', 'timeInForce': 'GTC', 'type': 'LIMIT', 'side': 'BUY', 'extraData': { 'reduceOnly': False, 'stopPrice': 0.0, 'workingType': 'CONTRACT_PRICE', 'avgPrice': 0.0, 'origType': 'LIMIT', 'positionSide': 'BOTH', 'activatePrice': None, 'priceRate': None, 'closePosition': False } }, { 'symbol': 'BTCUSDT', 'orderId': 3051990465, 'clientOrderId': 'SxyPikUE9ysMSZ8jbKGQAZ', 'transactTime': 1656335835113, 'price': 20000.0, 'origQty': 0.002, 'executedQty': 0.0, 'cummulativeQuoteQty': 0.0, 'status': 'CANCELED', 'timeInForce': 'GTC', 'type': 'LIMIT', 'side': 'BUY', 'extraData': { 'reduceOnly': False, 'stopPrice': 0.0, 'workingType': 'CONTRACT_PRICE', 'avgPrice': 0.0, 'origType': 'LIMIT', 'positionSide': 'BOTH', 'activatePrice': None, 'priceRate': None, 'closePosition': False } } ]
- cancelOrder(symbol, orderId=None, localOrderId=None, futures=False)
Cancel an active order
- Parameters
- Returns
The order data of the canceled order
- Return type
- Output
{ 'symbol': 'BTCUSDT', 'orderId': 3051988035, 'clientOrderId': '1656335100', 'transactTime': 1656335103251, 'price': 20000.0, 'origQty': 0.002, 'executedQty': 0.0, 'cummulativeQuoteQty': 0.0, 'status': 'CANCELED', 'timeInForce': 'GTC', 'type': 'LIMIT', 'side': 'BUY', 'extraData': { 'reduceOnly': False, 'stopPrice': 0.0, 'workingType': 'CONTRACT_PRICE', 'avgPrice': 0.0, 'origType': 'LIMIT', 'positionSide': 'BOTH', 'activatePrice': None, 'priceRate': None, 'closePosition': False } }
- Notes
Must specify either ‘orderId’ or ‘localOrderId’
- changeInitialLeverage(symbol, leverage)
Change initial leverage for a symbol
- changeMarginType(symbol, marginType, params=None)
Change position margin of a symbol
- Parameters
- Returns
True if changing was successful or False if unsuccessful
- Return type
- Output
True- Notes
For KuCoin, ‘CROSSED’ means enabling ‘auto_add_margin’, and ‘ISOLATED’ means disabling it.
For ByBit, you must specify ‘buyLeverage’ and ‘sellLeverage’ inside params. If switching from ‘CROSSED’ to ‘ISOLATED’, theses two numbers must be equal.
- changePositionMargin(symbol, amount)
Change position margin of a symbol
- Parameters
- Returns
True if changing was successful or False if unsuccessful
- Return type
- Output
True- Notes
The amount can be positive or negative for Binance exchange but it must be positive for other exchanges.
Use
changeMarginType()to make current position available for changing amount.
- createAndTestFuturesOrder(symbol, side, orderType, positionSide=None, timeInForce=None, quantity=None, reduceOnly=None, price=None, newClientOrderId=None, stopPrice=None, closePosition=None, activationPrice=None, callbackRate=None, workingType=None, priceProtect=None, newOrderRespType=None, extraParams=None, quoteQuantity=None)
Create a FuturesOrderData object and test the given parameters for validity. The object returned is then used to send an order to the exchange by
makeFuturesOrder()- Parameters
symbol (str) – Symbol of the order
side (str) – Side of the order. Either ‘BUY’ or ‘SELL’
orderType (str) – Type of the order. can be ‘MARKET’, ‘LIMIT’ or others (Check exchange’s API documentation)
positionSide (str , optional) – Only for binance. ‘BOTH’ for One-way Mode and ‘LONG’ or ‘SHORT’ for Hedge Mode. It must be sent in Hedge Mode.
timeInForce (str , optional) – Order’s time in force. Can be ‘GTC’, ‘IOC’, ‘FOK’ or specific to the exchange. Check the exchange’s API documentation for more options.
quantity (float , optional) – The amount of base asset of the order.
reduceOnly (bool , optional) – A flag to reduce the position size only.
price (float , optional) – Order price
newClientOrderId (str , optional) – Custom string to identify your order for yourself.
stopPrice (float , optional) – Price condition to trigger the order. Only for stop order type.
closePosition (bool , optional) – Whether to close the current open position or not.
activationPrice (float , optional) – Only for Binance. Used with ‘TRAILING_STOP_MARKET’ order type.
callbackRate (float , optional) – Only for Binance. Used with TRAILING_STOP_MARKET orders and specifies callback percentage.
workingType (str , optional) – With what price the stop order is triggered: ‘MARK_PRICE’ or ‘CONTRACT_PRICE’
priceProtect (bool , optional) – Only for Binance. Whether to protect the stop order from large difference of mark price and contract price.
newOrderRespType (str , optional) – Only for Binance. Response of the order, either ‘ACK’ or ‘RESULT’.
extraParams (dict , optional) – Extra parameters for other exchanges than Binance.
quoteQuantity (float , optional) – The amount of quote asset of the order.
- Returns
An orderData object of the created order, ready to be submitted using
makeFuturesOrder()- Return type
OrderData
- Notes
Input parameters are based on Binance API. We map the appropriate parameters from input to the exchange requirements, but other parameters must be inside the ‘extraParams’ dictionary.
Preferably use ‘quantity’ instead of ‘quoteQuantity’. Some exchanges don’t accept this parameter and we convert it to the quantity based on the price (if provided) or current market price.
Some parameters have values that are only valid for some exchanges. See each exchange’s documentation for these values.
ValueError exception is raised when wrong combination of parameters are sent. Check the exception’s message for guidance.
Do not send ‘price’ with ‘MARKET’ orders.
You must specify ‘price’ for ‘LIMIT’ orders.
Other than ByBit, use
makeSlTpLimitFuturesOrder()ormakeSlTpMarketFuturesOrder()to send take profit and stop loss.if ‘closePosition’ is used, do not specify ‘quantity’ or ‘quoteQuantity’.
For ByBit:
You can send take profit by specifying ‘take_profit’ (price) and ‘tp_trigger_by’ (’LastPrice’, ‘IndexPrice’ or ‘MarkPrice’) in ‘extraParams’.
You can send take profit by specifying ‘stop_loss’ (price) and ‘sl_trigger_by’ (’LastPrice’, ‘IndexPrice’ or ‘MarkPrice’) in ‘extraParams’.
For KuCoin:
You must send ‘leverage’ parameter inside ‘extraParams’ for the KuCoin exchange.
Send ‘stop’ (either ‘down’ or ‘up’) and ‘stopPriceType’ (either ‘TP’, ‘IP’ or ‘MP’) in the ‘extraParams’ when specifying ‘stopPrice’.
You can send ‘postOnly’, ‘hidden’, ‘iceberg’ and ‘visibleSize’ parameters inside ‘extraParams’.
There are two values for the ‘timeInForce’ variable: ‘GTC’ (Good Till Cancel) and ‘IOC’ (Immediate Or Cancel)
- createAndTestSpotOrder(symbol, side, orderType, quantity=None, price=None, timeInForce=None, stopPrice=None, icebergQty=None, newOrderRespType=None, newClientOrderId=None, extraParams=None)
Create a OrderData object and test the given parameters for validity. The object returned is then used to send an order to the exchange by
makeSpotOrder()- Parameters
symbol (str) – Symbol of the order
side (str) – Side of the order. Either ‘BUY’ or ‘SELL’
orderType (str) – Type of the order. can be ‘MARKET’, ‘LIMIT’ or others (Check exchange’s API documentation)
quantity (float , optional) – The amount of base asset of the order.
price (float , optional) – Order price
timeInForce (str , optional) – Order’s time in force. Can be ‘GTC’, ‘IOC’, ‘FOK’ or specific to the exchange. Check the exchange’s API documentation for more options.
stopPrice (float , optional) – Price condition to trigger the order. Only for stop order type.
icebergQty (float , optional) – Only for Binance. Amount of the base asset to be hide on the exchange.
newOrderRespType (str , optional) – Only for Binance. Response of the order, either ‘ACK’ or ‘RESULT’.
newClientOrderId (str , optional) – Custom string to identify your order for yourself.
extraParams (dict , optional) – Extra parameters for other exchanges than Binance.
- Returns
An orderData object of the created order, ready to be submitted using
makeSpotOrder()- Return type
OrderData
- Notes
Input parameters are based on Binance API. We map the appropriate parameters from input to the exchange requirements, but other parameters must be inside the ‘extraParams’ dictionary.
Some parameters have values that are only valid for some exchanges. See each exchange’s documentation for these values.
ValueError exception is raised when wrong combination of parameters are sent. Check the exception’s message for guidance.
Do not send ‘price’ with ‘MARKET’ orders.
You must specify ‘price’ for ‘LIMIT’ orders.
For ByBit:
Order type can only be ‘MARKET’, ‘LIMIT’ or ‘LIMIT_MAKER’
For KuCoin:
To send a stop order, set ‘orderType’ to STOP_MARKET or STOP_LIMIT.
Send ‘stop’ (either loss or entry) in the ‘extraParams’ when specifying ‘stopPrice’.
You can send ‘cancelAfter’ parameter inside ‘extraParams’ to cancel order after n seconds only if ‘timeInForce’ value is GTT
You can send ‘postOnly’, ‘hidden’, ‘iceberg’ (bool) and ‘visibleSize’ parameters inside ‘extraParams’.
Valid values for the ‘timeInForce’ variable: GTC (Good Till Cancel), IOC (Immediate Or Cancel), GTT (Good Till Time) and FOK (Fill Or Kill)
- getBalance(asset=None, futures=False)
Returns account balance of all assets or a single asset
- Parameters
- Returns
Returns a single asset balance or list of assets if no asset was specified.
- Return type
- Output with asset specified
{ 'asset': 'BNB', 'free': '1000.00000000', 'locked': '0.00000000' }
- Output without asset specified
[ { 'asset': 'BNB', 'free': '1000.00000000', 'locked': '0.00000000' }, { 'asset': 'BTC', 'free': '1.02000000', 'locked': '0.00000000' }, ... ]
- getExchangeTime(futures=False)
Get time of the exchange
- getIncomeHistory(symbol, incomeType=None, startTime=None, endTime=None, limit=None)
Returns list of changes to the account balance. (Only for futures accounts)
- Parameters
symbol (str) – The symbol which the incomes are related to
incomeType (str , Optional) – Type of income. For options visit the exchange’s API documentation.
startTime (str , Optional) – If specified, incomes will be fetched from that time forward. (Time string format : ‘%Y-%m-%d %H:%M:%S’)
endTime (str , Optional) – If specified, incomes will be fetched until that time. (Time string format : ‘%Y-%m-%d %H:%M:%S’)
limit (int) – Maximum number of entries returned. For available options visit the exchange’s API documentation.
- Returns
A list of incomes
- Return type
- Output
[ { 'symbol': 'BTCUSDT', 'incomeType': 'FUNDING_FEE', 'income': 0.26403463, 'asset': 'USDT', 'time': 1655280000000 }, { 'symbol': 'BTCUSDT', 'incomeType': 'REALIZED_PNL', 'income': 26.0335, 'asset': 'USDT', 'time': 1655281638000 }, { 'symbol': 'BTCUSDT', 'incomeType': 'COMMISSION', 'income': -0.08219559, 'asset': 'USDT', 'time': 1655281638000 }, ... ]
- getLatestSymbolNames(numOfSymbols=None, futures=True)
Returns list of newly added symbols to the exchange. Currently, only working for futures market.
- Parameters
- Returns
Returns a list of tuples containing asset names and a datetime object specifying its listed date.
- Return type
- Output
[ ('DOTBUSD', datetime.datetime(2022, 6, 7, 11, 30)), ('TLMBUSD', datetime.datetime(2022, 6, 7, 11, 30)), ('ICPBUSD', datetime.datetime(2022, 6, 7, 11, 30)), ('OPUSDT', datetime.datetime(2022, 6, 1, 11, 30)), ('LUNA2BUSD', datetime.datetime(2022, 5, 31, 11, 30)), ('1000LUNCBUSD', datetime.datetime(2022, 5, 30, 11, 30)), ('GALABUSD', datetime.datetime(2022, 5, 25, 11, 30)), ('TRXBUSD', datetime.datetime(2022, 5, 25, 11, 30)), ('DODOBUSD', datetime.datetime(2022, 5, 24, 11, 30)), ('ANCBUSD', datetime.datetime(2022, 5, 24, 11, 30)) ]
- getLongShortRatios(symbol, period, limit=None, startTime=None, endTime=None)
- getOpenOrders(symbol, futures=False)
Get order datas of all open orders for a symbol
- Parameters
- Returns
Order datas of the open orders
- Return type
- Output
[ { 'symbol': 'BTCUSDT', 'orderId': 3051997664, 'clientOrderId': 'VhxN3SezOKgpvACYe2qhO6', 'transactTime': 1656337589565, 'price': 20000.0, 'origQty': 0.002, 'executedQty': 0.0, 'cummulativeQuoteQty': 0.0, 'status': 'NEW', 'timeInForce': 'GTC', 'type': 'LIMIT', 'side': 'BUY', 'extraData': { 'reduceOnly': False, 'stopPrice': 0.0, 'workingType': 'CONTRACT_PRICE', 'avgPrice': 0.0, 'origType': 'LIMIT', 'positionSide': 'BOTH', 'activatePrice': None, 'priceRate': None, 'closePosition': False } }, { 'symbol': 'BTCUSDT', 'orderId': 3051997723, 'clientOrderId': 'v1nT9fQjDGVRqHBtDYotTh', 'transactTime': 1656337600701, 'price': 20000.0, 'origQty': 0.002, 'executedQty': 0.0, 'cummulativeQuoteQty': 0.0, 'status': 'NEW', 'timeInForce': 'GTC', 'type': 'LIMIT', 'side': 'BUY', 'extraData': { 'reduceOnly': False, 'stopPrice': 0.0, 'workingType': 'CONTRACT_PRICE', 'avgPrice': 0.0, 'origType': 'LIMIT', 'positionSide': 'BOTH', 'activatePrice': None, 'priceRate': None, 'closePosition': False } } ]
- getOrder(symbol, orderId=None, localOrderId=None, futures=False)
Get an order’s data
- Parameters
- Returns
The order data
- Return type
- Output
{ 'symbol': 'BTCUSDT', 'orderId': 3051988035, 'clientOrderId': '1656335100', 'transactTime': 1656335103251, 'price': 20000.0, 'origQty': 0.002, 'executedQty': 0.0, 'cummulativeQuoteQty': 0.0, 'status': 'CANCELED', 'timeInForce': 'GTC', 'type': 'LIMIT', 'side': 'BUY', 'extraData': { 'reduceOnly': False, 'stopPrice': 0.0, 'workingType': 'CONTRACT_PRICE', 'avgPrice': 0.0, 'origType': 'LIMIT', 'positionSide': 'BOTH', 'activatePrice': None, 'priceRate': None, 'closePosition': False } }
- Notes
Must specify either ‘orderId’ or ‘localOrderId’
- getPositionInfo(symbol=None)
Returns information of position or positions. (Only for futures accounts)
- Parameters
symbol (str , optional) – The symbol of the position
- Returns
A list of position information. If the symbol parameter is given, the list will contain only one element.
- Return type
- Output with symbol specified
[ { 'entryPrice': 19229.6, 'isAutoAddMargin': True, 'leverage': 10.0, 'maxNotionalValue': 1000000.0, 'liquidationPrice': 20935.5130297, 'markPrice': 19222.55166016, 'positionAmt': -0.01, 'symbol': 'BTCUSDT', 'unrealizedProfit': 0.07048339, 'marginType': 'isolated', 'isolatedMargin': 19.22316499, 'positionSide': 'BOTH' } ]
- Output without symbol specified
[ { 'entryPrice': 0.0, 'isAutoAddMargin': True, 'leverage': 20.0, 'maxNotionalValue': 25000.0, 'liquidationPrice': 0.0, 'markPrice': 0.0, 'positionAmt': 0.0, 'symbol': 'RAYUSDT', 'unrealizedProfit': 0.0, 'marginType': 'cross', 'isolatedMargin': 0.0, 'positionSide': 'BOTH' }, { 'entryPrice': 0.0, 'isAutoAddMargin': True, 'leverage': 20.0, 'maxNotionalValue': 25000.0, 'liquidationPrice': 0.0, 'markPrice': 0.0, 'positionAmt': 0.0, 'symbol': 'API3USDT', 'unrealizedProfit': 0.0, 'marginType': 'cross', 'isolatedMargin': 0.0, 'positionSide': 'BOTH' }, ... ]
- getSymbol24hChanges(futures=False)
Returns all symbols 24-hour change percentages
- Parameters
futures (bool , optional) – False for spot market and True for futures market, defaults to False
- Returns
Returns a list of tuples containing asset names and percentage of change in 24-hour
- Return type
- Output
[ ('PONDUSDT', 28.45), ('PONDBTC', 28.261), ('PONDBUSD', 28.162), ('NULSBTC', 24.321), ('NULSUSDT', 23.975), ('NULSBUSD', 23.244), ('CTXCBTC', 20.551), ('CTXCUSDT', 19.959), ('CTXCBUSD', 19.776), ... ]
- getSymbolKlines(symbol, interval, startTime=None, endTime=None, limit=None, futures=False, blvtnav=False, convertDateTime=False, doClean=False, toCleanDataframe=False)
Get a symbol’s Klines (candlestick) data
- Parameters
symbol (str) – The symbol to fetch the klines
interval (str) – The interval of klines data
startTime (long , optional) – Timestamp for the start time of the data
endTime (long , optional) – Timestamp for the end time of the data
limit (int , optional) – Number of klines data (candlesticks) to be returned
futures (bool , optional) – False for spot market and True for futures market, defaults to False
blvtnav (bool , optional) – Only for Binance. Return the blvtnav data.
convertDateTime (bool , optional) – Convert the timestamps to datetime objects in the returned data
doClean (bool , optional) – Only return desired columns of the data
toCleanDataframe (bool , optional) – Returned Pandas dataframe object of the data with desired columns
- Returns
Either a 2D array containing the data or a pandas dataframe object of the data
- Return type
list(list)) or pandas.DataFrame
- Output as list
[ [ 1656327600000, 21437.18, 21445.56, 21380.02, 21428.66, 525.2881, 1656328499999, 11246729.6314567, 9626.0, 277.31647, 5936870.8288083, 0.0 ], [ 1656328500000, 21428.66, 21450.0, 21339.83, 21376.49, 477.24441, 1656329399999, 10206890.129678, 9503.0, 208.56099, 4459849.0304778, 0.0 ] ]
- Output as DataFrame
open high low close date 2022-06-27 16:15:00 21367.67 21376.00 21285.48 21304.55 2022-06-27 16:30:00 21304.56 21329.91 21301.24 21308.73 volume closeDate tradesNum date 2022-06-27 16:15:00 470.24040 2022-06-27 16:29:59 8980.0 2022-06-27 16:30:00 113.05128 2022-06-27 16:44:59 2693.0
- Notes
‘startTime’ and ‘endTime’ variables must be timestamps. If neither are sent, will return the latest data.
‘limit’ parameter has a maximum value (usually 1000). if the given limit number is bigger than that, only the maximum number will be fetched.
Desired columns are: open - high - low - close - volume - closeDate - tradesNum
- getSymbolList(futures=False)
Returns list of symbol names available for trade
- getSymbolMinTrade(symbol, futures=False)
Returns information of valid minimum quantity, quote quantity and price precision.
- Parameters
- Returns
A dictionary containing information about the minimum valid values of the specified symbol
- Return type
- Output parameters
stepPrice
Price’s maximum precision
minQuantity
Minimum valid quantity
precisionStep
Quantity’s maximum precision
minQuoteQuantity
Minimum valid quote quantity
- Output
{ 'stepPrice': 0.01, 'minQuantity': 1e-05, 'precisionStep': 1e-05, 'minQuoteQuantity': 0.19279200000000002 }
- getSymbolOrderBook(symbol, limit=None, futures=False)
Returns list of current orders in the orderbook of the exchange
- Parameters
- Returns
A dictionary with bids and asks. Each bid and ask is a tuple of price and quantity.
- Return type
- Output (limit=5)
{ 'lastUpdateId': 1630819351623, 'bids': [ ['18009.90', '0.557'], ['18009.80', '0.076'], ['18009.30', '0.002'], ['18009.20', '0.004'], ['18008.20', '0.038'] ], 'asks': [ ['18010.00', '0.464'], ['18010.50', '0.101'], ['18010.70', '0.099'], ['18010.90', '0.017'], ['18011.20', '0.206'] ] }
- getSymbolOrders(symbol, futures=False, orderId=None, startTime=None, endTime=None, limit=None)
Get History of orders submitted
- Parameters
symbol (str) – The order’s symbol
orderId (long, optional) – Only return orders from the order with this orderId onwards.
startTime (long, optional) – Timestamp for the start of the data
endTime (long, optional) – Timestamp for the end of the data
limit (int, optional) – Maximum number of order datas to return
futures (bool , optional) – False for spot market and True for futures market, defaults to False
- Returns
A list of orders datas
- Return type
- Output
[ { 'symbol': 'BTCUSDT', 'orderId': 7020578, 'orderListId': -1, 'clientOrderId': 'tI8wxMsbaUk6hcf5QpC8zx', 'price': '20000.00000000', 'origQty': '0.00200000', 'executedQty': '0.00000000', 'cummulativeQuoteQty': '0.00000000', 'status': 'NEW', 'timeInForce': 'GTC', 'type': 'LIMIT', 'side': 'BUY', 'stopPrice': '0.00000000', 'icebergQty': '0.00000000', 'time': 1656338254295, 'updateTime': 1656338254295, 'isWorking': True, 'origQuoteOrderQty': '0.00000000' }, { 'symbol': 'BTCUSDT', 'orderId': 7048832, 'orderListId': -1, 'clientOrderId': 'Jes2sprMLHxEUXHyJOUEAr', 'price': '20000.00000000', 'origQty': '0.00200000', 'executedQty': '0.00000000', 'cummulativeQuoteQty': '0.00000000', 'status': 'NEW', 'timeInForce': 'GTC', 'type': 'LIMIT', 'side': 'BUY', 'stopPrice': '0.00000000', 'icebergQty': '0.00000000', 'time': 1656343106986, 'updateTime': 1656343106986, 'isWorking': True, 'origQuoteOrderQty': '0.00000000' } ]
- Notes
Specify the symbol for better output.
- getSymbolRecentTrades(symbol, limit=None, futures=False)
Returns list of the recent trades for a symbol
- Parameters
- Returns
A data frame of the trade infos
- Return type
- Output columns
- getSymbolTickerPrice(symbol, futures=False)
Get the latest price of a symbol
- getTradingFees(symbol=None, futures=None)
Get the fee structure of the exchange
- Parameters
- Returns
The fee structure of the exchange
- Return type
- Output
{ 'symbol': 'BTCUSDT', 'makerCommission': '0.001', 'takerCommission': '0.001' }
- Notes
Specify the symbol for better output.
- makeBatchFuturesOrder(batchOrders)
Make multiple futures order with single request
- Parameters
batchOrders (list(OrderData)) – list of OrderDatas created using
makeFuturesOrder()- Returns
List of order information submitted
- Return type
- Output
[ { 'symbol': 'BTCUSDT', 'orderId': 3049327900, 'clientOrderId': 'aLHt4lEJzO2Xeh21GebGCz0', 'transactTime': 1655704960910, 'price': 0.0, 'origQty': 0.003, 'executedQty': 0.0, 'cummulativeQuoteQty': 0.0, 'status': 'NEW', 'timeInForce': 'GTC', 'type': 'MARKET', 'side': 'BUY', 'extraData': { 'reduceOnly': False, 'stopPrice': 0.0, 'workingType': 'CONTRACT_PRICE', 'avgPrice': 0.0, 'origType': 'MARKET', 'positionSide': 'BOTH', 'activatePrice': None, 'priceRate': None, 'closePosition': False } }, { 'symbol': 'BTCUSDT', 'orderId': 3049327901, 'clientOrderId': 'hUacgz6xW3Vp71sc8yztxK1', 'transactTime': 1655704960910, 'price': 0.0, 'origQty': 0.005, 'executedQty': 0.0, 'cummulativeQuoteQty': 0.0, 'status': 'NEW', 'timeInForce': 'GTC', 'type': 'MARKET', 'side': 'BUY', 'extraData': { 'reduceOnly': False, 'stopPrice': 0.0, 'workingType': 'CONTRACT_PRICE', 'avgPrice': 0.0, 'origType': 'MARKET', 'positionSide': 'BOTH', 'activatePrice': None, 'priceRate': None, 'closePosition': False } } ]
- Notes
Not available for KuCoin exchange.
The execution of orders in the batch are not dependent on each other, so be careful if orders depend on one another.
- makeFuturesOrder(futuresOrderData)
Make a futures order
- Parameters
futuresOrderData (OrderData) – OrderData created using
makeFuturesOrder()- Returns
submitted order information
- Return type
- Output
{ 'symbol': 'BTCUSDT', 'orderId': 3049327900, 'clientOrderId': 'aLHt4lEJzO2Xeh21GebGCz0', 'transactTime': 1655704960910, 'price': 0.0, 'origQty': 0.003, 'executedQty': 0.0, 'cummulativeQuoteQty': 0.0, 'status': 'NEW', 'timeInForce': 'GTC', 'type': 'MARKET', 'side': 'BUY', 'extraData': { 'reduceOnly': False, 'stopPrice': 0.0, 'workingType': 'CONTRACT_PRICE', 'avgPrice': 0.0, 'origType': 'MARKET', 'positionSide': 'BOTH', 'activatePrice': None, 'priceRate': None, 'closePosition': False } }
- makeSlTpLimitFuturesOrder(symbol, orderSide, enterPrice, quantity=None, quoteQuantity=None, takeProfit=None, stopLoss=None, leverage=None, marginType=None)
Make market price futures order with take profit and stop loss.
- Parameters
symbol (str) – Name of the symbol
orderSide (str) – Side of the order.
enterPrice (float , optional) – Limit price of the order
quantity (float , optional) – Amount of the base asset
quoteQuantity (float , optional) – Amount of the quote asset
takeProfit (float , optional) – Take profit price
stopLoss (float , optional) – Stop loss price
leverage (int , optional) – Desired leverage for the order.
marginType (str , optional) – Margin type of the order
- Returns
Returns orderID’s of the orders submitted.
- Return type
- Output
{ 'mainOrder': 3048448085, 'stopLoss': 3048448086, 'takeProfit': 3048448087 }
- Notes
The orderSide parameter can either be BUY or SELL.
Should specify either quantity or quoteQuantity.
The leverage parameter is mandatory for the following exchanges:
KuCoin
The marginType is currently only valid for Binance exchange.
Be careful with the takeProfit and stopLoss prices, if they would trigger immidietly, there will be an error.
Use with a try catch block preferably.
- makeSlTpMarketFuturesOrder(symbol, orderSide, quantity=None, quoteQuantity=None, takeProfit=None, stopLoss=None, leverage=None, marginType=None)
Make market price futures order with take profit and stop loss.
- Parameters
symbol (str) – Name of the symbol
orderSide (str) – Side of the order.
quantity (float , optional) – Amount of the base asset
quoteQuantity (float , optional) – Amount of the quote asset
takeProfit (float , optional) – Take profit price
stopLoss (float , optional) – Stop loss price
leverage (int , optional) – Desired leverage for the order.
marginType (str , optional) – Margin type of the order
- Returns
Returns orderID’s of the orders submitted.
- Return type
- Output
{ 'mainOrder': 3048424829, 'stopLoss': 3048424830, 'takeProfit': 3048424828 }
- Notes
The orderSide parameter can either be BUY or SELL.
Should specify either quantity or quoteQuantity.
The leverage parameter is mandatory for the following exchanges:
KuCoin
The marginType is currently only valid for Binance exchange.
Be careful with the takeProfit and stopLoss prices, if they would trigger immidietly, there will be an error.
Use with a try catch block preferably.
- makeSpotOrder(orderData)
Make a spot order
- Parameters
orderData (OrderData) – OrderData created using
makeSpotOrder()- Returns
submitted order information
- Return type
- Output
{ 'symbol': 'BTCUSDT', 'orderId': 7048832, 'orderListId': -1, 'clientOrderId': 'Jes2sprMLHxEUXHyJOUEAr', 'transactTime': 1656343106986, 'price': '20000.00000000', 'origQty': '0.00200000', 'executedQty': '0.00000000', 'cummulativeQuoteQty': '0.00000000', 'status': 'NEW', 'timeInForce': 'GTC', 'type': 'LIMIT', 'side': 'BUY', 'fills': [] }
- spotBestBidAsks(symbol=None)
Returns best bid and best ask price with their quantities
- symbolAccountTradeHistory(symbol, fromId=None, limit=None, futures=False)
Returns list of the trade history for user orders
- Parameters
- Returns
A list of trade datas
- Return type
- Output
[ { 'symbol': 'BTCUSDT', 'id': 233453846, 'orderId': 3046255912, 'orderListId': None, 'price': 27426.7, 'qty': 0.61, 'quoteQty': 16730.287, 'commission': 0.0, 'commissionAsset': 'USDT', 'time': 1655001759033, 'isBuyer': False, 'isMaker': False, 'isBestMatch': None }, { 'symbol': 'BTCUSDT', 'id': 233480351, 'orderId': 3046360099, 'orderListId': None, 'price': 27300.0, 'qty': 0.002, 'quoteQty': 54.6, 'commission': 0.02184, 'commissionAsset': 'USDT', 'time': 1655027380068, 'isBuyer': True, 'isMaker': False, 'isBestMatch': None }, ... ]
- Notes
The orderListId returned parameter is either None or -1 if order was made with API.
The isBestMatch returned parameter is not reliable and not available on most of the exchanges.