ccxt 4.3.17__py2.py3-none-any.whl → 4.3.19__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 +3 -1
- ccxt/abstract/bybit.py +1 -0
- ccxt/abstract/okx.py +1 -0
- ccxt/abstract/woofipro.py +119 -0
- ccxt/ace.py +1 -1
- ccxt/ascendex.py +7 -8
- ccxt/async_support/__init__.py +3 -1
- ccxt/async_support/ace.py +1 -1
- ccxt/async_support/ascendex.py +7 -8
- ccxt/async_support/base/exchange.py +23 -2
- ccxt/async_support/bigone.py +4 -4
- ccxt/async_support/binance.py +34 -17
- ccxt/async_support/bingx.py +4 -4
- ccxt/async_support/bit2c.py +1 -1
- ccxt/async_support/bitbank.py +1 -1
- ccxt/async_support/bitbns.py +1 -1
- ccxt/async_support/bitfinex.py +28 -4
- ccxt/async_support/bitfinex2.py +62 -54
- ccxt/async_support/bitflyer.py +1 -1
- ccxt/async_support/bitget.py +8 -11
- ccxt/async_support/bithumb.py +1 -1
- ccxt/async_support/bitmart.py +8 -8
- ccxt/async_support/bitmex.py +2 -2
- ccxt/async_support/bitopro.py +1 -1
- ccxt/async_support/bitrue.py +3 -3
- ccxt/async_support/bitso.py +1 -1
- ccxt/async_support/bitstamp.py +3 -5
- ccxt/async_support/bitteam.py +1 -1
- ccxt/async_support/bitvavo.py +1 -1
- ccxt/async_support/bl3p.py +1 -1
- ccxt/async_support/blockchaincom.py +1 -1
- ccxt/async_support/blofin.py +3 -3
- ccxt/async_support/btcalpha.py +1 -1
- ccxt/async_support/btcbox.py +1 -1
- ccxt/async_support/btcmarkets.py +1 -1
- ccxt/async_support/btcturk.py +1 -1
- ccxt/async_support/bybit.py +9 -8
- ccxt/async_support/cex.py +1 -1
- ccxt/async_support/coinbase.py +2 -2
- ccxt/async_support/coinbasepro.py +1 -1
- ccxt/async_support/coincheck.py +1 -1
- ccxt/async_support/coinex.py +320 -520
- ccxt/async_support/coinlist.py +6 -7
- ccxt/async_support/coinmate.py +1 -1
- ccxt/async_support/coinmetro.py +1 -1
- ccxt/async_support/coinone.py +1 -1
- ccxt/async_support/coinsph.py +1 -1
- ccxt/async_support/coinspot.py +1 -1
- ccxt/async_support/cryptocom.py +1 -1
- ccxt/async_support/currencycom.py +2 -2
- ccxt/async_support/delta.py +4 -4
- ccxt/async_support/deribit.py +8 -8
- ccxt/async_support/digifinex.py +5 -5
- ccxt/async_support/exmo.py +1 -1
- ccxt/async_support/gate.py +5 -5
- ccxt/async_support/gemini.py +1 -1
- ccxt/async_support/hitbtc.py +3 -3
- ccxt/async_support/hollaex.py +4 -4
- ccxt/async_support/htx.py +4 -4
- 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 +2 -2
- ccxt/async_support/kraken.py +2 -2
- ccxt/async_support/krakenfutures.py +3 -3
- ccxt/async_support/kucoin.py +3 -3
- ccxt/async_support/kucoinfutures.py +3 -3
- ccxt/async_support/kuna.py +1 -1
- ccxt/async_support/latoken.py +6 -6
- ccxt/async_support/lbank.py +1 -1
- ccxt/async_support/luno.py +1 -1
- ccxt/async_support/lykke.py +1 -1
- ccxt/async_support/mercado.py +1 -1
- ccxt/async_support/mexc.py +7 -7
- ccxt/async_support/ndax.py +1 -1
- ccxt/async_support/novadax.py +3 -4
- ccxt/async_support/okcoin.py +3 -3
- ccxt/async_support/okx.py +27 -10
- ccxt/async_support/onetrading.py +1 -1
- ccxt/async_support/paymium.py +3 -3
- ccxt/async_support/phemex.py +5 -5
- ccxt/async_support/poloniex.py +3 -4
- ccxt/async_support/poloniexfutures.py +1 -1
- ccxt/async_support/probit.py +1 -1
- ccxt/async_support/timex.py +1 -1
- ccxt/async_support/tokocrypto.py +1 -1
- ccxt/async_support/upbit.py +1 -1
- ccxt/async_support/wavesexchange.py +3 -3
- ccxt/async_support/wazirx.py +1 -1
- ccxt/async_support/whitebit.py +2 -2
- ccxt/async_support/woo.py +25 -10
- ccxt/async_support/woofipro.py +2524 -0
- ccxt/async_support/yobit.py +1 -1
- ccxt/async_support/zaif.py +1 -1
- ccxt/async_support/zonda.py +3 -3
- ccxt/base/exchange.py +63 -17
- ccxt/base/types.py +20 -0
- ccxt/bigone.py +4 -4
- ccxt/binance.py +34 -17
- ccxt/bingx.py +4 -4
- ccxt/bit2c.py +1 -1
- ccxt/bitbank.py +1 -1
- ccxt/bitbns.py +1 -1
- ccxt/bitfinex.py +28 -4
- ccxt/bitfinex2.py +62 -54
- ccxt/bitflyer.py +1 -1
- ccxt/bitget.py +8 -11
- ccxt/bithumb.py +1 -1
- ccxt/bitmart.py +8 -8
- ccxt/bitmex.py +2 -2
- ccxt/bitopro.py +1 -1
- ccxt/bitrue.py +3 -3
- ccxt/bitso.py +1 -1
- ccxt/bitstamp.py +3 -5
- ccxt/bitteam.py +1 -1
- ccxt/bitvavo.py +1 -1
- ccxt/bl3p.py +1 -1
- ccxt/blockchaincom.py +1 -1
- ccxt/blofin.py +3 -3
- ccxt/btcalpha.py +1 -1
- ccxt/btcbox.py +1 -1
- ccxt/btcmarkets.py +1 -1
- ccxt/btcturk.py +1 -1
- ccxt/bybit.py +9 -8
- ccxt/cex.py +1 -1
- ccxt/coinbase.py +2 -2
- ccxt/coinbasepro.py +1 -1
- ccxt/coincheck.py +1 -1
- ccxt/coinex.py +320 -520
- ccxt/coinlist.py +6 -7
- ccxt/coinmate.py +1 -1
- ccxt/coinmetro.py +1 -1
- ccxt/coinone.py +1 -1
- ccxt/coinsph.py +1 -1
- ccxt/coinspot.py +1 -1
- ccxt/cryptocom.py +1 -1
- ccxt/currencycom.py +2 -2
- ccxt/delta.py +4 -4
- ccxt/deribit.py +8 -8
- ccxt/digifinex.py +5 -5
- ccxt/exmo.py +1 -1
- ccxt/gate.py +5 -5
- ccxt/gemini.py +1 -1
- ccxt/hitbtc.py +3 -3
- ccxt/hollaex.py +4 -4
- ccxt/htx.py +4 -4
- ccxt/huobijp.py +1 -1
- ccxt/idex.py +1 -1
- ccxt/independentreserve.py +1 -1
- ccxt/indodax.py +2 -2
- ccxt/kraken.py +2 -2
- ccxt/krakenfutures.py +3 -3
- ccxt/kucoin.py +3 -3
- ccxt/kucoinfutures.py +3 -3
- ccxt/kuna.py +1 -1
- ccxt/latoken.py +6 -6
- ccxt/lbank.py +1 -1
- ccxt/luno.py +1 -1
- ccxt/lykke.py +1 -1
- ccxt/mercado.py +1 -1
- ccxt/mexc.py +7 -7
- ccxt/ndax.py +1 -1
- ccxt/novadax.py +3 -4
- ccxt/okcoin.py +3 -3
- ccxt/okx.py +27 -10
- ccxt/onetrading.py +1 -1
- ccxt/paymium.py +3 -3
- ccxt/phemex.py +5 -5
- ccxt/poloniex.py +3 -4
- ccxt/poloniexfutures.py +1 -1
- ccxt/pro/__init__.py +3 -1
- ccxt/pro/bitget.py +127 -190
- ccxt/pro/bitvavo.py +1 -1
- ccxt/pro/bybit.py +4 -3
- ccxt/pro/coinbaseinternational.py +11 -4
- ccxt/pro/okx.py +79 -1
- ccxt/pro/woofipro.py +1183 -0
- ccxt/probit.py +1 -1
- ccxt/test/test_async.py +31 -1
- ccxt/test/test_sync.py +31 -1
- ccxt/timex.py +1 -1
- ccxt/tokocrypto.py +1 -1
- ccxt/upbit.py +1 -1
- ccxt/wavesexchange.py +3 -3
- ccxt/wazirx.py +1 -1
- ccxt/whitebit.py +2 -2
- ccxt/woo.py +25 -10
- ccxt/woofipro.py +2524 -0
- ccxt/yobit.py +1 -1
- ccxt/zaif.py +1 -1
- ccxt/zonda.py +3 -3
- {ccxt-4.3.17.dist-info → ccxt-4.3.19.dist-info}/METADATA +8 -6
- {ccxt-4.3.17.dist-info → ccxt-4.3.19.dist-info}/RECORD +195 -191
- {ccxt-4.3.17.dist-info → ccxt-4.3.19.dist-info}/WHEEL +0 -0
- {ccxt-4.3.17.dist-info → ccxt-4.3.19.dist-info}/top_level.txt +0 -0
ccxt/coinex.py
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
from ccxt.base.exchange import Exchange
|
7
7
|
from ccxt.abstract.coinex import ImplicitAPI
|
8
|
-
from ccxt.base.types import Balances, Currencies, Currency, Int, IsolatedBorrowRate, IsolatedBorrowRates, Leverage, Leverages, MarginModification, Market, Num, Order, OrderRequest, OrderSide, OrderType, Position, Str, Strings, Ticker, Tickers, Trade, TradingFeeInterface, TradingFees, Transaction, TransferEntry
|
8
|
+
from ccxt.base.types import Balances, Currencies, Currency, Int, IsolatedBorrowRate, IsolatedBorrowRates, Leverage, Leverages, MarginModification, Market, Num, Order, OrderRequest, OrderSide, OrderType, Position, Str, Strings, Ticker, Tickers, Trade, TradingFeeInterface, TradingFees, Transaction, TransferEntry, TransferEntries
|
9
9
|
from typing import List
|
10
10
|
from ccxt.base.errors import ExchangeError
|
11
11
|
from ccxt.base.errors import AuthenticationError
|
@@ -811,7 +811,7 @@ class coinex(Exchange, ImplicitAPI):
|
|
811
811
|
})
|
812
812
|
return result
|
813
813
|
|
814
|
-
def parse_ticker(self, ticker, market: Market = None) -> Ticker:
|
814
|
+
def parse_ticker(self, ticker: dict, market: Market = None) -> Ticker:
|
815
815
|
#
|
816
816
|
# Spot fetchTicker, fetchTickers
|
817
817
|
#
|
@@ -1127,106 +1127,49 @@ class coinex(Exchange, ImplicitAPI):
|
|
1127
1127
|
#
|
1128
1128
|
# Spot and Margin fetchMyTrades(private)
|
1129
1129
|
#
|
1130
|
-
#
|
1131
|
-
#
|
1132
|
-
#
|
1133
|
-
#
|
1134
|
-
#
|
1135
|
-
#
|
1136
|
-
#
|
1137
|
-
#
|
1138
|
-
#
|
1139
|
-
#
|
1140
|
-
# "fee_asset": "USDT",
|
1141
|
-
# "market": "AAVEUSDT",
|
1142
|
-
# "deal_money": "18.84442"
|
1143
|
-
# }
|
1130
|
+
# {
|
1131
|
+
# "amount": "0.00010087",
|
1132
|
+
# "created_at": 1714618087585,
|
1133
|
+
# "deal_id": 4161200602,
|
1134
|
+
# "margin_market": "",
|
1135
|
+
# "market": "BTCUSDT",
|
1136
|
+
# "order_id": 117654919342,
|
1137
|
+
# "price": "57464.04",
|
1138
|
+
# "side": "sell"
|
1139
|
+
# }
|
1144
1140
|
#
|
1145
1141
|
# Swap fetchMyTrades(private)
|
1146
1142
|
#
|
1147
1143
|
# {
|
1148
|
-
# "
|
1149
|
-
# "
|
1150
|
-
# "deal_insurance": "0",
|
1151
|
-
# "deal_margin": "15.8352",
|
1152
|
-
# "deal_order_id": 17797031903,
|
1153
|
-
# "deal_profit": "0",
|
1154
|
-
# "deal_stock": "47.5056",
|
1155
|
-
# "deal_type": 1,
|
1156
|
-
# "deal_user_id": 2969195,
|
1157
|
-
# "fee_asset": "",
|
1158
|
-
# "fee_discount": "0",
|
1159
|
-
# "fee_price": "0",
|
1160
|
-
# "fee_rate": "0.0005",
|
1161
|
-
# "fee_real_rate": "0.0005",
|
1162
|
-
# "id": 379044296,
|
1163
|
-
# "leverage": "3",
|
1164
|
-
# "margin_amount": "15.8352",
|
1144
|
+
# "deal_id": 1180222387,
|
1145
|
+
# "created_at": 1714119054558,
|
1165
1146
|
# "market": "BTCUSDT",
|
1166
|
-
# "
|
1167
|
-
# "order_id":
|
1168
|
-
# "
|
1169
|
-
# "
|
1170
|
-
# "position_type": 1,
|
1171
|
-
# "price": "39588",
|
1172
|
-
# "role": 2,
|
1173
|
-
# "side": 2,
|
1174
|
-
# "time": 1650675936.016103,
|
1175
|
-
# "user_id": 3620173
|
1147
|
+
# "side": "buy",
|
1148
|
+
# "order_id": 136915589622,
|
1149
|
+
# "price": "64376",
|
1150
|
+
# "amount": "0.0001"
|
1176
1151
|
# }
|
1177
1152
|
#
|
1178
|
-
timestamp = self.
|
1179
|
-
|
1180
|
-
|
1181
|
-
|
1182
|
-
orderId = self.safe_string(trade, 'order_id')
|
1183
|
-
priceString = self.safe_string(trade, 'price')
|
1184
|
-
amountString = self.safe_string(trade, 'amount')
|
1153
|
+
timestamp = self.safe_integer(trade, 'created_at')
|
1154
|
+
defaultType = self.safe_string(self.options, 'defaultType')
|
1155
|
+
if market is not None:
|
1156
|
+
defaultType = market['type']
|
1185
1157
|
marketId = self.safe_string(trade, 'market')
|
1186
|
-
marketType = self.safe_string(trade, 'market_type')
|
1187
|
-
defaultType = 'spot' if (marketType is None) else 'swap'
|
1188
1158
|
market = self.safe_market(marketId, market, None, defaultType)
|
1189
|
-
symbol = market['symbol']
|
1190
|
-
costString = self.safe_string(trade, 'deal_money')
|
1191
|
-
fee = None
|
1192
|
-
feeCostString = self.safe_string_2(trade, 'fee', 'deal_fee')
|
1193
|
-
if feeCostString is not None:
|
1194
|
-
feeCurrencyId = self.safe_string(trade, 'fee_asset')
|
1195
|
-
feeCurrencyCode = self.safe_currency_code(feeCurrencyId)
|
1196
|
-
fee = {
|
1197
|
-
'cost': feeCostString,
|
1198
|
-
'currency': feeCurrencyCode,
|
1199
|
-
}
|
1200
|
-
takerOrMaker = self.safe_string(trade, 'role')
|
1201
|
-
if takerOrMaker == '1':
|
1202
|
-
takerOrMaker = 'maker'
|
1203
|
-
elif takerOrMaker == '2':
|
1204
|
-
takerOrMaker = 'taker'
|
1205
|
-
side: Str = None
|
1206
|
-
if market['type'] == 'swap':
|
1207
|
-
rawSide = self.safe_integer(trade, 'side')
|
1208
|
-
if rawSide == 1:
|
1209
|
-
side = 'sell'
|
1210
|
-
elif rawSide == 2:
|
1211
|
-
side = 'buy'
|
1212
|
-
if side is None:
|
1213
|
-
side = self.safe_string_2(trade, 'type', 'side')
|
1214
|
-
else:
|
1215
|
-
side = self.safe_string_2(trade, 'type', 'side')
|
1216
1159
|
return self.safe_trade({
|
1217
1160
|
'info': trade,
|
1218
1161
|
'timestamp': timestamp,
|
1219
1162
|
'datetime': self.iso8601(timestamp),
|
1220
|
-
'symbol': symbol,
|
1221
|
-
'id':
|
1222
|
-
'order':
|
1163
|
+
'symbol': market['symbol'],
|
1164
|
+
'id': self.safe_string(trade, 'deal_id'),
|
1165
|
+
'order': self.safe_string(trade, 'order_id'),
|
1223
1166
|
'type': None,
|
1224
|
-
'side': side,
|
1225
|
-
'takerOrMaker':
|
1226
|
-
'price':
|
1227
|
-
'amount':
|
1228
|
-
'cost':
|
1229
|
-
'fee':
|
1167
|
+
'side': self.safe_string(trade, 'side'),
|
1168
|
+
'takerOrMaker': None,
|
1169
|
+
'price': self.safe_string(trade, 'price'),
|
1170
|
+
'amount': self.safe_string(trade, 'amount'),
|
1171
|
+
'cost': self.safe_string(trade, 'deal_money'),
|
1172
|
+
'fee': None,
|
1230
1173
|
}, market)
|
1231
1174
|
|
1232
1175
|
def fetch_trades(self, symbol: str, since: Int = None, limit: Int = None, params={}) -> List[Trade]:
|
@@ -3604,145 +3547,101 @@ class coinex(Exchange, ImplicitAPI):
|
|
3604
3547
|
def fetch_my_trades(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}):
|
3605
3548
|
"""
|
3606
3549
|
fetch all trades made by the user
|
3607
|
-
:see: https://
|
3608
|
-
:see: https://
|
3550
|
+
:see: https://docs.coinex.com/api/v2/spot/deal/http/list-user-deals
|
3551
|
+
:see: https://docs.coinex.com/api/v2/futures/deal/http/list-user-deals
|
3609
3552
|
:param str symbol: unified market symbol
|
3610
3553
|
:param int [since]: the earliest time in ms to fetch trades for
|
3611
|
-
:param int [limit]: the maximum number of
|
3554
|
+
:param int [limit]: the maximum number of trade structures to retrieve
|
3612
3555
|
:param dict [params]: extra parameters specific to the exchange API endpoint
|
3556
|
+
:param int [params.until]: timestamp in ms of the latest trades
|
3557
|
+
:param str [params.side]: the side of the trades, either 'buy' or 'sell', required for swap
|
3613
3558
|
:returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
|
3614
3559
|
"""
|
3560
|
+
if symbol is None:
|
3561
|
+
raise ArgumentsRequired(self.id + ' fetchMyTrades() requires a symbol argument')
|
3615
3562
|
self.load_markets()
|
3616
|
-
market =
|
3617
|
-
if limit is None:
|
3618
|
-
limit = 100
|
3563
|
+
market = self.market(symbol)
|
3619
3564
|
request = {
|
3620
|
-
'
|
3621
|
-
'offset': 0, # SWAP, means query from a certain record
|
3622
|
-
# 'page': 1, # SPOT
|
3623
|
-
# 'side': 2, # SWAP, 0 for no limit, 1 for sell, 2 for buy
|
3624
|
-
# 'start_time': since, # SWAP
|
3625
|
-
# 'end_time': 1524228297, # SWAP
|
3565
|
+
'market': market['id'],
|
3626
3566
|
}
|
3627
|
-
if
|
3628
|
-
|
3629
|
-
|
3630
|
-
|
3631
|
-
|
3632
|
-
if type != 'spot' and symbol is None:
|
3633
|
-
raise ArgumentsRequired(self.id + ' fetchMyTrades() requires a symbol argument for non-spot markets')
|
3634
|
-
swap = (type == 'swap')
|
3635
|
-
accountId = self.safe_integer(params, 'account_id')
|
3636
|
-
marginMode = None
|
3637
|
-
marginMode, params = self.handle_margin_mode_and_params('fetchMyTrades', params)
|
3638
|
-
if marginMode is not None:
|
3639
|
-
if accountId is None:
|
3640
|
-
raise BadRequest(self.id + ' fetchMyTrades() requires an account_id parameter for margin trades')
|
3641
|
-
request['account_id'] = accountId
|
3642
|
-
params = self.omit(params, 'account_id')
|
3567
|
+
if limit is not None:
|
3568
|
+
request['limit'] = limit
|
3569
|
+
if since is not None:
|
3570
|
+
request['start_time'] = since
|
3571
|
+
request, params = self.handle_until_option('end_time', request, params)
|
3643
3572
|
response = None
|
3644
|
-
if swap:
|
3645
|
-
|
3646
|
-
|
3647
|
-
|
3648
|
-
|
3573
|
+
if market['swap']:
|
3574
|
+
request['market_type'] = 'FUTURES'
|
3575
|
+
response = self.v2PrivateGetFuturesUserDeals(self.extend(request, params))
|
3576
|
+
#
|
3577
|
+
# {
|
3578
|
+
# "code": 0,
|
3579
|
+
# "data": [
|
3580
|
+
# {
|
3581
|
+
# "deal_id": 1180222387,
|
3582
|
+
# "created_at": 1714119054558,
|
3583
|
+
# "market": "BTCUSDT",
|
3584
|
+
# "side": "buy",
|
3585
|
+
# "order_id": 136915589622,
|
3586
|
+
# "price": "64376",
|
3587
|
+
# "amount": "0.0001"
|
3588
|
+
# }
|
3589
|
+
# ],
|
3590
|
+
# "message": "OK",
|
3591
|
+
# "pagination": {
|
3592
|
+
# "has_next": True
|
3593
|
+
# }
|
3594
|
+
# }
|
3595
|
+
#
|
3649
3596
|
else:
|
3650
|
-
|
3651
|
-
|
3652
|
-
|
3653
|
-
|
3654
|
-
|
3655
|
-
|
3656
|
-
|
3657
|
-
|
3658
|
-
|
3659
|
-
|
3660
|
-
|
3661
|
-
|
3662
|
-
|
3663
|
-
|
3664
|
-
|
3665
|
-
|
3666
|
-
|
3667
|
-
|
3668
|
-
|
3669
|
-
|
3670
|
-
|
3671
|
-
|
3672
|
-
|
3673
|
-
|
3674
|
-
|
3675
|
-
|
3676
|
-
|
3677
|
-
|
3678
|
-
|
3679
|
-
|
3680
|
-
#
|
3681
|
-
# Swap
|
3682
|
-
#
|
3683
|
-
# {
|
3684
|
-
# "code": 0,
|
3685
|
-
# "data": {
|
3686
|
-
# "limit": 100,
|
3687
|
-
# "offset": 0,
|
3688
|
-
# "records": [
|
3689
|
-
# {
|
3690
|
-
# "amount": "0.0012",
|
3691
|
-
# "deal_fee": "0.0237528",
|
3692
|
-
# "deal_insurance": "0",
|
3693
|
-
# "deal_margin": "15.8352",
|
3694
|
-
# "deal_order_id": 17797031903,
|
3695
|
-
# "deal_profit": "0",
|
3696
|
-
# "deal_stock": "47.5056",
|
3697
|
-
# "deal_type": 1,
|
3698
|
-
# "deal_user_id": 2969195,
|
3699
|
-
# "fee_asset": "",
|
3700
|
-
# "fee_discount": "0",
|
3701
|
-
# "fee_price": "0",
|
3702
|
-
# "fee_rate": "0.0005",
|
3703
|
-
# "fee_real_rate": "0.0005",
|
3704
|
-
# "id": 379044296,
|
3705
|
-
# "leverage": "3",
|
3706
|
-
# "margin_amount": "15.8352",
|
3707
|
-
# "market": "BTCUSDT",
|
3708
|
-
# "open_price": "39588",
|
3709
|
-
# "order_id": 17797092987,
|
3710
|
-
# "position_amount": "0.0012",
|
3711
|
-
# "position_id": 62052321,
|
3712
|
-
# "position_type": 1,
|
3713
|
-
# "price": "39588",
|
3714
|
-
# "role": 2,
|
3715
|
-
# "side": 2,
|
3716
|
-
# "time": 1650675936.016103,
|
3717
|
-
# "user_id": 3620173
|
3718
|
-
# }
|
3719
|
-
# ]
|
3720
|
-
# },
|
3721
|
-
# "message": "OK"
|
3722
|
-
# }
|
3723
|
-
#
|
3724
|
-
tradeRequest = 'records' if swap else 'data'
|
3725
|
-
data = self.safe_value(response, 'data')
|
3726
|
-
trades = self.safe_list(data, tradeRequest, [])
|
3727
|
-
return self.parse_trades(trades, market, since, limit)
|
3597
|
+
marginMode = None
|
3598
|
+
marginMode, params = self.handle_margin_mode_and_params('fetchMyTrades', params)
|
3599
|
+
if marginMode is not None:
|
3600
|
+
request['market_type'] = 'MARGIN'
|
3601
|
+
else:
|
3602
|
+
request['market_type'] = 'SPOT'
|
3603
|
+
response = self.v2PrivateGetSpotUserDeals(self.extend(request, params))
|
3604
|
+
#
|
3605
|
+
# {
|
3606
|
+
# "code": 0,
|
3607
|
+
# "data": [
|
3608
|
+
# {
|
3609
|
+
# "amount": "0.00010087",
|
3610
|
+
# "created_at": 1714618087585,
|
3611
|
+
# "deal_id": 4161200602,
|
3612
|
+
# "margin_market": "",
|
3613
|
+
# "market": "BTCUSDT",
|
3614
|
+
# "order_id": 117654919342,
|
3615
|
+
# "price": "57464.04",
|
3616
|
+
# "side": "sell"
|
3617
|
+
# }
|
3618
|
+
# ],
|
3619
|
+
# "message": "OK",
|
3620
|
+
# "pagination": {
|
3621
|
+
# "has_next": True
|
3622
|
+
# }
|
3623
|
+
# }
|
3624
|
+
#
|
3625
|
+
data = self.safe_list(response, 'data', [])
|
3626
|
+
return self.parse_trades(data, market, since, limit)
|
3728
3627
|
|
3729
3628
|
def fetch_positions(self, symbols: Strings = None, params={}):
|
3730
3629
|
"""
|
3731
3630
|
fetch all open positions
|
3732
|
-
:see: https://
|
3733
|
-
:see: https://
|
3631
|
+
:see: https://docs.coinex.com/api/v2/futures/position/http/list-pending-position
|
3632
|
+
:see: https://docs.coinex.com/api/v2/futures/position/http/list-finished-position
|
3734
3633
|
:param str[] [symbols]: list of unified market symbols
|
3735
3634
|
:param dict [params]: extra parameters specific to the exchange API endpoint
|
3736
|
-
:param str [params.method]: the method to use '
|
3737
|
-
:param int [params.side]: *history endpoint only* 0: All, 1: Sell, 2: Buy, default is 0
|
3635
|
+
:param str [params.method]: the method to use 'v2PrivateGetFuturesPendingPosition' or 'v2PrivateGetFuturesFinishedPosition' default is 'v2PrivateGetFuturesPendingPosition'
|
3738
3636
|
:returns dict[]: a list of `position structure <https://docs.ccxt.com/#/?id=position-structure>`
|
3739
3637
|
"""
|
3740
3638
|
self.load_markets()
|
3741
3639
|
defaultMethod = None
|
3742
|
-
defaultMethod, params = self.handle_option_and_params(params, 'fetchPositions', 'method', '
|
3743
|
-
isHistory = (defaultMethod == 'v1PerpetualPrivateGetPositionFinished')
|
3640
|
+
defaultMethod, params = self.handle_option_and_params(params, 'fetchPositions', 'method', 'v2PrivateGetFuturesPendingPosition')
|
3744
3641
|
symbols = self.market_symbols(symbols)
|
3745
|
-
request = {
|
3642
|
+
request = {
|
3643
|
+
'market_type': 'FUTURES',
|
3644
|
+
}
|
3746
3645
|
market = None
|
3747
3646
|
if symbols is not None:
|
3748
3647
|
symbol = None
|
@@ -3755,77 +3654,55 @@ class coinex(Exchange, ImplicitAPI):
|
|
3755
3654
|
symbol = symbols
|
3756
3655
|
market = self.market(symbol)
|
3757
3656
|
request['market'] = market['id']
|
3758
|
-
else:
|
3759
|
-
if isHistory:
|
3760
|
-
raise ArgumentsRequired(self.id + ' fetchPositions() requires a symbol argument for closed positions')
|
3761
|
-
if isHistory:
|
3762
|
-
request['limit'] = 100
|
3763
|
-
request['side'] = self.safe_integer(params, 'side', 0) # 0: All, 1: Sell, 2: Buy
|
3764
3657
|
response = None
|
3765
|
-
if defaultMethod == '
|
3766
|
-
response = self.
|
3658
|
+
if defaultMethod == 'v2PrivateGetFuturesPendingPosition':
|
3659
|
+
response = self.v2PrivateGetFuturesPendingPosition(self.extend(request, params))
|
3767
3660
|
else:
|
3768
|
-
response = self.
|
3661
|
+
response = self.v2PrivateGetFuturesFinishedPosition(self.extend(request, params))
|
3769
3662
|
#
|
3770
3663
|
# {
|
3771
3664
|
# "code": 0,
|
3772
3665
|
# "data": [
|
3773
3666
|
# {
|
3774
|
-
# "
|
3775
|
-
# "adl_sort_val": "0.00007786",
|
3776
|
-
# "amount": "0.0005",
|
3777
|
-
# "amount_max": "0.0005",
|
3778
|
-
# "amount_max_margin": "6.42101333333333333333",
|
3779
|
-
# "bkr_price": "25684.05333333333333346175",
|
3780
|
-
# "bkr_price_imply": "0.00000000000000000000",
|
3781
|
-
# "close_left": "0.0005",
|
3782
|
-
# "create_time": 1651294226.110899,
|
3783
|
-
# "deal_all": "19.26000000000000000000",
|
3784
|
-
# "deal_asset_fee": "0.00000000000000000000",
|
3785
|
-
# "fee_asset": "",
|
3786
|
-
# "finish_type": 1,
|
3787
|
-
# "first_price": "38526.08",
|
3788
|
-
# "insurance": "0.00000000000000000000",
|
3789
|
-
# "latest_price": "38526.08",
|
3790
|
-
# "leverage": "3",
|
3791
|
-
# "liq_amount": "0.00000000000000000000",
|
3792
|
-
# "liq_order_price": "0",
|
3793
|
-
# "liq_order_time": 0,
|
3794
|
-
# "liq_price": "25876.68373333333333346175",
|
3795
|
-
# "liq_price_imply": "0.00000000000000000000",
|
3796
|
-
# "liq_profit": "0.00000000000000000000",
|
3797
|
-
# "liq_time": 0,
|
3798
|
-
# "mainten_margin": "0.005",
|
3799
|
-
# "mainten_margin_amount": "0.09631520000000000000",
|
3800
|
-
# "maker_fee": "0.00000000000000000000",
|
3801
|
-
# "margin_amount": "6.42101333333333333333",
|
3667
|
+
# "position_id": 305891033,
|
3802
3668
|
# "market": "BTCUSDT",
|
3803
|
-
# "
|
3804
|
-
# "
|
3805
|
-
# "
|
3806
|
-
# "
|
3807
|
-
# "
|
3808
|
-
# "
|
3809
|
-
# "
|
3810
|
-
# "
|
3811
|
-
# "
|
3812
|
-
# "
|
3813
|
-
# "
|
3814
|
-
# "
|
3815
|
-
# "
|
3816
|
-
# "take_profit_price": "0
|
3817
|
-
# "
|
3818
|
-
# "
|
3819
|
-
# "
|
3820
|
-
# "
|
3821
|
-
# "
|
3822
|
-
# "
|
3823
|
-
#
|
3669
|
+
# "market_type": "FUTURES",
|
3670
|
+
# "side": "long",
|
3671
|
+
# "margin_mode": "cross",
|
3672
|
+
# "open_interest": "0.0001",
|
3673
|
+
# "close_avbl": "0.0001",
|
3674
|
+
# "ath_position_amount": "0.0001",
|
3675
|
+
# "unrealized_pnl": "0",
|
3676
|
+
# "realized_pnl": "-0.00311684",
|
3677
|
+
# "avg_entry_price": "62336.8",
|
3678
|
+
# "cml_position_value": "6.23368",
|
3679
|
+
# "max_position_value": "6.23368",
|
3680
|
+
# "created_at": 1715152208041,
|
3681
|
+
# "updated_at": 1715152208041,
|
3682
|
+
# "take_profit_price": "0",
|
3683
|
+
# "stop_loss_price": "0",
|
3684
|
+
# "take_profit_type": "",
|
3685
|
+
# "stop_loss_type": "",
|
3686
|
+
# "settle_price": "62336.8",
|
3687
|
+
# "settle_value": "6.23368",
|
3688
|
+
# "leverage": "3",
|
3689
|
+
# "margin_avbl": "2.07789333",
|
3690
|
+
# "ath_margin_size": "2.07789333",
|
3691
|
+
# "position_margin_rate": "2.40545879023305655728",
|
3692
|
+
# "maintenance_margin_rate": "0.005",
|
3693
|
+
# "maintenance_margin_value": "0.03118094",
|
3694
|
+
# "liq_price": "0",
|
3695
|
+
# "bkr_price": "0",
|
3696
|
+
# "adl_level": 1
|
3697
|
+
# }
|
3824
3698
|
# ],
|
3825
|
-
# "message": "OK"
|
3699
|
+
# "message": "OK",
|
3700
|
+
# "pagination": {
|
3701
|
+
# "has_next": False
|
3702
|
+
# }
|
3826
3703
|
# }
|
3827
3704
|
#
|
3828
|
-
position = self.
|
3705
|
+
position = self.safe_list(response, 'data', [])
|
3829
3706
|
result = []
|
3830
3707
|
for i in range(0, len(position)):
|
3831
3708
|
result.append(self.parse_position(position[i], market))
|
@@ -3834,215 +3711,129 @@ class coinex(Exchange, ImplicitAPI):
|
|
3834
3711
|
def fetch_position(self, symbol: str, params={}):
|
3835
3712
|
"""
|
3836
3713
|
fetch data on a single open contract trade position
|
3837
|
-
:see: https://
|
3838
|
-
:param str symbol: unified market symbol of the market the position is held in
|
3714
|
+
:see: https://docs.coinex.com/api/v2/futures/position/http/list-pending-position
|
3715
|
+
:param str symbol: unified market symbol of the market the position is held in
|
3839
3716
|
:param dict [params]: extra parameters specific to the exchange API endpoint
|
3840
3717
|
:returns dict: a `position structure <https://docs.ccxt.com/#/?id=position-structure>`
|
3841
3718
|
"""
|
3842
3719
|
self.load_markets()
|
3843
3720
|
market = self.market(symbol)
|
3844
3721
|
request = {
|
3722
|
+
'market_type': 'FUTURES',
|
3845
3723
|
'market': market['id'],
|
3846
3724
|
}
|
3847
|
-
response = self.
|
3725
|
+
response = self.v2PrivateGetFuturesPendingPosition(self.extend(request, params))
|
3848
3726
|
#
|
3849
3727
|
# {
|
3850
3728
|
# "code": 0,
|
3851
3729
|
# "data": [
|
3852
3730
|
# {
|
3853
|
-
# "
|
3854
|
-
# "adl_sort_val": "0.00007786",
|
3855
|
-
# "amount": "0.0005",
|
3856
|
-
# "amount_max": "0.0005",
|
3857
|
-
# "amount_max_margin": "6.42101333333333333333",
|
3858
|
-
# "bkr_price": "25684.05333333333333346175",
|
3859
|
-
# "bkr_price_imply": "0.00000000000000000000",
|
3860
|
-
# "close_left": "0.0005",
|
3861
|
-
# "create_time": 1651294226.110899,
|
3862
|
-
# "deal_all": "19.26000000000000000000",
|
3863
|
-
# "deal_asset_fee": "0.00000000000000000000",
|
3864
|
-
# "fee_asset": "",
|
3865
|
-
# "finish_type": 1,
|
3866
|
-
# "first_price": "38526.08",
|
3867
|
-
# "insurance": "0.00000000000000000000",
|
3868
|
-
# "latest_price": "38526.08",
|
3869
|
-
# "leverage": "3",
|
3870
|
-
# "liq_amount": "0.00000000000000000000",
|
3871
|
-
# "liq_order_price": "0",
|
3872
|
-
# "liq_order_time": 0,
|
3873
|
-
# "liq_price": "25876.68373333333333346175",
|
3874
|
-
# "liq_price_imply": "0.00000000000000000000",
|
3875
|
-
# "liq_profit": "0.00000000000000000000",
|
3876
|
-
# "liq_time": 0,
|
3877
|
-
# "mainten_margin": "0.005",
|
3878
|
-
# "mainten_margin_amount": "0.09631520000000000000",
|
3879
|
-
# "maker_fee": "0.00000000000000000000",
|
3880
|
-
# "margin_amount": "6.42101333333333333333",
|
3731
|
+
# "position_id": 305891033,
|
3881
3732
|
# "market": "BTCUSDT",
|
3882
|
-
# "
|
3883
|
-
# "
|
3884
|
-
# "
|
3885
|
-
# "
|
3886
|
-
# "
|
3887
|
-
# "
|
3888
|
-
# "
|
3889
|
-
# "
|
3890
|
-
# "
|
3891
|
-
# "
|
3892
|
-
# "
|
3893
|
-
# "
|
3894
|
-
# "
|
3895
|
-
# "take_profit_price": "0
|
3896
|
-
# "
|
3897
|
-
# "
|
3898
|
-
# "
|
3899
|
-
# "
|
3900
|
-
# "
|
3901
|
-
# "
|
3733
|
+
# "market_type": "FUTURES",
|
3734
|
+
# "side": "long",
|
3735
|
+
# "margin_mode": "cross",
|
3736
|
+
# "open_interest": "0.0001",
|
3737
|
+
# "close_avbl": "0.0001",
|
3738
|
+
# "ath_position_amount": "0.0001",
|
3739
|
+
# "unrealized_pnl": "0",
|
3740
|
+
# "realized_pnl": "-0.00311684",
|
3741
|
+
# "avg_entry_price": "62336.8",
|
3742
|
+
# "cml_position_value": "6.23368",
|
3743
|
+
# "max_position_value": "6.23368",
|
3744
|
+
# "created_at": 1715152208041,
|
3745
|
+
# "updated_at": 1715152208041,
|
3746
|
+
# "take_profit_price": "0",
|
3747
|
+
# "stop_loss_price": "0",
|
3748
|
+
# "take_profit_type": "",
|
3749
|
+
# "stop_loss_type": "",
|
3750
|
+
# "settle_price": "62336.8",
|
3751
|
+
# "settle_value": "6.23368",
|
3752
|
+
# "leverage": "3",
|
3753
|
+
# "margin_avbl": "2.07789333",
|
3754
|
+
# "ath_margin_size": "2.07789333",
|
3755
|
+
# "position_margin_rate": "2.40545879023305655728",
|
3756
|
+
# "maintenance_margin_rate": "0.005",
|
3757
|
+
# "maintenance_margin_value": "0.03118094",
|
3758
|
+
# "liq_price": "0",
|
3759
|
+
# "bkr_price": "0",
|
3760
|
+
# "adl_level": 1
|
3902
3761
|
# }
|
3903
3762
|
# ],
|
3904
|
-
# "message": "OK"
|
3763
|
+
# "message": "OK",
|
3764
|
+
# "pagination": {
|
3765
|
+
# "has_next": False
|
3766
|
+
# }
|
3905
3767
|
# }
|
3906
3768
|
#
|
3907
3769
|
data = self.safe_list(response, 'data', [])
|
3908
3770
|
return self.parse_position(data[0], market)
|
3909
3771
|
|
3910
3772
|
def parse_position(self, position, market: Market = None):
|
3911
|
-
#
|
3912
|
-
# fetchPosition
|
3913
3773
|
#
|
3914
3774
|
# {
|
3915
|
-
# "
|
3916
|
-
# "adl_sort_val": "0.00007786",
|
3917
|
-
# "amount": "0.0005",
|
3918
|
-
# "amount_max": "0.0005",
|
3919
|
-
# "amount_max_margin": "6.42101333333333333333",
|
3920
|
-
# "bkr_price": "25684.05333333333333346175",
|
3921
|
-
# "bkr_price_imply": "0.00000000000000000000",
|
3922
|
-
# "close_left": "0.0005",
|
3923
|
-
# "create_time": 1651294226.110899,
|
3924
|
-
# "deal_all": "19.26000000000000000000",
|
3925
|
-
# "deal_asset_fee": "0.00000000000000000000",
|
3926
|
-
# "fee_asset": "",
|
3927
|
-
# "finish_type": 1,
|
3928
|
-
# "first_price": "38526.08",
|
3929
|
-
# "insurance": "0.00000000000000000000",
|
3930
|
-
# "latest_price": "38526.08",
|
3931
|
-
# "leverage": "3",
|
3932
|
-
# "liq_amount": "0.00000000000000000000",
|
3933
|
-
# "liq_order_price": "0",
|
3934
|
-
# "liq_order_time": 0,
|
3935
|
-
# "liq_price": "25876.68373333333333346175",
|
3936
|
-
# "liq_price_imply": "0.00000000000000000000",
|
3937
|
-
# "liq_profit": "0.00000000000000000000",
|
3938
|
-
# "liq_time": 0,
|
3939
|
-
# "mainten_margin": "0.005",
|
3940
|
-
# "mainten_margin_amount": "0.09631520000000000000",
|
3941
|
-
# "maker_fee": "0.00000000000000000000",
|
3942
|
-
# "margin_amount": "6.42101333333333333333",
|
3775
|
+
# "position_id": 305891033,
|
3943
3776
|
# "market": "BTCUSDT",
|
3944
|
-
# "
|
3945
|
-
# "
|
3946
|
-
# "
|
3947
|
-
# "
|
3948
|
-
# "
|
3949
|
-
# "
|
3950
|
-
# "
|
3951
|
-
# "
|
3952
|
-
# "
|
3953
|
-
# "
|
3954
|
-
# "
|
3955
|
-
# "
|
3956
|
-
# "
|
3957
|
-
# "take_profit_price": "0
|
3958
|
-
# "
|
3959
|
-
# "
|
3960
|
-
# "
|
3961
|
-
# "
|
3962
|
-
# "
|
3963
|
-
# "
|
3777
|
+
# "market_type": "FUTURES",
|
3778
|
+
# "side": "long",
|
3779
|
+
# "margin_mode": "cross",
|
3780
|
+
# "open_interest": "0.0001",
|
3781
|
+
# "close_avbl": "0.0001",
|
3782
|
+
# "ath_position_amount": "0.0001",
|
3783
|
+
# "unrealized_pnl": "0",
|
3784
|
+
# "realized_pnl": "-0.00311684",
|
3785
|
+
# "avg_entry_price": "62336.8",
|
3786
|
+
# "cml_position_value": "6.23368",
|
3787
|
+
# "max_position_value": "6.23368",
|
3788
|
+
# "created_at": 1715152208041,
|
3789
|
+
# "updated_at": 1715152208041,
|
3790
|
+
# "take_profit_price": "0",
|
3791
|
+
# "stop_loss_price": "0",
|
3792
|
+
# "take_profit_type": "",
|
3793
|
+
# "stop_loss_type": "",
|
3794
|
+
# "settle_price": "62336.8",
|
3795
|
+
# "settle_value": "6.23368",
|
3796
|
+
# "leverage": "3",
|
3797
|
+
# "margin_avbl": "2.07789333",
|
3798
|
+
# "ath_margin_size": "2.07789333",
|
3799
|
+
# "position_margin_rate": "2.40545879023305655728",
|
3800
|
+
# "maintenance_margin_rate": "0.005",
|
3801
|
+
# "maintenance_margin_value": "0.03118094",
|
3802
|
+
# "liq_price": "0",
|
3803
|
+
# "bkr_price": "0",
|
3804
|
+
# "adl_level": 1
|
3964
3805
|
# }
|
3965
3806
|
#
|
3966
|
-
#
|
3967
|
-
# fetchPositionHistory
|
3968
|
-
#
|
3969
|
-
# {
|
3970
|
-
# amount_max: '10',
|
3971
|
-
# amount_max_margin: '2.03466666666666666666',
|
3972
|
-
# bkr_price: '0',
|
3973
|
-
# create_time: '1711150526.2581',
|
3974
|
-
# deal_all: '12.591',
|
3975
|
-
# deal_asset_fee: '0',
|
3976
|
-
# fee_asset: '',
|
3977
|
-
# finish_type: '5',
|
3978
|
-
# first_price: '0.6104',
|
3979
|
-
# latest_price: '0.6487',
|
3980
|
-
# leverage: '3',
|
3981
|
-
# liq_amount: '0',
|
3982
|
-
# liq_price: '0',
|
3983
|
-
# liq_profit: '0',
|
3984
|
-
# mainten_margin: '0.01',
|
3985
|
-
# market: 'XRPUSDT',
|
3986
|
-
# market_type: '1',
|
3987
|
-
# open_price: '0.6104',
|
3988
|
-
# open_val_max: '6.104',
|
3989
|
-
# position_id: '297371462',
|
3990
|
-
# profit_real: '0.35702107169',
|
3991
|
-
# settle_price: '0.6104',
|
3992
|
-
# settle_val: '0',
|
3993
|
-
# side: '2',
|
3994
|
-
# s ys: "0",
|
3995
|
-
# type: '2',
|
3996
|
-
# update_time: '1711391446.133233',
|
3997
|
-
# user_id: '3685860'
|
3998
|
-
# }
|
3999
|
-
#
|
4000
3807
|
marketId = self.safe_string(position, 'market')
|
4001
3808
|
market = self.safe_market(marketId, market, None, 'swap')
|
4002
|
-
|
4003
|
-
positionId = self.safe_integer(position, 'position_id')
|
4004
|
-
marginModeInteger = self.safe_integer(position, 'type')
|
4005
|
-
marginMode = 'isolated' if (marginModeInteger == 1) else 'cross'
|
4006
|
-
liquidationPrice = self.safe_string(position, 'liq_price')
|
4007
|
-
entryPrice = self.safe_string(position, 'open_price')
|
4008
|
-
unrealizedPnl = self.safe_string(position, 'profit_unreal')
|
4009
|
-
contracts = self.safe_number(position, 'amount')
|
4010
|
-
sideInteger = self.safe_integer(position, 'side')
|
4011
|
-
side = 'short' if (sideInteger == 1) else 'long'
|
4012
|
-
timestamp = self.safe_timestamp(position, 'update_time')
|
4013
|
-
maintenanceMargin = self.safe_string(position, 'mainten_margin_amount')
|
4014
|
-
maintenanceMarginPercentage = self.safe_string(position, 'mainten_margin')
|
4015
|
-
collateral = self.safe_string_2(position, 'margin_amount', 'amount_max_margin')
|
4016
|
-
leverage = self.safe_string(position, 'leverage')
|
4017
|
-
notional = self.safe_string(position, 'open_val')
|
4018
|
-
initialMargin = Precise.string_div(notional, leverage)
|
4019
|
-
initialMarginPercentage = Precise.string_div('1', leverage)
|
3809
|
+
timestamp = self.safe_integer(position, 'created_at')
|
4020
3810
|
return self.safe_position({
|
4021
3811
|
'info': position,
|
4022
|
-
'id':
|
4023
|
-
'symbol': symbol,
|
4024
|
-
'notional': self.
|
4025
|
-
'marginMode':
|
4026
|
-
'liquidationPrice':
|
4027
|
-
'entryPrice': self.
|
4028
|
-
'unrealizedPnl': self.
|
3812
|
+
'id': self.safe_integer(position, 'position_id'),
|
3813
|
+
'symbol': market['symbol'],
|
3814
|
+
'notional': self.safe_number(position, 'settle_value'),
|
3815
|
+
'marginMode': self.safe_string(position, 'margin_mode'),
|
3816
|
+
'liquidationPrice': self.safe_number(position, 'liq_price'),
|
3817
|
+
'entryPrice': self.safe_number(position, 'avg_entry_price'),
|
3818
|
+
'unrealizedPnl': self.safe_number(position, 'unrealized_pnl'),
|
3819
|
+
'realizedPnl': self.safe_number(position, 'realized_pnl'),
|
4029
3820
|
'percentage': None,
|
4030
|
-
'contracts':
|
3821
|
+
'contracts': self.safe_number(position, 'close_avbl'),
|
4031
3822
|
'contractSize': self.safe_number(market, 'contractSize'),
|
4032
3823
|
'markPrice': None,
|
4033
3824
|
'lastPrice': None,
|
4034
|
-
'side': side,
|
3825
|
+
'side': self.safe_string(position, 'side'),
|
4035
3826
|
'hedged': None,
|
4036
3827
|
'timestamp': timestamp,
|
4037
3828
|
'datetime': self.iso8601(timestamp),
|
4038
|
-
'lastUpdateTimestamp':
|
4039
|
-
'maintenanceMargin': self.
|
4040
|
-
'maintenanceMarginPercentage': self.
|
4041
|
-
'collateral': self.
|
4042
|
-
'initialMargin':
|
4043
|
-
'initialMarginPercentage':
|
4044
|
-
'leverage': self.
|
4045
|
-
'marginRatio':
|
3829
|
+
'lastUpdateTimestamp': self.safe_integer(position, 'updated_at'),
|
3830
|
+
'maintenanceMargin': self.safe_number(position, 'maintenance_margin_value'),
|
3831
|
+
'maintenanceMarginPercentage': self.safe_number(position, 'maintenance_margin_rate'),
|
3832
|
+
'collateral': self.safe_number(position, 'margin_avbl'),
|
3833
|
+
'initialMargin': None,
|
3834
|
+
'initialMarginPercentage': None,
|
3835
|
+
'leverage': self.safe_number(position, 'leverage'),
|
3836
|
+
'marginRatio': self.safe_number(position, 'position_margin_rate'),
|
4046
3837
|
'stopLossPrice': self.omit_zero(self.safe_string(position, 'stop_loss_price')),
|
4047
3838
|
'takeProfitPrice': self.omit_zero(self.safe_string(position, 'take_profit_price')),
|
4048
3839
|
})
|
@@ -4050,10 +3841,11 @@ class coinex(Exchange, ImplicitAPI):
|
|
4050
3841
|
def set_margin_mode(self, marginMode: str, symbol: Str = None, params={}):
|
4051
3842
|
"""
|
4052
3843
|
set margin mode to 'cross' or 'isolated'
|
4053
|
-
:see: https://
|
3844
|
+
:see: https://docs.coinex.com/api/v2/futures/position/http/adjust-position-leverage
|
4054
3845
|
:param str marginMode: 'cross' or 'isolated'
|
4055
3846
|
:param str symbol: unified market symbol
|
4056
3847
|
:param dict [params]: extra parameters specific to the exchange API endpoint
|
3848
|
+
:param int params['leverage']: the rate of leverage
|
4057
3849
|
:returns dict: response from the exchange
|
4058
3850
|
"""
|
4059
3851
|
if symbol is None:
|
@@ -4065,30 +3857,33 @@ class coinex(Exchange, ImplicitAPI):
|
|
4065
3857
|
market = self.market(symbol)
|
4066
3858
|
if market['type'] != 'swap':
|
4067
3859
|
raise BadSymbol(self.id + ' setMarginMode() supports swap contracts only')
|
4068
|
-
defaultPositionType = None
|
4069
|
-
if marginMode == 'isolated':
|
4070
|
-
defaultPositionType = 1
|
4071
|
-
elif marginMode == 'cross':
|
4072
|
-
defaultPositionType = 2
|
4073
3860
|
leverage = self.safe_integer(params, 'leverage')
|
4074
3861
|
maxLeverage = self.safe_integer(market['limits']['leverage'], 'max', 100)
|
4075
|
-
positionType = self.safe_integer(params, 'position_type', defaultPositionType)
|
4076
3862
|
if leverage is None:
|
4077
3863
|
raise ArgumentsRequired(self.id + ' setMarginMode() requires a leverage parameter')
|
4078
|
-
if
|
4079
|
-
raise
|
4080
|
-
if (leverage < 3) or (leverage > maxLeverage):
|
4081
|
-
raise BadRequest(self.id + ' setMarginMode() leverage should be between 3 and ' + str(maxLeverage) + ' for ' + symbol)
|
3864
|
+
if (leverage < 1) or (leverage > maxLeverage):
|
3865
|
+
raise BadRequest(self.id + ' setMarginMode() leverage should be between 1 and ' + str(maxLeverage) + ' for ' + symbol)
|
4082
3866
|
request = {
|
4083
3867
|
'market': market['id'],
|
4084
|
-
'
|
4085
|
-
'
|
3868
|
+
'market_type': 'FUTURES',
|
3869
|
+
'margin_mode': marginMode,
|
3870
|
+
'leverage': leverage,
|
4086
3871
|
}
|
4087
|
-
return self.
|
3872
|
+
return self.v2PrivatePostFuturesAdjustPositionLeverage(self.extend(request, params))
|
3873
|
+
#
|
3874
|
+
# {
|
3875
|
+
# "code": 0,
|
3876
|
+
# "data": {
|
3877
|
+
# "leverage": 1,
|
3878
|
+
# "margin_mode": "isolated"
|
3879
|
+
# },
|
3880
|
+
# "message": "OK"
|
3881
|
+
# }
|
3882
|
+
#
|
4088
3883
|
|
4089
3884
|
def set_leverage(self, leverage: Int, symbol: Str = None, params={}):
|
4090
3885
|
"""
|
4091
|
-
:see: https://
|
3886
|
+
:see: https://docs.coinex.com/api/v2/futures/position/http/adjust-position-leverage
|
4092
3887
|
set the level of leverage for a market
|
4093
3888
|
:param float leverage: the rate of leverage
|
4094
3889
|
:param str symbol: unified market symbol
|
@@ -4104,21 +3899,27 @@ class coinex(Exchange, ImplicitAPI):
|
|
4104
3899
|
raise BadSymbol(self.id + ' setLeverage() supports swap contracts only')
|
4105
3900
|
marginMode = None
|
4106
3901
|
marginMode, params = self.handle_margin_mode_and_params('setLeverage', params, 'cross')
|
4107
|
-
positionType = None
|
4108
|
-
if marginMode == 'isolated':
|
4109
|
-
positionType = 1
|
4110
|
-
elif marginMode == 'cross':
|
4111
|
-
positionType = 2
|
4112
3902
|
minLeverage = self.safe_integer(market['limits']['leverage'], 'min', 1)
|
4113
3903
|
maxLeverage = self.safe_integer(market['limits']['leverage'], 'max', 100)
|
4114
3904
|
if (leverage < minLeverage) or (leverage > maxLeverage):
|
4115
3905
|
raise BadRequest(self.id + ' setLeverage() leverage should be between ' + str(minLeverage) + ' and ' + str(maxLeverage) + ' for ' + symbol)
|
4116
3906
|
request = {
|
4117
3907
|
'market': market['id'],
|
4118
|
-
'
|
4119
|
-
'
|
3908
|
+
'market_type': 'FUTURES',
|
3909
|
+
'margin_mode': marginMode,
|
3910
|
+
'leverage': leverage,
|
4120
3911
|
}
|
4121
|
-
return self.
|
3912
|
+
return self.v2PrivatePostFuturesAdjustPositionLeverage(self.extend(request, params))
|
3913
|
+
#
|
3914
|
+
# {
|
3915
|
+
# "code": 0,
|
3916
|
+
# "data": {
|
3917
|
+
# "leverage": 1,
|
3918
|
+
# "margin_mode": "isolated"
|
3919
|
+
# },
|
3920
|
+
# "message": "OK"
|
3921
|
+
# }
|
3922
|
+
#
|
4122
3923
|
|
4123
3924
|
def fetch_leverage_tiers(self, symbols: Strings = None, params={}):
|
4124
3925
|
"""
|
@@ -4878,14 +4679,14 @@ class coinex(Exchange, ImplicitAPI):
|
|
4878
4679
|
'toAccount': toAccount,
|
4879
4680
|
})
|
4880
4681
|
|
4881
|
-
def parse_transfer_status(self, status):
|
4682
|
+
def parse_transfer_status(self, status: Str) -> Str:
|
4882
4683
|
statuses = {
|
4883
4684
|
'0': 'ok',
|
4884
4685
|
'SUCCESS': 'ok',
|
4885
4686
|
}
|
4886
4687
|
return self.safe_string(statuses, status, status)
|
4887
4688
|
|
4888
|
-
def parse_transfer(self, transfer, currency: Currency = None):
|
4689
|
+
def parse_transfer(self, transfer: dict, currency: Currency = None) -> TransferEntry:
|
4889
4690
|
#
|
4890
4691
|
# fetchTransfers Swap
|
4891
4692
|
#
|
@@ -4932,7 +4733,7 @@ class coinex(Exchange, ImplicitAPI):
|
|
4932
4733
|
currencyCode = self.safe_currency_code(currencyId, currency)
|
4933
4734
|
return {
|
4934
4735
|
'info': transfer,
|
4935
|
-
'id': self.
|
4736
|
+
'id': self.safe_string(transfer, 'id'),
|
4936
4737
|
'timestamp': timestamp,
|
4937
4738
|
'datetime': self.iso8601(timestamp),
|
4938
4739
|
'currency': currencyCode,
|
@@ -4942,7 +4743,7 @@ class coinex(Exchange, ImplicitAPI):
|
|
4942
4743
|
'status': self.parse_transfer_status(self.safe_string_2(transfer, 'code', 'status')),
|
4943
4744
|
}
|
4944
4745
|
|
4945
|
-
def fetch_transfers(self, code: Str = None, since: Int = None, limit: Int = None, params={}):
|
4746
|
+
def fetch_transfers(self, code: Str = None, since: Int = None, limit: Int = None, params={}) -> TransferEntries:
|
4946
4747
|
"""
|
4947
4748
|
fetch a history of internal transfers made on an account
|
4948
4749
|
:see: https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot002_account025_margin_transfer_history
|
@@ -5567,7 +5368,7 @@ class coinex(Exchange, ImplicitAPI):
|
|
5567
5368
|
leverages = self.safe_list(response, 'data', [])
|
5568
5369
|
return self.parse_leverages(leverages, symbols, 'market', marketType)
|
5569
5370
|
|
5570
|
-
def parse_leverage(self, leverage, market=None) -> Leverage:
|
5371
|
+
def parse_leverage(self, leverage: dict, market: Market = None) -> Leverage:
|
5571
5372
|
marketId = self.safe_string(leverage, 'market')
|
5572
5373
|
leverageValue = self.safe_integer(leverage, 'leverage')
|
5573
5374
|
return {
|
@@ -5581,71 +5382,70 @@ class coinex(Exchange, ImplicitAPI):
|
|
5581
5382
|
def fetch_position_history(self, symbol: str, since: Int = None, limit: Int = None, params={}) -> Position:
|
5582
5383
|
"""
|
5583
5384
|
fetches historical positions
|
5584
|
-
:see: https://
|
5385
|
+
:see: https://docs.coinex.com/api/v2/futures/position/http/list-finished-position
|
5585
5386
|
:param str symbol: unified contract symbol
|
5586
|
-
:param int [since]:
|
5587
|
-
:param int [limit]: the maximum amount of records to fetch, default
|
5588
|
-
:param dict params: extra parameters specific to the exchange api endpoint
|
5589
|
-
|
5590
|
-
* EXCHANGE SPECIFIC PARAMETERS
|
5591
|
-
:param int [params.side]: 0: all 1: sell, 2: buy
|
5387
|
+
:param int [since]: the earliest time in ms to fetch positions for
|
5388
|
+
:param int [limit]: the maximum amount of records to fetch, default is 10
|
5389
|
+
:param dict [params]: extra parameters specific to the exchange api endpoint
|
5390
|
+
:param int [params.until]: the latest time in ms to fetch positions for
|
5592
5391
|
:returns dict[]: a list of `position structures <https://docs.ccxt.com/#/?id=position-structure>`
|
5593
5392
|
"""
|
5594
5393
|
self.load_markets()
|
5595
5394
|
market = self.market(symbol)
|
5596
|
-
if limit is None:
|
5597
|
-
limit = 1000
|
5598
5395
|
request = {
|
5396
|
+
'market_type': 'FUTURES',
|
5599
5397
|
'market': market['id'],
|
5600
|
-
'side': 0,
|
5601
|
-
'limit': limit,
|
5602
5398
|
}
|
5603
|
-
|
5399
|
+
if limit is not None:
|
5400
|
+
request['limit'] = limit
|
5401
|
+
if since is not None:
|
5402
|
+
request['start_time'] = since
|
5403
|
+
request, params = self.handle_until_option('end_time', request, params)
|
5404
|
+
response = self.v2PrivateGetFuturesFinishedPosition(self.extend(request, params))
|
5604
5405
|
#
|
5605
|
-
#
|
5606
|
-
#
|
5607
|
-
#
|
5608
|
-
#
|
5609
|
-
#
|
5610
|
-
#
|
5611
|
-
#
|
5612
|
-
#
|
5613
|
-
#
|
5614
|
-
#
|
5615
|
-
#
|
5616
|
-
#
|
5617
|
-
#
|
5618
|
-
#
|
5619
|
-
#
|
5620
|
-
#
|
5621
|
-
#
|
5622
|
-
#
|
5623
|
-
#
|
5624
|
-
#
|
5625
|
-
#
|
5626
|
-
#
|
5627
|
-
#
|
5628
|
-
#
|
5629
|
-
#
|
5630
|
-
#
|
5631
|
-
#
|
5632
|
-
#
|
5633
|
-
#
|
5634
|
-
#
|
5635
|
-
#
|
5636
|
-
#
|
5637
|
-
#
|
5638
|
-
#
|
5639
|
-
#
|
5640
|
-
#
|
5641
|
-
#
|
5642
|
-
#
|
5643
|
-
#
|
5644
|
-
#
|
5645
|
-
#
|
5406
|
+
# {
|
5407
|
+
# "code": 0,
|
5408
|
+
# "data": [
|
5409
|
+
# {
|
5410
|
+
# "position_id": 305891033,
|
5411
|
+
# "market": "BTCUSDT",
|
5412
|
+
# "market_type": "FUTURES",
|
5413
|
+
# "side": "long",
|
5414
|
+
# "margin_mode": "cross",
|
5415
|
+
# "open_interest": "0.0001",
|
5416
|
+
# "close_avbl": "0.0001",
|
5417
|
+
# "ath_position_amount": "0.0001",
|
5418
|
+
# "unrealized_pnl": "0",
|
5419
|
+
# "realized_pnl": "-0.00311684",
|
5420
|
+
# "avg_entry_price": "62336.8",
|
5421
|
+
# "cml_position_value": "6.23368",
|
5422
|
+
# "max_position_value": "6.23368",
|
5423
|
+
# "created_at": 1715152208041,
|
5424
|
+
# "updated_at": 1715152208041,
|
5425
|
+
# "take_profit_price": "0",
|
5426
|
+
# "stop_loss_price": "0",
|
5427
|
+
# "take_profit_type": "",
|
5428
|
+
# "stop_loss_type": "",
|
5429
|
+
# "settle_price": "62336.8",
|
5430
|
+
# "settle_value": "6.23368",
|
5431
|
+
# "leverage": "3",
|
5432
|
+
# "margin_avbl": "2.07789333",
|
5433
|
+
# "ath_margin_size": "2.07789333",
|
5434
|
+
# "position_margin_rate": "2.40545879023305655728",
|
5435
|
+
# "maintenance_margin_rate": "0.005",
|
5436
|
+
# "maintenance_margin_value": "0.03118094",
|
5437
|
+
# "liq_price": "0",
|
5438
|
+
# "bkr_price": "0",
|
5439
|
+
# "adl_level": 1
|
5440
|
+
# }
|
5441
|
+
# ],
|
5442
|
+
# "message": "OK",
|
5443
|
+
# "pagination": {
|
5444
|
+
# "has_next": False
|
5445
|
+
# }
|
5446
|
+
# }
|
5646
5447
|
#
|
5647
|
-
|
5648
|
-
records = self.safe_list(data, 'records')
|
5448
|
+
records = self.safe_list(response, 'data', [])
|
5649
5449
|
positions = self.parse_positions(records)
|
5650
5450
|
return self.filter_by_symbol_since_limit(positions, symbol, since, limit)
|
5651
5451
|
|