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