ccxt 4.2.36__py2.py3-none-any.whl → 4.2.37__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ccxt/__init__.py +1 -1
- ccxt/abstract/bitfinex2.py +122 -122
- ccxt/async_support/__init__.py +1 -1
- ccxt/async_support/base/exchange.py +1 -1
- ccxt/async_support/binance.py +122 -55
- ccxt/async_support/bitfinex2.py +122 -122
- ccxt/async_support/bitmex.py +22 -3
- ccxt/async_support/bybit.py +11 -4
- ccxt/base/exchange.py +1 -1
- ccxt/binance.py +122 -55
- ccxt/bitfinex2.py +122 -122
- ccxt/bitmex.py +22 -3
- ccxt/bybit.py +11 -4
- ccxt/pro/__init__.py +1 -1
- ccxt/pro/gemini.py +165 -3
- ccxt/test/test_async.py +8 -6
- ccxt/test/test_sync.py +8 -6
- {ccxt-4.2.36.dist-info → ccxt-4.2.37.dist-info}/METADATA +6 -6
- {ccxt-4.2.36.dist-info → ccxt-4.2.37.dist-info}/RECORD +21 -21
- {ccxt-4.2.36.dist-info → ccxt-4.2.37.dist-info}/WHEEL +0 -0
- {ccxt-4.2.36.dist-info → ccxt-4.2.37.dist-info}/top_level.txt +0 -0
ccxt/async_support/bitmex.py
CHANGED
@@ -292,6 +292,7 @@ class bitmex(Exchange, ImplicitAPI):
|
|
292
292
|
async def fetch_currencies(self, params={}):
|
293
293
|
"""
|
294
294
|
fetches all available currencies on an exchange
|
295
|
+
:see: https://www.bitmex.com/api/explorer/#not /Wallet/Wallet_getAssetsConfig
|
295
296
|
:param dict [params]: extra parameters specific to the exchange API endpoint
|
296
297
|
:returns dict: an associative dictionary of currencies
|
297
298
|
"""
|
@@ -752,6 +753,7 @@ class bitmex(Exchange, ImplicitAPI):
|
|
752
753
|
async def fetch_balance(self, params={}) -> Balances:
|
753
754
|
"""
|
754
755
|
query for balance and get the amount of funds available for trading or funds locked in orders
|
756
|
+
:see: https://www.bitmex.com/api/explorer/#not /User/User_getMargin
|
755
757
|
:param dict [params]: extra parameters specific to the exchange API endpoint
|
756
758
|
:returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
|
757
759
|
"""
|
@@ -812,6 +814,7 @@ class bitmex(Exchange, ImplicitAPI):
|
|
812
814
|
async def fetch_order_book(self, symbol: str, limit: Int = None, params={}) -> OrderBook:
|
813
815
|
"""
|
814
816
|
fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
|
817
|
+
:see: https://www.bitmex.com/api/explorer/#not /OrderBook/OrderBook_getL2
|
815
818
|
:param str symbol: unified symbol of the market to fetch the order book for
|
816
819
|
:param int [limit]: the maximum amount of order book entries to return
|
817
820
|
:param dict [params]: extra parameters specific to the exchange API endpoint
|
@@ -850,6 +853,7 @@ class bitmex(Exchange, ImplicitAPI):
|
|
850
853
|
async def fetch_order(self, id: str, symbol: Str = None, params={}):
|
851
854
|
"""
|
852
855
|
fetches information on an order made by the user
|
856
|
+
:see: https://www.bitmex.com/api/explorer/#not /Order/Order_getOrders
|
853
857
|
:param str symbol: unified symbol of the market the order was made in
|
854
858
|
:param dict [params]: extra parameters specific to the exchange API endpoint
|
855
859
|
:returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
|
@@ -907,6 +911,7 @@ class bitmex(Exchange, ImplicitAPI):
|
|
907
911
|
async def fetch_open_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Order]:
|
908
912
|
"""
|
909
913
|
fetch all unfilled currently open orders
|
914
|
+
:see: https://www.bitmex.com/api/explorer/#not /Order/Order_getOrders
|
910
915
|
:param str symbol: unified market symbol
|
911
916
|
:param int [since]: the earliest time in ms to fetch open orders for
|
912
917
|
:param int [limit]: the maximum number of open orders structures to retrieve
|
@@ -923,6 +928,7 @@ class bitmex(Exchange, ImplicitAPI):
|
|
923
928
|
async def fetch_closed_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Order]:
|
924
929
|
"""
|
925
930
|
fetches information on multiple closed orders made by the user
|
931
|
+
:see: https://www.bitmex.com/api/explorer/#not /Order/Order_getOrders
|
926
932
|
:param str symbol: unified market symbol of the market orders were made in
|
927
933
|
:param int [since]: the earliest time in ms to fetch orders for
|
928
934
|
:param int [limit]: the maximum number of order structures to retrieve
|
@@ -935,8 +941,8 @@ class bitmex(Exchange, ImplicitAPI):
|
|
935
941
|
|
936
942
|
async def fetch_my_trades(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}):
|
937
943
|
"""
|
938
|
-
:see: https://www.bitmex.com/api/explorer/#not /Execution/Execution_getTradeHistory
|
939
944
|
fetch all trades made by the user
|
945
|
+
:see: https://www.bitmex.com/api/explorer/#not /Execution/Execution_getTradeHistory
|
940
946
|
:param str symbol: unified market symbol
|
941
947
|
:param int [since]: the earliest time in ms to fetch trades for
|
942
948
|
:param int [limit]: the maximum number of trades structures to retrieve
|
@@ -1132,6 +1138,7 @@ class bitmex(Exchange, ImplicitAPI):
|
|
1132
1138
|
async def fetch_ledger(self, code: Str = None, since: Int = None, limit: Int = None, params={}):
|
1133
1139
|
"""
|
1134
1140
|
fetch the history of changes, actions done by the user or operations that altered balance of the user
|
1141
|
+
:see: https://www.bitmex.com/api/explorer/#not /User/User_getWalletHistory
|
1135
1142
|
:param str code: unified currency code, default is None
|
1136
1143
|
:param int [since]: timestamp in ms of the earliest ledger entry, default is None
|
1137
1144
|
:param int [limit]: max number of ledger entrys to return, default is None
|
@@ -1179,6 +1186,7 @@ class bitmex(Exchange, ImplicitAPI):
|
|
1179
1186
|
async def fetch_deposits_withdrawals(self, code: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Transaction]:
|
1180
1187
|
"""
|
1181
1188
|
fetch history of deposits and withdrawals
|
1189
|
+
:see: https://www.bitmex.com/api/explorer/#not /User/User_getWalletHistory
|
1182
1190
|
:param str [code]: unified currency code for the currency of the deposit/withdrawals, default is None
|
1183
1191
|
:param int [since]: timestamp in ms of the earliest deposit/withdrawal, default is None
|
1184
1192
|
:param int [limit]: max number of deposit/withdrawals to return, default is None
|
@@ -1290,6 +1298,7 @@ class bitmex(Exchange, ImplicitAPI):
|
|
1290
1298
|
async def fetch_ticker(self, symbol: str, params={}) -> Ticker:
|
1291
1299
|
"""
|
1292
1300
|
fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
|
1301
|
+
:see: https://www.bitmex.com/api/explorer/#not /Instrument/Instrument_get
|
1293
1302
|
:param str symbol: unified symbol of the market to fetch the ticker for
|
1294
1303
|
:param dict [params]: extra parameters specific to the exchange API endpoint
|
1295
1304
|
:returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
|
@@ -1308,6 +1317,7 @@ class bitmex(Exchange, ImplicitAPI):
|
|
1308
1317
|
async def fetch_tickers(self, symbols: Strings = None, params={}) -> Tickers:
|
1309
1318
|
"""
|
1310
1319
|
fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
|
1320
|
+
:see: https://www.bitmex.com/api/explorer/#not /Instrument/Instrument_getActiveAndIndices
|
1311
1321
|
:param str[]|None symbols: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
|
1312
1322
|
:param dict [params]: extra parameters specific to the exchange API endpoint
|
1313
1323
|
:returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
|
@@ -1386,8 +1396,8 @@ class bitmex(Exchange, ImplicitAPI):
|
|
1386
1396
|
|
1387
1397
|
async def fetch_ohlcv(self, symbol: str, timeframe='1m', since: Int = None, limit: Int = None, params={}) -> List[list]:
|
1388
1398
|
"""
|
1389
|
-
:see: https://www.bitmex.com/api/explorer/#not /Trade/Trade_getBucketed
|
1390
1399
|
fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
|
1400
|
+
:see: https://www.bitmex.com/api/explorer/#not /Trade/Trade_getBucketed
|
1391
1401
|
:param str symbol: unified symbol of the market to fetch OHLCV data for
|
1392
1402
|
:param str timeframe: the length of time each candle represents
|
1393
1403
|
:param int [since]: timestamp in ms of the earliest candle to fetch
|
@@ -1683,8 +1693,8 @@ class bitmex(Exchange, ImplicitAPI):
|
|
1683
1693
|
|
1684
1694
|
async def fetch_trades(self, symbol: str, since: Int = None, limit: Int = None, params={}) -> List[Trade]:
|
1685
1695
|
"""
|
1686
|
-
:see: https://www.bitmex.com/api/explorer/#not /Trade/Trade_get
|
1687
1696
|
get the list of most recent trades for a particular symbol
|
1697
|
+
:see: https://www.bitmex.com/api/explorer/#not /Trade/Trade_get
|
1688
1698
|
:param str symbol: unified symbol of the market to fetch trades for
|
1689
1699
|
:param int [since]: timestamp in ms of the earliest trade to fetch
|
1690
1700
|
:param int [limit]: the maximum amount of trades to fetch
|
@@ -1866,6 +1876,7 @@ class bitmex(Exchange, ImplicitAPI):
|
|
1866
1876
|
async def cancel_order(self, id: str, symbol: Str = None, params={}):
|
1867
1877
|
"""
|
1868
1878
|
cancels an open order
|
1879
|
+
:see: https://www.bitmex.com/api/explorer/#not /Order/Order_cancel
|
1869
1880
|
:param str id: order id
|
1870
1881
|
:param str symbol: not used by bitmex cancelOrder()
|
1871
1882
|
:param dict [params]: extra parameters specific to the exchange API endpoint
|
@@ -1891,6 +1902,7 @@ class bitmex(Exchange, ImplicitAPI):
|
|
1891
1902
|
async def cancel_orders(self, ids, symbol: Str = None, params={}):
|
1892
1903
|
"""
|
1893
1904
|
cancel multiple orders
|
1905
|
+
:see: https://www.bitmex.com/api/explorer/#not /Order/Order_cancel
|
1894
1906
|
:param str[] ids: order ids
|
1895
1907
|
:param str symbol: not used by bitmex cancelOrders()
|
1896
1908
|
:param dict [params]: extra parameters specific to the exchange API endpoint
|
@@ -1912,6 +1924,7 @@ class bitmex(Exchange, ImplicitAPI):
|
|
1912
1924
|
async def cancel_all_orders(self, symbol: Str = None, params={}):
|
1913
1925
|
"""
|
1914
1926
|
cancel all open orders
|
1927
|
+
:see: https://www.bitmex.com/api/explorer/#not /Order/Order_cancelAll
|
1915
1928
|
:param str symbol: unified market symbol, only orders in the market of self symbol are cancelled when symbol is not None
|
1916
1929
|
:param dict [params]: extra parameters specific to the exchange API endpoint
|
1917
1930
|
:returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
|
@@ -1967,6 +1980,7 @@ class bitmex(Exchange, ImplicitAPI):
|
|
1967
1980
|
async def fetch_positions(self, symbols: Strings = None, params={}):
|
1968
1981
|
"""
|
1969
1982
|
fetch all open positions
|
1983
|
+
:see: https://www.bitmex.com/api/explorer/#not /Position/Position_get
|
1970
1984
|
:param str[]|None symbols: list of unified market symbols
|
1971
1985
|
:param dict [params]: extra parameters specific to the exchange API endpoint
|
1972
1986
|
:returns dict[]: a list of `position structure <https://docs.ccxt.com/#/?id=position-structure>`
|
@@ -2220,6 +2234,7 @@ class bitmex(Exchange, ImplicitAPI):
|
|
2220
2234
|
async def withdraw(self, code: str, amount: float, address, tag=None, params={}):
|
2221
2235
|
"""
|
2222
2236
|
make a withdrawal
|
2237
|
+
:see: https://www.bitmex.com/api/explorer/#not /User/User_requestWithdrawal
|
2223
2238
|
:param str code: unified currency code
|
2224
2239
|
:param float amount: the amount to withdraw
|
2225
2240
|
:param str address: the address to withdraw to
|
@@ -2265,6 +2280,7 @@ class bitmex(Exchange, ImplicitAPI):
|
|
2265
2280
|
async def fetch_funding_rates(self, symbols: Strings = None, params={}):
|
2266
2281
|
"""
|
2267
2282
|
fetch the funding rate for multiple markets
|
2283
|
+
:see: https://www.bitmex.com/api/explorer/#not /Instrument/Instrument_getActiveAndIndices
|
2268
2284
|
:param str[]|None symbols: list of unified market symbols
|
2269
2285
|
:param dict [params]: extra parameters specific to the exchange API endpoint
|
2270
2286
|
:returns dict: a dictionary of `funding rates structures <https://docs.ccxt.com/#/?id=funding-rates-structure>`, indexe by market symbols
|
@@ -2312,6 +2328,7 @@ class bitmex(Exchange, ImplicitAPI):
|
|
2312
2328
|
async def fetch_funding_rate_history(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}):
|
2313
2329
|
"""
|
2314
2330
|
Fetches the history of funding rates
|
2331
|
+
:see: https://www.bitmex.com/api/explorer/#not /Funding/Funding_get
|
2315
2332
|
:param str symbol: unified symbol of the market to fetch the funding rate history for
|
2316
2333
|
:param int [since]: timestamp in ms of the earliest funding rate to fetch
|
2317
2334
|
:param int [limit]: the maximum amount of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-history-structure>` to fetch
|
@@ -2386,6 +2403,7 @@ class bitmex(Exchange, ImplicitAPI):
|
|
2386
2403
|
async def set_leverage(self, leverage: Int, symbol: Str = None, params={}):
|
2387
2404
|
"""
|
2388
2405
|
set the level of leverage for a market
|
2406
|
+
:see: https://www.bitmex.com/api/explorer/#not /Position/Position_updateLeverage
|
2389
2407
|
:param float leverage: the rate of leverage
|
2390
2408
|
:param str symbol: unified market symbol
|
2391
2409
|
:param dict [params]: extra parameters specific to the exchange API endpoint
|
@@ -2408,6 +2426,7 @@ class bitmex(Exchange, ImplicitAPI):
|
|
2408
2426
|
async def set_margin_mode(self, marginMode, symbol: Str = None, params={}):
|
2409
2427
|
"""
|
2410
2428
|
set margin mode to 'cross' or 'isolated'
|
2429
|
+
:see: https://www.bitmex.com/api/explorer/#not /Position/Position_isolateMargin
|
2411
2430
|
:param str marginMode: 'cross' or 'isolated'
|
2412
2431
|
:param str symbol: unified market symbol
|
2413
2432
|
:param dict [params]: extra parameters specific to the exchange API endpoint
|
ccxt/async_support/bybit.py
CHANGED
@@ -3526,9 +3526,19 @@ class bybit(Exchange, ImplicitAPI):
|
|
3526
3526
|
if isStopLoss:
|
3527
3527
|
slTriggerPrice = self.safe_value_2(stopLoss, 'triggerPrice', 'stopPrice', stopLoss)
|
3528
3528
|
request['stopLoss'] = self.price_to_precision(symbol, slTriggerPrice)
|
3529
|
+
slLimitPrice = self.safe_value(stopLoss, 'price')
|
3530
|
+
if slLimitPrice is not None:
|
3531
|
+
request['tpslMode'] = 'Partial'
|
3532
|
+
request['slOrderType'] = 'Limit'
|
3533
|
+
request['slLimitPrice'] = self.price_to_precision(symbol, slLimitPrice)
|
3529
3534
|
if isTakeProfit:
|
3530
3535
|
tpTriggerPrice = self.safe_value_2(takeProfit, 'triggerPrice', 'stopPrice', takeProfit)
|
3531
3536
|
request['takeProfit'] = self.price_to_precision(symbol, tpTriggerPrice)
|
3537
|
+
tpLimitPrice = self.safe_value(takeProfit, 'price')
|
3538
|
+
if tpLimitPrice is not None:
|
3539
|
+
request['tpslMode'] = 'Partial'
|
3540
|
+
request['tpOrderType'] = 'Limit'
|
3541
|
+
request['tpLimitPrice'] = self.price_to_precision(symbol, tpLimitPrice)
|
3532
3542
|
if market['spot']:
|
3533
3543
|
# only works for spot market
|
3534
3544
|
if triggerPrice is not None:
|
@@ -5622,9 +5632,6 @@ class bybit(Exchange, ImplicitAPI):
|
|
5622
5632
|
timestamp = self.parse8601(self.safe_string(position, 'updated_at'))
|
5623
5633
|
if timestamp is None:
|
5624
5634
|
timestamp = self.safe_integer_n(position, ['updatedTime', 'updatedAt'])
|
5625
|
-
# default to cross of USDC margined positions
|
5626
|
-
tradeMode = self.safe_integer(position, 'tradeMode', 0)
|
5627
|
-
marginMode = 'isolated' if tradeMode else 'cross'
|
5628
5635
|
collateralString = self.safe_string(position, 'positionBalance')
|
5629
5636
|
entryPrice = self.omit_zero(self.safe_string_2(position, 'entryPrice', 'avgPrice'))
|
5630
5637
|
liquidationPrice = self.omit_zero(self.safe_string(position, 'liqPrice'))
|
@@ -5681,7 +5688,7 @@ class bybit(Exchange, ImplicitAPI):
|
|
5681
5688
|
'markPrice': self.safe_number(position, 'markPrice'),
|
5682
5689
|
'lastPrice': None,
|
5683
5690
|
'collateral': self.parse_number(collateralString),
|
5684
|
-
'marginMode':
|
5691
|
+
'marginMode': None,
|
5685
5692
|
'side': side,
|
5686
5693
|
'percentage': None,
|
5687
5694
|
'stopLossPrice': self.safe_number_2(position, 'stop_loss', 'stopLoss'),
|
ccxt/base/exchange.py
CHANGED
ccxt/binance.py
CHANGED
@@ -4840,7 +4840,7 @@ class binance(Exchange, ImplicitAPI):
|
|
4840
4840
|
# "msg": "Quantity greater than max quantity."
|
4841
4841
|
# }
|
4842
4842
|
#
|
4843
|
-
# createOrder: portfolio margin linear swap and future
|
4843
|
+
# createOrder, fetchOpenOrders: portfolio margin linear swap and future
|
4844
4844
|
#
|
4845
4845
|
# {
|
4846
4846
|
# "symbol": "BTCUSDT",
|
@@ -4863,7 +4863,7 @@ class binance(Exchange, ImplicitAPI):
|
|
4863
4863
|
# "status": "NEW"
|
4864
4864
|
# }
|
4865
4865
|
#
|
4866
|
-
# createOrder: portfolio margin inverse swap and future
|
4866
|
+
# createOrder, fetchOpenOrders: portfolio margin inverse swap and future
|
4867
4867
|
#
|
4868
4868
|
# {
|
4869
4869
|
# "symbol": "ETHUSD_PERP",
|
@@ -4885,7 +4885,7 @@ class binance(Exchange, ImplicitAPI):
|
|
4885
4885
|
# "status": "NEW"
|
4886
4886
|
# }
|
4887
4887
|
#
|
4888
|
-
# createOrder: portfolio margin linear swap and future conditional
|
4888
|
+
# createOrder, fetchOpenOrders: portfolio margin linear swap and future conditional
|
4889
4889
|
#
|
4890
4890
|
# {
|
4891
4891
|
# "newClientStrategyId": "x-xcKtGhcu27f109953d6e4dc0974006",
|
@@ -4908,7 +4908,7 @@ class binance(Exchange, ImplicitAPI):
|
|
4908
4908
|
# "selfTradePreventionMode": "NONE"
|
4909
4909
|
# }
|
4910
4910
|
#
|
4911
|
-
# createOrder: portfolio margin inverse swap and future conditional
|
4911
|
+
# createOrder, fetchOpenOrders: portfolio margin inverse swap and future conditional
|
4912
4912
|
#
|
4913
4913
|
# {
|
4914
4914
|
# "newClientStrategyId": "x-xcKtGhcuc6b86f053bb34933850739",
|
@@ -4929,7 +4929,7 @@ class binance(Exchange, ImplicitAPI):
|
|
4929
4929
|
# "priceProtect": False
|
4930
4930
|
# }
|
4931
4931
|
#
|
4932
|
-
# createOrder: portfolio margin spot margin
|
4932
|
+
# createOrder, cancelAllOrders: portfolio margin spot margin
|
4933
4933
|
#
|
4934
4934
|
# {
|
4935
4935
|
# "clientOrderId": "x-R4BD3S82e9ef29d8346440f0b28b86",
|
@@ -4948,13 +4948,39 @@ class binance(Exchange, ImplicitAPI):
|
|
4948
4948
|
# "type": "LIMIT"
|
4949
4949
|
# }
|
4950
4950
|
#
|
4951
|
+
# fetchOpenOrders: portfolio margin spot margin
|
4952
|
+
#
|
4953
|
+
# {
|
4954
|
+
# "symbol": "BTCUSDT",
|
4955
|
+
# "orderId": 24700763749,
|
4956
|
+
# "clientOrderId": "x-R4BD3S826f724c2a4af6425f98c7b6",
|
4957
|
+
# "price": "35000.00000000",
|
4958
|
+
# "origQty": "0.00100000",
|
4959
|
+
# "executedQty": "0.00000000",
|
4960
|
+
# "cummulativeQuoteQty": "0.00000000",
|
4961
|
+
# "status": "NEW",
|
4962
|
+
# "timeInForce": "GTC",
|
4963
|
+
# "type": "LIMIT",
|
4964
|
+
# "side": "BUY",
|
4965
|
+
# "stopPrice": "0.00000000",
|
4966
|
+
# "icebergQty": "0.00000000",
|
4967
|
+
# "time": 1707199187679,
|
4968
|
+
# "updateTime": 1707199187679,
|
4969
|
+
# "isWorking": True,
|
4970
|
+
# "accountId": 200180970,
|
4971
|
+
# "selfTradePreventionMode": "EXPIRE_MAKER",
|
4972
|
+
# "preventedMatchId": null,
|
4973
|
+
# "preventedQuantity": null
|
4974
|
+
# }
|
4975
|
+
#
|
4951
4976
|
code = self.safe_string(order, 'code')
|
4952
4977
|
if code is not None:
|
4953
4978
|
# cancelOrders/createOrders might have a partial success
|
4954
4979
|
return self.safe_order({'info': order, 'status': 'rejected'}, market)
|
4955
4980
|
status = self.parse_order_status(self.safe_string_2(order, 'status', 'strategyStatus'))
|
4956
4981
|
marketId = self.safe_string(order, 'symbol')
|
4957
|
-
|
4982
|
+
isContract = ('positionSide' in order) or ('cumQuote' in order)
|
4983
|
+
marketType = 'contract' if isContract else 'spot'
|
4958
4984
|
symbol = self.safe_symbol(marketId, market, None, marketType)
|
4959
4985
|
filled = self.safe_string(order, 'executedQty', '0')
|
4960
4986
|
timestamp = self.safe_integer_n(order, ['time', 'createTime', 'workingTime', 'transactTime', 'updateTime']) # order of the keys matters here
|
@@ -5218,16 +5244,6 @@ class binance(Exchange, ImplicitAPI):
|
|
5218
5244
|
else:
|
5219
5245
|
if reduceOnly:
|
5220
5246
|
request['sideEffectType'] = 'AUTO_REPAY'
|
5221
|
-
if not isPortfolioMargin:
|
5222
|
-
postOnly = self.is_post_only(isMarketOrder, initialUppercaseType == 'LIMIT_MAKER', params)
|
5223
|
-
if market['spot'] or marketType == 'margin':
|
5224
|
-
# only supported for spot/margin api(all margin markets are spot markets)
|
5225
|
-
if postOnly:
|
5226
|
-
type = 'LIMIT_MAKER'
|
5227
|
-
if marginMode == 'isolated':
|
5228
|
-
request['isIsolated'] = True
|
5229
|
-
if market['contract'] and postOnly:
|
5230
|
-
request['timeInForce'] = 'GTX'
|
5231
5247
|
triggerPrice = self.safe_string_2(params, 'triggerPrice', 'stopPrice')
|
5232
5248
|
stopLossPrice = self.safe_string(params, 'stopLossPrice', triggerPrice) # fallback to stopLoss
|
5233
5249
|
takeProfitPrice = self.safe_string(params, 'takeProfitPrice')
|
@@ -5285,6 +5301,15 @@ class binance(Exchange, ImplicitAPI):
|
|
5285
5301
|
request[clientOrderIdRequest] = brokerId + self.uuid22()
|
5286
5302
|
else:
|
5287
5303
|
request[clientOrderIdRequest] = clientOrderId
|
5304
|
+
postOnly = None
|
5305
|
+
if not isPortfolioMargin:
|
5306
|
+
postOnly = self.is_post_only(isMarketOrder, initialUppercaseType == 'LIMIT_MAKER', params)
|
5307
|
+
if market['spot'] or marketType == 'margin':
|
5308
|
+
# only supported for spot/margin api(all margin markets are spot markets)
|
5309
|
+
if postOnly:
|
5310
|
+
uppercaseType = 'LIMIT_MAKER'
|
5311
|
+
if marginMode == 'isolated':
|
5312
|
+
request['isIsolated'] = True
|
5288
5313
|
typeRequest = 'strategyType' if isPortfolioMarginConditional else 'type'
|
5289
5314
|
request[typeRequest] = uppercaseType
|
5290
5315
|
# additional required fields depending on the order type
|
@@ -5371,8 +5396,6 @@ class binance(Exchange, ImplicitAPI):
|
|
5371
5396
|
if price is None:
|
5372
5397
|
raise InvalidOrder(self.id + ' createOrder() requires a price argument for a ' + type + ' order')
|
5373
5398
|
request['price'] = self.price_to_precision(symbol, price)
|
5374
|
-
if timeInForceIsRequired:
|
5375
|
-
request['timeInForce'] = self.options['defaultTimeInForce'] # 'GTC' = Good To Cancel(default), 'IOC' = Immediate Or Cancel
|
5376
5399
|
if stopPriceIsRequired:
|
5377
5400
|
if market['contract']:
|
5378
5401
|
if stopPrice is None:
|
@@ -5383,16 +5406,10 @@ class binance(Exchange, ImplicitAPI):
|
|
5383
5406
|
raise InvalidOrder(self.id + ' createOrder() requires a stopPrice or trailingDelta param for a ' + type + ' order')
|
5384
5407
|
if stopPrice is not None:
|
5385
5408
|
request['stopPrice'] = self.price_to_precision(symbol, stopPrice)
|
5386
|
-
if
|
5387
|
-
|
5388
|
-
|
5389
|
-
|
5390
|
-
if postOnly:
|
5391
|
-
type = 'LIMIT_MAKER'
|
5392
|
-
if marginMode == 'isolated':
|
5393
|
-
request['isIsolated'] = True
|
5394
|
-
if market['contract'] and postOnly:
|
5395
|
-
request['timeInForce'] = 'GTX'
|
5409
|
+
if timeInForceIsRequired and (self.safe_string(params, 'timeInForce') is None):
|
5410
|
+
request['timeInForce'] = self.options['defaultTimeInForce'] # 'GTC' = Good To Cancel(default), 'IOC' = Immediate Or Cancel
|
5411
|
+
if not isPortfolioMargin and market['contract'] and postOnly:
|
5412
|
+
request['timeInForce'] = 'GTX'
|
5396
5413
|
# remove timeInForce from params because PO is only used by self.is_post_onlyand it's not a valid value for Binance
|
5397
5414
|
if self.safe_string(params, 'timeInForce') == 'PO':
|
5398
5415
|
params = self.omit(params, 'timeInForce')
|
@@ -5625,21 +5642,28 @@ class binance(Exchange, ImplicitAPI):
|
|
5625
5642
|
|
5626
5643
|
def fetch_open_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Order]:
|
5627
5644
|
"""
|
5645
|
+
fetch all unfilled currently open orders
|
5628
5646
|
:see: https://binance-docs.github.io/apidocs/spot/en/#cancel-an-existing-order-and-send-a-new-order-trade
|
5629
5647
|
:see: https://binance-docs.github.io/apidocs/futures/en/#current-all-open-orders-user_data
|
5630
5648
|
:see: https://binance-docs.github.io/apidocs/delivery/en/#current-all-open-orders-user_data
|
5631
5649
|
:see: https://binance-docs.github.io/apidocs/voptions/en/#query-current-open-option-orders-user_data
|
5632
|
-
fetch all unfilled currently open orders
|
5633
5650
|
:see: https://binance-docs.github.io/apidocs/spot/en/#current-open-orders-user_data
|
5634
5651
|
:see: https://binance-docs.github.io/apidocs/futures/en/#current-all-open-orders-user_data
|
5635
5652
|
:see: https://binance-docs.github.io/apidocs/delivery/en/#current-all-open-orders-user_data
|
5636
5653
|
:see: https://binance-docs.github.io/apidocs/voptions/en/#query-current-open-option-orders-user_data
|
5637
5654
|
:see: https://binance-docs.github.io/apidocs/spot/en/#query-margin-account-39-s-open-orders-user_data
|
5655
|
+
:see: https://binance-docs.github.io/apidocs/pm/en/#query-all-current-um-open-orders-user_data
|
5656
|
+
:see: https://binance-docs.github.io/apidocs/pm/en/#query-all-current-cm-open-orders-user_data
|
5657
|
+
:see: https://binance-docs.github.io/apidocs/pm/en/#query-all-current-um-open-conditional-orders-user_data
|
5658
|
+
:see: https://binance-docs.github.io/apidocs/pm/en/#query-all-current-cm-open-conditional-orders-user_data
|
5659
|
+
:see: https://binance-docs.github.io/apidocs/pm/en/#query-current-margin-open-order-user_data
|
5638
5660
|
:param str symbol: unified market symbol
|
5639
5661
|
:param int [since]: the earliest time in ms to fetch open orders for
|
5640
5662
|
:param int [limit]: the maximum number of open orders structures to retrieve
|
5641
5663
|
:param dict [params]: extra parameters specific to the exchange API endpoint
|
5642
5664
|
:param str [params.marginMode]: 'cross' or 'isolated', for spot margin trading
|
5665
|
+
:param boolean [params.portfolioMargin]: set to True if you would like to fetch open orders in the portfolio margin account
|
5666
|
+
:param boolean [params.stop]: set to True if you would like to fetch portfolio margin account conditional orders
|
5643
5667
|
:returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
|
5644
5668
|
"""
|
5645
5669
|
self.load_markets()
|
@@ -5647,14 +5671,16 @@ class binance(Exchange, ImplicitAPI):
|
|
5647
5671
|
type = None
|
5648
5672
|
request = {}
|
5649
5673
|
marginMode = None
|
5650
|
-
|
5651
|
-
|
5674
|
+
marginMode, params = self.handle_margin_mode_and_params('fetchOpenOrders', params)
|
5675
|
+
isPortfolioMargin = None
|
5676
|
+
isPortfolioMargin, params = self.handle_option_and_params_2(params, 'fetchOpenOrders', 'papi', 'portfolioMargin', False)
|
5677
|
+
isConditional = self.safe_bool_2(params, 'stop', 'conditional')
|
5652
5678
|
if symbol is not None:
|
5653
5679
|
market = self.market(symbol)
|
5654
5680
|
request['symbol'] = market['id']
|
5655
5681
|
defaultType = self.safe_string_2(self.options, 'fetchOpenOrders', 'defaultType', 'spot')
|
5656
5682
|
marketType = market['type'] if ('type' in market) else defaultType
|
5657
|
-
type = self.safe_string(
|
5683
|
+
type = self.safe_string(params, 'type', marketType)
|
5658
5684
|
elif self.options['warnOnFetchOpenOrdersWithoutSymbol']:
|
5659
5685
|
symbols = self.symbols
|
5660
5686
|
numSymbols = len(symbols)
|
@@ -5662,29 +5688,44 @@ class binance(Exchange, ImplicitAPI):
|
|
5662
5688
|
raise ExchangeError(self.id + ' fetchOpenOrders() WARNING: fetching open orders without specifying a symbol is rate-limited to one call per ' + str(fetchOpenOrdersRateLimit) + ' seconds. Do not call self method frequently to avoid ban. Set ' + self.id + '.options["warnOnFetchOpenOrdersWithoutSymbol"] = False to suppress self warning message.')
|
5663
5689
|
else:
|
5664
5690
|
defaultType = self.safe_string_2(self.options, 'fetchOpenOrders', 'defaultType', 'spot')
|
5665
|
-
type = self.safe_string(
|
5691
|
+
type = self.safe_string(params, 'type', defaultType)
|
5666
5692
|
subType = None
|
5667
|
-
subType,
|
5668
|
-
|
5693
|
+
subType, params = self.handle_sub_type_and_params('fetchOpenOrders', market, params)
|
5694
|
+
params = self.omit(params, ['type', 'stop', 'conditional'])
|
5669
5695
|
response = None
|
5670
5696
|
if type == 'option':
|
5671
5697
|
if since is not None:
|
5672
5698
|
request['startTime'] = since
|
5673
5699
|
if limit is not None:
|
5674
5700
|
request['limit'] = limit
|
5675
|
-
response = self.eapiPrivateGetOpenOrders(self.extend(request,
|
5701
|
+
response = self.eapiPrivateGetOpenOrders(self.extend(request, params))
|
5676
5702
|
elif self.is_linear(type, subType):
|
5677
|
-
|
5703
|
+
if isPortfolioMargin:
|
5704
|
+
if isConditional:
|
5705
|
+
response = self.papiGetUmConditionalOpenOrders(self.extend(request, params))
|
5706
|
+
else:
|
5707
|
+
response = self.papiGetUmOpenOrders(self.extend(request, params))
|
5708
|
+
else:
|
5709
|
+
response = self.fapiPrivateGetOpenOrders(self.extend(request, params))
|
5678
5710
|
elif self.is_inverse(type, subType):
|
5679
|
-
|
5711
|
+
if isPortfolioMargin:
|
5712
|
+
if isConditional:
|
5713
|
+
response = self.papiGetCmConditionalOpenOrders(self.extend(request, params))
|
5714
|
+
else:
|
5715
|
+
response = self.papiGetCmOpenOrders(self.extend(request, params))
|
5716
|
+
else:
|
5717
|
+
response = self.dapiPrivateGetOpenOrders(self.extend(request, params))
|
5680
5718
|
elif type == 'margin' or marginMode is not None:
|
5681
|
-
if
|
5682
|
-
|
5683
|
-
|
5684
|
-
|
5685
|
-
|
5719
|
+
if isPortfolioMargin:
|
5720
|
+
response = self.papiGetMarginOpenOrders(self.extend(request, params))
|
5721
|
+
else:
|
5722
|
+
if marginMode == 'isolated':
|
5723
|
+
request['isIsolated'] = True
|
5724
|
+
if symbol is None:
|
5725
|
+
raise ArgumentsRequired(self.id + ' fetchOpenOrders() requires a symbol argument for isolated markets')
|
5726
|
+
response = self.sapiGetMarginOpenOrders(self.extend(request, params))
|
5686
5727
|
else:
|
5687
|
-
response = self.privateGetOpenOrders(self.extend(request,
|
5728
|
+
response = self.privateGetOpenOrders(self.extend(request, params))
|
5688
5729
|
return self.parse_orders(response, market, since, limit)
|
5689
5730
|
|
5690
5731
|
def fetch_closed_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Order]:
|
@@ -5780,40 +5821,66 @@ class binance(Exchange, ImplicitAPI):
|
|
5780
5821
|
|
5781
5822
|
def cancel_all_orders(self, symbol: Str = None, params={}):
|
5782
5823
|
"""
|
5824
|
+
cancel all open orders in a market
|
5783
5825
|
:see: https://binance-docs.github.io/apidocs/spot/en/#cancel-all-open-orders-on-a-symbol-trade
|
5784
5826
|
:see: https://binance-docs.github.io/apidocs/futures/en/#cancel-all-open-orders-trade
|
5785
5827
|
:see: https://binance-docs.github.io/apidocs/delivery/en/#cancel-all-open-orders-trade
|
5786
5828
|
:see: https://binance-docs.github.io/apidocs/voptions/en/#cancel-all-option-orders-on-specific-symbol-trade
|
5787
5829
|
:see: https://binance-docs.github.io/apidocs/spot/en/#margin-account-cancel-order-trade
|
5788
|
-
cancel
|
5830
|
+
:see: https://binance-docs.github.io/apidocs/pm/en/#cancel-all-um-open-orders-trade
|
5831
|
+
:see: https://binance-docs.github.io/apidocs/pm/en/#cancel-all-cm-open-orders-trade
|
5832
|
+
:see: https://binance-docs.github.io/apidocs/pm/en/#cancel-all-um-open-conditional-orders-trade
|
5833
|
+
:see: https://binance-docs.github.io/apidocs/pm/en/#cancel-all-cm-open-conditional-orders-trade
|
5834
|
+
:see: https://binance-docs.github.io/apidocs/pm/en/#cancel-margin-account-all-open-orders-on-a-symbol-trade
|
5789
5835
|
:param str symbol: unified market symbol of the market to cancel orders in
|
5790
5836
|
:param dict [params]: extra parameters specific to the exchange API endpoint
|
5791
5837
|
:param str [params.marginMode]: 'cross' or 'isolated', for spot margin trading
|
5838
|
+
:param boolean [params.portfolioMargin]: set to True if you would like to cancel orders in a portfolio margin account
|
5839
|
+
:param boolean [params.stop]: set to True if you would like to cancel portfolio margin account conditional orders
|
5792
5840
|
:returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
|
5793
5841
|
"""
|
5794
5842
|
if symbol is None:
|
5795
|
-
raise ArgumentsRequired(self.id + '
|
5843
|
+
raise ArgumentsRequired(self.id + ' cancelAllOrders() requires a symbol argument')
|
5796
5844
|
self.load_markets()
|
5797
5845
|
market = self.market(symbol)
|
5798
5846
|
request = {
|
5799
5847
|
'symbol': market['id'],
|
5800
5848
|
}
|
5849
|
+
isPortfolioMargin = None
|
5850
|
+
isPortfolioMargin, params = self.handle_option_and_params_2(params, 'cancelAllOrders', 'papi', 'portfolioMargin', False)
|
5851
|
+
isConditional = self.safe_bool_2(params, 'stop', 'conditional')
|
5801
5852
|
type = self.safe_string(params, 'type', market['type'])
|
5802
|
-
params = self.omit(params, ['type'])
|
5803
|
-
marginMode
|
5853
|
+
params = self.omit(params, ['type', 'stop', 'conditional'])
|
5854
|
+
marginMode = None
|
5855
|
+
marginMode, params = self.handle_margin_mode_and_params('cancelAllOrders', params)
|
5804
5856
|
response = None
|
5805
5857
|
if market['option']:
|
5806
|
-
response = self.eapiPrivateDeleteAllOpenOrders(self.extend(request,
|
5858
|
+
response = self.eapiPrivateDeleteAllOpenOrders(self.extend(request, params))
|
5807
5859
|
elif market['linear']:
|
5808
|
-
|
5860
|
+
if isPortfolioMargin:
|
5861
|
+
if isConditional:
|
5862
|
+
response = self.papiDeleteUmConditionalAllOpenOrders(self.extend(request, params))
|
5863
|
+
else:
|
5864
|
+
response = self.papiDeleteUmAllOpenOrders(self.extend(request, params))
|
5865
|
+
else:
|
5866
|
+
response = self.fapiPrivateDeleteAllOpenOrders(self.extend(request, params))
|
5809
5867
|
elif market['inverse']:
|
5810
|
-
|
5868
|
+
if isPortfolioMargin:
|
5869
|
+
if isConditional:
|
5870
|
+
response = self.papiDeleteCmConditionalAllOpenOrders(self.extend(request, params))
|
5871
|
+
else:
|
5872
|
+
response = self.papiDeleteCmAllOpenOrders(self.extend(request, params))
|
5873
|
+
else:
|
5874
|
+
response = self.dapiPrivateDeleteAllOpenOrders(self.extend(request, params))
|
5811
5875
|
elif (type == 'margin') or (marginMode is not None):
|
5812
|
-
if
|
5813
|
-
|
5814
|
-
|
5876
|
+
if isPortfolioMargin:
|
5877
|
+
response = self.papiDeleteMarginAllOpenOrders(self.extend(request, params))
|
5878
|
+
else:
|
5879
|
+
if marginMode == 'isolated':
|
5880
|
+
request['isIsolated'] = True
|
5881
|
+
response = self.sapiDeleteMarginOpenOrders(self.extend(request, params))
|
5815
5882
|
else:
|
5816
|
-
response = self.privateDeleteOpenOrders(self.extend(request,
|
5883
|
+
response = self.privateDeleteOpenOrders(self.extend(request, params))
|
5817
5884
|
if isinstance(response, list):
|
5818
5885
|
return self.parse_orders(response, market)
|
5819
5886
|
else:
|