ccxt 4.4.27__py2.py3-none-any.whl → 4.4.29__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/binance.py +7 -0
- ccxt/abstract/binancecoinm.py +7 -0
- ccxt/abstract/binanceus.py +7 -0
- ccxt/abstract/binanceusdm.py +7 -0
- ccxt/abstract/bybit.py +0 -13
- ccxt/alpaca.py +45 -41
- ccxt/async_support/__init__.py +1 -1
- ccxt/async_support/alpaca.py +45 -41
- ccxt/async_support/base/exchange.py +4 -1
- ccxt/async_support/bigone.py +1 -1
- ccxt/async_support/binance.py +8 -1
- ccxt/async_support/bingx.py +1 -1
- ccxt/async_support/bitbank.py +1 -1
- ccxt/async_support/bitfinex.py +1 -1
- ccxt/async_support/bitfinex2.py +1 -1
- ccxt/async_support/bitflyer.py +1 -1
- ccxt/async_support/bitget.py +96 -8
- ccxt/async_support/bithumb.py +1 -1
- ccxt/async_support/bitmart.py +1 -1
- ccxt/async_support/bitmex.py +1 -1
- ccxt/async_support/bitopro.py +22 -22
- ccxt/async_support/bitrue.py +29 -29
- ccxt/async_support/bitso.py +1 -1
- ccxt/async_support/bitstamp.py +1 -1
- ccxt/async_support/bitvavo.py +4 -1
- ccxt/async_support/blockchaincom.py +1 -1
- ccxt/async_support/btcmarkets.py +1 -1
- ccxt/async_support/bybit.py +50 -585
- ccxt/async_support/coinbase.py +1 -1
- ccxt/async_support/coinbaseexchange.py +1 -1
- ccxt/async_support/coinbaseinternational.py +1 -1
- ccxt/async_support/coincatch.py +25 -5
- ccxt/async_support/coinex.py +1 -1
- ccxt/async_support/coinlist.py +1 -1
- ccxt/async_support/coinmate.py +1 -1
- ccxt/async_support/coinsph.py +1 -1
- ccxt/async_support/cryptocom.py +1 -1
- ccxt/async_support/deribit.py +1 -1
- ccxt/async_support/digifinex.py +1 -1
- ccxt/async_support/exmo.py +1 -1
- ccxt/async_support/gate.py +1 -1
- ccxt/async_support/gemini.py +1 -1
- ccxt/async_support/hashkey.py +1 -1
- ccxt/async_support/hitbtc.py +1 -1
- ccxt/async_support/hollaex.py +1 -1
- ccxt/async_support/htx.py +1 -1
- ccxt/async_support/huobijp.py +1 -1
- ccxt/async_support/idex.py +1 -1
- ccxt/async_support/independentreserve.py +1 -1
- ccxt/async_support/indodax.py +1 -1
- ccxt/async_support/kraken.py +44 -36
- ccxt/async_support/kucoin.py +1 -1
- ccxt/async_support/kuna.py +1 -1
- ccxt/async_support/lbank.py +6 -1
- ccxt/async_support/lykke.py +1 -1
- ccxt/async_support/mercado.py +1 -1
- ccxt/async_support/mexc.py +1 -1
- ccxt/async_support/ndax.py +1 -1
- ccxt/async_support/novadax.py +1 -1
- ccxt/async_support/okcoin.py +1 -1
- ccxt/async_support/okx.py +1 -1
- ccxt/async_support/onetrading.py +1 -1
- ccxt/async_support/oxfun.py +1 -1
- ccxt/async_support/phemex.py +1 -1
- ccxt/async_support/poloniex.py +1 -1
- ccxt/async_support/probit.py +1 -1
- ccxt/async_support/tokocrypto.py +1 -1
- ccxt/async_support/upbit.py +1 -1
- ccxt/async_support/vertex.py +52 -8
- ccxt/async_support/wavesexchange.py +2 -1
- ccxt/async_support/whitebit.py +1 -1
- ccxt/async_support/woo.py +1 -1
- ccxt/async_support/woofipro.py +1 -1
- ccxt/async_support/xt.py +1 -1
- ccxt/async_support/yobit.py +2 -2
- ccxt/async_support/zaif.py +1 -1
- ccxt/async_support/zonda.py +1 -1
- ccxt/base/exchange.py +4 -1
- ccxt/bigone.py +1 -1
- ccxt/binance.py +8 -1
- ccxt/bingx.py +1 -1
- ccxt/bitbank.py +1 -1
- ccxt/bitfinex.py +1 -1
- ccxt/bitfinex2.py +1 -1
- ccxt/bitflyer.py +1 -1
- ccxt/bitget.py +96 -8
- ccxt/bithumb.py +1 -1
- ccxt/bitmart.py +1 -1
- ccxt/bitmex.py +1 -1
- ccxt/bitopro.py +22 -22
- ccxt/bitrue.py +29 -29
- ccxt/bitso.py +1 -1
- ccxt/bitstamp.py +1 -1
- ccxt/bitvavo.py +4 -1
- ccxt/blockchaincom.py +1 -1
- ccxt/btcmarkets.py +1 -1
- ccxt/bybit.py +50 -585
- ccxt/coinbase.py +1 -1
- ccxt/coinbaseexchange.py +1 -1
- ccxt/coinbaseinternational.py +1 -1
- ccxt/coincatch.py +25 -5
- ccxt/coinex.py +1 -1
- ccxt/coinlist.py +1 -1
- ccxt/coinmate.py +1 -1
- ccxt/coinsph.py +1 -1
- ccxt/cryptocom.py +1 -1
- ccxt/deribit.py +1 -1
- ccxt/digifinex.py +1 -1
- ccxt/exmo.py +1 -1
- ccxt/gate.py +1 -1
- ccxt/gemini.py +1 -1
- ccxt/hashkey.py +1 -1
- ccxt/hitbtc.py +1 -1
- ccxt/hollaex.py +1 -1
- ccxt/htx.py +1 -1
- ccxt/huobijp.py +1 -1
- ccxt/idex.py +1 -1
- ccxt/independentreserve.py +1 -1
- ccxt/indodax.py +1 -1
- ccxt/kraken.py +44 -36
- ccxt/kucoin.py +1 -1
- ccxt/kuna.py +1 -1
- ccxt/lbank.py +6 -1
- ccxt/lykke.py +1 -1
- ccxt/mercado.py +1 -1
- ccxt/mexc.py +1 -1
- ccxt/ndax.py +1 -1
- ccxt/novadax.py +1 -1
- ccxt/okcoin.py +1 -1
- ccxt/okx.py +1 -1
- ccxt/onetrading.py +1 -1
- ccxt/oxfun.py +1 -1
- ccxt/phemex.py +1 -1
- ccxt/poloniex.py +1 -1
- ccxt/pro/__init__.py +1 -1
- ccxt/pro/binance.py +4 -5
- ccxt/pro/bitvavo.py +2 -1
- ccxt/pro/mexc.py +187 -30
- ccxt/probit.py +1 -1
- ccxt/tokocrypto.py +1 -1
- ccxt/upbit.py +1 -1
- ccxt/vertex.py +52 -8
- ccxt/wavesexchange.py +2 -1
- ccxt/whitebit.py +1 -1
- ccxt/woo.py +1 -1
- ccxt/woofipro.py +1 -1
- ccxt/xt.py +1 -1
- ccxt/yobit.py +2 -2
- ccxt/zaif.py +1 -1
- ccxt/zonda.py +1 -1
- {ccxt-4.4.27.dist-info → ccxt-4.4.29.dist-info}/METADATA +4 -4
- {ccxt-4.4.27.dist-info → ccxt-4.4.29.dist-info}/RECORD +156 -156
- {ccxt-4.4.27.dist-info → ccxt-4.4.29.dist-info}/LICENSE.txt +0 -0
- {ccxt-4.4.27.dist-info → ccxt-4.4.29.dist-info}/WHEEL +0 -0
- {ccxt-4.4.27.dist-info → ccxt-4.4.29.dist-info}/top_level.txt +0 -0
ccxt/async_support/bybit.py
CHANGED
@@ -410,21 +410,6 @@ class bybit(Exchange, ImplicitAPI):
|
|
410
410
|
'v5/broker/asset/query-sub-member-deposit-record': 10,
|
411
411
|
},
|
412
412
|
'post': {
|
413
|
-
# Legacy option USDC
|
414
|
-
'option/usdc/openapi/private/v1/place-order': 2.5,
|
415
|
-
'option/usdc/openapi/private/v1/replace-order': 2.5,
|
416
|
-
'option/usdc/openapi/private/v1/cancel-order': 2.5,
|
417
|
-
'option/usdc/openapi/private/v1/cancel-all': 2.5,
|
418
|
-
'option/usdc/openapi/private/v1/query-active-orders': 2.5,
|
419
|
-
'option/usdc/openapi/private/v1/query-order-history': 2.5,
|
420
|
-
'option/usdc/openapi/private/v1/execution-list': 2.5,
|
421
|
-
'option/usdc/openapi/private/v1/query-position': 2.5,
|
422
|
-
# Legacy perpetual swap USDC
|
423
|
-
'perpetual/usdc/openapi/private/v1/place-order': 2.5,
|
424
|
-
'perpetual/usdc/openapi/private/v1/replace-order': 2.5,
|
425
|
-
'perpetual/usdc/openapi/private/v1/cancel-order': 2.5,
|
426
|
-
'perpetual/usdc/openapi/private/v1/cancel-all': 2.5,
|
427
|
-
'perpetual/usdc/openapi/private/v1/position/leverage/save': 2.5,
|
428
413
|
# spot
|
429
414
|
'spot/v3/private/order': 2.5,
|
430
415
|
'spot/v3/private/cancel-order': 2.5,
|
@@ -2403,6 +2388,12 @@ class bybit(Exchange, ImplicitAPI):
|
|
2403
2388
|
fundingTimestamp = self.safe_integer(ticker, 'nextFundingTime')
|
2404
2389
|
markPrice = self.safe_number(ticker, 'markPrice')
|
2405
2390
|
indexPrice = self.safe_number(ticker, 'indexPrice')
|
2391
|
+
info = self.safe_dict(self.safe_market(marketId, market, None, 'swap'), 'info')
|
2392
|
+
fundingInterval = self.safe_integer(info, 'fundingInterval')
|
2393
|
+
intervalString = None
|
2394
|
+
if fundingInterval is not None:
|
2395
|
+
interval = self.parse_to_int(fundingInterval / 60)
|
2396
|
+
intervalString = str(interval) + 'h'
|
2406
2397
|
return {
|
2407
2398
|
'info': ticker,
|
2408
2399
|
'symbol': symbol,
|
@@ -2421,7 +2412,7 @@ class bybit(Exchange, ImplicitAPI):
|
|
2421
2412
|
'previousFundingRate': None,
|
2422
2413
|
'previousFundingTimestamp': None,
|
2423
2414
|
'previousFundingDatetime': None,
|
2424
|
-
'interval':
|
2415
|
+
'interval': intervalString,
|
2425
2416
|
}
|
2426
2417
|
|
2427
2418
|
async def fetch_funding_rates(self, symbols: Strings = None, params={}) -> FundingRates:
|
@@ -3482,11 +3473,8 @@ class bybit(Exchange, ImplicitAPI):
|
|
3482
3473
|
"""
|
3483
3474
|
await self.load_markets()
|
3484
3475
|
market = self.market(symbol)
|
3485
|
-
|
3486
|
-
|
3487
|
-
isUsdcSettled = market['settle'] == 'USDC'
|
3488
|
-
if isUsdcSettled and not isUnifiedAccount:
|
3489
|
-
return await self.create_usdc_order(symbol, type, side, amount, price, params)
|
3476
|
+
parts = await self.is_unified_enabled()
|
3477
|
+
enableUnifiedAccount = parts[1]
|
3490
3478
|
trailingAmount = self.safe_string_2(params, 'trailingAmount', 'trailingStop')
|
3491
3479
|
isTrailingAmountOrder = trailingAmount is not None
|
3492
3480
|
orderRequest = self.create_order_request(symbol, type, side, amount, price, params, enableUnifiedAccount)
|
@@ -3787,165 +3775,6 @@ class bybit(Exchange, ImplicitAPI):
|
|
3787
3775
|
#
|
3788
3776
|
return self.parse_orders(data)
|
3789
3777
|
|
3790
|
-
async def create_usdc_order(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={}):
|
3791
|
-
await self.load_markets()
|
3792
|
-
market = self.market(symbol)
|
3793
|
-
if type == 'market':
|
3794
|
-
raise NotSupported(self.id + ' createOrder does not allow market orders for ' + symbol + ' markets')
|
3795
|
-
lowerCaseType = type.lower()
|
3796
|
-
if (price is None) and (lowerCaseType == 'limit'):
|
3797
|
-
raise ArgumentsRequired(self.id + ' createOrder requires a price argument for limit orders')
|
3798
|
-
request: dict = {
|
3799
|
-
'symbol': market['id'],
|
3800
|
-
'side': self.capitalize(side),
|
3801
|
-
'orderType': self.capitalize(lowerCaseType), # limit or market
|
3802
|
-
'timeInForce': 'GoodTillCancel', # ImmediateOrCancel, FillOrKill, PostOnly
|
3803
|
-
'orderQty': self.get_amount(symbol, amount),
|
3804
|
-
# 'takeProfit': 123.45, # take profit price, only take effect upon opening the position
|
3805
|
-
# 'stopLoss': 123.45, # stop loss price, only take effect upon opening the position
|
3806
|
-
# 'reduceOnly': False, # reduce only, required for linear orders
|
3807
|
-
# when creating a closing order, bybit recommends a True value for
|
3808
|
-
# closeOnTrigger to avoid failing due to insufficient available margin
|
3809
|
-
# 'closeOnTrigger': False, required for linear orders
|
3810
|
-
# 'orderLinkId': 'string', # unique client order id, max 36 characters
|
3811
|
-
# 'triggerPrice': 123.45, # trigger price, required for conditional orders
|
3812
|
-
# 'trigger_by': 'MarkPrice', # IndexPrice, MarkPrice
|
3813
|
-
# 'tptriggerby': 'MarkPrice', # IndexPrice, MarkPrice
|
3814
|
-
# 'slTriggerBy': 'MarkPrice', # IndexPrice, MarkPrice
|
3815
|
-
# 'orderFilter': 'Order' or 'StopOrder'
|
3816
|
-
# 'mmp': False # market maker protection
|
3817
|
-
}
|
3818
|
-
isMarket = lowerCaseType == 'market'
|
3819
|
-
isLimit = lowerCaseType == 'limit'
|
3820
|
-
if isLimit is not None:
|
3821
|
-
request['orderPrice'] = self.get_price(symbol, self.number_to_string(price))
|
3822
|
-
exchangeSpecificParam = self.safe_string(params, 'time_in_force')
|
3823
|
-
timeInForce = self.safe_string_lower(params, 'timeInForce')
|
3824
|
-
postOnly = self.is_post_only(isMarket, exchangeSpecificParam == 'PostOnly', params)
|
3825
|
-
if postOnly:
|
3826
|
-
request['time_in_force'] = 'PostOnly'
|
3827
|
-
elif timeInForce == 'gtc':
|
3828
|
-
request['time_in_force'] = 'GoodTillCancel'
|
3829
|
-
elif timeInForce == 'fok':
|
3830
|
-
request['time_in_force'] = 'FillOrKill'
|
3831
|
-
elif timeInForce == 'ioc':
|
3832
|
-
request['time_in_force'] = 'ImmediateOrCancel'
|
3833
|
-
if market['swap']:
|
3834
|
-
triggerPrice = self.safe_value_2(params, 'stopPrice', 'triggerPrice')
|
3835
|
-
stopLossTriggerPrice = self.safe_value(params, 'stopLossPrice', triggerPrice)
|
3836
|
-
takeProfitTriggerPrice = self.safe_value(params, 'takeProfitPrice')
|
3837
|
-
stopLoss = self.safe_value(params, 'stopLoss')
|
3838
|
-
takeProfit = self.safe_value(params, 'takeProfit')
|
3839
|
-
isStopLossTriggerOrder = stopLossTriggerPrice is not None
|
3840
|
-
isTakeProfitTriggerOrder = takeProfitTriggerPrice is not None
|
3841
|
-
isStopLoss = stopLoss is not None
|
3842
|
-
isTakeProfit = takeProfit is not None
|
3843
|
-
isStopOrder = isStopLossTriggerOrder or isTakeProfitTriggerOrder
|
3844
|
-
if isStopOrder:
|
3845
|
-
request['orderFilter'] = 'StopOrder'
|
3846
|
-
request['trigger_by'] = 'LastPrice'
|
3847
|
-
stopPx = stopLossTriggerPrice if isStopLossTriggerOrder else takeProfitTriggerPrice
|
3848
|
-
preciseStopPrice = self.get_price(symbol, stopPx)
|
3849
|
-
request['triggerPrice'] = preciseStopPrice
|
3850
|
-
delta = self.number_to_string(market['precision']['price'])
|
3851
|
-
request['basePrice'] = Precise.string_sub(preciseStopPrice, delta) if isStopLossTriggerOrder else Precise.string_add(preciseStopPrice, delta)
|
3852
|
-
elif isStopLoss or isTakeProfit:
|
3853
|
-
if isStopLoss:
|
3854
|
-
slTriggerPrice = self.safe_value_2(stopLoss, 'triggerPrice', 'stopPrice', stopLoss)
|
3855
|
-
request['stopLoss'] = self.get_price(symbol, slTriggerPrice)
|
3856
|
-
if isTakeProfit:
|
3857
|
-
tpTriggerPrice = self.safe_value_2(takeProfit, 'triggerPrice', 'stopPrice', takeProfit)
|
3858
|
-
request['takeProfit'] = self.get_price(symbol, tpTriggerPrice)
|
3859
|
-
else:
|
3860
|
-
request['orderFilter'] = 'Order'
|
3861
|
-
clientOrderId = self.safe_string(params, 'clientOrderId')
|
3862
|
-
if clientOrderId is not None:
|
3863
|
-
request['orderLinkId'] = clientOrderId
|
3864
|
-
elif market['option']:
|
3865
|
-
# mandatory field for options
|
3866
|
-
request['orderLinkId'] = self.uuid16()
|
3867
|
-
params = self.omit(params, ['stopPrice', 'timeInForce', 'triggerPrice', 'stopLossPrice', 'takeProfitPrice', 'postOnly', 'clientOrderId'])
|
3868
|
-
response = None
|
3869
|
-
if market['option']:
|
3870
|
-
response = await self.privatePostOptionUsdcOpenapiPrivateV1PlaceOrder(self.extend(request, params))
|
3871
|
-
else:
|
3872
|
-
response = await self.privatePostPerpetualUsdcOpenapiPrivateV1PlaceOrder(self.extend(request, params))
|
3873
|
-
#
|
3874
|
-
# {
|
3875
|
-
# "retCode":0,
|
3876
|
-
# "retMsg":"",
|
3877
|
-
# "result":{
|
3878
|
-
# "orderId":"34450a59-325e-4296-8af0-63c7c524ae33",
|
3879
|
-
# "orderLinkId":"",
|
3880
|
-
# "mmp":false,
|
3881
|
-
# "symbol":"BTCPERP",
|
3882
|
-
# "orderType":"Limit",
|
3883
|
-
# "side":"Buy",
|
3884
|
-
# "orderQty":"0.00100000",
|
3885
|
-
# "orderPrice":"20000.00",
|
3886
|
-
# "iv":"0",
|
3887
|
-
# "timeInForce":"GoodTillCancel",
|
3888
|
-
# "orderStatus":"Created",
|
3889
|
-
# "createdAt":"1652261746007873",
|
3890
|
-
# "basePrice":"0.00",
|
3891
|
-
# "triggerPrice":"0.00",
|
3892
|
-
# "takeProfit":"0.00",
|
3893
|
-
# "stopLoss":"0.00",
|
3894
|
-
# "slTriggerBy":"UNKNOWN",
|
3895
|
-
# "tpTriggerBy":"UNKNOWN"
|
3896
|
-
# }
|
3897
|
-
#
|
3898
|
-
order = self.safe_dict(response, 'result', {})
|
3899
|
-
return self.parse_order(order, market)
|
3900
|
-
|
3901
|
-
async def edit_usdc_order(self, id, symbol, type, side, amount=None, price=None, params={}):
|
3902
|
-
await self.load_markets()
|
3903
|
-
market = self.market(symbol)
|
3904
|
-
request: dict = {
|
3905
|
-
'symbol': market['id'],
|
3906
|
-
'orderId': id,
|
3907
|
-
}
|
3908
|
-
if amount is not None:
|
3909
|
-
request['orderQty'] = self.get_amount(symbol, amount)
|
3910
|
-
if price is not None:
|
3911
|
-
request['orderPrice'] = self.get_price(symbol, price)
|
3912
|
-
response = None
|
3913
|
-
if market['option']:
|
3914
|
-
response = await self.privatePostOptionUsdcOpenapiPrivateV1ReplaceOrder(self.extend(request, params))
|
3915
|
-
else:
|
3916
|
-
isStop = self.safe_bool_2(params, 'stop', 'trigger', False)
|
3917
|
-
triggerPrice = self.safe_value_2(params, 'stopPrice', 'triggerPrice')
|
3918
|
-
stopLossPrice = self.safe_value(params, 'stopLossPrice')
|
3919
|
-
isStopLossOrder = stopLossPrice is not None
|
3920
|
-
takeProfitPrice = self.safe_value(params, 'takeProfitPrice')
|
3921
|
-
isTakeProfitOrder = takeProfitPrice is not None
|
3922
|
-
isStopOrder = isStopLossOrder or isTakeProfitOrder or isStop
|
3923
|
-
if isStopOrder:
|
3924
|
-
request['orderFilter'] = 'StopOrder' if isStop else 'Order'
|
3925
|
-
if triggerPrice is not None:
|
3926
|
-
request['triggerPrice'] = self.get_price(symbol, triggerPrice)
|
3927
|
-
if stopLossPrice is not None:
|
3928
|
-
request['stopLoss'] = self.get_price(symbol, stopLossPrice)
|
3929
|
-
if takeProfitPrice is not None:
|
3930
|
-
request['takeProfit'] = self.get_price(symbol, takeProfitPrice)
|
3931
|
-
params = self.omit(params, ['stop', 'stopPrice', 'triggerPrice', 'stopLossPrice', 'takeProfitPrice'])
|
3932
|
-
response = await self.privatePostPerpetualUsdcOpenapiPrivateV1ReplaceOrder(self.extend(request, params))
|
3933
|
-
#
|
3934
|
-
# {
|
3935
|
-
# "retCode": 0,
|
3936
|
-
# "retMsg": "OK",
|
3937
|
-
# "result": {
|
3938
|
-
# "outRequestId": "",
|
3939
|
-
# "symbol": "BTC-13MAY22-40000-C",
|
3940
|
-
# "orderId": "8c65df91-91fc-461d-9b14-786379ef138c",
|
3941
|
-
# "orderLinkId": "AAAAA41133"
|
3942
|
-
# },
|
3943
|
-
# "retExtMap": {}
|
3944
|
-
# }
|
3945
|
-
#
|
3946
|
-
result = self.safe_dict(response, 'result', {})
|
3947
|
-
return self.parse_order(result, market)
|
3948
|
-
|
3949
3778
|
def edit_order_request(self, id: str, symbol: str, type: OrderType, side: OrderSide, amount: Num = None, price: Num = None, params={}):
|
3950
3779
|
market = self.market(symbol)
|
3951
3780
|
request: dict = {
|
@@ -4034,14 +3863,8 @@ class bybit(Exchange, ImplicitAPI):
|
|
4034
3863
|
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
|
4035
3864
|
"""
|
4036
3865
|
await self.load_markets()
|
4037
|
-
market = self.market(symbol)
|
4038
3866
|
if symbol is None:
|
4039
3867
|
raise ArgumentsRequired(self.id + ' editOrder() requires a symbol argument')
|
4040
|
-
enableUnifiedMargin, enableUnifiedAccount = await self.is_unified_enabled()
|
4041
|
-
isUnifiedAccount = (enableUnifiedMargin or enableUnifiedAccount)
|
4042
|
-
isUsdcSettled = market['settle'] == 'USDC'
|
4043
|
-
if isUsdcSettled and not isUnifiedAccount:
|
4044
|
-
return await self.edit_usdc_order(id, symbol, type, side, amount, price, params)
|
4045
3868
|
request = self.edit_order_request(id, symbol, type, side, amount, price, params)
|
4046
3869
|
response = await self.privatePostV5OrderAmend(self.extend(request, params))
|
4047
3870
|
#
|
@@ -4062,42 +3885,6 @@ class bybit(Exchange, ImplicitAPI):
|
|
4062
3885
|
'id': self.safe_string(result, 'orderId'),
|
4063
3886
|
})
|
4064
3887
|
|
4065
|
-
async def cancel_usdc_order(self, id, symbol: Str = None, params={}):
|
4066
|
-
if symbol is None:
|
4067
|
-
raise ArgumentsRequired(self.id + ' cancelUsdcOrder() requires a symbol argument')
|
4068
|
-
await self.load_markets()
|
4069
|
-
market = self.market(symbol)
|
4070
|
-
request: dict = {
|
4071
|
-
'symbol': market['id'],
|
4072
|
-
# 'orderLinkId': 'string', # one of order_id, stop_order_id or order_link_id is required
|
4073
|
-
# 'orderId': id,
|
4074
|
-
}
|
4075
|
-
isStop = self.safe_bool_2(params, 'stop', 'trigger', False)
|
4076
|
-
params = self.omit(params, ['stop', 'trigger'])
|
4077
|
-
if id is not None: # The user can also use argument params["order_link_id"]
|
4078
|
-
request['orderId'] = id
|
4079
|
-
response = None
|
4080
|
-
if market['option']:
|
4081
|
-
response = await self.privatePostOptionUsdcOpenapiPrivateV1CancelOrder(self.extend(request, params))
|
4082
|
-
else:
|
4083
|
-
request['orderFilter'] = 'StopOrder' if isStop else 'Order'
|
4084
|
-
response = await self.privatePostPerpetualUsdcOpenapiPrivateV1CancelOrder(self.extend(request, params))
|
4085
|
-
#
|
4086
|
-
# {
|
4087
|
-
# "retCode": 0,
|
4088
|
-
# "retMsg": "OK",
|
4089
|
-
# "result": {
|
4090
|
-
# "outRequestId": "",
|
4091
|
-
# "symbol": "BTC-13MAY22-40000-C",
|
4092
|
-
# "orderId": "8c65df91-91fc-461d-9b14-786379ef138c",
|
4093
|
-
# "orderLinkId": ""
|
4094
|
-
# },
|
4095
|
-
# "retExtMap": {}
|
4096
|
-
# }
|
4097
|
-
#
|
4098
|
-
result = self.safe_dict(response, 'result', {})
|
4099
|
-
return self.parse_order(result, market)
|
4100
|
-
|
4101
3888
|
def cancel_order_request(self, id: str, symbol: Str = None, params={}):
|
4102
3889
|
market = self.market(symbol)
|
4103
3890
|
request: dict = {
|
@@ -4109,9 +3896,9 @@ class bybit(Exchange, ImplicitAPI):
|
|
4109
3896
|
}
|
4110
3897
|
if market['spot']:
|
4111
3898
|
# only works for spot market
|
4112
|
-
|
3899
|
+
isTrigger = self.safe_bool_2(params, 'stop', 'trigger', False)
|
4113
3900
|
params = self.omit(params, ['stop', 'trigger'])
|
4114
|
-
request['orderFilter'] = 'StopOrder' if
|
3901
|
+
request['orderFilter'] = 'StopOrder' if isTrigger else 'Order'
|
4115
3902
|
if id is not None: # The user can also use argument params["orderLinkId"]
|
4116
3903
|
request['orderId'] = id
|
4117
3904
|
if market['spot']:
|
@@ -4131,7 +3918,8 @@ class bybit(Exchange, ImplicitAPI):
|
|
4131
3918
|
:param str id: order id
|
4132
3919
|
:param str symbol: unified symbol of the market the order was made in
|
4133
3920
|
:param dict [params]: extra parameters specific to the exchange API endpoint
|
4134
|
-
:param boolean [params.
|
3921
|
+
:param boolean [params.trigger]: *spot only* whether the order is a trigger order
|
3922
|
+
:param boolean [params.stop]: alias for trigger
|
4135
3923
|
:param str [params.orderFilter]: *spot only* 'Order' or 'StopOrder' or 'tpslOrder'
|
4136
3924
|
:returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
|
4137
3925
|
"""
|
@@ -4139,11 +3927,6 @@ class bybit(Exchange, ImplicitAPI):
|
|
4139
3927
|
raise ArgumentsRequired(self.id + ' cancelOrder() requires a symbol argument')
|
4140
3928
|
await self.load_markets()
|
4141
3929
|
market = self.market(symbol)
|
4142
|
-
enableUnifiedMargin, enableUnifiedAccount = await self.is_unified_enabled()
|
4143
|
-
isUnifiedAccount = (enableUnifiedMargin or enableUnifiedAccount)
|
4144
|
-
isUsdcSettled = market['settle'] == 'USDC'
|
4145
|
-
if isUsdcSettled and not isUnifiedAccount:
|
4146
|
-
return await self.cancel_usdc_order(id, symbol, params)
|
4147
3930
|
requestExtended = self.cancel_order_request(id, symbol, params)
|
4148
3931
|
response = await self.privatePostV5OrderCancel(requestExtended)
|
4149
3932
|
#
|
@@ -4351,54 +4134,14 @@ class bybit(Exchange, ImplicitAPI):
|
|
4351
4134
|
row = self.safe_list(result, 'list', [])
|
4352
4135
|
return self.parse_orders(row, None)
|
4353
4136
|
|
4354
|
-
async def cancel_all_usdc_orders(self, symbol: Str = None, params={}):
|
4355
|
-
if symbol is None:
|
4356
|
-
raise ArgumentsRequired(self.id + ' cancelAllUsdcOrders() requires a symbol argument')
|
4357
|
-
await self.load_markets()
|
4358
|
-
market = self.market(symbol)
|
4359
|
-
request: dict = {
|
4360
|
-
'symbol': market['id'],
|
4361
|
-
}
|
4362
|
-
response = None
|
4363
|
-
if market['option']:
|
4364
|
-
response = await self.privatePostOptionUsdcOpenapiPrivateV1CancelAll(self.extend(request, params))
|
4365
|
-
else:
|
4366
|
-
isStop = self.safe_bool_2(params, 'stop', 'trigger', False)
|
4367
|
-
if isStop:
|
4368
|
-
request['orderFilter'] = 'StopOrder'
|
4369
|
-
else:
|
4370
|
-
request['orderFilter'] = 'Order'
|
4371
|
-
params = self.omit(params, ['stop', 'trigger'])
|
4372
|
-
response = await self.privatePostPerpetualUsdcOpenapiPrivateV1CancelAll(self.extend(request, params))
|
4373
|
-
#
|
4374
|
-
# {
|
4375
|
-
# "retCode": 0,
|
4376
|
-
# "retMsg": "OK",
|
4377
|
-
# "retExtMap": {},
|
4378
|
-
# "result": [
|
4379
|
-
# {
|
4380
|
-
# "outRequestId": "cancelAll-290119-1652176443114-0",
|
4381
|
-
# "symbol": "BTC-13MAY22-40000-C",
|
4382
|
-
# "orderId": "fa6cd740-56ed-477d-9385-90ccbfee49ca",
|
4383
|
-
# "orderLinkId": "",
|
4384
|
-
# "errorCode": 0,
|
4385
|
-
# "errorDesc": ""
|
4386
|
-
# }
|
4387
|
-
# ]
|
4388
|
-
# }
|
4389
|
-
#
|
4390
|
-
result = self.safe_value(response, 'result', [])
|
4391
|
-
if not isinstance(result, list):
|
4392
|
-
return response
|
4393
|
-
return self.parse_orders(result, market)
|
4394
|
-
|
4395
4137
|
async def cancel_all_orders(self, symbol: Str = None, params={}):
|
4396
4138
|
"""
|
4397
4139
|
cancel all open orders
|
4398
4140
|
:see: https://bybit-exchange.github.io/docs/v5/order/cancel-all
|
4399
4141
|
:param str symbol: unified market symbol, only orders in the market of self symbol are cancelled when symbol is not None
|
4400
4142
|
:param dict [params]: extra parameters specific to the exchange API endpoint
|
4401
|
-
:param boolean [params.
|
4143
|
+
:param boolean [params.trigger]: True if trigger order
|
4144
|
+
:param boolean [params.stop]: alias for trigger
|
4402
4145
|
:param str [params.type]: market type, ['swap', 'option', 'spot']
|
4403
4146
|
:param str [params.subType]: market subType, ['linear', 'inverse']
|
4404
4147
|
:param str [params.baseCoin]: Base coin. Supports linear, inverse & option
|
@@ -4412,9 +4155,6 @@ class bybit(Exchange, ImplicitAPI):
|
|
4412
4155
|
request: dict = {}
|
4413
4156
|
if symbol is not None:
|
4414
4157
|
market = self.market(symbol)
|
4415
|
-
isUsdcSettled = market['settle'] == 'USDC'
|
4416
|
-
if isUsdcSettled and not isUnifiedAccount:
|
4417
|
-
return await self.cancel_all_usdc_orders(symbol, params)
|
4418
4158
|
request['symbol'] = market['id']
|
4419
4159
|
type = None
|
4420
4160
|
type, params = self.get_bybit_type('cancelAllOrders', market, params)
|
@@ -4426,9 +4166,9 @@ class bybit(Exchange, ImplicitAPI):
|
|
4426
4166
|
if symbol is None and baseCoin is None:
|
4427
4167
|
defaultSettle = self.safe_string(self.options, 'defaultSettle', 'USDT')
|
4428
4168
|
request['settleCoin'] = self.safe_string(params, 'settleCoin', defaultSettle)
|
4429
|
-
|
4169
|
+
isTrigger = self.safe_bool_2(params, 'stop', 'trigger', False)
|
4430
4170
|
params = self.omit(params, ['stop', 'trigger'])
|
4431
|
-
if
|
4171
|
+
if isTrigger:
|
4432
4172
|
request['orderFilter'] = 'StopOrder'
|
4433
4173
|
response = await self.privatePostV5OrderCancelAll(self.extend(request, params))
|
4434
4174
|
#
|
@@ -4465,88 +4205,6 @@ class bybit(Exchange, ImplicitAPI):
|
|
4465
4205
|
return response
|
4466
4206
|
return self.parse_orders(orders, market)
|
4467
4207
|
|
4468
|
-
async def fetch_usdc_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}):
|
4469
|
-
await self.load_markets()
|
4470
|
-
market = None
|
4471
|
-
request: dict = {
|
4472
|
-
# 'category': '', # Type. PERPETUAL, OPTION
|
4473
|
-
# 'symbol': '', # Contract name
|
4474
|
-
# 'baseCoin': '', # Base currency
|
4475
|
-
# 'orderId': '', # Order ID
|
4476
|
-
# 'orderLinkId': '', # Custom ID used for cross-platform strategy remarks; a max. of 32 characters
|
4477
|
-
# 'orderStatus': '', # Order status
|
4478
|
-
# 'orderFilter': '', # refer to Order Filter
|
4479
|
-
# 'direction': '', # prev: prev page, next: next page.
|
4480
|
-
# 'limit': 0, # Limit for data size per page, max size is 50. Default 20 pieces of data per page
|
4481
|
-
# 'cursor': '', # API pass-through
|
4482
|
-
}
|
4483
|
-
if symbol is not None:
|
4484
|
-
market = self.market(symbol)
|
4485
|
-
request['symbol'] = market['id']
|
4486
|
-
type = None
|
4487
|
-
type, params = self.handle_market_type_and_params('fetchOrders', market, params)
|
4488
|
-
if type == 'swap':
|
4489
|
-
request['category'] = 'PERPETUAL'
|
4490
|
-
else:
|
4491
|
-
request['category'] = 'OPTION'
|
4492
|
-
isStop = self.safe_bool_2(params, 'stop', 'trigger', False)
|
4493
|
-
params = self.omit(params, ['stop', 'trigger'])
|
4494
|
-
if isStop:
|
4495
|
-
request['orderFilter'] = 'StopOrder'
|
4496
|
-
if limit is not None:
|
4497
|
-
request['limit'] = limit
|
4498
|
-
response = await self.privatePostOptionUsdcOpenapiPrivateV1QueryOrderHistory(self.extend(request, params))
|
4499
|
-
#
|
4500
|
-
# {
|
4501
|
-
# "result": {
|
4502
|
-
# "cursor": "640034d1-97ec-4382-9983-694898c03ba3%3A1640854950675%2C640034d1-97ec-4382-9983-694898c03ba3%3A1640854950675",
|
4503
|
-
# "resultTotalSize": 1,
|
4504
|
-
# "dataList": [
|
4505
|
-
# {
|
4506
|
-
# "symbol": "ETHPERP",
|
4507
|
-
# "orderType": "Limit",
|
4508
|
-
# "orderLinkId": "",
|
4509
|
-
# "orderId": "c04ad17d-ca85-45d1-859e-561e7236f6db",
|
4510
|
-
# "cancelType": "UNKNOWN",
|
4511
|
-
# "stopOrderType": "UNKNOWN",
|
4512
|
-
# "orderStatus": "Filled",
|
4513
|
-
# "updateTimeStamp": "1666178097006",
|
4514
|
-
# "takeProfit": "0.0000",
|
4515
|
-
# "cumExecValue": "12.9825",
|
4516
|
-
# "createdAt": "1666178096996",
|
4517
|
-
# "blockTradeId": "",
|
4518
|
-
# "orderPnl": "",
|
4519
|
-
# "price": "1300.0",
|
4520
|
-
# "tpTriggerBy": "UNKNOWN",
|
4521
|
-
# "timeInForce": "GoodTillCancel",
|
4522
|
-
# "updatedAt": "1666178097006",
|
4523
|
-
# "basePrice": "",
|
4524
|
-
# "realisedPnl": "0.0000",
|
4525
|
-
# "side": "Buy",
|
4526
|
-
# "triggerPrice": "0.0",
|
4527
|
-
# "cumExecFee": "0.0078",
|
4528
|
-
# "leavesQty": "0.000",
|
4529
|
-
# "cashFlow": "",
|
4530
|
-
# "slTriggerBy": "UNKNOWN",
|
4531
|
-
# "iv": "",
|
4532
|
-
# "closeOnTrigger": "UNKNOWN",
|
4533
|
-
# "cumExecQty": "0.010",
|
4534
|
-
# "reduceOnly": 0,
|
4535
|
-
# "qty": "0.010",
|
4536
|
-
# "stopLoss": "0.0000",
|
4537
|
-
# "triggerBy": "UNKNOWN",
|
4538
|
-
# "orderIM": ""
|
4539
|
-
# }
|
4540
|
-
# ]
|
4541
|
-
# },
|
4542
|
-
# "retCode": 0,
|
4543
|
-
# "retMsg": "Success."
|
4544
|
-
# }
|
4545
|
-
#
|
4546
|
-
result = self.safe_dict(response, 'result', {})
|
4547
|
-
data = self.safe_list(result, 'dataList', [])
|
4548
|
-
return self.parse_orders(data, market, since, limit)
|
4549
|
-
|
4550
4208
|
async def fetch_order_classic(self, id: str, symbol: Str = None, params={}):
|
4551
4209
|
"""
|
4552
4210
|
fetches information on an order made by the user *classic accounts only*
|
@@ -4673,7 +4331,8 @@ class bybit(Exchange, ImplicitAPI):
|
|
4673
4331
|
:param int [since]: the earliest time in ms to fetch orders for
|
4674
4332
|
:param int [limit]: the maximum number of order structures to retrieve
|
4675
4333
|
:param dict [params]: extra parameters specific to the exchange API endpoint
|
4676
|
-
:param boolean [params.
|
4334
|
+
:param boolean [params.trigger]: True if trigger order
|
4335
|
+
:param boolean [params.stop]: alias for trigger
|
4677
4336
|
:param str [params.type]: market type, ['swap', 'option']
|
4678
4337
|
:param str [params.subType]: market subType, ['linear', 'inverse']
|
4679
4338
|
:param str [params.orderFilter]: 'Order' or 'StopOrder' or 'tpslOrder'
|
@@ -4694,7 +4353,8 @@ class bybit(Exchange, ImplicitAPI):
|
|
4694
4353
|
:param int [since]: the earliest time in ms to fetch orders for
|
4695
4354
|
:param int [limit]: the maximum number of order structures to retrieve
|
4696
4355
|
:param dict [params]: extra parameters specific to the exchange API endpoint
|
4697
|
-
:param boolean [params.
|
4356
|
+
:param boolean [params.trigger]: True if trigger order
|
4357
|
+
:param boolean [params.stop]: alias for trigger
|
4698
4358
|
:param str [params.type]: market type, ['swap', 'option', 'spot']
|
4699
4359
|
:param str [params.subType]: market subType, ['linear', 'inverse']
|
4700
4360
|
:param str [params.orderFilter]: 'Order' or 'StopOrder' or 'tpslOrder'
|
@@ -4707,25 +4367,19 @@ class bybit(Exchange, ImplicitAPI):
|
|
4707
4367
|
paginate, params = self.handle_option_and_params(params, 'fetchOrders', 'paginate')
|
4708
4368
|
if paginate:
|
4709
4369
|
return await self.fetch_paginated_call_cursor('fetchOrders', symbol, since, limit, params, 'nextPageCursor', 'cursor', None, 50)
|
4710
|
-
enableUnifiedMargin, enableUnifiedAccount = await self.is_unified_enabled()
|
4711
|
-
isUnifiedAccount = (enableUnifiedMargin or enableUnifiedAccount)
|
4712
4370
|
request: dict = {}
|
4713
4371
|
market = None
|
4714
|
-
isUsdcSettled = False
|
4715
4372
|
if symbol is not None:
|
4716
4373
|
market = self.market(symbol)
|
4717
|
-
isUsdcSettled = market['settle'] == 'USDC'
|
4718
4374
|
request['symbol'] = market['id']
|
4719
4375
|
type = None
|
4720
4376
|
type, params = self.get_bybit_type('fetchOrders', market, params)
|
4721
|
-
if ((type == 'option') or isUsdcSettled) and not isUnifiedAccount:
|
4722
|
-
return await self.fetch_usdc_orders(symbol, since, limit, params)
|
4723
4377
|
if type == 'spot':
|
4724
4378
|
raise NotSupported(self.id + ' fetchOrders() is not supported for spot markets')
|
4725
4379
|
request['category'] = type
|
4726
|
-
|
4380
|
+
isTrigger = self.safe_bool_n(params, ['trigger', 'stop'], False)
|
4727
4381
|
params = self.omit(params, ['trigger', 'stop'])
|
4728
|
-
if
|
4382
|
+
if isTrigger:
|
4729
4383
|
request['orderFilter'] = 'StopOrder'
|
4730
4384
|
if limit is not None:
|
4731
4385
|
request['limit'] = limit
|
@@ -4797,7 +4451,8 @@ class bybit(Exchange, ImplicitAPI):
|
|
4797
4451
|
:param str id: order id
|
4798
4452
|
:param str [symbol]: unified symbol of the market the order was made in
|
4799
4453
|
:param dict [params]: extra parameters specific to the exchange API endpoint
|
4800
|
-
:param boolean [params.
|
4454
|
+
:param boolean [params.trigger]: set to True for fetching a closed trigger order
|
4455
|
+
:param boolean [params.stop]: alias for trigger
|
4801
4456
|
:param str [params.type]: market type, ['swap', 'option', 'spot']
|
4802
4457
|
:param str [params.subType]: market subType, ['linear', 'inverse']
|
4803
4458
|
:param str [params.orderFilter]: 'Order' or 'StopOrder' or 'tpslOrder'
|
@@ -4824,7 +4479,8 @@ class bybit(Exchange, ImplicitAPI):
|
|
4824
4479
|
:param str id: order id
|
4825
4480
|
:param str [symbol]: unified symbol of the market the order was made in
|
4826
4481
|
:param dict [params]: extra parameters specific to the exchange API endpoint
|
4827
|
-
:param boolean [params.
|
4482
|
+
:param boolean [params.trigger]: set to True for fetching an open trigger order
|
4483
|
+
:param boolean [params.stop]: alias for trigger
|
4828
4484
|
:param str [params.type]: market type, ['swap', 'option', 'spot']
|
4829
4485
|
:param str [params.subType]: market subType, ['linear', 'inverse']
|
4830
4486
|
:param str [params.baseCoin]: Base coin. Supports linear, inverse & option
|
@@ -4854,7 +4510,8 @@ class bybit(Exchange, ImplicitAPI):
|
|
4854
4510
|
:param int [since]: the earliest time in ms to fetch orders for
|
4855
4511
|
:param int [limit]: the maximum number of order structures to retrieve
|
4856
4512
|
:param dict [params]: extra parameters specific to the exchange API endpoint
|
4857
|
-
:param boolean [params.
|
4513
|
+
:param boolean [params.trigger]: set to True for fetching trigger orders
|
4514
|
+
:param boolean [params.stop]: alias for trigger
|
4858
4515
|
:param str [params.type]: market type, ['swap', 'option', 'spot']
|
4859
4516
|
:param str [params.subType]: market subType, ['linear', 'inverse']
|
4860
4517
|
:param str [params.orderFilter]: 'Order' or 'StopOrder' or 'tpslOrder'
|
@@ -4867,23 +4524,17 @@ class bybit(Exchange, ImplicitAPI):
|
|
4867
4524
|
paginate, params = self.handle_option_and_params(params, 'fetchCanceledAndClosedOrders', 'paginate')
|
4868
4525
|
if paginate:
|
4869
4526
|
return await self.fetch_paginated_call_cursor('fetchCanceledAndClosedOrders', symbol, since, limit, params, 'nextPageCursor', 'cursor', None, 50)
|
4870
|
-
enableUnifiedMargin, enableUnifiedAccount = await self.is_unified_enabled()
|
4871
|
-
isUnifiedAccount = (enableUnifiedMargin or enableUnifiedAccount)
|
4872
4527
|
request: dict = {}
|
4873
4528
|
market = None
|
4874
|
-
isUsdcSettled = False
|
4875
4529
|
if symbol is not None:
|
4876
4530
|
market = self.market(symbol)
|
4877
|
-
isUsdcSettled = market['settle'] == 'USDC'
|
4878
4531
|
request['symbol'] = market['id']
|
4879
4532
|
type = None
|
4880
4533
|
type, params = self.get_bybit_type('fetchCanceledAndClosedOrders', market, params)
|
4881
|
-
if ((type == 'option') or isUsdcSettled) and not isUnifiedAccount:
|
4882
|
-
return await self.fetch_usdc_orders(symbol, since, limit, params)
|
4883
4534
|
request['category'] = type
|
4884
|
-
|
4535
|
+
isTrigger = self.safe_bool_n(params, ['trigger', 'stop'], False)
|
4885
4536
|
params = self.omit(params, ['trigger', 'stop'])
|
4886
|
-
if
|
4537
|
+
if isTrigger:
|
4887
4538
|
request['orderFilter'] = 'StopOrder'
|
4888
4539
|
if limit is not None:
|
4889
4540
|
request['limit'] = limit
|
@@ -4956,7 +4607,8 @@ class bybit(Exchange, ImplicitAPI):
|
|
4956
4607
|
:param int [since]: the earliest time in ms to fetch orders for
|
4957
4608
|
:param int [limit]: the maximum number of order structures to retrieve
|
4958
4609
|
:param dict [params]: extra parameters specific to the exchange API endpoint
|
4959
|
-
:param boolean [params.
|
4610
|
+
:param boolean [params.trigger]: set to True for fetching closed trigger orders
|
4611
|
+
:param boolean [params.stop]: alias for trigger
|
4960
4612
|
:param str [params.type]: market type, ['swap', 'option', 'spot']
|
4961
4613
|
:param str [params.subType]: market subType, ['linear', 'inverse']
|
4962
4614
|
:param str [params.orderFilter]: 'Order' or 'StopOrder' or 'tpslOrder'
|
@@ -4978,7 +4630,8 @@ class bybit(Exchange, ImplicitAPI):
|
|
4978
4630
|
:param int [since]: timestamp in ms of the earliest order, default is None
|
4979
4631
|
:param int [limit]: max number of orders to return, default is None
|
4980
4632
|
:param dict [params]: extra parameters specific to the exchange API endpoint
|
4981
|
-
:param boolean [params.
|
4633
|
+
:param boolean [params.trigger]: True if trigger order
|
4634
|
+
:param boolean [params.stop]: alias for trigger
|
4982
4635
|
:param str [params.type]: market type, ['swap', 'option', 'spot']
|
4983
4636
|
:param str [params.subType]: market subType, ['linear', 'inverse']
|
4984
4637
|
:param str [params.orderFilter]: 'Order' or 'StopOrder' or 'tpslOrder'
|
@@ -4992,47 +4645,6 @@ class bybit(Exchange, ImplicitAPI):
|
|
4992
4645
|
}
|
4993
4646
|
return await self.fetch_canceled_and_closed_orders(symbol, since, limit, self.extend(request, params))
|
4994
4647
|
|
4995
|
-
async def fetch_usdc_open_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}):
|
4996
|
-
await self.load_markets()
|
4997
|
-
request: dict = {}
|
4998
|
-
market = None
|
4999
|
-
if symbol is not None:
|
5000
|
-
market = self.market(symbol)
|
5001
|
-
request['symbol'] = market['id']
|
5002
|
-
type = None
|
5003
|
-
type, params = self.handle_market_type_and_params('fetchUsdcOpenOrders', market, params)
|
5004
|
-
request['category'] = 'perpetual' if (type == 'swap') else 'option'
|
5005
|
-
response = await self.privatePostOptionUsdcOpenapiPrivateV1QueryActiveOrders(self.extend(request, params))
|
5006
|
-
result = self.safe_dict(response, 'result', {})
|
5007
|
-
orders = self.safe_list(result, 'dataList', [])
|
5008
|
-
#
|
5009
|
-
# {
|
5010
|
-
# "retCode": 0,
|
5011
|
-
# "retMsg": "OK",
|
5012
|
-
# "result": {
|
5013
|
-
# "resultTotalSize": 1,
|
5014
|
-
# "cursor": "id%3D1662019818569%23df31e03b-fc00-4b4c-bd1c-b97fd72b5c5c",
|
5015
|
-
# "dataList": [
|
5016
|
-
# {
|
5017
|
-
# "orderId": "df31e03b-fc00-4b4c-bd1c-b97fd72b5c5c",
|
5018
|
-
# "orderLinkId": "",
|
5019
|
-
# "symbol": "BTC-2SEP22-18000-C",
|
5020
|
-
# "orderStatus": "New",
|
5021
|
-
# "orderPrice": "500",
|
5022
|
-
# "side": "Buy",
|
5023
|
-
# "remainingQty": "0.1",
|
5024
|
-
# "orderType": "Limit",
|
5025
|
-
# "qty": "0.1",
|
5026
|
-
# "iv": "0.0000",
|
5027
|
-
# "cancelType": "",
|
5028
|
-
# "updateTimestamp": "1662019818579"
|
5029
|
-
# }
|
5030
|
-
# ]
|
5031
|
-
# }
|
5032
|
-
# }
|
5033
|
-
#
|
5034
|
-
return self.parse_orders(orders, market, since, limit)
|
5035
|
-
|
5036
4648
|
async def fetch_open_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Order]:
|
5037
4649
|
"""
|
5038
4650
|
fetch all unfilled currently open orders
|
@@ -5041,7 +4653,8 @@ class bybit(Exchange, ImplicitAPI):
|
|
5041
4653
|
:param int [since]: the earliest time in ms to fetch open orders for
|
5042
4654
|
:param int [limit]: the maximum number of open orders structures to retrieve
|
5043
4655
|
:param dict [params]: extra parameters specific to the exchange API endpoint
|
5044
|
-
:param boolean [params.
|
4656
|
+
:param boolean [params.trigger]: set to True for fetching open trigger orders
|
4657
|
+
:param boolean [params.stop]: alias for trigger
|
5045
4658
|
:param str [params.type]: market type, ['swap', 'option', 'spot']
|
5046
4659
|
:param str [params.subType]: market subType, ['linear', 'inverse']
|
5047
4660
|
:param str [params.baseCoin]: Base coin. Supports linear, inverse & option
|
@@ -5055,14 +4668,10 @@ class bybit(Exchange, ImplicitAPI):
|
|
5055
4668
|
paginate, params = self.handle_option_and_params(params, 'fetchOpenOrders', 'paginate')
|
5056
4669
|
if paginate:
|
5057
4670
|
return await self.fetch_paginated_call_cursor('fetchOpenOrders', symbol, since, limit, params, 'nextPageCursor', 'cursor', None, 50)
|
5058
|
-
enableUnifiedMargin, enableUnifiedAccount = await self.is_unified_enabled()
|
5059
|
-
isUnifiedAccount = (enableUnifiedMargin or enableUnifiedAccount)
|
5060
4671
|
request: dict = {}
|
5061
4672
|
market = None
|
5062
|
-
isUsdcSettled = False
|
5063
4673
|
if symbol is not None:
|
5064
4674
|
market = self.market(symbol)
|
5065
|
-
isUsdcSettled = market['settle'] == 'USDC'
|
5066
4675
|
request['symbol'] = market['id']
|
5067
4676
|
type = None
|
5068
4677
|
type, params = self.get_bybit_type('fetchOpenOrders', market, params)
|
@@ -5072,13 +4681,10 @@ class bybit(Exchange, ImplicitAPI):
|
|
5072
4681
|
defaultSettle = self.safe_string(self.options, 'defaultSettle', 'USDT')
|
5073
4682
|
settleCoin = self.safe_string(params, 'settleCoin', defaultSettle)
|
5074
4683
|
request['settleCoin'] = settleCoin
|
5075
|
-
isUsdcSettled = (settleCoin == 'USDC')
|
5076
|
-
if ((type == 'option') or isUsdcSettled) and not isUnifiedAccount:
|
5077
|
-
return await self.fetch_usdc_open_orders(symbol, since, limit, params)
|
5078
4684
|
request['category'] = type
|
5079
|
-
|
4685
|
+
isTrigger = self.safe_bool_2(params, 'stop', 'trigger', False)
|
5080
4686
|
params = self.omit(params, ['stop', 'trigger'])
|
5081
|
-
if
|
4687
|
+
if isTrigger:
|
5082
4688
|
request['orderFilter'] = 'StopOrder'
|
5083
4689
|
if limit is not None:
|
5084
4690
|
request['limit'] = limit
|
@@ -5155,49 +4761,6 @@ class bybit(Exchange, ImplicitAPI):
|
|
5155
4761
|
params = self.omit(params, ['clientOrderId', 'orderLinkId'])
|
5156
4762
|
return await self.fetch_my_trades(symbol, since, limit, self.extend(request, params))
|
5157
4763
|
|
5158
|
-
async def fetch_my_usdc_trades(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}):
|
5159
|
-
await self.load_markets()
|
5160
|
-
market = None
|
5161
|
-
request: dict = {}
|
5162
|
-
if symbol is not None:
|
5163
|
-
market = self.market(symbol)
|
5164
|
-
request['symbol'] = market['id']
|
5165
|
-
request['category'] = 'OPTION' if market['option'] else 'PERPETUAL'
|
5166
|
-
else:
|
5167
|
-
request['category'] = 'PERPETUAL'
|
5168
|
-
response = await self.privatePostOptionUsdcOpenapiPrivateV1ExecutionList(self.extend(request, params))
|
5169
|
-
#
|
5170
|
-
# {
|
5171
|
-
# "result": {
|
5172
|
-
# "cursor": "29%3A1%2C28%3A1",
|
5173
|
-
# "resultTotalSize": 2,
|
5174
|
-
# "dataList": [
|
5175
|
-
# {
|
5176
|
-
# "symbol": "ETHPERP",
|
5177
|
-
# "orderLinkId": "",
|
5178
|
-
# "side": "Sell",
|
5179
|
-
# "orderId": "d83f8b4d-2f60-4e04-a64a-a3f207989dc6",
|
5180
|
-
# "execFee": "0.0210",
|
5181
|
-
# "feeRate": "0.000600",
|
5182
|
-
# "blockTradeId": "",
|
5183
|
-
# "tradeTime": "1669196423581",
|
5184
|
-
# "execPrice": "1161.45",
|
5185
|
-
# "lastLiquidityInd": "TAKER",
|
5186
|
-
# "execValue": "34.8435",
|
5187
|
-
# "execType": "Trade",
|
5188
|
-
# "execQty": "0.030",
|
5189
|
-
# "tradeId": "d9aa8590-9e6a-575e-a1be-d6261e6ed2e5"
|
5190
|
-
# }, ...
|
5191
|
-
# ]
|
5192
|
-
# },
|
5193
|
-
# "retCode": 0,
|
5194
|
-
# "retMsg": "Success."
|
5195
|
-
# }
|
5196
|
-
#
|
5197
|
-
result = self.safe_dict(response, 'result', {})
|
5198
|
-
dataList = self.safe_list(result, 'dataList', [])
|
5199
|
-
return self.parse_trades(dataList, market, since, limit)
|
5200
|
-
|
5201
4764
|
async def fetch_my_trades(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}):
|
5202
4765
|
"""
|
5203
4766
|
fetch all trades made by the user
|
@@ -5216,21 +4779,15 @@ class bybit(Exchange, ImplicitAPI):
|
|
5216
4779
|
paginate, params = self.handle_option_and_params(params, 'fetchMyTrades', 'paginate')
|
5217
4780
|
if paginate:
|
5218
4781
|
return await self.fetch_paginated_call_cursor('fetchMyTrades', symbol, since, limit, params, 'nextPageCursor', 'cursor', None, 100)
|
5219
|
-
enableUnifiedMargin, enableUnifiedAccount = await self.is_unified_enabled()
|
5220
|
-
isUnifiedAccount = (enableUnifiedMargin or enableUnifiedAccount)
|
5221
4782
|
request: dict = {
|
5222
4783
|
'execType': 'Trade',
|
5223
4784
|
}
|
5224
4785
|
market = None
|
5225
|
-
isUsdcSettled = False
|
5226
4786
|
if symbol is not None:
|
5227
4787
|
market = self.market(symbol)
|
5228
|
-
isUsdcSettled = market['settle'] == 'USDC'
|
5229
4788
|
request['symbol'] = market['id']
|
5230
4789
|
type = None
|
5231
4790
|
type, params = self.get_bybit_type('fetchMyTrades', market, params)
|
5232
|
-
if ((type == 'option') or isUsdcSettled) and not isUnifiedAccount:
|
5233
|
-
return await self.fetch_my_usdc_trades(symbol, since, limit, params)
|
5234
4791
|
request['category'] = type
|
5235
4792
|
if limit is not None:
|
5236
4793
|
request['limit'] = limit
|
@@ -5894,7 +5451,7 @@ class bybit(Exchange, ImplicitAPI):
|
|
5894
5451
|
}
|
5895
5452
|
return self.safe_string(types, type, type)
|
5896
5453
|
|
5897
|
-
async def withdraw(self, code: str, amount: float, address: str, tag=None, params={}):
|
5454
|
+
async def withdraw(self, code: str, amount: float, address: str, tag=None, params={}) -> Transaction:
|
5898
5455
|
"""
|
5899
5456
|
make a withdrawal
|
5900
5457
|
:see: https://bybit-exchange.github.io/docs/v5/asset/withdraw
|
@@ -5954,18 +5511,11 @@ class bybit(Exchange, ImplicitAPI):
|
|
5954
5511
|
request: dict = {
|
5955
5512
|
'symbol': market['id'],
|
5956
5513
|
}
|
5957
|
-
enableUnifiedMargin, enableUnifiedAccount = await self.is_unified_enabled()
|
5958
|
-
isUnifiedAccount = (enableUnifiedMargin or enableUnifiedAccount)
|
5959
|
-
isUsdcSettled = market['settle'] == 'USDC'
|
5960
5514
|
response = None
|
5961
5515
|
type = None
|
5962
5516
|
type, params = self.get_bybit_type('fetchPosition', market, params)
|
5963
|
-
|
5964
|
-
|
5965
|
-
response = await self.privatePostOptionUsdcOpenapiPrivateV1QueryPosition(self.extend(request, params))
|
5966
|
-
else:
|
5967
|
-
request['category'] = type
|
5968
|
-
response = await self.privateGetV5PositionList(self.extend(request, params))
|
5517
|
+
request['category'] = type
|
5518
|
+
response = await self.privateGetV5PositionList(self.extend(request, params))
|
5969
5519
|
#
|
5970
5520
|
# {
|
5971
5521
|
# "retCode": 0,
|
@@ -6015,76 +5565,6 @@ class bybit(Exchange, ImplicitAPI):
|
|
6015
5565
|
position['datetime'] = self.iso8601(timestamp)
|
6016
5566
|
return position
|
6017
5567
|
|
6018
|
-
async def fetch_usdc_positions(self, symbols: Strings = None, params={}):
|
6019
|
-
await self.load_markets()
|
6020
|
-
request: dict = {}
|
6021
|
-
market = None
|
6022
|
-
if isinstance(symbols, list):
|
6023
|
-
length = len(symbols)
|
6024
|
-
if length != 1:
|
6025
|
-
raise ArgumentsRequired(self.id + ' fetchUsdcPositions() takes an array with exactly one symbol')
|
6026
|
-
symbol = self.safe_string(symbols, 0)
|
6027
|
-
market = self.market(symbol)
|
6028
|
-
request['symbol'] = market['id']
|
6029
|
-
elif symbols is not None:
|
6030
|
-
market = self.market(symbols)
|
6031
|
-
request['symbol'] = market['id']
|
6032
|
-
type = None
|
6033
|
-
type, params = self.get_bybit_type('fetchUsdcPositions', market, params)
|
6034
|
-
request['category'] = 'OPTION' if (type == 'option') else 'PERPETUAL'
|
6035
|
-
response = await self.privatePostOptionUsdcOpenapiPrivateV1QueryPosition(self.extend(request, params))
|
6036
|
-
#
|
6037
|
-
# {
|
6038
|
-
# "result": {
|
6039
|
-
# "cursor": "BTC-31DEC21-24000-P%3A1640834421431%2CBTC-31DEC21-24000-P%3A1640834421431",
|
6040
|
-
# "resultTotalSize": 1,
|
6041
|
-
# "dataList": [
|
6042
|
-
# {
|
6043
|
-
# "symbol": "BTC-31DEC21-24000-P",
|
6044
|
-
# "leverage": "",
|
6045
|
-
# "occClosingFee": "",
|
6046
|
-
# "liqPrice": "",
|
6047
|
-
# "positionValue": "",
|
6048
|
-
# "takeProfit": "",
|
6049
|
-
# "riskId": "",
|
6050
|
-
# "trailingStop": "",
|
6051
|
-
# "unrealisedPnl": "",
|
6052
|
-
# "createdAt": "1640834421431",
|
6053
|
-
# "markPrice": "0.00",
|
6054
|
-
# "cumRealisedPnl": "",
|
6055
|
-
# "positionMM": "359.5271",
|
6056
|
-
# "positionIM": "467.0633",
|
6057
|
-
# "updatedAt": "1640834421431",
|
6058
|
-
# "tpSLMode": "",
|
6059
|
-
# "side": "Sell",
|
6060
|
-
# "bustPrice": "",
|
6061
|
-
# "deleverageIndicator": 0,
|
6062
|
-
# "entryPrice": "1.4",
|
6063
|
-
# "size": "-0.100",
|
6064
|
-
# "sessionRPL": "",
|
6065
|
-
# "positionStatus": "",
|
6066
|
-
# "sessionUPL": "",
|
6067
|
-
# "stopLoss": "",
|
6068
|
-
# "orderMargin": "",
|
6069
|
-
# "sessionAvgPrice": "1.5"
|
6070
|
-
# }
|
6071
|
-
# ]
|
6072
|
-
# },
|
6073
|
-
# "retCode": 0,
|
6074
|
-
# "retMsg": "Success."
|
6075
|
-
# }
|
6076
|
-
#
|
6077
|
-
result = self.safe_dict(response, 'result', {})
|
6078
|
-
positions = self.safe_list(result, 'dataList', [])
|
6079
|
-
results = []
|
6080
|
-
for i in range(0, len(positions)):
|
6081
|
-
rawPosition = positions[i]
|
6082
|
-
if ('data' in rawPosition) and ('is_valid' in rawPosition):
|
6083
|
-
# futures only
|
6084
|
-
rawPosition = self.safe_dict(rawPosition, 'data')
|
6085
|
-
results.append(self.parse_position(rawPosition, market))
|
6086
|
-
return self.filter_by_array_positions(results, 'symbol', symbols, False)
|
6087
|
-
|
6088
5568
|
async def fetch_positions(self, symbols: Strings = None, params={}):
|
6089
5569
|
"""
|
6090
5570
|
fetch all open positions
|
@@ -6109,16 +5589,12 @@ class bybit(Exchange, ImplicitAPI):
|
|
6109
5589
|
elif symbols is not None:
|
6110
5590
|
symbol = symbols
|
6111
5591
|
symbols = [self.symbol(symbol)]
|
6112
|
-
enableUnifiedMargin, enableUnifiedAccount = await self.is_unified_enabled()
|
6113
|
-
isUnifiedAccount = (enableUnifiedMargin or enableUnifiedAccount)
|
6114
5592
|
request: dict = {}
|
6115
5593
|
market = None
|
6116
|
-
isUsdcSettled = False
|
6117
5594
|
if symbol is not None:
|
6118
5595
|
market = self.market(symbol)
|
6119
5596
|
symbol = market['symbol']
|
6120
5597
|
request['symbol'] = market['id']
|
6121
|
-
isUsdcSettled = market['settle'] == 'USDC'
|
6122
5598
|
type = None
|
6123
5599
|
type, params = self.get_bybit_type('fetchPositions', market, params)
|
6124
5600
|
if type == 'linear' or type == 'inverse':
|
@@ -6128,13 +5604,10 @@ class bybit(Exchange, ImplicitAPI):
|
|
6128
5604
|
defaultSettle = self.safe_string(self.options, 'defaultSettle', 'USDT')
|
6129
5605
|
settleCoin = self.safe_string(params, 'settleCoin', defaultSettle)
|
6130
5606
|
request['settleCoin'] = settleCoin
|
6131
|
-
isUsdcSettled = (settleCoin == 'USDC')
|
6132
5607
|
else:
|
6133
5608
|
# inverse
|
6134
5609
|
if symbol is None and baseCoin is None:
|
6135
5610
|
request['category'] = 'inverse'
|
6136
|
-
if ((type == 'option') or isUsdcSettled) and not isUnifiedAccount:
|
6137
|
-
return await self.fetch_usdc_positions(symbols, params)
|
6138
5611
|
params = self.omit(params, ['type'])
|
6139
5612
|
request['category'] = type
|
6140
5613
|
response = await self.privateGetV5PositionList(self.extend(request, params))
|
@@ -6536,9 +6009,6 @@ class bybit(Exchange, ImplicitAPI):
|
|
6536
6009
|
market = self.market(symbol)
|
6537
6010
|
# WARNING: THIS WILL INCREASE LIQUIDATION PRICE FOR OPEN ISOLATED LONG POSITIONS
|
6538
6011
|
# AND DECREASE LIQUIDATION PRICE FOR OPEN ISOLATED SHORT POSITIONS
|
6539
|
-
enableUnifiedMargin, enableUnifiedAccount = await self.is_unified_enabled()
|
6540
|
-
isUnifiedAccount = (enableUnifiedMargin or enableUnifiedAccount)
|
6541
|
-
isUsdcSettled = market['settle'] == 'USDC'
|
6542
6012
|
# engage in leverage setting
|
6543
6013
|
# we reuse the code here instead of having two methods
|
6544
6014
|
leverageString = self.number_to_string(leverage)
|
@@ -6547,20 +6017,15 @@ class bybit(Exchange, ImplicitAPI):
|
|
6547
6017
|
'buyLeverage': leverageString,
|
6548
6018
|
'sellLeverage': leverageString,
|
6549
6019
|
}
|
6550
|
-
|
6551
|
-
|
6552
|
-
|
6553
|
-
|
6020
|
+
request['buyLeverage'] = leverageString
|
6021
|
+
request['sellLeverage'] = leverageString
|
6022
|
+
if market['linear']:
|
6023
|
+
request['category'] = 'linear'
|
6024
|
+
elif market['inverse']:
|
6025
|
+
request['category'] = 'inverse'
|
6554
6026
|
else:
|
6555
|
-
|
6556
|
-
|
6557
|
-
if market['linear']:
|
6558
|
-
request['category'] = 'linear'
|
6559
|
-
elif market['inverse']:
|
6560
|
-
request['category'] = 'inverse'
|
6561
|
-
else:
|
6562
|
-
raise NotSupported(self.id + ' setLeverage() only support linear and inverse market')
|
6563
|
-
response = await self.privatePostV5PositionSetLeverage(self.extend(request, params))
|
6027
|
+
raise NotSupported(self.id + ' setLeverage() only support linear and inverse market')
|
6028
|
+
response = await self.privatePostV5PositionSetLeverage(self.extend(request, params))
|
6564
6029
|
return response
|
6565
6030
|
|
6566
6031
|
async def set_position_mode(self, hedged: bool, symbol: Str = None, params={}):
|