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