ccxt 4.4.21__py2.py3-none-any.whl → 4.4.22__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ccxt/__init__.py +1 -1
- ccxt/abstract/bitflyer.py +1 -0
- ccxt/abstract/bitget.py +3 -0
- ccxt/abstract/cex.py +28 -29
- ccxt/abstract/gate.py +5 -0
- ccxt/abstract/gateio.py +5 -0
- ccxt/abstract/kucoin.py +1 -0
- ccxt/abstract/kucoinfutures.py +1 -0
- ccxt/abstract/okx.py +1 -0
- ccxt/alpaca.py +1 -0
- ccxt/async_support/__init__.py +1 -1
- ccxt/async_support/alpaca.py +1 -0
- ccxt/async_support/base/exchange.py +7 -1
- ccxt/async_support/bigone.py +3 -0
- ccxt/async_support/binance.py +96 -1
- ccxt/async_support/bitflyer.py +56 -1
- ccxt/async_support/bitget.py +73 -1
- ccxt/async_support/bybit.py +74 -1
- ccxt/async_support/cex.py +1247 -1326
- ccxt/async_support/cryptocom.py +1 -1
- ccxt/async_support/gate.py +97 -2
- ccxt/async_support/htx.py +1 -5
- ccxt/async_support/hyperliquid.py +10 -8
- ccxt/async_support/kucoin.py +27 -57
- ccxt/async_support/okx.py +67 -1
- ccxt/base/exchange.py +21 -1
- ccxt/base/types.py +9 -0
- ccxt/bigone.py +3 -0
- ccxt/binance.py +96 -1
- ccxt/bitflyer.py +56 -1
- ccxt/bitget.py +73 -1
- ccxt/bybit.py +74 -1
- ccxt/cex.py +1246 -1326
- ccxt/cryptocom.py +1 -1
- ccxt/gate.py +97 -2
- ccxt/htx.py +1 -5
- ccxt/hyperliquid.py +10 -8
- ccxt/kucoin.py +27 -57
- ccxt/okx.py +67 -1
- ccxt/pro/__init__.py +1 -1
- ccxt/test/tests_async.py +4 -4
- ccxt/test/tests_sync.py +4 -4
- {ccxt-4.4.21.dist-info → ccxt-4.4.22.dist-info}/METADATA +5 -5
- {ccxt-4.4.21.dist-info → ccxt-4.4.22.dist-info}/RECORD +47 -47
- {ccxt-4.4.21.dist-info → ccxt-4.4.22.dist-info}/LICENSE.txt +0 -0
- {ccxt-4.4.21.dist-info → ccxt-4.4.22.dist-info}/WHEEL +0 -0
- {ccxt-4.4.21.dist-info → ccxt-4.4.22.dist-info}/top_level.txt +0 -0
ccxt/cex.py
CHANGED
@@ -6,19 +6,13 @@
|
|
6
6
|
from ccxt.base.exchange import Exchange
|
7
7
|
from ccxt.abstract.cex import ImplicitAPI
|
8
8
|
import hashlib
|
9
|
-
import
|
10
|
-
from ccxt.base.types import Balances, Currencies, DepositAddress, Int, Market, Num, Order, OrderBook, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, TradingFees
|
9
|
+
from ccxt.base.types import Account, Balances, Currencies, Currency, DepositAddress, Int, LedgerEntry, Market, Num, Order, OrderBook, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, TradingFeeInterface, TradingFees, Transaction, TransferEntry
|
11
10
|
from typing import List
|
12
11
|
from ccxt.base.errors import ExchangeError
|
13
|
-
from ccxt.base.errors import
|
12
|
+
from ccxt.base.errors import PermissionDenied
|
14
13
|
from ccxt.base.errors import ArgumentsRequired
|
15
|
-
from ccxt.base.errors import
|
14
|
+
from ccxt.base.errors import BadRequest
|
16
15
|
from ccxt.base.errors import InsufficientFunds
|
17
|
-
from ccxt.base.errors import InvalidOrder
|
18
|
-
from ccxt.base.errors import OrderNotFound
|
19
|
-
from ccxt.base.errors import DDoSProtection
|
20
|
-
from ccxt.base.errors import RateLimitExceeded
|
21
|
-
from ccxt.base.errors import InvalidNonce
|
22
16
|
from ccxt.base.errors import NullResponse
|
23
17
|
from ccxt.base.decimal_to_precision import TICK_SIZE
|
24
18
|
from ccxt.base.precise import Precise
|
@@ -31,161 +25,87 @@ class cex(Exchange, ImplicitAPI):
|
|
31
25
|
'id': 'cex',
|
32
26
|
'name': 'CEX.IO',
|
33
27
|
'countries': ['GB', 'EU', 'CY', 'RU'],
|
34
|
-
'rateLimit':
|
28
|
+
'rateLimit': 1667, # 100 req/min
|
35
29
|
'pro': True,
|
36
30
|
'has': {
|
37
31
|
'CORS': None,
|
38
32
|
'spot': True,
|
39
|
-
'margin': False, # has but not through api
|
33
|
+
'margin': False, # has, but not through api
|
40
34
|
'swap': False,
|
41
35
|
'future': False,
|
42
36
|
'option': False,
|
43
|
-
'addMargin': False,
|
44
37
|
'cancelAllOrders': True,
|
45
38
|
'cancelOrder': True,
|
46
|
-
'cancelOrders': False,
|
47
|
-
'createDepositAddress': False,
|
48
|
-
'createMarketBuyOrderWithCost': True,
|
49
|
-
'createMarketOrderWithCost': False,
|
50
|
-
'createMarketSellOrderWithCost': False,
|
51
39
|
'createOrder': True,
|
52
|
-
'
|
53
|
-
'createStopMarketOrder': False,
|
54
|
-
'createStopOrder': False,
|
55
|
-
'editOrder': True,
|
40
|
+
'fetchAccounts': True,
|
56
41
|
'fetchBalance': True,
|
57
42
|
'fetchClosedOrders': True,
|
58
43
|
'fetchCurrencies': True,
|
59
|
-
'fetchDeposit': False,
|
60
44
|
'fetchDepositAddress': True,
|
61
|
-
'
|
62
|
-
'
|
63
|
-
'fetchDeposits': False,
|
64
|
-
'fetchDepositsWithdrawals': False,
|
65
|
-
'fetchFundingHistory': False,
|
66
|
-
'fetchFundingRate': False,
|
67
|
-
'fetchFundingRateHistory': False,
|
68
|
-
'fetchFundingRates': False,
|
69
|
-
'fetchIndexOHLCV': False,
|
70
|
-
'fetchMarginMode': False,
|
45
|
+
'fetchDepositsWithdrawals': True,
|
46
|
+
'fetchLedger': True,
|
71
47
|
'fetchMarkets': True,
|
72
|
-
'fetchMarkOHLCV': False,
|
73
48
|
'fetchOHLCV': True,
|
74
|
-
'fetchOpenInterestHistory': False,
|
75
49
|
'fetchOpenOrders': True,
|
76
|
-
'fetchOrder': True,
|
77
50
|
'fetchOrderBook': True,
|
78
|
-
'fetchOrders': True,
|
79
|
-
'fetchPosition': False,
|
80
|
-
'fetchPositionHistory': False,
|
81
|
-
'fetchPositionMode': False,
|
82
|
-
'fetchPositions': False,
|
83
|
-
'fetchPositionsForSymbol': False,
|
84
|
-
'fetchPositionsHistory': False,
|
85
|
-
'fetchPositionsRisk': False,
|
86
|
-
'fetchPremiumIndexOHLCV': False,
|
87
51
|
'fetchTicker': True,
|
88
52
|
'fetchTickers': True,
|
53
|
+
'fetchTime': True,
|
89
54
|
'fetchTrades': True,
|
90
|
-
'fetchTradingFee': False,
|
91
55
|
'fetchTradingFees': True,
|
92
|
-
'
|
93
|
-
'fetchTransfer': False,
|
94
|
-
'fetchTransfers': False,
|
95
|
-
'fetchWithdrawal': False,
|
96
|
-
'fetchWithdrawals': False,
|
97
|
-
'fetchWithdrawalWhitelist': False,
|
98
|
-
'reduceMargin': False,
|
99
|
-
'setLeverage': False,
|
100
|
-
'setMargin': False,
|
101
|
-
'setMarginMode': False,
|
102
|
-
'transfer': False,
|
103
|
-
'withdraw': False,
|
104
|
-
},
|
105
|
-
'timeframes': {
|
106
|
-
'1m': '1m',
|
107
|
-
'1h': '1h',
|
108
|
-
'1d': '1d',
|
56
|
+
'transfer': True,
|
109
57
|
},
|
110
58
|
'urls': {
|
111
59
|
'logo': 'https://user-images.githubusercontent.com/1294454/27766442-8ddc33b0-5ed8-11e7-8b98-f786aef0f3c9.jpg',
|
112
60
|
'api': {
|
113
|
-
'
|
61
|
+
'public': 'https://trade.cex.io/api/spot/rest-public',
|
62
|
+
'private': 'https://trade.cex.io/api/spot/rest',
|
114
63
|
},
|
115
64
|
'www': 'https://cex.io',
|
116
|
-
'doc': 'https://cex.io/
|
65
|
+
'doc': 'https://trade.cex.io/docs/',
|
117
66
|
'fees': [
|
118
67
|
'https://cex.io/fee-schedule',
|
119
68
|
'https://cex.io/limits-commissions',
|
120
69
|
],
|
121
70
|
'referral': 'https://cex.io/r/0/up105393824/0/',
|
122
71
|
},
|
123
|
-
'requiredCredentials': {
|
124
|
-
'apiKey': True,
|
125
|
-
'secret': True,
|
126
|
-
'uid': True,
|
127
|
-
},
|
128
72
|
'api': {
|
129
73
|
'public': {
|
130
|
-
'get':
|
131
|
-
|
132
|
-
'
|
133
|
-
'
|
134
|
-
'
|
135
|
-
'
|
136
|
-
'
|
137
|
-
'
|
138
|
-
'
|
139
|
-
'
|
140
|
-
|
141
|
-
'post': [
|
142
|
-
'convert/{pair}',
|
143
|
-
'price_stats/{pair}',
|
144
|
-
],
|
74
|
+
'get': {},
|
75
|
+
'post': {
|
76
|
+
'get_server_time': 1,
|
77
|
+
'get_pairs_info': 1,
|
78
|
+
'get_currencies_info': 1,
|
79
|
+
'get_processing_info': 10,
|
80
|
+
'get_ticker': 1,
|
81
|
+
'get_trade_history': 1,
|
82
|
+
'get_order_book': 1,
|
83
|
+
'get_candles': 1,
|
84
|
+
},
|
145
85
|
},
|
146
86
|
'private': {
|
147
|
-
'
|
148
|
-
|
149
|
-
'
|
150
|
-
'
|
151
|
-
'
|
152
|
-
'
|
153
|
-
'
|
154
|
-
'
|
155
|
-
'
|
156
|
-
'
|
157
|
-
'
|
158
|
-
'
|
159
|
-
'
|
160
|
-
'
|
161
|
-
'
|
162
|
-
'
|
163
|
-
'
|
164
|
-
'
|
165
|
-
'
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
'fees': {
|
170
|
-
'trading': {
|
171
|
-
'maker': self.parse_number('0.0016'),
|
172
|
-
'taker': self.parse_number('0.0025'),
|
173
|
-
},
|
174
|
-
'funding': {
|
175
|
-
'withdraw': {},
|
176
|
-
'deposit': {
|
177
|
-
# 'USD': amount => amount * 0.035 + 0.25,
|
178
|
-
# 'EUR': amount => amount * 0.035 + 0.24,
|
179
|
-
# 'RUB': amount => amount * 0.05 + 15.57,
|
180
|
-
# 'GBP': amount => amount * 0.035 + 0.2,
|
181
|
-
'BTC': 0.0,
|
182
|
-
'ETH': 0.0,
|
183
|
-
'BCH': 0.0,
|
184
|
-
'DASH': 0.0,
|
185
|
-
'BTG': 0.0,
|
186
|
-
'ZEC': 0.0,
|
187
|
-
'XRP': 0.0,
|
188
|
-
'XLM': 0.0,
|
87
|
+
'get': {},
|
88
|
+
'post': {
|
89
|
+
'get_my_current_fee': 5,
|
90
|
+
'get_fee_strategy': 1,
|
91
|
+
'get_my_volume': 5,
|
92
|
+
'do_create_account': 1,
|
93
|
+
'get_my_account_status_v3': 5,
|
94
|
+
'get_my_wallet_balance': 5,
|
95
|
+
'get_my_orders': 5,
|
96
|
+
'do_my_new_order': 1,
|
97
|
+
'do_cancel_my_order': 1,
|
98
|
+
'do_cancel_all_orders': 5,
|
99
|
+
'get_order_book': 1,
|
100
|
+
'get_candles': 1,
|
101
|
+
'get_trade_history': 1,
|
102
|
+
'get_my_transaction_history': 1,
|
103
|
+
'get_my_funding_history': 5,
|
104
|
+
'do_my_internal_transfer': 1,
|
105
|
+
'get_processing_info': 10,
|
106
|
+
'get_deposit_address': 5,
|
107
|
+
'do_deposit_funds_from_wallet': 1,
|
108
|
+
'do_withdrawal_funds_to_wallet': 1,
|
189
109
|
},
|
190
110
|
},
|
191
111
|
},
|
@@ -193,1415 +113,1415 @@ class cex(Exchange, ImplicitAPI):
|
|
193
113
|
'exceptions': {
|
194
114
|
'exact': {},
|
195
115
|
'broad': {
|
116
|
+
'You have negative balance on following accounts': InsufficientFunds,
|
117
|
+
'Mandatory parameter side should be one of BUY,SELL': BadRequest,
|
118
|
+
'API orders from Main account are not allowed': BadRequest,
|
119
|
+
'check failed': BadRequest,
|
196
120
|
'Insufficient funds': InsufficientFunds,
|
197
|
-
'
|
198
|
-
'
|
199
|
-
'Order not found': OrderNotFound,
|
200
|
-
'limit exceeded': RateLimitExceeded, # {"error":"rate limit exceeded"}
|
201
|
-
'Invalid API key': AuthenticationError,
|
202
|
-
'There was an error while placing your order': InvalidOrder,
|
203
|
-
'Sorry, too many clients already': DDoSProtection,
|
204
|
-
'Invalid Symbols Pair': BadSymbol,
|
205
|
-
'Wrong currency pair': BadSymbol, # {"error":"There was an error while placing your order: Wrong currency pair.","safe":true}
|
121
|
+
'Get deposit address for main account is not allowed': PermissionDenied,
|
122
|
+
'Market Trigger orders are not allowed': BadRequest, # for some reason, triggerPrice does not work for market orders
|
206
123
|
},
|
207
124
|
},
|
125
|
+
'timeframes': {
|
126
|
+
'1m': '1m',
|
127
|
+
'5m': '5m',
|
128
|
+
'15m': '15m',
|
129
|
+
'30m': '30m',
|
130
|
+
'1h': '1h',
|
131
|
+
'2h': '2h',
|
132
|
+
'4h': '4h',
|
133
|
+
'1d': '1d',
|
134
|
+
},
|
208
135
|
'options': {
|
209
|
-
'fetchOHLCVWarning': True,
|
210
|
-
'createMarketBuyOrderRequiresPrice': True,
|
211
|
-
'order': {
|
212
|
-
'status': {
|
213
|
-
'c': 'canceled',
|
214
|
-
'd': 'closed',
|
215
|
-
'cd': 'canceled',
|
216
|
-
'a': 'open',
|
217
|
-
},
|
218
|
-
},
|
219
|
-
'defaultNetwork': 'ERC20',
|
220
|
-
'defaultNetworks': {
|
221
|
-
'USDT': 'TRC20',
|
222
|
-
},
|
223
136
|
'networks': {
|
224
|
-
'
|
225
|
-
'
|
226
|
-
'
|
227
|
-
'
|
137
|
+
'BTC': 'bitcoin',
|
138
|
+
'ERC20': 'ERC20',
|
139
|
+
'BSC20': 'binancesmartchain',
|
140
|
+
'DOGE': 'dogecoin',
|
141
|
+
'ALGO': 'algorand',
|
142
|
+
'XLM': 'stellar',
|
143
|
+
'ATOM': 'cosmos',
|
144
|
+
'LTC': 'litecoin',
|
145
|
+
'XRP': 'ripple',
|
146
|
+
'FTM': 'fantom',
|
147
|
+
'MINA': 'mina',
|
148
|
+
'THETA': 'theta',
|
149
|
+
'XTZ': 'tezos',
|
150
|
+
'TIA': 'celestia',
|
151
|
+
'CRONOS': 'cronos', # CRC20
|
152
|
+
'MATIC': 'polygon',
|
153
|
+
'TON': 'ton',
|
154
|
+
'TRC20': 'tron',
|
155
|
+
'SOLANA': 'solana',
|
156
|
+
'SGB': 'songbird',
|
157
|
+
'DYDX': 'dydx',
|
158
|
+
'DASH': 'dash',
|
159
|
+
'ZIL': 'zilliqa',
|
160
|
+
'EOS': 'eos',
|
161
|
+
'AVALANCHEC': 'avalanche',
|
162
|
+
'ETHPOW': 'ethereumpow',
|
163
|
+
'NEAR': 'near',
|
164
|
+
'ARB': 'arbitrum',
|
165
|
+
'DOT': 'polkadot',
|
166
|
+
'OPT': 'optimism',
|
167
|
+
'INJ': 'injective',
|
168
|
+
'ADA': 'cardano',
|
169
|
+
'ONT': 'ontology',
|
170
|
+
'ICP': 'icp',
|
171
|
+
'KAVA': 'kava',
|
172
|
+
'KSM': 'kusama',
|
173
|
+
'SEI': 'sei',
|
174
|
+
# 'OSM': 'osmosis',
|
175
|
+
'NEO': 'neo',
|
176
|
+
'NEO3': 'neo3',
|
177
|
+
# 'TERRAOLD': 'terra', # tbd
|
178
|
+
# 'TERRA': 'terra2', # tbd
|
179
|
+
# 'EVER': 'everscale', # tbd
|
180
|
+
'XDC': 'xdc',
|
228
181
|
},
|
229
182
|
},
|
230
183
|
})
|
231
184
|
|
232
|
-
def fetch_currencies_from_cache(self, params={}):
|
233
|
-
# self method is now redundant
|
234
|
-
# currencies are now fetched before markets
|
235
|
-
options = self.safe_value(self.options, 'fetchCurrencies', {})
|
236
|
-
timestamp = self.safe_integer(options, 'timestamp')
|
237
|
-
expires = self.safe_integer(options, 'expires', 1000)
|
238
|
-
now = self.milliseconds()
|
239
|
-
if (timestamp is None) or ((now - timestamp) > expires):
|
240
|
-
response = self.publicGetCurrencyProfile(params)
|
241
|
-
self.options['fetchCurrencies'] = self.extend(options, {
|
242
|
-
'response': response,
|
243
|
-
'timestamp': now,
|
244
|
-
})
|
245
|
-
return self.safe_value(self.options['fetchCurrencies'], 'response')
|
246
|
-
|
247
185
|
def fetch_currencies(self, params={}) -> Currencies:
|
248
186
|
"""
|
249
187
|
fetches all available currencies on an exchange
|
188
|
+
:see: https://trade.cex.io/docs/#rest-public-api-calls-currencies-info
|
250
189
|
:param dict [params]: extra parameters specific to the exchange API endpoint
|
251
190
|
:returns dict: an associative dictionary of currencies
|
252
191
|
"""
|
253
|
-
|
254
|
-
self.
|
255
|
-
'timestamp': self.milliseconds(),
|
256
|
-
'response': response,
|
257
|
-
}
|
192
|
+
promises = []
|
193
|
+
promises.append(self.publicPostGetCurrenciesInfo(params))
|
258
194
|
#
|
259
|
-
#
|
260
|
-
#
|
261
|
-
#
|
262
|
-
#
|
263
|
-
#
|
264
|
-
#
|
265
|
-
#
|
266
|
-
#
|
267
|
-
#
|
268
|
-
#
|
269
|
-
#
|
270
|
-
#
|
271
|
-
# "scale":0,
|
272
|
-
# "minimumCurrencyAmount":"0.00000001",
|
273
|
-
# "minimalWithdrawalAmount":-1
|
274
|
-
# },
|
275
|
-
# {
|
276
|
-
# "code":"BTC",
|
277
|
-
# "contract":false,
|
278
|
-
# "commodity":false,
|
279
|
-
# "fiat":false,
|
280
|
-
# "description":"",
|
281
|
-
# "precision":8,
|
282
|
-
# "scale":0,
|
283
|
-
# "minimumCurrencyAmount":"0.00000001",
|
284
|
-
# "minimalWithdrawalAmount":0.002
|
285
|
-
# },
|
286
|
-
# {
|
287
|
-
# "code":"ETH",
|
288
|
-
# "contract":false,
|
289
|
-
# "commodity":false,
|
290
|
-
# "fiat":false,
|
291
|
-
# "description":"",
|
292
|
-
# "precision":8,
|
293
|
-
# "scale":2,
|
294
|
-
# "minimumCurrencyAmount":"0.00000100",
|
295
|
-
# "minimalWithdrawalAmount":0.01
|
296
|
-
# }
|
297
|
-
# ],
|
298
|
-
# "pairs":[
|
299
|
-
# {
|
300
|
-
# "symbol1":"BTC",
|
301
|
-
# "symbol2":"USD",
|
302
|
-
# "pricePrecision":1,
|
303
|
-
# "priceScale":"/1000000",
|
304
|
-
# "minLotSize":0.002,
|
305
|
-
# "minLotSizeS2":20
|
306
|
-
# },
|
307
|
-
# {
|
308
|
-
# "symbol1":"ETH",
|
309
|
-
# "symbol2":"USD",
|
310
|
-
# "pricePrecision":2,
|
311
|
-
# "priceScale":"/10000",
|
312
|
-
# "minLotSize":0.1,
|
313
|
-
# "minLotSizeS2":20
|
314
|
-
# }
|
315
|
-
# ]
|
316
|
-
# }
|
317
|
-
# }
|
195
|
+
# {
|
196
|
+
# "ok": "ok",
|
197
|
+
# "data": [
|
198
|
+
# {
|
199
|
+
# "currency": "ZAP",
|
200
|
+
# "fiat": False,
|
201
|
+
# "precision": "8",
|
202
|
+
# "walletPrecision": "6",
|
203
|
+
# "walletDeposit": True,
|
204
|
+
# "walletWithdrawal": True
|
205
|
+
# },
|
206
|
+
# ...
|
318
207
|
#
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
208
|
+
promises.append(self.publicPostGetProcessingInfo(params))
|
209
|
+
#
|
210
|
+
# {
|
211
|
+
# "ok": "ok",
|
212
|
+
# "data": {
|
213
|
+
# "ADA": {
|
214
|
+
# "name": "Cardano",
|
215
|
+
# "blockchains": {
|
216
|
+
# "cardano": {
|
217
|
+
# "type": "coin",
|
218
|
+
# "deposit": "enabled",
|
219
|
+
# "minDeposit": "1",
|
220
|
+
# "withdrawal": "enabled",
|
221
|
+
# "minWithdrawal": "5",
|
222
|
+
# "withdrawalFee": "1",
|
223
|
+
# "withdrawalFeePercent": "0",
|
224
|
+
# "depositConfirmations": "15"
|
225
|
+
# }
|
226
|
+
# }
|
227
|
+
# },
|
228
|
+
# ...
|
229
|
+
#
|
230
|
+
responses = promises
|
231
|
+
dataCurrencies = self.safe_list(responses[0], 'data', [])
|
232
|
+
dataNetworks = self.safe_dict(responses[1], 'data', {})
|
233
|
+
currenciesIndexed = self.index_by(dataCurrencies, 'currency')
|
234
|
+
data = self.deep_extend(currenciesIndexed, dataNetworks)
|
235
|
+
return self.parse_currencies(self.to_array(data))
|
236
|
+
|
237
|
+
def parse_currency(self, rawCurrency: dict) -> Currency:
|
238
|
+
id = self.safe_string(rawCurrency, 'currency')
|
239
|
+
code = self.safe_currency_code(id)
|
240
|
+
type = 'fiat' if self.safe_bool(rawCurrency, 'fiat') else 'crypto'
|
241
|
+
currencyDepositEnabled = self.safe_bool(rawCurrency, 'walletDeposit')
|
242
|
+
currencyWithdrawEnabled = self.safe_bool(rawCurrency, 'walletWithdrawal')
|
243
|
+
currencyPrecision = self.parse_number(self.parse_precision(self.safe_string(rawCurrency, 'precision')))
|
244
|
+
networks: dict = {}
|
245
|
+
rawNetworks = self.safe_dict(rawCurrency, 'blockchains', {})
|
246
|
+
keys = list(rawNetworks.keys())
|
247
|
+
for j in range(0, len(keys)):
|
248
|
+
networkId = keys[j]
|
249
|
+
rawNetwork = rawNetworks[networkId]
|
250
|
+
networkCode = self.network_id_to_code(networkId)
|
251
|
+
deposit = self.safe_string(rawNetwork, 'deposit') == 'enabled'
|
252
|
+
withdraw = self.safe_string(rawNetwork, 'withdrawal') == 'enabled'
|
253
|
+
networks[networkCode] = {
|
254
|
+
'id': networkId,
|
255
|
+
'network': networkCode,
|
256
|
+
'margin': None,
|
257
|
+
'deposit': deposit,
|
258
|
+
'withdraw': withdraw,
|
259
|
+
'fee': self.safe_number(rawNetwork, 'withdrawalFee'),
|
260
|
+
'precision': currencyPrecision,
|
336
261
|
'limits': {
|
337
|
-
'
|
338
|
-
'min': self.safe_number(
|
262
|
+
'deposit': {
|
263
|
+
'min': self.safe_number(rawNetwork, 'minDeposit'),
|
339
264
|
'max': None,
|
340
265
|
},
|
341
266
|
'withdraw': {
|
342
|
-
'min': self.safe_number(
|
267
|
+
'min': self.safe_number(rawNetwork, 'minWithdrawal'),
|
343
268
|
'max': None,
|
344
269
|
},
|
345
270
|
},
|
346
|
-
'info':
|
271
|
+
'info': rawNetwork,
|
347
272
|
}
|
348
|
-
return
|
273
|
+
return self.safe_currency_structure({
|
274
|
+
'id': id,
|
275
|
+
'code': code,
|
276
|
+
'name': None,
|
277
|
+
'type': type,
|
278
|
+
'active': None,
|
279
|
+
'deposit': currencyDepositEnabled,
|
280
|
+
'withdraw': currencyWithdrawEnabled,
|
281
|
+
'fee': None,
|
282
|
+
'precision': currencyPrecision,
|
283
|
+
'limits': {
|
284
|
+
'amount': {
|
285
|
+
'min': None,
|
286
|
+
'max': None,
|
287
|
+
},
|
288
|
+
'withdraw': {
|
289
|
+
'min': None,
|
290
|
+
'max': None,
|
291
|
+
},
|
292
|
+
},
|
293
|
+
'networks': networks,
|
294
|
+
'info': rawCurrency,
|
295
|
+
})
|
349
296
|
|
350
297
|
def fetch_markets(self, params={}) -> List[Market]:
|
351
298
|
"""
|
352
|
-
retrieves data on all markets for
|
299
|
+
retrieves data on all markets for ace
|
300
|
+
:see: https://trade.cex.io/docs/#rest-public-api-calls-pairs-info
|
353
301
|
:param dict [params]: extra parameters specific to the exchange API endpoint
|
354
302
|
:returns dict[]: an array of objects representing market data
|
355
303
|
"""
|
356
|
-
|
357
|
-
currenciesData = self.safe_value(currenciesResponse, 'data', {})
|
358
|
-
currencies = self.safe_value(currenciesData, 'symbols', [])
|
359
|
-
currenciesById = self.index_by(currencies, 'code')
|
360
|
-
pairs = self.safe_value(currenciesData, 'pairs', [])
|
361
|
-
response = self.publicGetCurrencyLimits(params)
|
304
|
+
response = self.publicPostGetPairsInfo(params)
|
362
305
|
#
|
363
|
-
#
|
364
|
-
#
|
365
|
-
#
|
366
|
-
#
|
367
|
-
#
|
368
|
-
#
|
369
|
-
#
|
370
|
-
#
|
371
|
-
#
|
372
|
-
#
|
373
|
-
#
|
374
|
-
#
|
375
|
-
#
|
376
|
-
#
|
377
|
-
#
|
378
|
-
#
|
379
|
-
#
|
380
|
-
#
|
381
|
-
#
|
382
|
-
# "maxLotSize":null,
|
383
|
-
# "minPrice":"25",
|
384
|
-
# "maxPrice":"8192"
|
385
|
-
# }
|
386
|
-
# ]
|
387
|
-
# }
|
388
|
-
# }
|
306
|
+
# {
|
307
|
+
# "ok": "ok",
|
308
|
+
# "data": [
|
309
|
+
# {
|
310
|
+
# "base": "AI",
|
311
|
+
# "quote": "USD",
|
312
|
+
# "baseMin": "30",
|
313
|
+
# "baseMax": "2516000",
|
314
|
+
# "baseLotSize": "0.000001",
|
315
|
+
# "quoteMin": "10",
|
316
|
+
# "quoteMax": "1000000",
|
317
|
+
# "quoteLotSize": "0.01000000",
|
318
|
+
# "basePrecision": "6",
|
319
|
+
# "quotePrecision": "8",
|
320
|
+
# "pricePrecision": "4",
|
321
|
+
# "minPrice": "0.0377",
|
322
|
+
# "maxPrice": "19.5000"
|
323
|
+
# },
|
324
|
+
# ...
|
389
325
|
#
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
'
|
425
|
-
|
426
|
-
|
427
|
-
'inverse': None,
|
428
|
-
'contractSize': None,
|
429
|
-
'expiry': None,
|
430
|
-
'expiryDatetime': None,
|
431
|
-
'strike': None,
|
432
|
-
'optionType': None,
|
433
|
-
'precision': {
|
434
|
-
'amount': self.parse_number(self.parse_precision(amountPrecisionString)),
|
435
|
-
'price': self.parse_number(self.parse_precision(pricePrecisionString)),
|
326
|
+
data = self.safe_list(response, 'data', [])
|
327
|
+
return self.parse_markets(data)
|
328
|
+
|
329
|
+
def parse_market(self, market: dict) -> Market:
|
330
|
+
baseId = self.safe_string(market, 'base')
|
331
|
+
base = self.safe_currency_code(baseId)
|
332
|
+
quoteId = self.safe_string(market, 'quote')
|
333
|
+
quote = self.safe_currency_code(quoteId)
|
334
|
+
id = base + '-' + quote # not actual id, but for self exchange we can use self abbreviation, because e.g. tickers have hyphen in between
|
335
|
+
symbol = base + '/' + quote
|
336
|
+
return self.safe_market_structure({
|
337
|
+
'id': id,
|
338
|
+
'symbol': symbol,
|
339
|
+
'base': base,
|
340
|
+
'baseId': baseId,
|
341
|
+
'quote': quote,
|
342
|
+
'quoteId': quoteId,
|
343
|
+
'settle': None,
|
344
|
+
'settleId': None,
|
345
|
+
'type': 'spot',
|
346
|
+
'spot': True,
|
347
|
+
'margin': False,
|
348
|
+
'swap': False,
|
349
|
+
'future': False,
|
350
|
+
'option': False,
|
351
|
+
'contract': False,
|
352
|
+
'linear': None,
|
353
|
+
'inverse': None,
|
354
|
+
'contractSize': None,
|
355
|
+
'expiry': None,
|
356
|
+
'expiryDatetime': None,
|
357
|
+
'strike': None,
|
358
|
+
'optionType': None,
|
359
|
+
'limits': {
|
360
|
+
'amount': {
|
361
|
+
'min': self.safe_number(market, 'baseMin'),
|
362
|
+
'max': self.safe_number(market, 'baseMax'),
|
436
363
|
},
|
437
|
-
'
|
438
|
-
'
|
439
|
-
|
440
|
-
'max': None,
|
441
|
-
},
|
442
|
-
'amount': {
|
443
|
-
'min': self.safe_number(market, 'minLotSize'),
|
444
|
-
'max': self.safe_number(market, 'maxLotSize'),
|
445
|
-
},
|
446
|
-
'price': {
|
447
|
-
'min': self.safe_number(market, 'minPrice'),
|
448
|
-
'max': self.safe_number(market, 'maxPrice'),
|
449
|
-
},
|
450
|
-
'cost': {
|
451
|
-
'min': self.safe_number(market, 'minLotSizeS2'),
|
452
|
-
'max': None,
|
453
|
-
},
|
364
|
+
'price': {
|
365
|
+
'min': self.safe_number(market, 'minPrice'),
|
366
|
+
'max': self.safe_number(market, 'maxPrice'),
|
454
367
|
},
|
455
|
-
'
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
368
|
+
'cost': {
|
369
|
+
'min': self.safe_number(market, 'quoteMin'),
|
370
|
+
'max': self.safe_number(market, 'quoteMax'),
|
371
|
+
},
|
372
|
+
'leverage': {
|
373
|
+
'min': None,
|
374
|
+
'max': None,
|
375
|
+
},
|
376
|
+
},
|
377
|
+
'precision': {
|
378
|
+
'amount': self.safe_string(market, 'baseLotSize'),
|
379
|
+
'price': self.parse_number(self.parse_precision(self.safe_string(market, 'pricePrecision'))),
|
380
|
+
# 'cost': self.parse_number(self.parse_precision(self.safe_string(market, 'quoteLotSize'))), # buggy, doesn't reflect their documentation
|
381
|
+
'base': self.parse_number(self.parse_precision(self.safe_string(market, 'basePrecision'))),
|
382
|
+
'quote': self.parse_number(self.parse_precision(self.safe_string(market, 'quotePrecision'))),
|
383
|
+
},
|
384
|
+
'active': None,
|
385
|
+
'created': None,
|
386
|
+
'info': market,
|
387
|
+
})
|
475
388
|
|
476
|
-
def
|
389
|
+
def fetch_time(self, params={}):
|
477
390
|
"""
|
478
|
-
|
479
|
-
query for balance and get the amount of funds available for trading or funds locked in orders
|
391
|
+
fetches the current integer timestamp in milliseconds from the exchange server
|
480
392
|
:param dict [params]: extra parameters specific to the exchange API endpoint
|
481
|
-
:returns
|
393
|
+
:returns int: the current integer timestamp in milliseconds from the exchange server
|
482
394
|
"""
|
483
|
-
self.
|
484
|
-
|
485
|
-
|
395
|
+
response = self.publicPostGetServerTime(params)
|
396
|
+
#
|
397
|
+
# {
|
398
|
+
# "ok": "ok",
|
399
|
+
# "data": {
|
400
|
+
# "timestamp": "1728472063472",
|
401
|
+
# "ISODate": "2024-10-09T11:07:43.472Z"
|
402
|
+
# }
|
403
|
+
# }
|
404
|
+
#
|
405
|
+
data = self.safe_dict(response, 'data')
|
406
|
+
timestamp = self.safe_integer(data, 'timestamp')
|
407
|
+
return timestamp
|
486
408
|
|
487
|
-
def
|
409
|
+
def fetch_ticker(self, symbol: str, params={}) -> Ticker:
|
488
410
|
"""
|
489
|
-
|
490
|
-
|
491
|
-
:param str
|
492
|
-
:param int [limit]: the maximum amount of order book entries to return
|
411
|
+
fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
|
412
|
+
:see: https://trade.cex.io/docs/#rest-public-api-calls-ticker
|
413
|
+
:param str[]|None symbols: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
|
493
414
|
:param dict [params]: extra parameters specific to the exchange API endpoint
|
494
|
-
:returns dict:
|
415
|
+
:returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
|
495
416
|
"""
|
496
417
|
self.load_markets()
|
497
|
-
|
498
|
-
|
499
|
-
'pair': market['id'],
|
500
|
-
}
|
501
|
-
if limit is not None:
|
502
|
-
request['depth'] = limit
|
503
|
-
response = self.publicGetOrderBookPair(self.extend(request, params))
|
504
|
-
timestamp = self.safe_timestamp(response, 'timestamp')
|
505
|
-
return self.parse_order_book(response, market['symbol'], timestamp)
|
506
|
-
|
507
|
-
def parse_ohlcv(self, ohlcv, market: Market = None) -> list:
|
508
|
-
#
|
509
|
-
# [
|
510
|
-
# 1591403940,
|
511
|
-
# 0.024972,
|
512
|
-
# 0.024972,
|
513
|
-
# 0.024969,
|
514
|
-
# 0.024969,
|
515
|
-
# 0.49999900
|
516
|
-
# ]
|
517
|
-
#
|
518
|
-
return [
|
519
|
-
self.safe_timestamp(ohlcv, 0),
|
520
|
-
self.safe_number(ohlcv, 1),
|
521
|
-
self.safe_number(ohlcv, 2),
|
522
|
-
self.safe_number(ohlcv, 3),
|
523
|
-
self.safe_number(ohlcv, 4),
|
524
|
-
self.safe_number(ohlcv, 5),
|
525
|
-
]
|
418
|
+
response = self.fetch_tickers([symbol], params)
|
419
|
+
return self.safe_dict(response, symbol, {})
|
526
420
|
|
527
|
-
def
|
421
|
+
def fetch_tickers(self, symbols: Strings = None, params={}) -> Tickers:
|
528
422
|
"""
|
529
|
-
|
530
|
-
|
531
|
-
:param str
|
532
|
-
:param str timeframe: the length of time each candle represents
|
533
|
-
:param int [since]: timestamp in ms of the earliest candle to fetch
|
534
|
-
:param int [limit]: the maximum amount of candles to fetch
|
423
|
+
fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
|
424
|
+
:see: https://trade.cex.io/docs/#rest-public-api-calls-ticker
|
425
|
+
:param str[]|None symbols: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
|
535
426
|
:param dict [params]: extra parameters specific to the exchange API endpoint
|
536
|
-
:returns
|
427
|
+
:returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
|
537
428
|
"""
|
538
429
|
self.load_markets()
|
539
|
-
|
540
|
-
if
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
430
|
+
request = {}
|
431
|
+
if symbols is not None:
|
432
|
+
request['pairs'] = self.market_ids(symbols)
|
433
|
+
response = self.publicPostGetTicker(self.extend(request, params))
|
434
|
+
#
|
435
|
+
# {
|
436
|
+
# "ok": "ok",
|
437
|
+
# "data": {
|
438
|
+
# "AI-USD": {
|
439
|
+
# "bestBid": "0.3917",
|
440
|
+
# "bestAsk": "0.3949",
|
441
|
+
# "bestBidChange": "0.0035",
|
442
|
+
# "bestBidChangePercentage": "0.90",
|
443
|
+
# "bestAskChange": "0.0038",
|
444
|
+
# "bestAskChangePercentage": "0.97",
|
445
|
+
# "low": "0.3787",
|
446
|
+
# "high": "0.3925",
|
447
|
+
# "volume30d": "2945.722277",
|
448
|
+
# "lastTradeDateISO": "2024-10-11T06:18:42.077Z",
|
449
|
+
# "volume": "120.736000",
|
450
|
+
# "quoteVolume": "46.65654070",
|
451
|
+
# "lastTradeVolume": "67.914000",
|
452
|
+
# "volumeUSD": "46.65",
|
453
|
+
# "last": "0.3949",
|
454
|
+
# "lastTradePrice": "0.3925",
|
455
|
+
# "priceChange": "0.0038",
|
456
|
+
# "priceChangePercentage": "0.97"
|
457
|
+
# },
|
458
|
+
# ...
|
459
|
+
#
|
460
|
+
data = self.safe_dict(response, 'data', {})
|
461
|
+
return self.parse_tickers(data, symbols)
|
565
462
|
|
566
463
|
def parse_ticker(self, ticker: dict, market: Market = None) -> Ticker:
|
567
|
-
|
568
|
-
|
569
|
-
high = self.safe_string(ticker, 'high')
|
570
|
-
low = self.safe_string(ticker, 'low')
|
571
|
-
bid = self.safe_string(ticker, 'bid')
|
572
|
-
ask = self.safe_string(ticker, 'ask')
|
573
|
-
last = self.safe_string(ticker, 'last')
|
574
|
-
symbol = self.safe_symbol(None, market)
|
464
|
+
marketId = self.safe_string(ticker, 'id')
|
465
|
+
symbol = self.safe_symbol(marketId, market)
|
575
466
|
return self.safe_ticker({
|
576
467
|
'symbol': symbol,
|
577
|
-
'timestamp':
|
578
|
-
'datetime':
|
579
|
-
'high': high,
|
580
|
-
'low': low,
|
581
|
-
'bid':
|
468
|
+
'timestamp': None,
|
469
|
+
'datetime': None,
|
470
|
+
'high': self.safe_number(ticker, 'high'),
|
471
|
+
'low': self.safe_number(ticker, 'low'),
|
472
|
+
'bid': self.safe_number(ticker, 'bestBid'),
|
582
473
|
'bidVolume': None,
|
583
|
-
'ask':
|
474
|
+
'ask': self.safe_number(ticker, 'bestAsk'),
|
584
475
|
'askVolume': None,
|
585
476
|
'vwap': None,
|
586
477
|
'open': None,
|
587
|
-
'close':
|
588
|
-
'last': last,
|
478
|
+
'close': self.safe_string(ticker, 'lastTradePrice'),
|
589
479
|
'previousClose': None,
|
590
|
-
'change':
|
591
|
-
'percentage':
|
480
|
+
'change': self.safe_number(ticker, 'priceChange'),
|
481
|
+
'percentage': self.safe_number(ticker, 'priceChangePercentage'),
|
592
482
|
'average': None,
|
593
|
-
'baseVolume': volume,
|
594
|
-
'quoteVolume':
|
483
|
+
'baseVolume': self.safe_string(ticker, 'volume'),
|
484
|
+
'quoteVolume': self.safe_string(ticker, 'quoteVolume'),
|
595
485
|
'info': ticker,
|
596
486
|
}, market)
|
597
487
|
|
598
|
-
def
|
599
|
-
"""
|
600
|
-
fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
|
601
|
-
:param str[]|None symbols: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
|
602
|
-
:param dict [params]: extra parameters specific to the exchange API endpoint
|
603
|
-
:returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
|
604
|
-
"""
|
605
|
-
self.load_markets()
|
606
|
-
symbols = self.market_symbols(symbols)
|
607
|
-
currencies = list(self.currencies.keys())
|
608
|
-
request: dict = {
|
609
|
-
'currencies': '/'.join(currencies),
|
610
|
-
}
|
611
|
-
response = self.publicGetTickersCurrencies(self.extend(request, params))
|
612
|
-
tickers = self.safe_value(response, 'data', [])
|
613
|
-
result: dict = {}
|
614
|
-
for t in range(0, len(tickers)):
|
615
|
-
ticker = tickers[t]
|
616
|
-
marketId = self.safe_string(ticker, 'pair')
|
617
|
-
market = self.safe_market(marketId, None, ':')
|
618
|
-
symbol = market['symbol']
|
619
|
-
result[symbol] = self.parse_ticker(ticker, market)
|
620
|
-
return self.filter_by_array_tickers(result, 'symbol', symbols)
|
621
|
-
|
622
|
-
def fetch_ticker(self, symbol: str, params={}) -> Ticker:
|
488
|
+
def fetch_trades(self, symbol: str, since: Int = None, limit: Int = None, params={}) -> List[Trade]:
|
623
489
|
"""
|
624
|
-
|
625
|
-
|
626
|
-
:param str symbol: unified symbol of the market to fetch
|
490
|
+
get the list of most recent trades for a particular symbol
|
491
|
+
:see: https://trade.cex.io/docs/#rest-public-api-calls-trade-history
|
492
|
+
:param str symbol: unified symbol of the market to fetch trades for
|
493
|
+
:param int [since]: timestamp in ms of the earliest trade to fetch
|
494
|
+
:param int [limit]: the maximum amount of trades to fetch
|
627
495
|
:param dict [params]: extra parameters specific to the exchange API endpoint
|
628
|
-
:
|
496
|
+
:param int [params.until]: timestamp in ms of the latest entry
|
497
|
+
:returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
|
629
498
|
"""
|
630
499
|
self.load_markets()
|
631
500
|
market = self.market(symbol)
|
632
501
|
request: dict = {
|
633
502
|
'pair': market['id'],
|
634
503
|
}
|
635
|
-
|
636
|
-
|
504
|
+
if since is not None:
|
505
|
+
request['fromDateISO'] = self.iso8601(since)
|
506
|
+
until = None
|
507
|
+
until, params = self.handle_param_integer_2(params, 'until', 'till')
|
508
|
+
if until is not None:
|
509
|
+
request['toDateISO'] = self.iso8601(until)
|
510
|
+
if limit is not None:
|
511
|
+
request['pageSize'] = min(limit, 10000) # has a bug, still returns more trades
|
512
|
+
response = self.publicPostGetTradeHistory(self.extend(request, params))
|
513
|
+
#
|
514
|
+
# {
|
515
|
+
# "ok": "ok",
|
516
|
+
# "data": {
|
517
|
+
# "pageSize": "10",
|
518
|
+
# "trades": [
|
519
|
+
# {
|
520
|
+
# "tradeId": "1728630559823-0",
|
521
|
+
# "dateISO": "2024-10-11T07:09:19.823Z",
|
522
|
+
# "side": "SELL",
|
523
|
+
# "price": "60879.5",
|
524
|
+
# "amount": "0.00165962"
|
525
|
+
# },
|
526
|
+
# ... followed by older trades
|
527
|
+
#
|
528
|
+
data = self.safe_dict(response, 'data', {})
|
529
|
+
trades = self.safe_list(data, 'trades', [])
|
530
|
+
return self.parse_trades(trades, market, since, limit)
|
637
531
|
|
638
532
|
def parse_trade(self, trade: dict, market: Market = None) -> Trade:
|
639
533
|
#
|
640
|
-
# fetchTrades
|
534
|
+
# public fetchTrades
|
641
535
|
#
|
642
|
-
#
|
643
|
-
#
|
644
|
-
#
|
645
|
-
#
|
646
|
-
#
|
647
|
-
#
|
648
|
-
#
|
536
|
+
# {
|
537
|
+
# "tradeId": "1728630559823-0",
|
538
|
+
# "dateISO": "2024-10-11T07:09:19.823Z",
|
539
|
+
# "side": "SELL",
|
540
|
+
# "price": "60879.5",
|
541
|
+
# "amount": "0.00165962"
|
542
|
+
# },
|
649
543
|
#
|
650
|
-
|
651
|
-
|
652
|
-
type = None
|
653
|
-
side = self.safe_string(trade, 'type')
|
654
|
-
priceString = self.safe_string(trade, 'price')
|
655
|
-
amountString = self.safe_string(trade, 'amount')
|
544
|
+
dateStr = self.safe_string(trade, 'dateISO')
|
545
|
+
timestamp = self.parse8601(dateStr)
|
656
546
|
market = self.safe_market(None, market)
|
657
547
|
return self.safe_trade({
|
658
548
|
'info': trade,
|
659
|
-
'id': id,
|
660
549
|
'timestamp': timestamp,
|
661
550
|
'datetime': self.iso8601(timestamp),
|
662
551
|
'symbol': market['symbol'],
|
663
|
-
'
|
664
|
-
'side': side,
|
552
|
+
'id': self.safe_string(trade, 'tradeId'),
|
665
553
|
'order': None,
|
554
|
+
'type': None,
|
666
555
|
'takerOrMaker': None,
|
667
|
-
'
|
668
|
-
'
|
556
|
+
'side': self.safe_string_lower(trade, 'side'),
|
557
|
+
'price': self.safe_string(trade, 'price'),
|
558
|
+
'amount': self.safe_string(trade, 'amount'),
|
669
559
|
'cost': None,
|
670
560
|
'fee': None,
|
671
561
|
}, market)
|
672
562
|
|
673
|
-
def
|
563
|
+
def fetch_order_book(self, symbol: str, limit: Int = None, params={}) -> OrderBook:
|
674
564
|
"""
|
675
|
-
|
676
|
-
|
677
|
-
:param str symbol: unified symbol of the market to fetch
|
678
|
-
:param int [
|
679
|
-
:param int [limit]: the maximum amount of trades to fetch
|
565
|
+
fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
|
566
|
+
:see: https://trade.cex.io/docs/#rest-public-api-calls-order-book
|
567
|
+
:param str symbol: unified symbol of the market to fetch the order book for
|
568
|
+
:param int [limit]: the maximum amount of order book entries to return
|
680
569
|
:param dict [params]: extra parameters specific to the exchange API endpoint
|
681
|
-
:returns
|
570
|
+
:returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
|
682
571
|
"""
|
683
572
|
self.load_markets()
|
684
573
|
market = self.market(symbol)
|
685
574
|
request: dict = {
|
686
575
|
'pair': market['id'],
|
687
576
|
}
|
688
|
-
response = self.
|
689
|
-
|
577
|
+
response = self.publicPostGetOrderBook(self.extend(request, params))
|
578
|
+
#
|
579
|
+
# {
|
580
|
+
# "ok": "ok",
|
581
|
+
# "data": {
|
582
|
+
# "timestamp": "1728636922648",
|
583
|
+
# "currency1": "BTC",
|
584
|
+
# "currency2": "USDT",
|
585
|
+
# "bids": [
|
586
|
+
# [
|
587
|
+
# "60694.1",
|
588
|
+
# "13.12849761"
|
589
|
+
# ],
|
590
|
+
# [
|
591
|
+
# "60694.0",
|
592
|
+
# "0.71829244"
|
593
|
+
# ],
|
594
|
+
# ...
|
595
|
+
#
|
596
|
+
orderBook = self.safe_dict(response, 'data', {})
|
597
|
+
timestamp = self.safe_integer(orderBook, 'timestamp')
|
598
|
+
return self.parse_order_book(orderBook, market['symbol'], timestamp)
|
599
|
+
|
600
|
+
def fetch_ohlcv(self, symbol: str, timeframe='1m', since: Int = None, limit: Int = None, params={}) -> List[list]:
|
601
|
+
"""
|
602
|
+
fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
|
603
|
+
:see: https://trade.cex.io/docs/#rest-public-api-calls-candles
|
604
|
+
:param str symbol: unified symbol of the market to fetch OHLCV data for
|
605
|
+
:param str timeframe: the length of time each candle represents
|
606
|
+
:param int [since]: timestamp in ms of the earliest candle to fetch
|
607
|
+
:param int [limit]: the maximum amount of candles to fetch
|
608
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
609
|
+
:param int [params.until]: timestamp in ms of the latest entry
|
610
|
+
:returns int[][]: A list of candles ordered, open, high, low, close, volume
|
611
|
+
"""
|
612
|
+
dataType = None
|
613
|
+
dataType, params = self.handle_option_and_params(params, 'fetchOHLCV', 'dataType')
|
614
|
+
if dataType is None:
|
615
|
+
raise ArgumentsRequired(self.id + ' fetchOHLCV requires a parameter "dataType" to be either "bestBid" or "bestAsk"')
|
616
|
+
self.load_markets()
|
617
|
+
market = self.market(symbol)
|
618
|
+
request: dict = {
|
619
|
+
'pair': market['id'],
|
620
|
+
'resolution': self.timeframes[timeframe],
|
621
|
+
'dataType': dataType,
|
622
|
+
}
|
623
|
+
if since is not None:
|
624
|
+
request['fromISO'] = self.iso8601(since)
|
625
|
+
until = None
|
626
|
+
until, params = self.handle_param_integer_2(params, 'until', 'till')
|
627
|
+
if until is not None:
|
628
|
+
request['toISO'] = self.iso8601(until)
|
629
|
+
elif since is None:
|
630
|
+
# exchange still requires that we provide one of them
|
631
|
+
request['toISO'] = self.iso8601(self.milliseconds())
|
632
|
+
if since is not None and until is not None and limit is not None:
|
633
|
+
raise ArgumentsRequired(self.id + ' fetchOHLCV does not support fetching candles with both a limit and since/until')
|
634
|
+
elif (since is not None or until is not None) and limit is None:
|
635
|
+
raise ArgumentsRequired(self.id + ' fetchOHLCV requires a limit parameter when fetching candles with since or until')
|
636
|
+
if limit is not None:
|
637
|
+
request['limit'] = limit
|
638
|
+
response = self.publicPostGetCandles(self.extend(request, params))
|
639
|
+
#
|
640
|
+
# {
|
641
|
+
# "ok": "ok",
|
642
|
+
# "data": [
|
643
|
+
# {
|
644
|
+
# "timestamp": "1728643320000",
|
645
|
+
# "open": "61061",
|
646
|
+
# "high": "61095.1",
|
647
|
+
# "low": "61048.5",
|
648
|
+
# "close": "61087.8",
|
649
|
+
# "volume": "0",
|
650
|
+
# "resolution": "1m",
|
651
|
+
# "isClosed": True,
|
652
|
+
# "timestampISO": "2024-10-11T10:42:00.000Z"
|
653
|
+
# },
|
654
|
+
# ...
|
655
|
+
#
|
656
|
+
data = self.safe_list(response, 'data', [])
|
657
|
+
return self.parse_ohlcvs(data, market, timeframe, since, limit)
|
658
|
+
|
659
|
+
def parse_ohlcv(self, ohlcv, market: Market = None) -> list:
|
660
|
+
return [
|
661
|
+
self.safe_integer(ohlcv, 'timestamp'),
|
662
|
+
self.safe_number(ohlcv, 'open'),
|
663
|
+
self.safe_number(ohlcv, 'high'),
|
664
|
+
self.safe_number(ohlcv, 'low'),
|
665
|
+
self.safe_number(ohlcv, 'close'),
|
666
|
+
self.safe_number(ohlcv, 'volume'),
|
667
|
+
]
|
690
668
|
|
691
669
|
def fetch_trading_fees(self, params={}) -> TradingFees:
|
692
670
|
"""
|
693
|
-
:see: https://docs.cex.io/#get-my-fee
|
694
671
|
fetch the trading fees for multiple markets
|
672
|
+
:see: https://trade.cex.io/docs/#rest-public-api-calls-candles
|
695
673
|
:param dict [params]: extra parameters specific to the exchange API endpoint
|
696
674
|
:returns dict: a dictionary of `fee structures <https://docs.ccxt.com/#/?id=fee-structure>` indexed by market symbols
|
697
675
|
"""
|
698
676
|
self.load_markets()
|
699
|
-
response = self.
|
677
|
+
response = self.privatePostGetMyCurrentFee(params)
|
700
678
|
#
|
701
|
-
#
|
702
|
-
#
|
703
|
-
#
|
704
|
-
#
|
705
|
-
#
|
706
|
-
#
|
707
|
-
#
|
708
|
-
#
|
709
|
-
# }
|
679
|
+
# {
|
680
|
+
# "ok": "ok",
|
681
|
+
# "data": {
|
682
|
+
# "tradingFee": {
|
683
|
+
# "AI-USD": {
|
684
|
+
# "percent": "0.25"
|
685
|
+
# },
|
686
|
+
# ...
|
710
687
|
#
|
711
|
-
data = self.
|
688
|
+
data = self.safe_dict(response, 'data', {})
|
689
|
+
fees = self.safe_dict(data, 'tradingFee', {})
|
690
|
+
return self.parse_trading_fees(fees, True)
|
691
|
+
|
692
|
+
def parse_trading_fees(self, response, useKeyAsId=False) -> TradingFees:
|
712
693
|
result: dict = {}
|
694
|
+
keys = list(response.keys())
|
695
|
+
for i in range(0, len(keys)):
|
696
|
+
key = keys[i]
|
697
|
+
market = None
|
698
|
+
if useKeyAsId:
|
699
|
+
market = self.safe_market(key)
|
700
|
+
parsed = self.parse_trading_fee(response[key], market)
|
701
|
+
result[parsed['symbol']] = parsed
|
713
702
|
for i in range(0, len(self.symbols)):
|
714
703
|
symbol = self.symbols[i]
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
takerString = self.safe_string(fee, 'buy')
|
719
|
-
maker = self.parse_number(Precise.string_div(makerString, '100'))
|
720
|
-
taker = self.parse_number(Precise.string_div(takerString, '100'))
|
721
|
-
result[symbol] = {
|
722
|
-
'info': fee,
|
723
|
-
'symbol': symbol,
|
724
|
-
'maker': maker,
|
725
|
-
'taker': taker,
|
726
|
-
'percentage': True,
|
727
|
-
}
|
704
|
+
if not (symbol in result):
|
705
|
+
market = self.market(symbol)
|
706
|
+
result[symbol] = self.parse_trading_fee(response, market)
|
728
707
|
return result
|
729
708
|
|
709
|
+
def parse_trading_fee(self, fee: dict, market: Market = None) -> TradingFeeInterface:
|
710
|
+
return {
|
711
|
+
'info': fee,
|
712
|
+
'symbol': self.safe_string(market, 'symbol'),
|
713
|
+
'maker': self.safe_number(fee, 'percent'),
|
714
|
+
'taker': self.safe_number(fee, 'percent'),
|
715
|
+
'percentage': None,
|
716
|
+
'tierBased': None,
|
717
|
+
}
|
718
|
+
|
719
|
+
def fetch_accounts(self, params={}) -> List[Account]:
|
720
|
+
self.load_markets()
|
721
|
+
response = self.privatePostGetMyAccountStatusV3(params)
|
722
|
+
#
|
723
|
+
# {
|
724
|
+
# "ok": "ok",
|
725
|
+
# "data": {
|
726
|
+
# "convertedCurrency": "USD",
|
727
|
+
# "balancesPerAccounts": {
|
728
|
+
# "": {
|
729
|
+
# "AI": {
|
730
|
+
# "balance": "0.000000",
|
731
|
+
# "balanceOnHold": "0.000000"
|
732
|
+
# },
|
733
|
+
# "USDT": {
|
734
|
+
# "balance": "0.00000000",
|
735
|
+
# "balanceOnHold": "0.00000000"
|
736
|
+
# }
|
737
|
+
# }
|
738
|
+
# }
|
739
|
+
# }
|
740
|
+
# }
|
741
|
+
#
|
742
|
+
data = self.safe_dict(response, 'data', {})
|
743
|
+
balances = self.safe_dict(data, 'balancesPerAccounts', {})
|
744
|
+
arrays = self.to_array(balances)
|
745
|
+
return self.parse_accounts(arrays, params)
|
746
|
+
|
747
|
+
def parse_account(self, account: dict) -> Account:
|
748
|
+
return {
|
749
|
+
'id': None,
|
750
|
+
'type': None,
|
751
|
+
'code': None,
|
752
|
+
'info': account,
|
753
|
+
}
|
754
|
+
|
755
|
+
def fetch_balance(self, params={}) -> Balances:
|
756
|
+
"""
|
757
|
+
query for balance and get the amount of funds available for trading or funds locked in orders
|
758
|
+
:see: https://trade.cex.io/docs/#rest-private-api-calls-account-status-v3
|
759
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
760
|
+
:param dict [params.method]: 'privatePostGetMyWalletBalance' or 'privatePostGetMyAccountStatusV3'
|
761
|
+
:param dict [params.account]: in case 'privatePostGetMyAccountStatusV3' is chosen, self can specify the account name(default is empty string)
|
762
|
+
:returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
|
763
|
+
"""
|
764
|
+
accountName = None
|
765
|
+
accountName, params = self.handle_param_string(params, 'account', '') # default is empty string
|
766
|
+
method = None
|
767
|
+
method, params = self.handle_param_string(params, 'method', 'privatePostGetMyWalletBalance')
|
768
|
+
accountBalance = None
|
769
|
+
if method == 'privatePostGetMyAccountStatusV3':
|
770
|
+
response = self.privatePostGetMyAccountStatusV3(params)
|
771
|
+
#
|
772
|
+
# {
|
773
|
+
# "ok": "ok",
|
774
|
+
# "data": {
|
775
|
+
# "convertedCurrency": "USD",
|
776
|
+
# "balancesPerAccounts": {
|
777
|
+
# "": {
|
778
|
+
# "AI": {
|
779
|
+
# "balance": "0.000000",
|
780
|
+
# "balanceOnHold": "0.000000"
|
781
|
+
# },
|
782
|
+
# ....
|
783
|
+
#
|
784
|
+
data = self.safe_dict(response, 'data', {})
|
785
|
+
balances = self.safe_dict(data, 'balancesPerAccounts', {})
|
786
|
+
accountBalance = self.safe_dict(balances, accountName, {})
|
787
|
+
else:
|
788
|
+
response = self.privatePostGetMyWalletBalance(params)
|
789
|
+
#
|
790
|
+
# {
|
791
|
+
# "ok": "ok",
|
792
|
+
# "data": {
|
793
|
+
# "AI": {
|
794
|
+
# "balance": "25.606429"
|
795
|
+
# },
|
796
|
+
# "USDT": {
|
797
|
+
# "balance": "7.935449"
|
798
|
+
# },
|
799
|
+
# ...
|
800
|
+
#
|
801
|
+
accountBalance = self.safe_dict(response, 'data', {})
|
802
|
+
return self.parse_balance(accountBalance)
|
803
|
+
|
804
|
+
def parse_balance(self, response) -> Balances:
|
805
|
+
result: dict = {
|
806
|
+
'info': response,
|
807
|
+
}
|
808
|
+
keys = list(response.keys())
|
809
|
+
for i in range(0, len(keys)):
|
810
|
+
key = keys[i]
|
811
|
+
balance = self.safe_dict(response, key, {})
|
812
|
+
code = self.safe_currency_code(key)
|
813
|
+
account: dict = {
|
814
|
+
'used': self.safe_string(balance, 'balanceOnHold'),
|
815
|
+
'free': self.safe_string(balance, 'balance'),
|
816
|
+
}
|
817
|
+
result[code] = account
|
818
|
+
return self.safe_balance(result)
|
819
|
+
|
820
|
+
def fetch_orders_by_status(self, status: str, symbol: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Order]:
|
821
|
+
"""
|
822
|
+
fetches information on multiple orders made by the user
|
823
|
+
:see: https://trade.cex.io/docs/#rest-private-api-calls-orders
|
824
|
+
:param str symbol: unified market symbol of the market orders were made in
|
825
|
+
:param int [since]: the earliest time in ms to fetch orders for
|
826
|
+
:param int [limit]: the maximum number of order structures to retrieve
|
827
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
828
|
+
:param int [params.until]: timestamp in ms of the latest entry
|
829
|
+
:returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
|
830
|
+
"""
|
831
|
+
self.load_markets()
|
832
|
+
request: dict = {}
|
833
|
+
isClosedOrders = (status == 'closed')
|
834
|
+
if isClosedOrders:
|
835
|
+
request['archived'] = True
|
836
|
+
market = None
|
837
|
+
if symbol is not None:
|
838
|
+
market = self.market(symbol)
|
839
|
+
request['pair'] = market['id']
|
840
|
+
if limit is not None:
|
841
|
+
request['pageSize'] = limit
|
842
|
+
if since is not None:
|
843
|
+
request['serverCreateTimestampFrom'] = since
|
844
|
+
elif isClosedOrders:
|
845
|
+
# exchange requires a `since` parameter for closed orders, so set default to allowed 365
|
846
|
+
request['serverCreateTimestampFrom'] = self.milliseconds() - 364 * 24 * 60 * 60 * 1000
|
847
|
+
until = None
|
848
|
+
until, params = self.handle_param_integer_2(params, 'until', 'till')
|
849
|
+
if until is not None:
|
850
|
+
request['serverCreateTimestampTo'] = until
|
851
|
+
response = self.privatePostGetMyOrders(self.extend(request, params))
|
852
|
+
#
|
853
|
+
# if called without `pair`
|
854
|
+
#
|
855
|
+
# {
|
856
|
+
# "ok": "ok",
|
857
|
+
# "data": [
|
858
|
+
# {
|
859
|
+
# "orderId": "1313003",
|
860
|
+
# "clientOrderId": "037F0AFEB93A",
|
861
|
+
# "clientId": "up421412345",
|
862
|
+
# "accountId": null,
|
863
|
+
# "status": "FILLED",
|
864
|
+
# "statusIsFinal": True,
|
865
|
+
# "currency1": "AI",
|
866
|
+
# "currency2": "USDT",
|
867
|
+
# "side": "BUY",
|
868
|
+
# "orderType": "Market",
|
869
|
+
# "timeInForce": "IOC",
|
870
|
+
# "comment": null,
|
871
|
+
# "rejectCode": null,
|
872
|
+
# "rejectReason": null,
|
873
|
+
# "initialOnHoldAmountCcy1": null,
|
874
|
+
# "initialOnHoldAmountCcy2": "10.23456700",
|
875
|
+
# "executedAmountCcy1": "25.606429",
|
876
|
+
# "executedAmountCcy2": "10.20904439",
|
877
|
+
# "requestedAmountCcy1": null,
|
878
|
+
# "requestedAmountCcy2": "10.20904439",
|
879
|
+
# "originalAmountCcy2": "10.23456700",
|
880
|
+
# "feeAmount": "0.02552261",
|
881
|
+
# "feeCurrency": "USDT",
|
882
|
+
# "price": null,
|
883
|
+
# "averagePrice": "0.3986",
|
884
|
+
# "clientCreateTimestamp": "1728474625320",
|
885
|
+
# "serverCreateTimestamp": "1728474624956",
|
886
|
+
# "lastUpdateTimestamp": "1728474628015",
|
887
|
+
# "expireTime": null,
|
888
|
+
# "effectiveTime": null
|
889
|
+
# },
|
890
|
+
# ...
|
891
|
+
#
|
892
|
+
data = self.safe_value(response, 'data', [])
|
893
|
+
return self.parse_orders(data, market, since, limit)
|
894
|
+
|
895
|
+
def fetch_closed_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}):
|
896
|
+
"""
|
897
|
+
fetches information on multiple canceled orders made by the user
|
898
|
+
:param str symbol: unified market symbol of the market orders were made in
|
899
|
+
:param int [since]: timestamp in ms of the earliest order, default is None
|
900
|
+
:param int [limit]: max number of orders to return, default is None
|
901
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
902
|
+
:returns dict: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
|
903
|
+
"""
|
904
|
+
return self.fetch_orders_by_status('closed', symbol, since, limit, params)
|
905
|
+
|
906
|
+
def fetch_open_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}):
|
907
|
+
"""
|
908
|
+
fetches information on multiple canceled orders made by the user
|
909
|
+
:param str symbol: unified market symbol of the market orders were made in
|
910
|
+
:param int [since]: timestamp in ms of the earliest order, default is None
|
911
|
+
:param int [limit]: max number of orders to return, default is None
|
912
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
913
|
+
:returns dict: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
|
914
|
+
"""
|
915
|
+
return self.fetch_orders_by_status('open', symbol, since, limit, params)
|
916
|
+
|
917
|
+
def parse_order_status(self, status: Str):
|
918
|
+
statuses: dict = {
|
919
|
+
'FILLED': 'closed',
|
920
|
+
'CANCELLED': 'canceled',
|
921
|
+
}
|
922
|
+
return self.safe_string(statuses, status, None)
|
923
|
+
|
924
|
+
def parse_order(self, order: dict, market: Market = None) -> Order:
|
925
|
+
#
|
926
|
+
# "orderId": "1313003",
|
927
|
+
# "clientOrderId": "037F0AFEB93A",
|
928
|
+
# "clientId": "up421412345",
|
929
|
+
# "accountId": null,
|
930
|
+
# "status": "FILLED",
|
931
|
+
# "statusIsFinal": True,
|
932
|
+
# "currency1": "AI",
|
933
|
+
# "currency2": "USDT",
|
934
|
+
# "side": "BUY",
|
935
|
+
# "orderType": "Market",
|
936
|
+
# "timeInForce": "IOC",
|
937
|
+
# "comment": null,
|
938
|
+
# "rejectCode": null,
|
939
|
+
# "rejectReason": null,
|
940
|
+
# "initialOnHoldAmountCcy1": null,
|
941
|
+
# "initialOnHoldAmountCcy2": "10.23456700",
|
942
|
+
# "executedAmountCcy1": "25.606429",
|
943
|
+
# "executedAmountCcy2": "10.20904439",
|
944
|
+
# "requestedAmountCcy1": null,
|
945
|
+
# "requestedAmountCcy2": "10.20904439",
|
946
|
+
# "originalAmountCcy2": "10.23456700",
|
947
|
+
# "feeAmount": "0.02552261",
|
948
|
+
# "feeCurrency": "USDT",
|
949
|
+
# "price": null,
|
950
|
+
# "averagePrice": "0.3986",
|
951
|
+
# "clientCreateTimestamp": "1728474625320",
|
952
|
+
# "serverCreateTimestamp": "1728474624956",
|
953
|
+
# "lastUpdateTimestamp": "1728474628015",
|
954
|
+
# "expireTime": null,
|
955
|
+
# "effectiveTime": null
|
956
|
+
#
|
957
|
+
currency1 = self.safe_string(order, 'currency1')
|
958
|
+
currency2 = self.safe_string(order, 'currency2')
|
959
|
+
marketId = None
|
960
|
+
if currency1 is not None and currency2 is not None:
|
961
|
+
marketId = currency1 + '-' + currency2
|
962
|
+
market = self.safe_market(marketId, market)
|
963
|
+
symbol = market['symbol']
|
964
|
+
status = self.parse_order_status(self.safe_string(order, 'status'))
|
965
|
+
fee = {}
|
966
|
+
feeAmount = self.safe_number(order, 'feeAmount')
|
967
|
+
if feeAmount is not None:
|
968
|
+
currencyId = self.safe_string(order, 'feeCurrency')
|
969
|
+
feeCode = self.safe_currency_code(currencyId)
|
970
|
+
fee['currency'] = feeCode
|
971
|
+
fee['fee'] = feeAmount
|
972
|
+
timestamp = self.safe_integer(order, 'serverCreateTimestamp')
|
973
|
+
requestedBase = self.safe_number(order, 'requestedAmountCcy1')
|
974
|
+
executedBase = self.safe_number(order, 'executedAmountCcy1')
|
975
|
+
# requestedQuote = self.safe_number(order, 'requestedAmountCcy2')
|
976
|
+
executedQuote = self.safe_number(order, 'executedAmountCcy2')
|
977
|
+
return self.safe_order({
|
978
|
+
'id': self.safe_string(order, 'orderId'),
|
979
|
+
'clientOrderId': self.safe_string(order, 'clientOrderId'),
|
980
|
+
'timestamp': timestamp,
|
981
|
+
'datetime': self.iso8601(timestamp),
|
982
|
+
'lastUpdateTimestamp': self.safe_integer(order, 'lastUpdateTimestamp'),
|
983
|
+
'lastTradeTimestamp': None,
|
984
|
+
'symbol': symbol,
|
985
|
+
'type': self.safe_string_lower(order, 'orderType'),
|
986
|
+
'timeInForce': self.safe_string(order, 'timeInForce'),
|
987
|
+
'postOnly': None,
|
988
|
+
'side': self.safe_string_lower(order, 'side'),
|
989
|
+
'price': self.safe_number(order, 'price'),
|
990
|
+
'stopPrice': self.safe_number(order, 'stopPrice'),
|
991
|
+
'amount': requestedBase,
|
992
|
+
'cost': executedQuote,
|
993
|
+
'average': self.safe_number(order, 'averagePrice'),
|
994
|
+
'filled': executedBase,
|
995
|
+
'remaining': None,
|
996
|
+
'status': status,
|
997
|
+
'fee': fee,
|
998
|
+
'trades': None,
|
999
|
+
'info': order,
|
1000
|
+
}, market)
|
1001
|
+
|
730
1002
|
def create_order(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={}):
|
731
1003
|
"""
|
732
|
-
:see: https://docs.cex.io/#place-order
|
733
1004
|
create a trade order
|
734
|
-
:see: https://cex.io/rest-api
|
1005
|
+
:see: https://trade.cex.io/docs/#rest-private-api-calls-new-order
|
735
1006
|
:param str symbol: unified symbol of the market to create an order in
|
736
1007
|
:param str type: 'market' or 'limit'
|
737
1008
|
:param str side: 'buy' or 'sell'
|
738
1009
|
:param float amount: how much of currency you want to trade in units of base currency
|
739
1010
|
:param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
|
740
1011
|
:param dict [params]: extra parameters specific to the exchange API endpoint
|
741
|
-
:param
|
1012
|
+
:param str [params.accountId]: account-id to use(default is empty string)
|
742
1013
|
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
|
743
1014
|
"""
|
1015
|
+
accountId = None
|
1016
|
+
accountId, params = self.handle_option_and_params(params, 'createOrder', 'accountId')
|
1017
|
+
if accountId is None:
|
1018
|
+
raise ArgumentsRequired(self.id + ' createOrder() : API trading is now allowed from main account, set params["accountId"] or .options["createOrder"]["accountId"] to the name of your sub-account')
|
744
1019
|
self.load_markets()
|
745
1020
|
market = self.market(symbol)
|
746
1021
|
request: dict = {
|
747
|
-
'
|
748
|
-
'
|
1022
|
+
'clientOrderId': self.uuid(),
|
1023
|
+
'currency1': market['baseId'],
|
1024
|
+
'currency2': market['quoteId'],
|
1025
|
+
'accountId': accountId,
|
1026
|
+
'orderType': self.capitalize(type.lower()),
|
1027
|
+
'side': side.upper(),
|
1028
|
+
'timestamp': self.milliseconds(),
|
1029
|
+
'amountCcy1': self.amount_to_precision(symbol, amount),
|
749
1030
|
}
|
750
|
-
|
751
|
-
|
752
|
-
quoteAmount = None
|
753
|
-
createMarketBuyOrderRequiresPrice = True
|
754
|
-
createMarketBuyOrderRequiresPrice, params = self.handle_option_and_params(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', True)
|
755
|
-
cost = self.safe_string(params, 'cost')
|
756
|
-
params = self.omit(params, 'cost')
|
757
|
-
if cost is not None:
|
758
|
-
quoteAmount = self.cost_to_precision(symbol, cost)
|
759
|
-
elif createMarketBuyOrderRequiresPrice:
|
760
|
-
if price is None:
|
761
|
-
raise InvalidOrder(self.id + ' createOrder() requires the price argument for market buy orders to calculate the total cost to spend(amount * price), alternatively set the createMarketBuyOrderRequiresPrice option or param to False and pass the cost to spend in the amount argument')
|
762
|
-
else:
|
763
|
-
amountString = self.number_to_string(amount)
|
764
|
-
priceString = self.number_to_string(price)
|
765
|
-
costRequest = Precise.string_mul(amountString, priceString)
|
766
|
-
quoteAmount = self.cost_to_precision(symbol, costRequest)
|
767
|
-
else:
|
768
|
-
quoteAmount = self.cost_to_precision(symbol, amount)
|
769
|
-
request['amount'] = quoteAmount
|
770
|
-
else:
|
771
|
-
request['amount'] = self.amount_to_precision(symbol, amount)
|
1031
|
+
timeInForce = None
|
1032
|
+
timeInForce, params = self.handle_option_and_params(params, 'createOrder', 'timeInForce', 'GTC')
|
772
1033
|
if type == 'limit':
|
773
|
-
request['price'] = self.
|
774
|
-
|
775
|
-
|
776
|
-
|
1034
|
+
request['price'] = self.price_to_precision(symbol, price)
|
1035
|
+
request['timeInForce'] = timeInForce
|
1036
|
+
triggerPrice = None
|
1037
|
+
triggerPrice, params = self.handle_param_string(params, 'triggerPrice')
|
1038
|
+
if triggerPrice is not None:
|
1039
|
+
request['type'] = 'Stop Limit'
|
1040
|
+
request['stopPrice'] = triggerPrice
|
1041
|
+
response = self.privatePostDoMyNewOrder(self.extend(request, params))
|
777
1042
|
#
|
778
|
-
#
|
779
|
-
# "id": "12978363524",
|
780
|
-
# "time": 1586610022259,
|
781
|
-
# "type": "buy",
|
782
|
-
# "price": "0.033934",
|
783
|
-
# "amount": "0.10722802",
|
784
|
-
# "pending": "0.10722802",
|
785
|
-
# "complete": False
|
786
|
-
# }
|
1043
|
+
# on success
|
787
1044
|
#
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
1045
|
+
# {
|
1046
|
+
# "ok": "ok",
|
1047
|
+
# "data": {
|
1048
|
+
# "messageType": "executionReport",
|
1049
|
+
# "clientId": "up132245425",
|
1050
|
+
# "orderId": "1318485",
|
1051
|
+
# "clientOrderId": "b5b6cd40-154c-4c1c-bd51-4a442f3d50b9",
|
1052
|
+
# "accountId": "sub1",
|
1053
|
+
# "status": "FILLED",
|
1054
|
+
# "currency1": "LTC",
|
1055
|
+
# "currency2": "USDT",
|
1056
|
+
# "side": "BUY",
|
1057
|
+
# "executedAmountCcy1": "0.23000000",
|
1058
|
+
# "executedAmountCcy2": "15.09030000",
|
1059
|
+
# "requestedAmountCcy1": "0.23000000",
|
1060
|
+
# "requestedAmountCcy2": null,
|
1061
|
+
# "orderType": "Market",
|
1062
|
+
# "timeInForce": null,
|
1063
|
+
# "comment": null,
|
1064
|
+
# "executionType": "Trade",
|
1065
|
+
# "executionId": "1726747124624_101_41116",
|
1066
|
+
# "transactTime": "2024-10-15T15:08:12.794Z",
|
1067
|
+
# "expireTime": null,
|
1068
|
+
# "effectiveTime": null,
|
1069
|
+
# "averagePrice": "65.61",
|
1070
|
+
# "lastQuantity": "0.23000000",
|
1071
|
+
# "lastAmountCcy1": "0.23000000",
|
1072
|
+
# "lastAmountCcy2": "15.09030000",
|
1073
|
+
# "lastPrice": "65.61",
|
1074
|
+
# "feeAmount": "0.03772575",
|
1075
|
+
# "feeCurrency": "USDT",
|
1076
|
+
# "clientCreateTimestamp": "1729004892014",
|
1077
|
+
# "serverCreateTimestamp": "1729004891628",
|
1078
|
+
# "lastUpdateTimestamp": "1729004892786"
|
1079
|
+
# }
|
1080
|
+
# }
|
1081
|
+
#
|
1082
|
+
# on failure, there are extra fields
|
1083
|
+
#
|
1084
|
+
# "status": "REJECTED",
|
1085
|
+
# "requestedAmountCcy1": null,
|
1086
|
+
# "orderRejectReason": "{\\" code \\ ":405,\\" reason \\ ":\\" Either AmountCcy1(OrderQty)or AmountCcy2(CashOrderQty)should be specified for market order not both \\ "}",
|
1087
|
+
# "rejectCode": 405,
|
1088
|
+
# "rejectReason": "Either AmountCcy1(OrderQty) or AmountCcy2(CashOrderQty) should be specified for market order not both",
|
1089
|
+
#
|
1090
|
+
data = self.safe_dict(response, 'data')
|
1091
|
+
return self.parse_order(data, market)
|
816
1092
|
|
817
1093
|
def cancel_order(self, id: str, symbol: Str = None, params={}):
|
818
1094
|
"""
|
819
|
-
:see: https://docs.cex.io/#cancel-order
|
820
1095
|
cancels an open order
|
1096
|
+
:see: https://trade.cex.io/docs/#rest-private-api-calls-cancel-order
|
821
1097
|
:param str id: order id
|
822
|
-
:param str symbol:
|
1098
|
+
:param str symbol: unified symbol of the market the order was made in
|
823
1099
|
:param dict [params]: extra parameters specific to the exchange API endpoint
|
824
1100
|
:returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
|
825
1101
|
"""
|
826
1102
|
self.load_markets()
|
827
1103
|
request: dict = {
|
828
|
-
'
|
1104
|
+
'orderId': int(id),
|
1105
|
+
'cancelRequestId': 'c_' + str((self.milliseconds())),
|
1106
|
+
'timestamp': self.milliseconds(),
|
829
1107
|
}
|
830
|
-
response = self.
|
831
|
-
#
|
832
|
-
|
1108
|
+
response = self.privatePostDoCancelMyOrder(self.extend(request, params))
|
1109
|
+
#
|
1110
|
+
# {"ok":"ok","data":{}}
|
1111
|
+
#
|
1112
|
+
data = self.safe_dict(response, 'data', {})
|
1113
|
+
return self.parse_order(data)
|
833
1114
|
|
834
1115
|
def cancel_all_orders(self, symbol: Str = None, params={}):
|
835
1116
|
"""
|
836
|
-
:see: https://docs.cex.io/#cancel-all-orders-for-given-pair
|
837
1117
|
cancel all open orders in a market
|
838
|
-
:
|
839
|
-
:param
|
840
|
-
:param
|
1118
|
+
:see: https://trade.cex.io/docs/#rest-private-api-calls-cancel-all-orders
|
1119
|
+
:param str symbol: alpaca cancelAllOrders cannot setting symbol, it will cancel all open orders
|
1120
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
841
1121
|
:returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
|
842
1122
|
"""
|
843
|
-
if symbol is None:
|
844
|
-
raise ArgumentsRequired(self.id + ' cancelAllOrders requires a symbol.')
|
845
1123
|
self.load_markets()
|
846
|
-
|
847
|
-
request: dict = {
|
848
|
-
'pair': market['id'],
|
849
|
-
}
|
850
|
-
orders = self.privatePostCancelOrdersPair(self.extend(request, params))
|
1124
|
+
response = self.privatePostDoCancelAllOrders(params)
|
851
1125
|
#
|
852
|
-
#
|
853
|
-
#
|
854
|
-
#
|
855
|
-
#
|
856
|
-
#
|
857
|
-
#
|
1126
|
+
# {
|
1127
|
+
# "ok": "ok",
|
1128
|
+
# "data": {
|
1129
|
+
# "clientOrderIds": [
|
1130
|
+
# "3AF77B67109F"
|
1131
|
+
# ]
|
1132
|
+
# }
|
1133
|
+
# }
|
858
1134
|
#
|
859
|
-
|
1135
|
+
data = self.safe_dict(response, 'data', {})
|
1136
|
+
ids = self.safe_list(data, 'clientOrderIds', [])
|
1137
|
+
orders = []
|
1138
|
+
for i in range(0, len(ids)):
|
1139
|
+
id = ids[i]
|
1140
|
+
orders.append({'clientOrderId': id})
|
1141
|
+
return self.parse_orders(orders)
|
860
1142
|
|
861
|
-
def
|
862
|
-
# Depending on the call, 'time' can be a unix int, unix string or ISO string
|
863
|
-
# Yes, really
|
864
|
-
timestamp = self.safe_value(order, 'time')
|
865
|
-
if isinstance(timestamp, str) and timestamp.find('T') >= 0:
|
866
|
-
# ISO8601 string
|
867
|
-
timestamp = self.parse8601(timestamp)
|
868
|
-
elif timestamp is not None:
|
869
|
-
# either integer or string integer
|
870
|
-
timestamp = int(timestamp)
|
871
|
-
symbol = None
|
872
|
-
baseId = self.safe_string(order, 'symbol1')
|
873
|
-
quoteId = self.safe_string(order, 'symbol2')
|
874
|
-
if market is None and baseId is not None and quoteId is not None:
|
875
|
-
base = self.safe_currency_code(baseId)
|
876
|
-
quote = self.safe_currency_code(quoteId)
|
877
|
-
if (base is not None) and (quote is not None):
|
878
|
-
symbol = base + '/' + quote
|
879
|
-
if symbol in self.markets:
|
880
|
-
market = self.market(symbol)
|
881
|
-
status = self.parse_order_status(self.safe_string(order, 'status'))
|
882
|
-
price = self.safe_string(order, 'price')
|
883
|
-
amount = self.omit_zero(self.safe_string(order, 'amount'))
|
884
|
-
# sell orders can have a negative amount
|
885
|
-
# https://github.com/ccxt/ccxt/issues/5338
|
886
|
-
if amount is not None:
|
887
|
-
amount = Precise.string_abs(amount)
|
888
|
-
elif market is not None:
|
889
|
-
amountKey = 'a:' + market['base'] + 'cds:'
|
890
|
-
amount = Precise.string_abs(self.safe_string(order, amountKey))
|
891
|
-
remaining = self.safe_string_2(order, 'pending', 'remains')
|
892
|
-
filled = Precise.string_sub(amount, remaining)
|
893
|
-
fee = None
|
894
|
-
cost = None
|
895
|
-
if market is not None:
|
896
|
-
symbol = market['symbol']
|
897
|
-
taCost = self.safe_string(order, 'ta:' + market['quote'])
|
898
|
-
ttaCost = self.safe_string(order, 'tta:' + market['quote'])
|
899
|
-
cost = Precise.string_add(taCost, ttaCost)
|
900
|
-
baseFee = 'fa:' + market['base']
|
901
|
-
baseTakerFee = 'tfa:' + market['base']
|
902
|
-
quoteFee = 'fa:' + market['quote']
|
903
|
-
quoteTakerFee = 'tfa:' + market['quote']
|
904
|
-
feeRate = self.safe_string(order, 'tradingFeeMaker')
|
905
|
-
if not feeRate:
|
906
|
-
feeRate = self.safe_string(order, 'tradingFeeTaker', feeRate)
|
907
|
-
if feeRate:
|
908
|
-
feeRate = Precise.string_div(feeRate, '100') # convert to mathematically-correct percentage coefficients: 1.0 = 100%
|
909
|
-
if (baseFee in order) or (baseTakerFee in order):
|
910
|
-
baseFeeCost = self.safe_number_2(order, baseFee, baseTakerFee)
|
911
|
-
fee = {
|
912
|
-
'currency': market['base'],
|
913
|
-
'rate': self.parse_number(feeRate),
|
914
|
-
'cost': baseFeeCost,
|
915
|
-
}
|
916
|
-
elif (quoteFee in order) or (quoteTakerFee in order):
|
917
|
-
quoteFeeCost = self.safe_number_2(order, quoteFee, quoteTakerFee)
|
918
|
-
fee = {
|
919
|
-
'currency': market['quote'],
|
920
|
-
'rate': self.parse_number(feeRate),
|
921
|
-
'cost': quoteFeeCost,
|
922
|
-
}
|
923
|
-
if not cost:
|
924
|
-
cost = Precise.string_mul(price, filled)
|
925
|
-
side = self.safe_string(order, 'type')
|
926
|
-
trades = None
|
927
|
-
orderId = self.safe_string(order, 'id')
|
928
|
-
if 'vtx' in order:
|
929
|
-
trades = []
|
930
|
-
for i in range(0, len(order['vtx'])):
|
931
|
-
item = order['vtx'][i]
|
932
|
-
tradeSide = self.safe_string(item, 'type')
|
933
|
-
if tradeSide == 'cancel':
|
934
|
-
# looks like self might represent the cancelled part of an order
|
935
|
-
# {"id": "4426729543",
|
936
|
-
# "type": "cancel",
|
937
|
-
# "time": "2017-09-22T00:24:30.476Z",
|
938
|
-
# "user": "up106404164",
|
939
|
-
# "c": "user:up106404164:a:BCH",
|
940
|
-
# "d": "order:4426728375:a:BCH",
|
941
|
-
# "a": "0.09935956",
|
942
|
-
# "amount": "0.09935956",
|
943
|
-
# "balance": "0.42580261",
|
944
|
-
# "symbol": "BCH",
|
945
|
-
# "order": "4426728375",
|
946
|
-
# "buy": null,
|
947
|
-
# "sell": null,
|
948
|
-
# "pair": null,
|
949
|
-
# "pos": null,
|
950
|
-
# "cs": "0.42580261",
|
951
|
-
# "ds": 0}
|
952
|
-
continue
|
953
|
-
tradePrice = self.safe_string(item, 'price')
|
954
|
-
if tradePrice is None:
|
955
|
-
# self represents the order
|
956
|
-
# {
|
957
|
-
# "a": "0.47000000",
|
958
|
-
# "c": "user:up106404164:a:EUR",
|
959
|
-
# "d": "order:6065499239:a:EUR",
|
960
|
-
# "cs": "1432.93",
|
961
|
-
# "ds": "476.72",
|
962
|
-
# "id": "6065499249",
|
963
|
-
# "buy": null,
|
964
|
-
# "pos": null,
|
965
|
-
# "pair": null,
|
966
|
-
# "sell": null,
|
967
|
-
# "time": "2018-04-22T13:07:22.152Z",
|
968
|
-
# "type": "buy",
|
969
|
-
# "user": "up106404164",
|
970
|
-
# "order": "6065499239",
|
971
|
-
# "amount": "-715.97000000",
|
972
|
-
# "symbol": "EUR",
|
973
|
-
# "balance": "1432.93000000"}
|
974
|
-
continue
|
975
|
-
# todo: deal with these
|
976
|
-
if tradeSide == 'costsNothing':
|
977
|
-
continue
|
978
|
-
# --
|
979
|
-
# if side != tradeSide:
|
980
|
-
# raise Error(json.dumps(order, null, 2))
|
981
|
-
# if orderId != item['order']:
|
982
|
-
# raise Error(json.dumps(order, null, 2))
|
983
|
-
# --
|
984
|
-
# partial buy trade
|
985
|
-
# {
|
986
|
-
# "a": "0.01589885",
|
987
|
-
# "c": "user:up106404164:a:BTC",
|
988
|
-
# "d": "order:6065499239:a:BTC",
|
989
|
-
# "cs": "0.36300000",
|
990
|
-
# "ds": 0,
|
991
|
-
# "id": "6067991213",
|
992
|
-
# "buy": "6065499239",
|
993
|
-
# "pos": null,
|
994
|
-
# "pair": null,
|
995
|
-
# "sell": "6067991206",
|
996
|
-
# "time": "2018-04-22T23:09:11.773Z",
|
997
|
-
# "type": "buy",
|
998
|
-
# "user": "up106404164",
|
999
|
-
# "order": "6065499239",
|
1000
|
-
# "price": 7146.5,
|
1001
|
-
# "amount": "0.01589885",
|
1002
|
-
# "symbol": "BTC",
|
1003
|
-
# "balance": "0.36300000",
|
1004
|
-
# "symbol2": "EUR",
|
1005
|
-
# "fee_amount": "0.19"}
|
1006
|
-
# --
|
1007
|
-
# trade with zero amount, but non-zero fee
|
1008
|
-
# {
|
1009
|
-
# "a": "0.00000000",
|
1010
|
-
# "c": "user:up106404164:a:EUR",
|
1011
|
-
# "d": "order:5840654423:a:EUR",
|
1012
|
-
# "cs": 559744,
|
1013
|
-
# "ds": 0,
|
1014
|
-
# "id": "5840654429",
|
1015
|
-
# "buy": "5807238573",
|
1016
|
-
# "pos": null,
|
1017
|
-
# "pair": null,
|
1018
|
-
# "sell": "5840654423",
|
1019
|
-
# "time": "2018-03-15T03:20:14.010Z",
|
1020
|
-
# "type": "sell",
|
1021
|
-
# "user": "up106404164",
|
1022
|
-
# "order": "5840654423",
|
1023
|
-
# "price": 730,
|
1024
|
-
# "amount": "0.00000000",
|
1025
|
-
# "symbol": "EUR",
|
1026
|
-
# "balance": "5597.44000000",
|
1027
|
-
# "symbol2": "BCH",
|
1028
|
-
# "fee_amount": "0.01"}
|
1029
|
-
# --
|
1030
|
-
# trade which should have an amount of exactly 0.002BTC
|
1031
|
-
# {
|
1032
|
-
# "a": "16.70000000",
|
1033
|
-
# "c": "user:up106404164:a:GBP",
|
1034
|
-
# "d": "order:9927386681:a:GBP",
|
1035
|
-
# "cs": "86.90",
|
1036
|
-
# "ds": 0,
|
1037
|
-
# "id": "9927401610",
|
1038
|
-
# "buy": "9927401601",
|
1039
|
-
# "pos": null,
|
1040
|
-
# "pair": null,
|
1041
|
-
# "sell": "9927386681",
|
1042
|
-
# "time": "2019-08-21T15:25:37.777Z",
|
1043
|
-
# "type": "sell",
|
1044
|
-
# "user": "up106404164",
|
1045
|
-
# "order": "9927386681",
|
1046
|
-
# "price": 8365,
|
1047
|
-
# "amount": "16.70000000",
|
1048
|
-
# "office": "UK",
|
1049
|
-
# "symbol": "GBP",
|
1050
|
-
# "balance": "86.90000000",
|
1051
|
-
# "symbol2": "BTC",
|
1052
|
-
# "fee_amount": "0.03"
|
1053
|
-
# }
|
1054
|
-
tradeTimestamp = self.parse8601(self.safe_string(item, 'time'))
|
1055
|
-
tradeAmount = self.safe_string(item, 'amount')
|
1056
|
-
feeCost = self.safe_string(item, 'fee_amount')
|
1057
|
-
absTradeAmount = Precise.string_abs(tradeAmount)
|
1058
|
-
tradeCost = None
|
1059
|
-
if tradeSide == 'sell':
|
1060
|
-
tradeCost = absTradeAmount
|
1061
|
-
absTradeAmount = Precise.string_div(Precise.string_add(feeCost, tradeCost), tradePrice)
|
1062
|
-
else:
|
1063
|
-
tradeCost = Precise.string_mul(absTradeAmount, tradePrice)
|
1064
|
-
trades.append({
|
1065
|
-
'id': self.safe_string(item, 'id'),
|
1066
|
-
'timestamp': tradeTimestamp,
|
1067
|
-
'datetime': self.iso8601(tradeTimestamp),
|
1068
|
-
'order': orderId,
|
1069
|
-
'symbol': symbol,
|
1070
|
-
'price': self.parse_number(tradePrice),
|
1071
|
-
'amount': self.parse_number(absTradeAmount),
|
1072
|
-
'cost': self.parse_number(tradeCost),
|
1073
|
-
'side': tradeSide,
|
1074
|
-
'fee': {
|
1075
|
-
'cost': self.parse_number(feeCost),
|
1076
|
-
'currency': market['quote'],
|
1077
|
-
},
|
1078
|
-
'info': item,
|
1079
|
-
'type': None,
|
1080
|
-
'takerOrMaker': None,
|
1081
|
-
})
|
1082
|
-
return self.safe_order({
|
1083
|
-
'info': order,
|
1084
|
-
'id': orderId,
|
1085
|
-
'clientOrderId': None,
|
1086
|
-
'datetime': self.iso8601(timestamp),
|
1087
|
-
'timestamp': timestamp,
|
1088
|
-
'lastTradeTimestamp': None,
|
1089
|
-
'status': status,
|
1090
|
-
'symbol': symbol,
|
1091
|
-
'type': 'market' if (price is None) else 'limit',
|
1092
|
-
'timeInForce': None,
|
1093
|
-
'postOnly': None,
|
1094
|
-
'side': side,
|
1095
|
-
'price': price,
|
1096
|
-
'stopPrice': None,
|
1097
|
-
'triggerPrice': None,
|
1098
|
-
'cost': cost,
|
1099
|
-
'amount': amount,
|
1100
|
-
'filled': filled,
|
1101
|
-
'remaining': remaining,
|
1102
|
-
'trades': trades,
|
1103
|
-
'fee': fee,
|
1104
|
-
'average': None,
|
1105
|
-
})
|
1106
|
-
|
1107
|
-
def fetch_open_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Order]:
|
1143
|
+
def fetch_ledger(self, code: Str = None, since: Int = None, limit: Int = None, params={}) -> List[LedgerEntry]:
|
1108
1144
|
"""
|
1109
|
-
|
1110
|
-
|
1111
|
-
:param str
|
1112
|
-
:param int [since]:
|
1113
|
-
:param int [limit]:
|
1145
|
+
fetch the history of changes, actions done by the user or operations that altered the balance of the user
|
1146
|
+
:see: https://trade.cex.io/docs/#rest-private-api-calls-transaction-history
|
1147
|
+
:param str [code]: unified currency code
|
1148
|
+
:param int [since]: timestamp in ms of the earliest ledger entry
|
1149
|
+
:param int [limit]: max number of ledger entries to return
|
1114
1150
|
:param dict [params]: extra parameters specific to the exchange API endpoint
|
1115
|
-
:
|
1151
|
+
:param int [params.until]: timestamp in ms of the latest ledger entry
|
1152
|
+
:returns dict: a `ledger structure <https://docs.ccxt.com/#/?id=ledger-structure>`
|
1116
1153
|
"""
|
1117
1154
|
self.load_markets()
|
1155
|
+
currency = None
|
1118
1156
|
request: dict = {}
|
1119
|
-
|
1120
|
-
|
1121
|
-
|
1122
|
-
|
1123
|
-
request['
|
1124
|
-
|
1157
|
+
if code is not None:
|
1158
|
+
currency = self.currency(code)
|
1159
|
+
request['currency'] = currency['id']
|
1160
|
+
if since is not None:
|
1161
|
+
request['dateFrom'] = since
|
1162
|
+
if limit is not None:
|
1163
|
+
request['pageSize'] = limit
|
1164
|
+
until = None
|
1165
|
+
until, params = self.handle_param_integer_2(params, 'until', 'till')
|
1166
|
+
if until is not None:
|
1167
|
+
request['dateTo'] = until
|
1168
|
+
response = self.privatePostGetMyTransactionHistory(self.extend(request, params))
|
1169
|
+
#
|
1170
|
+
# {
|
1171
|
+
# "ok": "ok",
|
1172
|
+
# "data": [
|
1173
|
+
# {
|
1174
|
+
# "transactionId": "30367722",
|
1175
|
+
# "timestamp": "2024-10-14T14:08:49.987Z",
|
1176
|
+
# "accountId": "",
|
1177
|
+
# "type": "withdraw",
|
1178
|
+
# "amount": "-12.39060600",
|
1179
|
+
# "details": "Withdraw fundingId=1235039 clientId=up421412345 walletTxId=76337154166",
|
1180
|
+
# "currency": "USDT"
|
1181
|
+
# },
|
1182
|
+
# ...
|
1183
|
+
#
|
1184
|
+
data = self.safe_list(response, 'data', [])
|
1185
|
+
return self.parse_ledger(data, currency, since, limit)
|
1186
|
+
|
1187
|
+
def parse_ledger_entry(self, item: dict, currency: Currency = None) -> LedgerEntry:
|
1188
|
+
amount = self.safe_string(item, 'amount')
|
1189
|
+
direction = None
|
1190
|
+
if Precise.string_le(amount, '0'):
|
1191
|
+
direction = 'out'
|
1192
|
+
amount = Precise.string_mul('-1', amount)
|
1125
1193
|
else:
|
1126
|
-
|
1127
|
-
|
1128
|
-
|
1129
|
-
|
1194
|
+
direction = 'in'
|
1195
|
+
currencyId = self.safe_string(item, 'currency')
|
1196
|
+
currency = self.safe_currency(currencyId, currency)
|
1197
|
+
code = self.safe_currency_code(currencyId, currency)
|
1198
|
+
timestampString = self.safe_string(item, 'timestamp')
|
1199
|
+
timestamp = self.parse8601(timestampString)
|
1200
|
+
type = self.safe_string(item, 'type')
|
1201
|
+
return self.safe_ledger_entry({
|
1202
|
+
'info': item,
|
1203
|
+
'id': self.safe_string(item, 'transactionId'),
|
1204
|
+
'direction': direction,
|
1205
|
+
'account': self.safe_string(item, 'accountId', ''),
|
1206
|
+
'referenceAccount': None,
|
1207
|
+
'referenceId': None,
|
1208
|
+
'type': self.parse_ledger_entry_type(type),
|
1209
|
+
'currency': code,
|
1210
|
+
'amount': self.parse_number(amount),
|
1211
|
+
'timestamp': timestamp,
|
1212
|
+
'datetime': self.iso8601(timestamp),
|
1213
|
+
'before': None,
|
1214
|
+
'after': None,
|
1215
|
+
'status': None,
|
1216
|
+
'fee': None,
|
1217
|
+
}, currency)
|
1130
1218
|
|
1131
|
-
def
|
1219
|
+
def parse_ledger_entry_type(self, type):
|
1220
|
+
ledgerType: dict = {
|
1221
|
+
'deposit': 'deposit',
|
1222
|
+
'withdraw': 'withdrawal',
|
1223
|
+
'commission': 'fee',
|
1224
|
+
}
|
1225
|
+
return self.safe_string(ledgerType, type, type)
|
1226
|
+
|
1227
|
+
def fetch_deposits_withdrawals(self, code: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Transaction]:
|
1132
1228
|
"""
|
1133
|
-
|
1134
|
-
|
1135
|
-
:param str
|
1136
|
-
:param int [since]:
|
1137
|
-
:param int [limit]:
|
1229
|
+
fetch history of deposits and withdrawals
|
1230
|
+
:see: https://trade.cex.io/docs/#rest-private-api-calls-funding-history
|
1231
|
+
:param str [code]: unified currency code for the currency of the deposit/withdrawals, default is None
|
1232
|
+
:param int [since]: timestamp in ms of the earliest deposit/withdrawal, default is None
|
1233
|
+
:param int [limit]: max number of deposit/withdrawals to return, default is None
|
1138
1234
|
:param dict [params]: extra parameters specific to the exchange API endpoint
|
1139
|
-
:returns
|
1235
|
+
:returns dict: a list of `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
|
1140
1236
|
"""
|
1141
|
-
if symbol is None:
|
1142
|
-
raise ArgumentsRequired(self.id + ' fetchClosedOrders() requires a symbol argument')
|
1143
1237
|
self.load_markets()
|
1144
|
-
|
1145
|
-
|
1146
|
-
|
1147
|
-
|
1238
|
+
request: dict = {}
|
1239
|
+
currency = None
|
1240
|
+
if code is not None:
|
1241
|
+
currency = self.currency(code)
|
1242
|
+
if since is not None:
|
1243
|
+
request['dateFrom'] = since
|
1244
|
+
if limit is not None:
|
1245
|
+
request['pageSize'] = limit
|
1246
|
+
until = None
|
1247
|
+
until, params = self.handle_param_integer_2(params, 'until', 'till')
|
1248
|
+
if until is not None:
|
1249
|
+
request['dateTo'] = until
|
1250
|
+
response = self.privatePostGetMyFundingHistory(self.extend(request, params))
|
1251
|
+
#
|
1252
|
+
# {
|
1253
|
+
# "ok": "ok",
|
1254
|
+
# "data": [
|
1255
|
+
# {
|
1256
|
+
# "clientId": "up421412345",
|
1257
|
+
# "accountId": "",
|
1258
|
+
# "currency": "USDT",
|
1259
|
+
# "direction": "withdraw",
|
1260
|
+
# "amount": "12.39060600",
|
1261
|
+
# "commissionAmount": "0.00000000",
|
1262
|
+
# "status": "approved",
|
1263
|
+
# "updatedAt": "2024-10-14T14:08:50.013Z",
|
1264
|
+
# "txId": "30367718",
|
1265
|
+
# "details": {}
|
1266
|
+
# },
|
1267
|
+
# ...
|
1268
|
+
#
|
1269
|
+
data = self.safe_list(response, 'data', [])
|
1270
|
+
return self.parse_transactions(data, currency, since, limit)
|
1271
|
+
|
1272
|
+
def parse_transaction(self, transaction: dict, currency: Currency = None) -> Transaction:
|
1273
|
+
currencyId = self.safe_string(transaction, 'currency')
|
1274
|
+
direction = self.safe_string(transaction, 'direction')
|
1275
|
+
type = 'withdrawal' if (direction == 'withdraw') else 'deposit'
|
1276
|
+
code = self.safe_currency_code(currencyId, currency)
|
1277
|
+
updatedAt = self.safe_string(transaction, 'updatedAt')
|
1278
|
+
timestamp = self.parse8601(updatedAt)
|
1279
|
+
return {
|
1280
|
+
'info': transaction,
|
1281
|
+
'id': self.safe_string(transaction, 'txId'),
|
1282
|
+
'txid': None,
|
1283
|
+
'type': type,
|
1284
|
+
'currency': code,
|
1285
|
+
'network': None,
|
1286
|
+
'amount': self.safe_number(transaction, 'amount'),
|
1287
|
+
'status': self.parse_transaction_status(self.safe_string(transaction, 'status')),
|
1288
|
+
'timestamp': timestamp,
|
1289
|
+
'datetime': self.iso8601(timestamp),
|
1290
|
+
'address': None,
|
1291
|
+
'addressFrom': None,
|
1292
|
+
'addressTo': None,
|
1293
|
+
'tag': None,
|
1294
|
+
'tagFrom': None,
|
1295
|
+
'tagTo': None,
|
1296
|
+
'updated': None,
|
1297
|
+
'comment': None,
|
1298
|
+
'fee': {
|
1299
|
+
'currency': code,
|
1300
|
+
'cost': self.safe_number(transaction, 'commissionAmount'),
|
1301
|
+
},
|
1302
|
+
'internal': None,
|
1303
|
+
}
|
1148
1304
|
|
1149
|
-
def
|
1305
|
+
def parse_transaction_status(self, status: Str):
|
1306
|
+
statuses: dict = {
|
1307
|
+
'rejected': 'rejected',
|
1308
|
+
'pending': 'pending',
|
1309
|
+
'approved': 'ok',
|
1310
|
+
}
|
1311
|
+
return self.safe_string(statuses, status, status)
|
1312
|
+
|
1313
|
+
def transfer(self, code: str, amount: float, fromAccount: str, toAccount: str, params={}) -> TransferEntry:
|
1150
1314
|
"""
|
1151
|
-
|
1152
|
-
|
1153
|
-
:param str
|
1154
|
-
:param
|
1315
|
+
transfer currency internally between wallets on the same account
|
1316
|
+
:see: https://trade.cex.io/docs/#rest-private-api-calls-internal-transfer
|
1317
|
+
:param str code: unified currency code
|
1318
|
+
:param float amount: amount to transfer
|
1319
|
+
:param str fromAccount: 'SPOT', 'FUND', or 'CONTRACT'
|
1320
|
+
:param str toAccount: 'SPOT', 'FUND', or 'CONTRACT'
|
1155
1321
|
:param dict [params]: extra parameters specific to the exchange API endpoint
|
1156
|
-
:returns dict:
|
1322
|
+
:returns dict: a `transfer structure <https://docs.ccxt.com/#/?id=transfer-structure>`
|
1157
1323
|
"""
|
1324
|
+
transfer = None
|
1325
|
+
if toAccount != '' and fromAccount != '':
|
1326
|
+
transfer = self.transfer_between_sub_accounts(code, amount, fromAccount, toAccount, params)
|
1327
|
+
else:
|
1328
|
+
transfer = self.transfer_between_main_and_sub_account(code, amount, fromAccount, toAccount, params)
|
1329
|
+
fillResponseFromRequest = self.handle_option('transfer', 'fillResponseFromRequest', True)
|
1330
|
+
if fillResponseFromRequest:
|
1331
|
+
transfer['fromAccount'] = fromAccount
|
1332
|
+
transfer['toAccount'] = toAccount
|
1333
|
+
return transfer
|
1334
|
+
|
1335
|
+
def transfer_between_main_and_sub_account(self, code: str, amount: float, fromAccount: str, toAccount: str, params={}) -> TransferEntry:
|
1158
1336
|
self.load_markets()
|
1337
|
+
currency = self.currency(code)
|
1338
|
+
fromMain = (fromAccount == '')
|
1339
|
+
targetAccount = toAccount if fromMain else fromAccount
|
1340
|
+
guid = self.safe_string(params, 'guid', self.uuid())
|
1159
1341
|
request: dict = {
|
1160
|
-
'
|
1342
|
+
'currency': currency['id'],
|
1343
|
+
'amount': self.currency_to_precision(code, amount),
|
1344
|
+
'accountId': targetAccount,
|
1345
|
+
'clientTxId': guid,
|
1161
1346
|
}
|
1162
|
-
response =
|
1163
|
-
|
1347
|
+
response = None
|
1348
|
+
if fromMain:
|
1349
|
+
response = self.privatePostDoDepositFundsFromWallet(self.extend(request, params))
|
1350
|
+
else:
|
1351
|
+
response = self.privatePostDoWithdrawalFundsToWallet(self.extend(request, params))
|
1352
|
+
# both endpoints return the same structure, the only difference is that
|
1353
|
+
# the "accountId" is filled with the "subAccount"
|
1164
1354
|
#
|
1165
1355
|
# {
|
1166
|
-
# "
|
1167
|
-
# "
|
1168
|
-
#
|
1169
|
-
#
|
1170
|
-
#
|
1171
|
-
#
|
1172
|
-
#
|
1173
|
-
# "status": "d",
|
1174
|
-
# "symbol1": "ETH",
|
1175
|
-
# "symbol2": "EUR",
|
1176
|
-
# "amount": "0.50000000",
|
1177
|
-
# "kind": "api",
|
1178
|
-
# "price": "923.3386",
|
1179
|
-
# "tfacf": "1",
|
1180
|
-
# "fa:EUR": "0.55",
|
1181
|
-
# "ta:EUR": "369.77",
|
1182
|
-
# "remains": "0.00000000",
|
1183
|
-
# "tfa:EUR": "0.22",
|
1184
|
-
# "tta:EUR": "91.95",
|
1185
|
-
# "a:ETH:cds": "0.50000000",
|
1186
|
-
# "a:EUR:cds": "461.72",
|
1187
|
-
# "f:EUR:cds": "0.77",
|
1188
|
-
# "tradingFeeMaker": "0.15",
|
1189
|
-
# "tradingFeeTaker": "0.23",
|
1190
|
-
# "tradingFeeStrategy": "userVolumeAmount",
|
1191
|
-
# "tradingFeeUserVolumeAmount": "2896912572",
|
1192
|
-
# "orderId": "5442731603",
|
1193
|
-
# "next": False,
|
1194
|
-
# "vtx": [
|
1195
|
-
# {
|
1196
|
-
# "id": "5442734452",
|
1197
|
-
# "type": "sell",
|
1198
|
-
# "time": "2018-01-16T19:52:58.452Z",
|
1199
|
-
# "user": "up106404164",
|
1200
|
-
# "c": "user:up106404164:a:EUR",
|
1201
|
-
# "d": "order:5442731603:a:EUR",
|
1202
|
-
# "a": "104.53000000",
|
1203
|
-
# "amount": "104.53000000",
|
1204
|
-
# "balance": "932.71000000",
|
1205
|
-
# "symbol": "EUR",
|
1206
|
-
# "order": "5442731603",
|
1207
|
-
# "buy": "5442734443",
|
1208
|
-
# "sell": "5442731603",
|
1209
|
-
# "pair": null,
|
1210
|
-
# "pos": null,
|
1211
|
-
# "office": null,
|
1212
|
-
# "cs": "932.71",
|
1213
|
-
# "ds": 0,
|
1214
|
-
# "price": 923.3386,
|
1215
|
-
# "symbol2": "ETH",
|
1216
|
-
# "fee_amount": "0.16"
|
1217
|
-
# },
|
1218
|
-
# {
|
1219
|
-
# "id": "5442731609",
|
1220
|
-
# "type": "sell",
|
1221
|
-
# "time": "2018-01-16T19:52:38.071Z",
|
1222
|
-
# "user": "up106404164",
|
1223
|
-
# "c": "user:up106404164:a:EUR",
|
1224
|
-
# "d": "order:5442731603:a:EUR",
|
1225
|
-
# "a": "91.73000000",
|
1226
|
-
# "amount": "91.73000000",
|
1227
|
-
# "balance": "563.49000000",
|
1228
|
-
# "symbol": "EUR",
|
1229
|
-
# "order": "5442731603",
|
1230
|
-
# "buy": "5442618127",
|
1231
|
-
# "sell": "5442731603",
|
1232
|
-
# "pair": null,
|
1233
|
-
# "pos": null,
|
1234
|
-
# "office": null,
|
1235
|
-
# "cs": "563.49",
|
1236
|
-
# "ds": 0,
|
1237
|
-
# "price": 924.0092,
|
1238
|
-
# "symbol2": "ETH",
|
1239
|
-
# "fee_amount": "0.22"
|
1240
|
-
# },
|
1241
|
-
# {
|
1242
|
-
# "id": "5442731604",
|
1243
|
-
# "type": "sell",
|
1244
|
-
# "time": "2018-01-16T19:52:38.071Z",
|
1245
|
-
# "user": "up106404164",
|
1246
|
-
# "c": "order:5442731603:a:ETH",
|
1247
|
-
# "d": "user:up106404164:a:ETH",
|
1248
|
-
# "a": "0.50000000",
|
1249
|
-
# "amount": "-0.50000000",
|
1250
|
-
# "balance": "15.80995000",
|
1251
|
-
# "symbol": "ETH",
|
1252
|
-
# "order": "5442731603",
|
1253
|
-
# "buy": null,
|
1254
|
-
# "sell": null,
|
1255
|
-
# "pair": null,
|
1256
|
-
# "pos": null,
|
1257
|
-
# "office": null,
|
1258
|
-
# "cs": "0.50000000",
|
1259
|
-
# "ds": "15.80995000"
|
1260
|
-
# }
|
1261
|
-
# ]
|
1356
|
+
# "ok": "ok",
|
1357
|
+
# "data": {
|
1358
|
+
# "accountId": "sub1",
|
1359
|
+
# "clientTxId": "27ba8284-67cf-4386-9ec7-80b3871abd45",
|
1360
|
+
# "currency": "USDT",
|
1361
|
+
# "status": "approved"
|
1362
|
+
# }
|
1262
1363
|
# }
|
1263
1364
|
#
|
1264
|
-
|
1365
|
+
data = self.safe_dict(response, 'data', {})
|
1366
|
+
return self.parse_transfer(data, currency)
|
1265
1367
|
|
1266
|
-
def
|
1267
|
-
"""
|
1268
|
-
:see: https://docs.cex.io/#archived-orders
|
1269
|
-
fetches information on multiple orders made by the user
|
1270
|
-
:param str symbol: unified market symbol of the market orders were made in
|
1271
|
-
:param int [since]: the earliest time in ms to fetch orders for
|
1272
|
-
:param int [limit]: the maximum number of order structures to retrieve
|
1273
|
-
:param dict [params]: extra parameters specific to the exchange API endpoint
|
1274
|
-
:returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
|
1275
|
-
"""
|
1368
|
+
def transfer_between_sub_accounts(self, code: str, amount: float, fromAccount: str, toAccount: str, params={}) -> TransferEntry:
|
1276
1369
|
self.load_markets()
|
1277
|
-
|
1370
|
+
currency = self.currency(code)
|
1278
1371
|
request: dict = {
|
1279
|
-
'
|
1280
|
-
'
|
1281
|
-
'
|
1372
|
+
'currency': currency['id'],
|
1373
|
+
'amount': self.currency_to_precision(code, amount),
|
1374
|
+
'fromAccountId': fromAccount,
|
1375
|
+
'toAccountId': toAccount,
|
1282
1376
|
}
|
1283
|
-
response = self.
|
1284
|
-
|
1285
|
-
|
1286
|
-
|
1287
|
-
|
1288
|
-
|
1289
|
-
|
1290
|
-
|
1291
|
-
|
1292
|
-
|
1293
|
-
|
1294
|
-
# "symbol1": "ETH",
|
1295
|
-
# "symbol2": "GBP",
|
1296
|
-
# "amount": "0.20000000",
|
1297
|
-
# "price": "200.5625",
|
1298
|
-
# "remains": "0.20000000",
|
1299
|
-
# 'a:ETH:cds': "0.20000000",
|
1300
|
-
# "tradingFeeMaker": "0",
|
1301
|
-
# "tradingFeeTaker": "0.16",
|
1302
|
-
# "tradingFeeUserVolumeAmount": "10155061217",
|
1303
|
-
# "orderId": "4005785516"}
|
1304
|
-
# --
|
1305
|
-
# cancelled(partially filled buy):
|
1306
|
-
# {"id": "4084911657",
|
1307
|
-
# "type": "buy",
|
1308
|
-
# "time": "2017-08-05T03:18:39.596Z",
|
1309
|
-
# "lastTxTime": "2019-03-19T17:37:46.404Z",
|
1310
|
-
# "lastTx": "8459265833",
|
1311
|
-
# "pos": null,
|
1312
|
-
# "status": "cd",
|
1313
|
-
# "symbol1": "BTC",
|
1314
|
-
# "symbol2": "GBP",
|
1315
|
-
# "amount": "0.05000000",
|
1316
|
-
# "price": "2241.4692",
|
1317
|
-
# "tfacf": "1",
|
1318
|
-
# "remains": "0.03910535",
|
1319
|
-
# 'tfa:GBP': "0.04",
|
1320
|
-
# 'tta:GBP': "24.39",
|
1321
|
-
# 'a:BTC:cds': "0.01089465",
|
1322
|
-
# 'a:GBP:cds': "112.26",
|
1323
|
-
# 'f:GBP:cds': "0.04",
|
1324
|
-
# "tradingFeeMaker": "0",
|
1325
|
-
# "tradingFeeTaker": "0.16",
|
1326
|
-
# "tradingFeeUserVolumeAmount": "13336396963",
|
1327
|
-
# "orderId": "4084911657"}
|
1328
|
-
# --
|
1329
|
-
# cancelled(partially filled sell):
|
1330
|
-
# {"id": "4426728375",
|
1331
|
-
# "type": "sell",
|
1332
|
-
# "time": "2017-09-22T00:24:20.126Z",
|
1333
|
-
# "lastTxTime": "2017-09-22T00:24:30.476Z",
|
1334
|
-
# "lastTx": "4426729543",
|
1335
|
-
# "pos": null,
|
1336
|
-
# "status": "cd",
|
1337
|
-
# "symbol1": "BCH",
|
1338
|
-
# "symbol2": "BTC",
|
1339
|
-
# "amount": "0.10000000",
|
1340
|
-
# "price": "0.11757182",
|
1341
|
-
# "tfacf": "1",
|
1342
|
-
# "remains": "0.09935956",
|
1343
|
-
# 'tfa:BTC': "0.00000014",
|
1344
|
-
# 'tta:BTC': "0.00007537",
|
1345
|
-
# 'a:BCH:cds': "0.10000000",
|
1346
|
-
# 'a:BTC:cds': "0.00007537",
|
1347
|
-
# 'f:BTC:cds': "0.00000014",
|
1348
|
-
# "tradingFeeMaker": "0",
|
1349
|
-
# "tradingFeeTaker": "0.18",
|
1350
|
-
# "tradingFeeUserVolumeAmount": "3466715450",
|
1351
|
-
# "orderId": "4426728375"}
|
1352
|
-
# --
|
1353
|
-
# filled:
|
1354
|
-
# {"id": "5342275378",
|
1355
|
-
# "type": "sell",
|
1356
|
-
# "time": "2018-01-04T00:28:12.992Z",
|
1357
|
-
# "lastTxTime": "2018-01-04T00:28:12.992Z",
|
1358
|
-
# "lastTx": "5342275393",
|
1359
|
-
# "pos": null,
|
1360
|
-
# "status": "d",
|
1361
|
-
# "symbol1": "BCH",
|
1362
|
-
# "symbol2": "BTC",
|
1363
|
-
# "amount": "0.10000000",
|
1364
|
-
# "kind": "api",
|
1365
|
-
# "price": "0.17",
|
1366
|
-
# "remains": "0.00000000",
|
1367
|
-
# 'tfa:BTC': "0.00003902",
|
1368
|
-
# 'tta:BTC': "0.01699999",
|
1369
|
-
# 'a:BCH:cds': "0.10000000",
|
1370
|
-
# 'a:BTC:cds': "0.01699999",
|
1371
|
-
# 'f:BTC:cds': "0.00003902",
|
1372
|
-
# "tradingFeeMaker": "0.15",
|
1373
|
-
# "tradingFeeTaker": "0.23",
|
1374
|
-
# "tradingFeeUserVolumeAmount": "1525951128",
|
1375
|
-
# "orderId": "5342275378"}
|
1376
|
-
# --
|
1377
|
-
# market order(buy):
|
1378
|
-
# {"id": "6281946200",
|
1379
|
-
# "pos": null,
|
1380
|
-
# "time": "2018-05-23T11:55:43.467Z",
|
1381
|
-
# "type": "buy",
|
1382
|
-
# "amount": "0.00000000",
|
1383
|
-
# "lastTx": "6281946210",
|
1384
|
-
# "status": "d",
|
1385
|
-
# "amount2": "20.00",
|
1386
|
-
# "orderId": "6281946200",
|
1387
|
-
# "remains": "0.00000000",
|
1388
|
-
# "symbol1": "ETH",
|
1389
|
-
# "symbol2": "EUR",
|
1390
|
-
# "tfa:EUR": "0.05",
|
1391
|
-
# "tta:EUR": "19.94",
|
1392
|
-
# "a:ETH:cds": "0.03764100",
|
1393
|
-
# "a:EUR:cds": "20.00",
|
1394
|
-
# "f:EUR:cds": "0.05",
|
1395
|
-
# "lastTxTime": "2018-05-23T11:55:43.467Z",
|
1396
|
-
# "tradingFeeTaker": "0.25",
|
1397
|
-
# "tradingFeeUserVolumeAmount": "55998097"}
|
1398
|
-
# --
|
1399
|
-
# market order(sell):
|
1400
|
-
# {"id": "6282200948",
|
1401
|
-
# "pos": null,
|
1402
|
-
# "time": "2018-05-23T12:42:58.315Z",
|
1403
|
-
# "type": "sell",
|
1404
|
-
# "amount": "-0.05000000",
|
1405
|
-
# "lastTx": "6282200958",
|
1406
|
-
# "status": "d",
|
1407
|
-
# "orderId": "6282200948",
|
1408
|
-
# "remains": "0.00000000",
|
1409
|
-
# "symbol1": "ETH",
|
1410
|
-
# "symbol2": "EUR",
|
1411
|
-
# "tfa:EUR": "0.07",
|
1412
|
-
# "tta:EUR": "26.49",
|
1413
|
-
# "a:ETH:cds": "0.05000000",
|
1414
|
-
# "a:EUR:cds": "26.49",
|
1415
|
-
# "f:EUR:cds": "0.07",
|
1416
|
-
# "lastTxTime": "2018-05-23T12:42:58.315Z",
|
1417
|
-
# "tradingFeeTaker": "0.25",
|
1418
|
-
# "tradingFeeUserVolumeAmount": "56294576"}
|
1419
|
-
order = response[i]
|
1420
|
-
status = self.parse_order_status(self.safe_string(order, 'status'))
|
1421
|
-
baseId = self.safe_string(order, 'symbol1')
|
1422
|
-
quoteId = self.safe_string(order, 'symbol2')
|
1423
|
-
base = self.safe_currency_code(baseId)
|
1424
|
-
quote = self.safe_currency_code(quoteId)
|
1425
|
-
symbolInner = base + '/' + quote
|
1426
|
-
side = self.safe_string(order, 'type')
|
1427
|
-
baseAmount = self.safe_number(order, 'a:' + baseId + ':cds')
|
1428
|
-
quoteAmount = self.safe_number(order, 'a:' + quoteId + ':cds')
|
1429
|
-
fee = self.safe_number(order, 'f:' + quoteId + ':cds')
|
1430
|
-
amount = self.safe_string(order, 'amount')
|
1431
|
-
price = self.safe_string(order, 'price')
|
1432
|
-
remaining = self.safe_string(order, 'remains')
|
1433
|
-
filled = Precise.string_sub(amount, remaining)
|
1434
|
-
orderAmount = None
|
1435
|
-
cost = None
|
1436
|
-
average = None
|
1437
|
-
type = None
|
1438
|
-
if not price:
|
1439
|
-
type = 'market'
|
1440
|
-
orderAmount = baseAmount
|
1441
|
-
cost = quoteAmount
|
1442
|
-
average = Precise.string_div(orderAmount, cost)
|
1443
|
-
else:
|
1444
|
-
ta = self.safe_string(order, 'ta:' + quoteId, '0')
|
1445
|
-
tta = self.safe_string(order, 'tta:' + quoteId, '0')
|
1446
|
-
fa = self.safe_string(order, 'fa:' + quoteId, '0')
|
1447
|
-
tfa = self.safe_string(order, 'tfa:' + quoteId, '0')
|
1448
|
-
if side == 'sell':
|
1449
|
-
cost = Precise.string_add(Precise.string_add(ta, tta), Precise.string_add(fa, tfa))
|
1450
|
-
else:
|
1451
|
-
cost = Precise.string_sub(Precise.string_add(ta, tta), Precise.string_add(fa, tfa))
|
1452
|
-
type = 'limit'
|
1453
|
-
orderAmount = amount
|
1454
|
-
average = Precise.string_div(cost, filled)
|
1455
|
-
time = self.safe_string(order, 'time')
|
1456
|
-
lastTxTime = self.safe_string(order, 'lastTxTime')
|
1457
|
-
timestamp = self.parse8601(time)
|
1458
|
-
safeOrder = self.safe_order({
|
1459
|
-
'info': order,
|
1460
|
-
'id': self.safe_string(order, 'id'),
|
1461
|
-
'timestamp': timestamp,
|
1462
|
-
'datetime': self.iso8601(timestamp),
|
1463
|
-
'lastUpdated': self.parse8601(lastTxTime),
|
1464
|
-
'status': status,
|
1465
|
-
'symbol': symbolInner,
|
1466
|
-
'side': side,
|
1467
|
-
'price': price,
|
1468
|
-
'amount': orderAmount,
|
1469
|
-
'average': average,
|
1470
|
-
'type': type,
|
1471
|
-
'filled': filled,
|
1472
|
-
'cost': cost,
|
1473
|
-
'remaining': remaining,
|
1474
|
-
'fee': {
|
1475
|
-
'cost': fee,
|
1476
|
-
'currency': quote,
|
1477
|
-
},
|
1478
|
-
})
|
1479
|
-
results.append(safeOrder)
|
1480
|
-
return results
|
1481
|
-
|
1482
|
-
def parse_order_status(self, status: Str):
|
1483
|
-
return self.safe_string(self.options['order']['status'], status, status)
|
1377
|
+
response = self.privatePostDoMyInternalTransfer(self.extend(request, params))
|
1378
|
+
#
|
1379
|
+
# {
|
1380
|
+
# "ok": "ok",
|
1381
|
+
# "data": {
|
1382
|
+
# "transactionId": "30225415"
|
1383
|
+
# }
|
1384
|
+
# }
|
1385
|
+
#
|
1386
|
+
data = self.safe_dict(response, 'data', {})
|
1387
|
+
return self.parse_transfer(data, currency)
|
1484
1388
|
|
1485
|
-
def
|
1486
|
-
|
1487
|
-
|
1488
|
-
|
1489
|
-
|
1490
|
-
:
|
1491
|
-
:
|
1492
|
-
:
|
1493
|
-
|
1494
|
-
|
1495
|
-
|
1496
|
-
|
1497
|
-
|
1498
|
-
|
1499
|
-
|
1500
|
-
|
1501
|
-
|
1502
|
-
|
1503
|
-
|
1504
|
-
#
|
1505
|
-
|
1506
|
-
|
1507
|
-
|
1508
|
-
|
1509
|
-
|
1510
|
-
|
1389
|
+
def parse_transfer(self, transfer: dict, currency: Currency = None) -> TransferEntry:
|
1390
|
+
#
|
1391
|
+
# transferBetweenSubAccounts
|
1392
|
+
#
|
1393
|
+
# {
|
1394
|
+
# "ok": "ok",
|
1395
|
+
# "data": {
|
1396
|
+
# "transactionId": "30225415"
|
1397
|
+
# }
|
1398
|
+
# }
|
1399
|
+
#
|
1400
|
+
# transfer between main/sub
|
1401
|
+
#
|
1402
|
+
# {
|
1403
|
+
# "ok": "ok",
|
1404
|
+
# "data": {
|
1405
|
+
# "accountId": "sub1",
|
1406
|
+
# "clientTxId": "27ba8284-67cf-4386-9ec7-80b3871abd45",
|
1407
|
+
# "currency": "USDT",
|
1408
|
+
# "status": "approved"
|
1409
|
+
# }
|
1410
|
+
# }
|
1411
|
+
#
|
1412
|
+
currencyId = self.safe_string(transfer, 'currency')
|
1413
|
+
currencyCode = self.safe_currency_code(currencyId, currency)
|
1414
|
+
return {
|
1415
|
+
'info': transfer,
|
1416
|
+
'id': self.safe_string_2(transfer, 'transactionId', 'clientTxId'),
|
1417
|
+
'timestamp': None,
|
1418
|
+
'datetime': None,
|
1419
|
+
'currency': currencyCode,
|
1420
|
+
'amount': None,
|
1421
|
+
'fromAccount': None,
|
1422
|
+
'toAccount': None,
|
1423
|
+
'status': self.parse_transaction_status(self.safe_string(transfer, 'status')),
|
1511
1424
|
}
|
1512
|
-
response = self.privatePostCancelReplaceOrderPair(self.extend(request, params))
|
1513
|
-
return self.parse_order(response, market)
|
1514
1425
|
|
1515
1426
|
def fetch_deposit_address(self, code: str, params={}) -> DepositAddress:
|
1516
1427
|
"""
|
1517
|
-
:see: https://docs.cex.io/#get-crypto-address
|
1518
1428
|
fetch the deposit address for a currency associated with self account
|
1429
|
+
:see: https://trade.cex.io/docs/#rest-private-api-calls-deposit-address
|
1519
1430
|
:param str code: unified currency code
|
1520
1431
|
:param dict [params]: extra parameters specific to the exchange API endpoint
|
1432
|
+
:param str [params.accountId]: account-id(default to empty string) to refer to(at self moment, only sub-accounts allowed by exchange)
|
1521
1433
|
:returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
|
1522
1434
|
"""
|
1435
|
+
accountId = None
|
1436
|
+
accountId, params = self.handle_option_and_params(params, 'createOrder', 'accountId')
|
1437
|
+
if accountId is None:
|
1438
|
+
raise ArgumentsRequired(self.id + ' fetchDepositAddress() : main account is not allowed to fetch deposit address from api, set params["accountId"] or .options["createOrder"]["accountId"] to the name of your sub-account')
|
1523
1439
|
self.load_markets()
|
1440
|
+
networkCode = None
|
1441
|
+
networkCode, params = self.handle_network_code_and_params(params)
|
1524
1442
|
currency = self.currency(code)
|
1525
1443
|
request: dict = {
|
1526
|
-
'
|
1444
|
+
'accountId': accountId,
|
1445
|
+
'currency': currency['id'], # documentation is wrong about self param
|
1446
|
+
'blockchain': self.network_code_to_id(networkCode),
|
1527
1447
|
}
|
1528
|
-
|
1529
|
-
# atm, cex doesn't support network in the request
|
1530
|
-
response = self.privatePostGetCryptoAddress(self.extend(request, query))
|
1448
|
+
response = self.privatePostGetDepositAddress(self.extend(request, params))
|
1531
1449
|
#
|
1532
1450
|
# {
|
1533
|
-
#
|
1534
|
-
#
|
1535
|
-
#
|
1536
|
-
#
|
1537
|
-
#
|
1538
|
-
#
|
1539
|
-
#
|
1540
|
-
#
|
1541
|
-
#
|
1542
|
-
# # for others coins(i.e. XRP, XLM) other keys are present:
|
1543
|
-
# # "destination": "rF1sdh25BJX3qFwneeTBwaq3zPEWYcwjp2",
|
1544
|
-
# # "destinationTag": "7519113655",
|
1545
|
-
# # "memo": "XLM-memo12345",
|
1546
|
-
# }
|
1547
|
-
# ]
|
1548
|
-
# }
|
1549
|
-
# }
|
1451
|
+
# "ok": "ok",
|
1452
|
+
# "data": {
|
1453
|
+
# "address": "TCr..................1AE",
|
1454
|
+
# "accountId": "sub1",
|
1455
|
+
# "currency": "USDT",
|
1456
|
+
# "blockchain": "tron"
|
1457
|
+
# }
|
1458
|
+
# }
|
1550
1459
|
#
|
1551
|
-
data = self.
|
1552
|
-
|
1553
|
-
|
1554
|
-
|
1555
|
-
|
1556
|
-
|
1460
|
+
data = self.safe_dict(response, 'data', {})
|
1461
|
+
return self.parse_deposit_address(data, currency)
|
1462
|
+
|
1463
|
+
def parse_deposit_address(self, depositAddress, currency: Currency = None) -> DepositAddress:
|
1464
|
+
address = self.safe_string(depositAddress, 'address')
|
1465
|
+
currencyId = self.safe_string(depositAddress, 'currency')
|
1466
|
+
currency = self.safe_currency(currencyId, currency)
|
1557
1467
|
self.check_address(address)
|
1558
1468
|
return {
|
1559
|
-
'info':
|
1560
|
-
'currency': code,
|
1561
|
-
'network': self.network_id_to_code(
|
1469
|
+
'info': depositAddress,
|
1470
|
+
'currency': currency['code'],
|
1471
|
+
'network': self.network_id_to_code(self.safe_string(depositAddress, 'blockchain')),
|
1562
1472
|
'address': address,
|
1563
|
-
'tag':
|
1473
|
+
'tag': None,
|
1564
1474
|
}
|
1565
1475
|
|
1566
|
-
def nonce(self):
|
1567
|
-
return self.milliseconds()
|
1568
|
-
|
1569
1476
|
def sign(self, path, api='public', method='GET', params={}, headers=None, body=None):
|
1570
|
-
url = self.urls['api'][
|
1477
|
+
url = self.urls['api'][api] + '/' + self.implode_params(path, params)
|
1571
1478
|
query = self.omit(params, self.extract_params(path))
|
1572
1479
|
if api == 'public':
|
1573
|
-
if
|
1574
|
-
|
1480
|
+
if method == 'GET':
|
1481
|
+
if query:
|
1482
|
+
url += '?' + self.urlencode(query)
|
1483
|
+
else:
|
1484
|
+
body = self.json(query)
|
1485
|
+
headers = {
|
1486
|
+
'Content-Type': 'application/json',
|
1487
|
+
}
|
1575
1488
|
else:
|
1576
1489
|
self.check_required_credentials()
|
1577
|
-
|
1578
|
-
|
1579
|
-
|
1580
|
-
|
1581
|
-
'key': self.apiKey,
|
1582
|
-
'signature': signature.upper(),
|
1583
|
-
'nonce': nonce,
|
1584
|
-
}, query))
|
1490
|
+
seconds = str(self.seconds())
|
1491
|
+
body = self.json(query)
|
1492
|
+
auth = path + seconds + body
|
1493
|
+
signature = self.hmac(self.encode(auth), self.encode(self.secret), hashlib.sha256, 'base64')
|
1585
1494
|
headers = {
|
1586
1495
|
'Content-Type': 'application/json',
|
1496
|
+
'X-AGGR-KEY': self.apiKey,
|
1497
|
+
'X-AGGR-TIMESTAMP': seconds,
|
1498
|
+
'X-AGGR-SIGNATURE': signature,
|
1587
1499
|
}
|
1588
1500
|
return {'url': url, 'method': method, 'body': body, 'headers': headers}
|
1589
1501
|
|
1590
1502
|
def handle_errors(self, code: int, reason: str, url: str, method: str, headers: dict, body: str, response, requestHeaders, requestBody):
|
1591
|
-
|
1592
|
-
|
1593
|
-
|
1594
|
-
return None
|
1503
|
+
# in some cases, like from createOrder, exchange returns nested escaped JSON string:
|
1504
|
+
# {"ok":"ok","data":{"messageType":"executionReport", "orderRejectReason":"{\"code\":405}"}}
|
1505
|
+
# and because of `.parseJson` bug, we need extra fix
|
1595
1506
|
if response is None:
|
1596
|
-
|
1597
|
-
|
1598
|
-
|
1599
|
-
|
1600
|
-
|
1601
|
-
|
1602
|
-
|
1507
|
+
if body is None:
|
1508
|
+
raise NullResponse(self.id + ' returned empty response')
|
1509
|
+
elif body[0] == '{':
|
1510
|
+
fixed = self.fix_stringified_json_members(body)
|
1511
|
+
response = self.parse_json(fixed)
|
1512
|
+
else:
|
1513
|
+
raise NullResponse(self.id + ' returned unparsed response: ' + body)
|
1514
|
+
error = self.safe_string(response, 'error')
|
1515
|
+
if error is not None:
|
1603
1516
|
feedback = self.id + ' ' + body
|
1604
|
-
self.throw_exactly_matched_exception(self.exceptions['exact'],
|
1605
|
-
self.throw_broadly_matched_exception(self.exceptions['broad'],
|
1517
|
+
self.throw_exactly_matched_exception(self.exceptions['exact'], error, feedback)
|
1518
|
+
self.throw_broadly_matched_exception(self.exceptions['broad'], error, feedback)
|
1606
1519
|
raise ExchangeError(feedback)
|
1520
|
+
# check errors in order-engine(the responses are not standard, so we parse here)
|
1521
|
+
if url.find('do_my_new_order') >= 0:
|
1522
|
+
data = self.safe_dict(response, 'data', {})
|
1523
|
+
rejectReason = self.safe_string(data, 'rejectReason')
|
1524
|
+
if rejectReason is not None:
|
1525
|
+
self.throw_broadly_matched_exception(self.exceptions['broad'], rejectReason, rejectReason)
|
1526
|
+
raise ExchangeError(self.id + ' createOrder() ' + rejectReason)
|
1607
1527
|
return None
|