ccxt 4.1.89__py2.py3-none-any.whl → 4.1.90__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.
Potentially problematic release.
This version of ccxt might be problematic. Click here for more details.
- ccxt/__init__.py +1 -1
- ccxt/async_support/__init__.py +1 -1
- ccxt/async_support/base/exchange.py +3 -3
- ccxt/async_support/binance.py +1 -1
- ccxt/async_support/bitforex.py +2 -0
- ccxt/async_support/bitget.py +9 -4
- ccxt/async_support/bitmex.py +2 -0
- ccxt/async_support/blockchaincom.py +0 -37
- ccxt/async_support/bybit.py +23 -14
- ccxt/async_support/coinlist.py +2 -0
- ccxt/async_support/coinsph.py +2 -0
- ccxt/async_support/cryptocom.py +2 -0
- ccxt/async_support/gate.py +258 -11
- ccxt/async_support/htx.py +223 -207
- ccxt/async_support/kuna.py +2 -0
- ccxt/async_support/mexc.py +2 -0
- ccxt/async_support/okcoin.py +3 -1
- ccxt/async_support/phemex.py +48 -1
- ccxt/async_support/poloniex.py +23 -2
- ccxt/async_support/tokocrypto.py +2 -0
- ccxt/async_support/wazirx.py +2 -0
- ccxt/async_support/whitebit.py +2 -0
- ccxt/base/exchange.py +3 -3
- ccxt/binance.py +1 -1
- ccxt/bitforex.py +2 -0
- ccxt/bitget.py +9 -4
- ccxt/bitmex.py +2 -0
- ccxt/blockchaincom.py +0 -37
- ccxt/bybit.py +23 -14
- ccxt/coinlist.py +2 -0
- ccxt/coinsph.py +2 -0
- ccxt/cryptocom.py +2 -0
- ccxt/gate.py +258 -11
- ccxt/htx.py +223 -207
- ccxt/kuna.py +2 -0
- ccxt/mexc.py +2 -0
- ccxt/okcoin.py +3 -1
- ccxt/phemex.py +48 -1
- ccxt/poloniex.py +23 -2
- ccxt/pro/__init__.py +1 -1
- ccxt/pro/binance.py +6 -6
- ccxt/pro/poloniex.py +15 -11
- ccxt/tokocrypto.py +2 -0
- ccxt/wazirx.py +2 -0
- ccxt/whitebit.py +2 -0
- {ccxt-4.1.89.dist-info → ccxt-4.1.90.dist-info}/METADATA +4 -4
- {ccxt-4.1.89.dist-info → ccxt-4.1.90.dist-info}/RECORD +49 -49
- {ccxt-4.1.89.dist-info → ccxt-4.1.90.dist-info}/WHEEL +0 -0
- {ccxt-4.1.89.dist-info → ccxt-4.1.90.dist-info}/top_level.txt +0 -0
ccxt/gate.py
CHANGED
@@ -94,9 +94,14 @@ class gate(Exchange, ImplicitAPI):
|
|
94
94
|
'future': True,
|
95
95
|
'option': True,
|
96
96
|
'addMargin': True,
|
97
|
+
'borrowCrossMargin': True,
|
98
|
+
'borrowIsolatedMargin': True,
|
97
99
|
'cancelAllOrders': True,
|
98
100
|
'cancelOrder': True,
|
101
|
+
'createMarketBuyOrderWithCost': True,
|
99
102
|
'createMarketOrder': True,
|
103
|
+
'createMarketOrderWithCost': False,
|
104
|
+
'createMarketSellOrderWithCost': False,
|
100
105
|
'createOrder': True,
|
101
106
|
'createOrders': True,
|
102
107
|
'createPostOnlyOrder': True,
|
@@ -158,6 +163,8 @@ class gate(Exchange, ImplicitAPI):
|
|
158
163
|
'fetchVolatilityHistory': False,
|
159
164
|
'fetchWithdrawals': True,
|
160
165
|
'reduceMargin': True,
|
166
|
+
'repayCrossMargin': True,
|
167
|
+
'repayIsolatedMargin': True,
|
161
168
|
'setLeverage': True,
|
162
169
|
'setMarginMode': False,
|
163
170
|
'setPositionMode': True,
|
@@ -3552,6 +3559,7 @@ class gate(Exchange, ImplicitAPI):
|
|
3552
3559
|
:param bool [params.close]: *contract only* Set to close the position, with size set to 0
|
3553
3560
|
:param bool [params.auto_size]: *contract only* Set side to close dual-mode position, close_long closes the long side, while close_short the short one, size also needs to be set to 0
|
3554
3561
|
:param int [params.price_type]: *contract only* 0 latest deal price, 1 mark price, 2 index price
|
3562
|
+
:param float [params.cost]: *spot market buy only* the quote quantity that can be used alternative for the amount
|
3555
3563
|
:returns dict|None: `An order structure <https://docs.ccxt.com/#/?id=order-structure>`
|
3556
3564
|
"""
|
3557
3565
|
self.load_markets()
|
@@ -3724,9 +3732,13 @@ class gate(Exchange, ImplicitAPI):
|
|
3724
3732
|
if contract:
|
3725
3733
|
price = 0
|
3726
3734
|
if contract:
|
3727
|
-
|
3728
|
-
|
3729
|
-
|
3735
|
+
isClose = self.safe_value(params, 'close')
|
3736
|
+
if isClose:
|
3737
|
+
amount = 0
|
3738
|
+
else:
|
3739
|
+
amountToPrecision = self.amount_to_precision(symbol, amount)
|
3740
|
+
signedAmount = Precise.string_neg(amountToPrecision) if (side == 'sell') else amountToPrecision
|
3741
|
+
amount = int(signedAmount)
|
3730
3742
|
request = None
|
3731
3743
|
nonTriggerOrder = not isStopOrder and (trigger is None)
|
3732
3744
|
if nonTriggerOrder:
|
@@ -3767,20 +3779,25 @@ class gate(Exchange, ImplicitAPI):
|
|
3767
3779
|
# 'auto_borrow': False, # used in margin or cross margin trading to allow automatic loan of insufficient amount if balance is not enough
|
3768
3780
|
# 'auto_repay': False, # automatic repayment for automatic borrow loan generated by cross margin order, diabled by default
|
3769
3781
|
}
|
3770
|
-
createMarketBuyOrderRequiresPrice = self.safe_value(self.options, 'createMarketBuyOrderRequiresPrice', True)
|
3771
3782
|
if isMarketOrder and (side == 'buy'):
|
3772
|
-
|
3783
|
+
quoteAmount = None
|
3784
|
+
createMarketBuyOrderRequiresPrice = True
|
3785
|
+
createMarketBuyOrderRequiresPrice, params = self.handle_option_and_params(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', True)
|
3786
|
+
cost = self.safe_number(params, 'cost')
|
3787
|
+
params = self.omit(params, 'cost')
|
3788
|
+
if cost is not None:
|
3789
|
+
quoteAmount = self.cost_to_precision(symbol, cost)
|
3790
|
+
elif createMarketBuyOrderRequiresPrice:
|
3773
3791
|
if price is None:
|
3774
|
-
raise InvalidOrder(self.id + ' createOrder() requires price argument for market buy orders
|
3792
|
+
raise InvalidOrder(self.id + ' createOrder() requires the price argument for market buy orders to calculate the total cost to spend(amount * price), alternatively set the createMarketBuyOrderRequiresPrice option or param to False and pass the cost to spend(quote quantity) in the amount argument')
|
3775
3793
|
else:
|
3776
3794
|
amountString = self.number_to_string(amount)
|
3777
3795
|
priceString = self.number_to_string(price)
|
3778
|
-
|
3779
|
-
|
3796
|
+
costRequest = Precise.string_mul(amountString, priceString)
|
3797
|
+
quoteAmount = self.cost_to_precision(symbol, costRequest)
|
3780
3798
|
else:
|
3781
|
-
|
3782
|
-
|
3783
|
-
request['amount'] = self.cost_to_precision(symbol, cost)
|
3799
|
+
quoteAmount = self.cost_to_precision(symbol, amount)
|
3800
|
+
request['amount'] = quoteAmount
|
3784
3801
|
else:
|
3785
3802
|
request['amount'] = self.amount_to_precision(symbol, amount)
|
3786
3803
|
if isLimitOrder:
|
@@ -3885,6 +3902,22 @@ class gate(Exchange, ImplicitAPI):
|
|
3885
3902
|
}
|
3886
3903
|
return self.extend(request, params)
|
3887
3904
|
|
3905
|
+
def create_market_buy_order_with_cost(self, symbol: str, cost, params={}):
|
3906
|
+
"""
|
3907
|
+
create a market buy order by providing the symbol and cost
|
3908
|
+
:see: https://www.gate.io/docs/developers/apiv4/en/#create-an-order
|
3909
|
+
:param str symbol: unified symbol of the market to create an order in
|
3910
|
+
:param float cost: how much you want to trade in units of the quote currency
|
3911
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
3912
|
+
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
|
3913
|
+
"""
|
3914
|
+
self.load_markets()
|
3915
|
+
market = self.market(symbol)
|
3916
|
+
if not market['spot']:
|
3917
|
+
raise NotSupported(self.id + ' createMarketBuyOrderWithCost() supports spot orders only')
|
3918
|
+
params['createMarketBuyOrderRequiresPrice'] = False
|
3919
|
+
return self.create_order(symbol, 'market', 'buy', cost, None, params)
|
3920
|
+
|
3888
3921
|
def edit_order(self, id: str, symbol, type, side, amount=None, price=None, params={}):
|
3889
3922
|
"""
|
3890
3923
|
edit a trade order, gate currently only supports the modification of the price or amount fields
|
@@ -5340,6 +5373,201 @@ class gate(Exchange, ImplicitAPI):
|
|
5340
5373
|
floor = cap
|
5341
5374
|
return tiers
|
5342
5375
|
|
5376
|
+
def repay_isolated_margin(self, symbol: str, code: str, amount, params={}):
|
5377
|
+
"""
|
5378
|
+
repay borrowed margin and interest
|
5379
|
+
:see: https://www.gate.io/docs/apiv4/en/#repay-a-loan
|
5380
|
+
:param str symbol: unified market symbol
|
5381
|
+
:param str code: unified currency code of the currency to repay
|
5382
|
+
:param float amount: the amount to repay
|
5383
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
5384
|
+
:param str [params.mode]: 'all' or 'partial' payment mode, extra parameter required for isolated margin
|
5385
|
+
:param str [params.id]: '34267567' loan id, extra parameter required for isolated margin
|
5386
|
+
:returns dict: a `margin loan structure <https://docs.ccxt.com/#/?id=margin-loan-structure>`
|
5387
|
+
"""
|
5388
|
+
self.load_markets()
|
5389
|
+
currency = self.currency(code)
|
5390
|
+
request = {
|
5391
|
+
'currency': currency['id'].upper(),
|
5392
|
+
'amount': self.currency_to_precision(code, amount),
|
5393
|
+
}
|
5394
|
+
market = self.market(symbol)
|
5395
|
+
request['currency_pair'] = market['id']
|
5396
|
+
request['type'] = 'repay'
|
5397
|
+
response = self.privateMarginPostUniLoans(self.extend(request, params))
|
5398
|
+
#
|
5399
|
+
# empty response
|
5400
|
+
#
|
5401
|
+
return self.parse_margin_loan(response, currency)
|
5402
|
+
|
5403
|
+
def repay_cross_margin(self, code: str, amount, params={}):
|
5404
|
+
"""
|
5405
|
+
repay cross margin borrowed margin and interest
|
5406
|
+
:see: https://www.gate.io/docs/developers/apiv4/en/#cross-margin-repayments
|
5407
|
+
:param str code: unified currency code of the currency to repay
|
5408
|
+
:param float amount: the amount to repay
|
5409
|
+
:param str symbol: unified market symbol, required for isolated margin
|
5410
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
5411
|
+
:param str [params.mode]: 'all' or 'partial' payment mode, extra parameter required for isolated margin
|
5412
|
+
:param str [params.id]: '34267567' loan id, extra parameter required for isolated margin
|
5413
|
+
:returns dict: a `margin loan structure <https://docs.ccxt.com/#/?id=margin-loan-structure>`
|
5414
|
+
"""
|
5415
|
+
self.load_markets()
|
5416
|
+
currency = self.currency(code)
|
5417
|
+
request = {
|
5418
|
+
'currency': currency['id'].upper(),
|
5419
|
+
'amount': self.currency_to_precision(code, amount),
|
5420
|
+
}
|
5421
|
+
response = self.privateMarginPostCrossRepayments(self.extend(request, params))
|
5422
|
+
#
|
5423
|
+
# [
|
5424
|
+
# {
|
5425
|
+
# "id": "17",
|
5426
|
+
# "create_time": 1620381696159,
|
5427
|
+
# "update_time": 1620381696159,
|
5428
|
+
# "currency": "EOS",
|
5429
|
+
# "amount": "110.553635",
|
5430
|
+
# "text": "web",
|
5431
|
+
# "status": 2,
|
5432
|
+
# "repaid": "110.506649705159",
|
5433
|
+
# "repaid_interest": "0.046985294841",
|
5434
|
+
# "unpaid_interest": "0.0000074393366667"
|
5435
|
+
# }
|
5436
|
+
# ]
|
5437
|
+
#
|
5438
|
+
response = self.safe_value(response, 0)
|
5439
|
+
return self.parse_margin_loan(response, currency)
|
5440
|
+
|
5441
|
+
def borrow_isolated_margin(self, symbol: str, code: str, amount, params={}):
|
5442
|
+
"""
|
5443
|
+
create a loan to borrow margin
|
5444
|
+
:see: https://www.gate.io/docs/developers/apiv4/en/#marginuni
|
5445
|
+
:param str code: unified currency code of the currency to borrow
|
5446
|
+
:param float amount: the amount to borrow
|
5447
|
+
:param str symbol: unified market symbol, required for isolated margin
|
5448
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
5449
|
+
:param str [params.rate]: '0.0002' or '0.002' extra parameter required for isolated margin
|
5450
|
+
:returns dict: a `margin loan structure <https://docs.ccxt.com/#/?id=margin-loan-structure>`
|
5451
|
+
"""
|
5452
|
+
self.load_markets()
|
5453
|
+
currency = self.currency(code)
|
5454
|
+
request = {
|
5455
|
+
'currency': currency['id'].upper(),
|
5456
|
+
'amount': self.currency_to_precision(code, amount),
|
5457
|
+
}
|
5458
|
+
response = None
|
5459
|
+
market = self.market(symbol)
|
5460
|
+
request['currency_pair'] = market['id']
|
5461
|
+
request['type'] = 'borrow'
|
5462
|
+
response = self.privateMarginPostUniLoans(self.extend(request, params))
|
5463
|
+
#
|
5464
|
+
# {
|
5465
|
+
# "id": "34267567",
|
5466
|
+
# "create_time": "1656394778",
|
5467
|
+
# "expire_time": "1657258778",
|
5468
|
+
# "status": "loaned",
|
5469
|
+
# "side": "borrow",
|
5470
|
+
# "currency": "USDT",
|
5471
|
+
# "rate": "0.0002",
|
5472
|
+
# "amount": "100",
|
5473
|
+
# "days": 10,
|
5474
|
+
# "auto_renew": False,
|
5475
|
+
# "currency_pair": "LTC_USDT",
|
5476
|
+
# "left": "0",
|
5477
|
+
# "repaid": "0",
|
5478
|
+
# "paid_interest": "0",
|
5479
|
+
# "unpaid_interest": "0.003333333333"
|
5480
|
+
# }
|
5481
|
+
#
|
5482
|
+
return self.parse_margin_loan(response, currency)
|
5483
|
+
|
5484
|
+
def borrow_cross_margin(self, code: str, amount, params={}):
|
5485
|
+
"""
|
5486
|
+
create a loan to borrow margin
|
5487
|
+
:see: https://www.gate.io/docs/apiv4/en/#create-a-cross-margin-borrow-loan
|
5488
|
+
:param str code: unified currency code of the currency to borrow
|
5489
|
+
:param float amount: the amount to borrow
|
5490
|
+
:param str symbol: unified market symbol, required for isolated margin
|
5491
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
5492
|
+
:param str [params.rate]: '0.0002' or '0.002' extra parameter required for isolated margin
|
5493
|
+
:returns dict: a `margin loan structure <https://docs.ccxt.com/#/?id=margin-loan-structure>`
|
5494
|
+
"""
|
5495
|
+
self.load_markets()
|
5496
|
+
currency = self.currency(code)
|
5497
|
+
request = {
|
5498
|
+
'currency': currency['id'].upper(),
|
5499
|
+
'amount': self.currency_to_precision(code, amount),
|
5500
|
+
}
|
5501
|
+
response = self.privateMarginPostCrossLoans(self.extend(request, params))
|
5502
|
+
#
|
5503
|
+
# {
|
5504
|
+
# "id": "17",
|
5505
|
+
# "create_time": 1620381696159,
|
5506
|
+
# "update_time": 1620381696159,
|
5507
|
+
# "currency": "EOS",
|
5508
|
+
# "amount": "110.553635",
|
5509
|
+
# "text": "web",
|
5510
|
+
# "status": 2,
|
5511
|
+
# "repaid": "110.506649705159",
|
5512
|
+
# "repaid_interest": "0.046985294841",
|
5513
|
+
# "unpaid_interest": "0.0000074393366667"
|
5514
|
+
# }
|
5515
|
+
#
|
5516
|
+
return self.parse_margin_loan(response, currency)
|
5517
|
+
|
5518
|
+
def parse_margin_loan(self, info, currency: Currency = None):
|
5519
|
+
#
|
5520
|
+
# Cross
|
5521
|
+
#
|
5522
|
+
# {
|
5523
|
+
# "id": "17",
|
5524
|
+
# "create_time": 1620381696159,
|
5525
|
+
# "update_time": 1620381696159,
|
5526
|
+
# "currency": "EOS",
|
5527
|
+
# "amount": "110.553635",
|
5528
|
+
# "text": "web",
|
5529
|
+
# "status": 2,
|
5530
|
+
# "repaid": "110.506649705159",
|
5531
|
+
# "repaid_interest": "0.046985294841",
|
5532
|
+
# "unpaid_interest": "0.0000074393366667"
|
5533
|
+
# }
|
5534
|
+
#
|
5535
|
+
# Isolated
|
5536
|
+
#
|
5537
|
+
# {
|
5538
|
+
# "id": "34267567",
|
5539
|
+
# "create_time": "1656394778",
|
5540
|
+
# "expire_time": "1657258778",
|
5541
|
+
# "status": "loaned",
|
5542
|
+
# "side": "borrow",
|
5543
|
+
# "currency": "USDT",
|
5544
|
+
# "rate": "0.0002",
|
5545
|
+
# "amount": "100",
|
5546
|
+
# "days": 10,
|
5547
|
+
# "auto_renew": False,
|
5548
|
+
# "currency_pair": "LTC_USDT",
|
5549
|
+
# "left": "0",
|
5550
|
+
# "repaid": "0",
|
5551
|
+
# "paid_interest": "0",
|
5552
|
+
# "unpaid_interest": "0.003333333333"
|
5553
|
+
# }
|
5554
|
+
#
|
5555
|
+
marginMode = self.safe_string_2(self.options, 'defaultMarginMode', 'marginMode', 'cross')
|
5556
|
+
timestamp = self.safe_integer(info, 'create_time')
|
5557
|
+
if marginMode == 'isolated':
|
5558
|
+
timestamp = self.safe_timestamp(info, 'create_time')
|
5559
|
+
currencyId = self.safe_string(info, 'currency')
|
5560
|
+
marketId = self.safe_string(info, 'currency_pair')
|
5561
|
+
return {
|
5562
|
+
'id': self.safe_integer(info, 'id'),
|
5563
|
+
'currency': self.safe_currency_code(currencyId, currency),
|
5564
|
+
'amount': self.safe_number(info, 'amount'),
|
5565
|
+
'symbol': self.safe_symbol(marketId, None, '_', 'margin'),
|
5566
|
+
'timestamp': timestamp,
|
5567
|
+
'datetime': self.iso8601(timestamp),
|
5568
|
+
'info': info,
|
5569
|
+
}
|
5570
|
+
|
5343
5571
|
def sign(self, path, api=[], method='GET', params={}, headers=None, body=None):
|
5344
5572
|
authentication = api[0] # public, private
|
5345
5573
|
type = api[1] # spot, margin, future, delivery
|
@@ -6265,6 +6493,25 @@ class gate(Exchange, ImplicitAPI):
|
|
6265
6493
|
'info': greeks,
|
6266
6494
|
}
|
6267
6495
|
|
6496
|
+
def close_position(self, symbol: str, side: OrderSide = None, params={}) -> Order:
|
6497
|
+
"""
|
6498
|
+
closes open positions for a market
|
6499
|
+
:see: https://www.gate.io/docs/developers/apiv4/en/#create-a-futures-order
|
6500
|
+
:see: https://www.gate.io/docs/developers/apiv4/en/#create-a-futures-order-2
|
6501
|
+
:see: https://www.gate.io/docs/developers/apiv4/en/#create-an-options-order
|
6502
|
+
:param str symbol: Unified CCXT market symbol
|
6503
|
+
:param str side: 'buy' or 'sell'
|
6504
|
+
:param dict [params]: extra parameters specific to the okx api endpoint
|
6505
|
+
:returns [dict]: `A list of position structures <https://docs.ccxt.com/#/?id=position-structure>`
|
6506
|
+
"""
|
6507
|
+
request = {
|
6508
|
+
'close': True,
|
6509
|
+
}
|
6510
|
+
params = self.extend(request, params)
|
6511
|
+
if side is None:
|
6512
|
+
side = '' # side is not used but needs to be present, otherwise crashes in php
|
6513
|
+
return self.create_order(symbol, 'market', side, 0, None, params)
|
6514
|
+
|
6268
6515
|
def handle_errors(self, code, reason, url, method, headers, body, response, requestHeaders, requestBody):
|
6269
6516
|
if response is None:
|
6270
6517
|
return None
|