ccxt 4.4.85__py2.py3-none-any.whl → 4.4.87__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 +7 -5
- ccxt/abstract/modetrade.py +119 -0
- ccxt/abstract/myokx.py +2 -0
- ccxt/abstract/okx.py +2 -0
- ccxt/abstract/okxus.py +349 -0
- ccxt/ascendex.py +187 -151
- ccxt/async_support/__init__.py +7 -5
- ccxt/async_support/ascendex.py +187 -151
- ccxt/async_support/base/exchange.py +30 -26
- ccxt/async_support/bequant.py +1 -1
- ccxt/async_support/binance.py +1 -1
- ccxt/async_support/bitget.py +4 -4
- ccxt/async_support/bitmart.py +1 -1
- ccxt/async_support/bitteam.py +31 -0
- ccxt/async_support/{huobijp.py → bittrade.py} +11 -11
- ccxt/async_support/coinbase.py +2 -5
- ccxt/async_support/coinmetro.py +3 -0
- ccxt/async_support/deribit.py +4 -5
- ccxt/async_support/gate.py +91 -73
- ccxt/async_support/hollaex.py +106 -49
- ccxt/async_support/htx.py +30 -51
- ccxt/async_support/hyperliquid.py +36 -20
- ccxt/async_support/kraken.py +5 -8
- ccxt/async_support/mexc.py +2 -2
- ccxt/async_support/modetrade.py +2727 -0
- ccxt/async_support/ndax.py +25 -24
- ccxt/async_support/okcoin.py +12 -29
- ccxt/async_support/okx.py +99 -3
- ccxt/async_support/okxus.py +54 -0
- ccxt/async_support/onetrading.py +10 -7
- ccxt/async_support/oxfun.py +40 -110
- ccxt/async_support/paradex.py +6 -0
- ccxt/async_support/phemex.py +4 -6
- ccxt/async_support/poloniex.py +172 -159
- ccxt/async_support/probit.py +18 -47
- ccxt/async_support/timex.py +5 -10
- ccxt/async_support/vertex.py +3 -4
- ccxt/async_support/whitebit.py +41 -11
- ccxt/async_support/woo.py +101 -75
- ccxt/async_support/woofipro.py +25 -20
- ccxt/async_support/xt.py +31 -41
- ccxt/base/exchange.py +12 -9
- ccxt/bequant.py +1 -1
- ccxt/binance.py +1 -1
- ccxt/bitget.py +4 -4
- ccxt/bitmart.py +1 -1
- ccxt/bitteam.py +31 -0
- ccxt/{huobijp.py → bittrade.py} +11 -11
- ccxt/coinbase.py +2 -5
- ccxt/coinmetro.py +3 -0
- ccxt/deribit.py +4 -5
- ccxt/gate.py +91 -73
- ccxt/hollaex.py +106 -49
- ccxt/htx.py +30 -51
- ccxt/hyperliquid.py +36 -20
- ccxt/kraken.py +5 -8
- ccxt/mexc.py +2 -2
- ccxt/modetrade.py +2727 -0
- ccxt/ndax.py +25 -24
- ccxt/okcoin.py +12 -29
- ccxt/okx.py +99 -3
- ccxt/okxus.py +54 -0
- ccxt/onetrading.py +10 -7
- ccxt/oxfun.py +40 -110
- ccxt/paradex.py +6 -0
- ccxt/phemex.py +4 -6
- ccxt/poloniex.py +172 -159
- ccxt/pro/__init__.py +101 -3
- ccxt/pro/binance.py +1 -0
- ccxt/pro/{huobijp.py → bittrade.py} +3 -3
- ccxt/pro/luno.py +6 -5
- ccxt/pro/mexc.py +2 -0
- ccxt/pro/modetrade.py +1271 -0
- ccxt/pro/okxus.py +38 -0
- ccxt/probit.py +18 -47
- ccxt/test/tests_async.py +17 -1
- ccxt/test/tests_sync.py +17 -1
- ccxt/timex.py +5 -10
- ccxt/vertex.py +3 -4
- ccxt/whitebit.py +41 -11
- ccxt/woo.py +100 -75
- ccxt/woofipro.py +24 -20
- ccxt/xt.py +31 -41
- {ccxt-4.4.85.dist-info → ccxt-4.4.87.dist-info}/METADATA +19 -8
- {ccxt-4.4.85.dist-info → ccxt-4.4.87.dist-info}/RECORD +89 -84
- ccxt/abstract/kuna.py +0 -182
- ccxt/async_support/kuna.py +0 -1935
- ccxt/kuna.py +0 -1935
- /ccxt/abstract/{huobijp.py → bittrade.py} +0 -0
- {ccxt-4.4.85.dist-info → ccxt-4.4.87.dist-info}/LICENSE.txt +0 -0
- {ccxt-4.4.85.dist-info → ccxt-4.4.87.dist-info}/WHEEL +0 -0
- {ccxt-4.4.85.dist-info → ccxt-4.4.87.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,2727 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
# PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
|
4
|
+
# https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
|
5
|
+
|
6
|
+
from ccxt.async_support.base.exchange import Exchange
|
7
|
+
from ccxt.abstract.modetrade import ImplicitAPI
|
8
|
+
from ccxt.base.types import Any, Balances, Currencies, Currency, Int, LedgerEntry, Leverage, Market, Num, Order, OrderBook, OrderRequest, OrderSide, OrderType, Position, Str, Strings, FundingRate, FundingRates, Trade, TradingFees, Transaction
|
9
|
+
from typing import List
|
10
|
+
from ccxt.base.errors import ExchangeError
|
11
|
+
from ccxt.base.errors import AuthenticationError
|
12
|
+
from ccxt.base.errors import ArgumentsRequired
|
13
|
+
from ccxt.base.errors import BadRequest
|
14
|
+
from ccxt.base.errors import InsufficientFunds
|
15
|
+
from ccxt.base.errors import InvalidOrder
|
16
|
+
from ccxt.base.errors import NotSupported
|
17
|
+
from ccxt.base.errors import NetworkError
|
18
|
+
from ccxt.base.errors import RateLimitExceeded
|
19
|
+
from ccxt.base.decimal_to_precision import TICK_SIZE
|
20
|
+
from ccxt.base.precise import Precise
|
21
|
+
|
22
|
+
|
23
|
+
class modetrade(Exchange, ImplicitAPI):
|
24
|
+
|
25
|
+
def describe(self) -> Any:
|
26
|
+
return self.deep_extend(super(modetrade, self).describe(), {
|
27
|
+
'id': 'modetrade',
|
28
|
+
'name': 'Mode Trade',
|
29
|
+
'countries': ['KY'], # Cayman Islands
|
30
|
+
'rateLimit': 100,
|
31
|
+
'version': 'v1',
|
32
|
+
'certified': True,
|
33
|
+
'pro': True,
|
34
|
+
'dex': True,
|
35
|
+
'hostname': 'trade.mode.network',
|
36
|
+
'has': {
|
37
|
+
'CORS': None,
|
38
|
+
'spot': False,
|
39
|
+
'margin': False,
|
40
|
+
'swap': True,
|
41
|
+
'future': False,
|
42
|
+
'option': False,
|
43
|
+
'addMargin': False,
|
44
|
+
'cancelAllOrders': True,
|
45
|
+
'cancelOrder': True,
|
46
|
+
'cancelOrders': True,
|
47
|
+
'cancelWithdraw': False,
|
48
|
+
'closeAllPositions': False,
|
49
|
+
'closePosition': False,
|
50
|
+
'createConvertTrade': False,
|
51
|
+
'createDepositAddress': False,
|
52
|
+
'createMarketBuyOrderWithCost': False,
|
53
|
+
'createMarketOrder': False,
|
54
|
+
'createMarketOrderWithCost': False,
|
55
|
+
'createMarketSellOrderWithCost': False,
|
56
|
+
'createOrder': True,
|
57
|
+
'createOrderWithTakeProfitAndStopLoss': True,
|
58
|
+
'createReduceOnlyOrder': True,
|
59
|
+
'createStopLimitOrder': False,
|
60
|
+
'createStopLossOrder': True,
|
61
|
+
'createStopMarketOrder': False,
|
62
|
+
'createStopOrder': False,
|
63
|
+
'createTakeProfitOrder': True,
|
64
|
+
'createTrailingAmountOrder': False,
|
65
|
+
'createTrailingPercentOrder': False,
|
66
|
+
'createTriggerOrder': True,
|
67
|
+
'fetchAccounts': False,
|
68
|
+
'fetchBalance': True,
|
69
|
+
'fetchCanceledOrders': False,
|
70
|
+
'fetchClosedOrder': False,
|
71
|
+
'fetchClosedOrders': True,
|
72
|
+
'fetchConvertCurrencies': False,
|
73
|
+
'fetchConvertQuote': False,
|
74
|
+
'fetchCurrencies': True,
|
75
|
+
'fetchDepositAddress': False,
|
76
|
+
'fetchDeposits': True,
|
77
|
+
'fetchDepositsWithdrawals': True,
|
78
|
+
'fetchFundingHistory': True,
|
79
|
+
'fetchFundingInterval': True,
|
80
|
+
'fetchFundingIntervals': False,
|
81
|
+
'fetchFundingRate': True,
|
82
|
+
'fetchFundingRateHistory': True,
|
83
|
+
'fetchFundingRates': True,
|
84
|
+
'fetchIndexOHLCV': False,
|
85
|
+
'fetchLedger': True,
|
86
|
+
'fetchLeverage': True,
|
87
|
+
'fetchMarginAdjustmentHistory': False,
|
88
|
+
'fetchMarginMode': False,
|
89
|
+
'fetchMarkets': True,
|
90
|
+
'fetchMarkOHLCV': False,
|
91
|
+
'fetchMyTrades': True,
|
92
|
+
'fetchOHLCV': True,
|
93
|
+
'fetchOpenInterestHistory': False,
|
94
|
+
'fetchOpenOrder': False,
|
95
|
+
'fetchOpenOrders': True,
|
96
|
+
'fetchOrder': True,
|
97
|
+
'fetchOrderBook': True,
|
98
|
+
'fetchOrders': True,
|
99
|
+
'fetchOrderTrades': True,
|
100
|
+
'fetchPosition': True,
|
101
|
+
'fetchPositionMode': False,
|
102
|
+
'fetchPositions': True,
|
103
|
+
'fetchPremiumIndexOHLCV': False,
|
104
|
+
'fetchStatus': True,
|
105
|
+
'fetchTicker': False,
|
106
|
+
'fetchTickers': False,
|
107
|
+
'fetchTime': True,
|
108
|
+
'fetchTrades': True,
|
109
|
+
'fetchTradingFee': False,
|
110
|
+
'fetchTradingFees': True,
|
111
|
+
'fetchTransactions': 'emulated',
|
112
|
+
'fetchTransfers': False,
|
113
|
+
'fetchWithdrawals': True,
|
114
|
+
'reduceMargin': False,
|
115
|
+
'setLeverage': True,
|
116
|
+
'setMargin': False,
|
117
|
+
'setPositionMode': False,
|
118
|
+
'transfer': False,
|
119
|
+
'withdraw': True, # exchange have that endpoint disabled atm, but was once implemented in ccxt per old docs: https://kronosresearch.github.io/wootrade-documents/#token-withdraw
|
120
|
+
},
|
121
|
+
'timeframes': {
|
122
|
+
'1m': '1m',
|
123
|
+
'5m': '5m',
|
124
|
+
'15m': '15m',
|
125
|
+
'30m': '30m',
|
126
|
+
'1h': '1h',
|
127
|
+
'4h': '4h',
|
128
|
+
'12h': '12h',
|
129
|
+
'1d': '1d',
|
130
|
+
'1w': '1w',
|
131
|
+
'1M': '1mon',
|
132
|
+
'1y': '1y',
|
133
|
+
},
|
134
|
+
'urls': {
|
135
|
+
'logo': 'https://github.com/user-attachments/assets/cec2b7f1-3b2b-4502-971b-447ee1937d6b',
|
136
|
+
'api': {
|
137
|
+
'public': 'https://api-evm.orderly.org',
|
138
|
+
'private': 'https://api-evm.orderly.org',
|
139
|
+
},
|
140
|
+
'test': {
|
141
|
+
'public': 'https://testnet-api-evm.orderly.org',
|
142
|
+
'private': 'https://testnet-api-evm.orderly.org',
|
143
|
+
},
|
144
|
+
'www': 'https://trade.mode.network',
|
145
|
+
'referral': {
|
146
|
+
'url': 'https://trade.mode.network?ref=MODETRADE',
|
147
|
+
'discount': 0.2,
|
148
|
+
},
|
149
|
+
},
|
150
|
+
'api': {
|
151
|
+
'v1': {
|
152
|
+
'public': {
|
153
|
+
'get': {
|
154
|
+
'public/volume/stats': 1,
|
155
|
+
'public/broker/name': 1,
|
156
|
+
'public/chain_info/{broker_id}': 1,
|
157
|
+
'public/system_info': 1,
|
158
|
+
'public/vault_balance': 1,
|
159
|
+
'public/insurancefund': 1,
|
160
|
+
'public/chain_info': 1,
|
161
|
+
'faucet/usdc': 1,
|
162
|
+
'public/account': 1,
|
163
|
+
'get_account': 1,
|
164
|
+
'registration_nonce': 1,
|
165
|
+
'get_orderly_key': 1,
|
166
|
+
'public/liquidation': 1,
|
167
|
+
'public/liquidated_positions': 1,
|
168
|
+
'public/config': 1,
|
169
|
+
'public/campaign/ranking': 10,
|
170
|
+
'public/campaign/stats': 10,
|
171
|
+
'public/campaign/user': 10,
|
172
|
+
'public/campaign/stats/details': 10,
|
173
|
+
'public/campaigns': 10,
|
174
|
+
'public/points/leaderboard': 1,
|
175
|
+
'client/points': 1,
|
176
|
+
'public/points/epoch': 1,
|
177
|
+
'public/points/epoch_dates': 1,
|
178
|
+
'public/referral/check_ref_code': 1,
|
179
|
+
'public/referral/verify_ref_code': 1,
|
180
|
+
'referral/admin_info': 1,
|
181
|
+
'referral/info': 1,
|
182
|
+
'referral/referee_info': 1,
|
183
|
+
'referral/referee_rebate_summary': 1,
|
184
|
+
'referral/referee_history': 1,
|
185
|
+
'referral/referral_history': 1,
|
186
|
+
'referral/rebate_summary': 1,
|
187
|
+
'client/distribution_history': 1,
|
188
|
+
'tv/config': 1,
|
189
|
+
'tv/history': 1,
|
190
|
+
'tv/symbol_info': 1,
|
191
|
+
'public/funding_rate_history': 1,
|
192
|
+
'public/funding_rate/{symbol}': 0.33,
|
193
|
+
'public/funding_rates': 1,
|
194
|
+
'public/info': 1,
|
195
|
+
'public/info/{symbol}': 1,
|
196
|
+
'public/market_trades': 1,
|
197
|
+
'public/token': 1,
|
198
|
+
'public/futures': 1,
|
199
|
+
'public/futures/{symbol}': 1,
|
200
|
+
},
|
201
|
+
'post': {
|
202
|
+
'register_account': 1,
|
203
|
+
},
|
204
|
+
},
|
205
|
+
'private': {
|
206
|
+
'get': {
|
207
|
+
'client/key_info': 6,
|
208
|
+
'client/orderly_key_ip_restriction': 6,
|
209
|
+
'order/{oid}': 1,
|
210
|
+
'client/order/{client_order_id}': 1,
|
211
|
+
'algo/order/{oid}': 1,
|
212
|
+
'algo/client/order/{client_order_id}': 1,
|
213
|
+
'orders': 1,
|
214
|
+
'algo/orders': 1,
|
215
|
+
'trade/{tid}': 1,
|
216
|
+
'trades': 1,
|
217
|
+
'order/{oid}/trades': 1,
|
218
|
+
'client/liquidator_liquidations': 1,
|
219
|
+
'liquidations': 1,
|
220
|
+
'asset/history': 60,
|
221
|
+
'client/holding': 1,
|
222
|
+
'withdraw_nonce': 1,
|
223
|
+
'settle_nonce': 1,
|
224
|
+
'pnl_settlement/history': 1,
|
225
|
+
'volume/user/daily': 60,
|
226
|
+
'volume/user/stats': 60,
|
227
|
+
'client/statistics': 60,
|
228
|
+
'client/info': 60,
|
229
|
+
'client/statistics/daily': 60,
|
230
|
+
'positions': 3.33,
|
231
|
+
'position/{symbol}': 3.33,
|
232
|
+
'funding_fee/history': 30,
|
233
|
+
'notification/inbox/notifications': 60,
|
234
|
+
'notification/inbox/unread': 60,
|
235
|
+
'volume/broker/daily': 60,
|
236
|
+
'broker/fee_rate/default': 10,
|
237
|
+
'broker/user_info': 10,
|
238
|
+
'orderbook/{symbol}': 1,
|
239
|
+
'kline': 1,
|
240
|
+
},
|
241
|
+
'post': {
|
242
|
+
'orderly_key': 1,
|
243
|
+
'client/set_orderly_key_ip_restriction': 6,
|
244
|
+
'client/reset_orderly_key_ip_restriction': 6,
|
245
|
+
'order': 1,
|
246
|
+
'batch-order': 10,
|
247
|
+
'algo/order': 1,
|
248
|
+
'liquidation': 1,
|
249
|
+
'claim_insurance_fund': 1,
|
250
|
+
'withdraw_request': 1,
|
251
|
+
'settle_pnl': 1,
|
252
|
+
'notification/inbox/mark_read': 60,
|
253
|
+
'notification/inbox/mark_read_all': 60,
|
254
|
+
'client/leverage': 120,
|
255
|
+
'client/maintenance_config': 60,
|
256
|
+
'delegate_signer': 10,
|
257
|
+
'delegate_orderly_key': 10,
|
258
|
+
'delegate_settle_pnl': 10,
|
259
|
+
'delegate_withdraw_request': 10,
|
260
|
+
'broker/fee_rate/set': 10,
|
261
|
+
'broker/fee_rate/set_default': 10,
|
262
|
+
'broker/fee_rate/default': 10,
|
263
|
+
'referral/create': 10,
|
264
|
+
'referral/update': 10,
|
265
|
+
'referral/bind': 10,
|
266
|
+
'referral/edit_split': 10,
|
267
|
+
},
|
268
|
+
'put': {
|
269
|
+
'order': 1,
|
270
|
+
'algo/order': 1,
|
271
|
+
},
|
272
|
+
'delete': {
|
273
|
+
'order': 1,
|
274
|
+
'algo/order': 1,
|
275
|
+
'client/order': 1,
|
276
|
+
'algo/client/order': 1,
|
277
|
+
'algo/orders': 1,
|
278
|
+
'orders': 1,
|
279
|
+
'batch-order': 1,
|
280
|
+
'client/batch-order': 1,
|
281
|
+
},
|
282
|
+
},
|
283
|
+
},
|
284
|
+
},
|
285
|
+
'requiredCredentials': {
|
286
|
+
'apiKey': True,
|
287
|
+
'secret': True,
|
288
|
+
'accountId': True,
|
289
|
+
'privateKey': False,
|
290
|
+
},
|
291
|
+
'fees': {
|
292
|
+
'trading': {
|
293
|
+
'tierBased': True,
|
294
|
+
'percentage': True,
|
295
|
+
'maker': self.parse_number('0.0002'),
|
296
|
+
'taker': self.parse_number('0.0005'),
|
297
|
+
},
|
298
|
+
},
|
299
|
+
'options': {
|
300
|
+
'sandboxMode': False,
|
301
|
+
'brokerId': 'CCXT',
|
302
|
+
'verifyingContractAddress': '0x6F7a338F2aA472838dEFD3283eB360d4Dff5D203',
|
303
|
+
},
|
304
|
+
'features': {
|
305
|
+
'default': {
|
306
|
+
'sandbox': True,
|
307
|
+
'createOrder': {
|
308
|
+
'marginMode': False,
|
309
|
+
'triggerPrice': True,
|
310
|
+
'triggerPriceType': None,
|
311
|
+
'triggerDirection': False,
|
312
|
+
'stopLossPrice': False, # todo by triggerPrice
|
313
|
+
'takeProfitPrice': False, # todo by triggerPrice
|
314
|
+
'attachedStopLossTakeProfit': None,
|
315
|
+
'timeInForce': {
|
316
|
+
'IOC': True,
|
317
|
+
'FOK': True,
|
318
|
+
'PO': True,
|
319
|
+
'GTD': False,
|
320
|
+
},
|
321
|
+
'hedged': False,
|
322
|
+
'trailing': True,
|
323
|
+
'leverage': True, # todo implement
|
324
|
+
'marketBuyByCost': False,
|
325
|
+
'marketBuyRequiresPrice': False,
|
326
|
+
'selfTradePrevention': False,
|
327
|
+
'iceberg': True, # todo implement
|
328
|
+
},
|
329
|
+
'createOrders': {
|
330
|
+
'max': 10,
|
331
|
+
},
|
332
|
+
'fetchMyTrades': {
|
333
|
+
'marginMode': False,
|
334
|
+
'limit': 500,
|
335
|
+
'daysBack': None,
|
336
|
+
'untilDays': 100000,
|
337
|
+
'symbolRequired': False,
|
338
|
+
},
|
339
|
+
'fetchOrder': {
|
340
|
+
'marginMode': False,
|
341
|
+
'trigger': True,
|
342
|
+
'trailing': False,
|
343
|
+
'symbolRequired': False,
|
344
|
+
},
|
345
|
+
'fetchOpenOrders': {
|
346
|
+
'marginMode': False,
|
347
|
+
'limit': 500,
|
348
|
+
'trigger': True,
|
349
|
+
'trailing': False,
|
350
|
+
'symbolRequired': False,
|
351
|
+
},
|
352
|
+
'fetchOrders': None,
|
353
|
+
'fetchClosedOrders': {
|
354
|
+
'marginMode': False,
|
355
|
+
'limit': 500,
|
356
|
+
'daysBack': None,
|
357
|
+
'daysBackCanceled': None,
|
358
|
+
'untilDays': 100000,
|
359
|
+
'trigger': True,
|
360
|
+
'trailing': False,
|
361
|
+
'symbolRequired': False,
|
362
|
+
},
|
363
|
+
'fetchOHLCV': {
|
364
|
+
'limit': 1000,
|
365
|
+
},
|
366
|
+
},
|
367
|
+
'spot': {
|
368
|
+
'extends': 'default',
|
369
|
+
},
|
370
|
+
'forDerivatives': {
|
371
|
+
'extends': 'default',
|
372
|
+
'createOrder': {
|
373
|
+
# todo: implementation needs unification
|
374
|
+
'triggerPriceType': None,
|
375
|
+
'attachedStopLossTakeProfit': {
|
376
|
+
# todo: implementation needs unification
|
377
|
+
'triggerPriceType': None,
|
378
|
+
'price': False,
|
379
|
+
},
|
380
|
+
},
|
381
|
+
},
|
382
|
+
'swap': {
|
383
|
+
'linear': {
|
384
|
+
'extends': 'forDerivatives',
|
385
|
+
},
|
386
|
+
'inverse': None,
|
387
|
+
},
|
388
|
+
'future': {
|
389
|
+
'linear': None,
|
390
|
+
'inverse': None,
|
391
|
+
},
|
392
|
+
},
|
393
|
+
'commonCurrencies': {},
|
394
|
+
'exceptions': {
|
395
|
+
'exact': {
|
396
|
+
'-1000': ExchangeError, # UNKNOWN The data does not exist
|
397
|
+
'-1001': AuthenticationError, # INVALID_SIGNATURE The api key or secret is in wrong format.
|
398
|
+
'-1002': AuthenticationError, # UNAUTHORIZED API key or secret is invalid, it may because key have insufficient permission or the key is expired/revoked.
|
399
|
+
'-1003': RateLimitExceeded, # TOO_MANY_REQUEST Rate limit exceed.
|
400
|
+
'-1004': BadRequest, # UNKNOWN_PARAM An unknown parameter was sent.
|
401
|
+
'-1005': BadRequest, # INVALID_PARAM Some parameters are in wrong format for api.
|
402
|
+
'-1006': InvalidOrder, # RESOURCE_NOT_FOUND The data is not found in server. For example, when client try canceling a CANCELLED order, will raise self error.
|
403
|
+
'-1007': BadRequest, # DUPLICATE_REQUEST The data is already exists or your request is duplicated.
|
404
|
+
'-1008': InvalidOrder, # QUANTITY_TOO_HIGH The quantity of settlement is too high than you can request.
|
405
|
+
'-1009': InsufficientFunds, # CAN_NOT_WITHDRAWAL Can not request withdrawal settlement, you need to deposit other arrears first.
|
406
|
+
'-1011': NetworkError, # RPC_NOT_CONNECT Can not place/cancel orders, it may because internal network error. Please try again in a few seconds.
|
407
|
+
'-1012': BadRequest, # RPC_REJECT The place/cancel order request is rejected by internal module, it may because the account is in liquidation or other internal errors. Please try again in a few seconds.
|
408
|
+
'-1101': InsufficientFunds, # RISK_TOO_HIGH The risk exposure for client is too high, it may cause by sending too big order or the leverage is too low. please refer to client info to check the current exposure.
|
409
|
+
'-1102': InvalidOrder, # MIN_NOTIONAL The order value(price * size) is too small.
|
410
|
+
'-1103': InvalidOrder, # PRICE_FILTER The order price is not following the tick size rule for the symbol.
|
411
|
+
'-1104': InvalidOrder, # SIZE_FILTER The order quantity is not following the step size rule for the symbol.
|
412
|
+
'-1105': InvalidOrder, # PERCENTAGE_FILTER Price is X% too high or X% too low from the mid price.
|
413
|
+
'-1201': BadRequest, # LIQUIDATION_REQUEST_RATIO_TOO_SMALL total notional < 10000, least req ratio should = 1
|
414
|
+
'-1202': BadRequest, # LIQUIDATION_STATUS_ERROR No need to liquidation because user margin is enough.
|
415
|
+
'29': BadRequest, # {"success":false,"code":29,"message":"Verify contract is invalid"}
|
416
|
+
'9': AuthenticationError, # {"success":false,"code":9,"message":"Address and signature do not match"}
|
417
|
+
'3': AuthenticationError, # {"success":false,"code":3,"message":"Signature error"}
|
418
|
+
'2': BadRequest, # {"success":false,"code":2,"message":"Timestamp expired"}
|
419
|
+
'15': BadRequest, # {"success":false,"code":15,"message":"BrokerId is not exist"}
|
420
|
+
},
|
421
|
+
'broad': {
|
422
|
+
},
|
423
|
+
},
|
424
|
+
'precisionMode': TICK_SIZE,
|
425
|
+
})
|
426
|
+
|
427
|
+
def set_sandbox_mode(self, enable: bool):
|
428
|
+
super(modetrade, self).set_sandbox_mode(enable)
|
429
|
+
self.options['sandboxMode'] = enable
|
430
|
+
|
431
|
+
async def fetch_status(self, params={}):
|
432
|
+
"""
|
433
|
+
the latest known information on the availability of the exchange API
|
434
|
+
|
435
|
+
https://orderly.network/docs/build-on-evm/evm-api/restful-api/public/get-system-maintenance-status
|
436
|
+
|
437
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
438
|
+
:returns dict: a `status structure <https://docs.ccxt.com/#/?id=exchange-status-structure>`
|
439
|
+
"""
|
440
|
+
response = await self.v1PublicGetPublicSystemInfo(params)
|
441
|
+
#
|
442
|
+
# {
|
443
|
+
# "success": True,
|
444
|
+
# "data": {
|
445
|
+
# "status": 0,
|
446
|
+
# "msg": "System is functioning properly."
|
447
|
+
# },
|
448
|
+
# "timestamp": "1709274106602"
|
449
|
+
# }
|
450
|
+
#
|
451
|
+
data = self.safe_dict(response, 'data', {})
|
452
|
+
status = self.safe_string(data, 'status')
|
453
|
+
if status is None:
|
454
|
+
status = 'error'
|
455
|
+
elif status == '0':
|
456
|
+
status = 'ok'
|
457
|
+
else:
|
458
|
+
status = 'maintenance'
|
459
|
+
return {
|
460
|
+
'status': status,
|
461
|
+
'updated': None,
|
462
|
+
'eta': None,
|
463
|
+
'url': None,
|
464
|
+
'info': response,
|
465
|
+
}
|
466
|
+
|
467
|
+
async def fetch_time(self, params={}) -> Int:
|
468
|
+
"""
|
469
|
+
fetches the current integer timestamp in milliseconds from the exchange server
|
470
|
+
|
471
|
+
https://orderly.network/docs/build-on-evm/evm-api/restful-api/public/get-system-maintenance-status
|
472
|
+
|
473
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
474
|
+
:returns int: the current integer timestamp in milliseconds from the exchange server
|
475
|
+
"""
|
476
|
+
response = await self.v1PublicGetPublicSystemInfo(params)
|
477
|
+
#
|
478
|
+
# {
|
479
|
+
# "success": True,
|
480
|
+
# "data": {
|
481
|
+
# "status": 0,
|
482
|
+
# "msg": "System is functioning properly."
|
483
|
+
# },
|
484
|
+
# "timestamp": "1709274106602"
|
485
|
+
# }
|
486
|
+
#
|
487
|
+
return self.safe_integer(response, 'timestamp')
|
488
|
+
|
489
|
+
def parse_market(self, market: dict) -> Market:
|
490
|
+
#
|
491
|
+
# {
|
492
|
+
# "symbol": "PERP_BTC_USDC",
|
493
|
+
# "quote_min": 123,
|
494
|
+
# "quote_max": 100000,
|
495
|
+
# "quote_tick": 0.1,
|
496
|
+
# "base_min": 0.00001,
|
497
|
+
# "base_max": 20,
|
498
|
+
# "base_tick": 0.00001,
|
499
|
+
# "min_notional": 1,
|
500
|
+
# "price_range": 0.02,
|
501
|
+
# "price_scope": 0.4,
|
502
|
+
# "std_liquidation_fee": 0.03,
|
503
|
+
# "liquidator_fee": 0.015,
|
504
|
+
# "claim_insurance_fund_discount": 0.0075,
|
505
|
+
# "funding_period": 8,
|
506
|
+
# "cap_funding": 0.000375,
|
507
|
+
# "floor_funding": -0.000375,
|
508
|
+
# "interest_rate": 0.0001,
|
509
|
+
# "created_time": 1684140107326,
|
510
|
+
# "updated_time": 1685345968053,
|
511
|
+
# "base_mmr": 0.05,
|
512
|
+
# "base_imr": 0.1,
|
513
|
+
# "imr_factor": 0.0002512,
|
514
|
+
# "liquidation_tier": "1"
|
515
|
+
# }
|
516
|
+
#
|
517
|
+
marketId = self.safe_string(market, 'symbol')
|
518
|
+
parts = marketId.split('_')
|
519
|
+
marketType = 'swap'
|
520
|
+
baseId = self.safe_string(parts, 1)
|
521
|
+
quoteId = self.safe_string(parts, 2)
|
522
|
+
base = self.safe_currency_code(baseId)
|
523
|
+
quote = self.safe_currency_code(quoteId)
|
524
|
+
settleId: Str = self.safe_string(parts, 2)
|
525
|
+
settle: Str = self.safe_currency_code(settleId)
|
526
|
+
symbol = base + '/' + quote + ':' + settle
|
527
|
+
return {
|
528
|
+
'id': marketId,
|
529
|
+
'symbol': symbol,
|
530
|
+
'base': base,
|
531
|
+
'quote': quote,
|
532
|
+
'settle': settle,
|
533
|
+
'baseId': baseId,
|
534
|
+
'quoteId': quoteId,
|
535
|
+
'settleId': settleId,
|
536
|
+
'type': marketType,
|
537
|
+
'spot': False,
|
538
|
+
'margin': False,
|
539
|
+
'swap': True,
|
540
|
+
'future': False,
|
541
|
+
'option': False,
|
542
|
+
'active': None,
|
543
|
+
'contract': True,
|
544
|
+
'linear': True,
|
545
|
+
'inverse': False,
|
546
|
+
'contractSize': self.parse_number('1'),
|
547
|
+
'expiry': None,
|
548
|
+
'expiryDatetime': None,
|
549
|
+
'strike': None,
|
550
|
+
'optionType': None,
|
551
|
+
'precision': {
|
552
|
+
'amount': self.safe_number(market, 'base_tick'),
|
553
|
+
'price': self.safe_number(market, 'quote_tick'),
|
554
|
+
},
|
555
|
+
'limits': {
|
556
|
+
'leverage': {
|
557
|
+
'min': None,
|
558
|
+
'max': None,
|
559
|
+
},
|
560
|
+
'amount': {
|
561
|
+
'min': self.safe_number(market, 'base_min'),
|
562
|
+
'max': self.safe_number(market, 'base_max'),
|
563
|
+
},
|
564
|
+
'price': {
|
565
|
+
'min': self.safe_number(market, 'quote_min'),
|
566
|
+
'max': self.safe_number(market, 'quote_max'),
|
567
|
+
},
|
568
|
+
'cost': {
|
569
|
+
'min': self.safe_number(market, 'min_notional'),
|
570
|
+
'max': None,
|
571
|
+
},
|
572
|
+
},
|
573
|
+
'created': self.safe_integer(market, 'created_time'),
|
574
|
+
'info': market,
|
575
|
+
}
|
576
|
+
|
577
|
+
async def fetch_markets(self, params={}) -> List[Market]:
|
578
|
+
"""
|
579
|
+
retrieves data on all markets for modetrade
|
580
|
+
|
581
|
+
https://orderly.network/docs/build-on-evm/evm-api/restful-api/public/get-available-symbols
|
582
|
+
|
583
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
584
|
+
:returns dict[]: an array of objects representing market data
|
585
|
+
"""
|
586
|
+
response = await self.v1PublicGetPublicInfo(params)
|
587
|
+
#
|
588
|
+
# {
|
589
|
+
# "success": True,
|
590
|
+
# "timestamp": 1702989203989,
|
591
|
+
# "data": {
|
592
|
+
# "rows": [
|
593
|
+
# {
|
594
|
+
# "symbol": "PERP_BTC_USDC",
|
595
|
+
# "quote_min": 123,
|
596
|
+
# "quote_max": 100000,
|
597
|
+
# "quote_tick": 0.1,
|
598
|
+
# "base_min": 0.00001,
|
599
|
+
# "base_max": 20,
|
600
|
+
# "base_tick": 0.00001,
|
601
|
+
# "min_notional": 1,
|
602
|
+
# "price_range": 0.02,
|
603
|
+
# "price_scope": 0.4,
|
604
|
+
# "std_liquidation_fee": 0.03,
|
605
|
+
# "liquidator_fee": 0.015,
|
606
|
+
# "claim_insurance_fund_discount": 0.0075,
|
607
|
+
# "funding_period": 8,
|
608
|
+
# "cap_funding": 0.000375,
|
609
|
+
# "floor_funding": -0.000375,
|
610
|
+
# "interest_rate": 0.0001,
|
611
|
+
# "created_time": 1684140107326,
|
612
|
+
# "updated_time": 1685345968053,
|
613
|
+
# "base_mmr": 0.05,
|
614
|
+
# "base_imr": 0.1,
|
615
|
+
# "imr_factor": 0.0002512,
|
616
|
+
# "liquidation_tier": "1"
|
617
|
+
# }
|
618
|
+
# ]
|
619
|
+
# }
|
620
|
+
# }
|
621
|
+
#
|
622
|
+
data = self.safe_dict(response, 'data', {})
|
623
|
+
rows = self.safe_list(data, 'rows', [])
|
624
|
+
return self.parse_markets(rows)
|
625
|
+
|
626
|
+
async def fetch_currencies(self, params={}) -> Currencies:
|
627
|
+
"""
|
628
|
+
fetches all available currencies on an exchange
|
629
|
+
|
630
|
+
https://orderly.network/docs/build-on-evm/evm-api/restful-api/public/get-token-info
|
631
|
+
|
632
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
633
|
+
:returns dict: an associative dictionary of currencies
|
634
|
+
"""
|
635
|
+
result: dict = {}
|
636
|
+
response = await self.v1PublicGetPublicToken(params)
|
637
|
+
#
|
638
|
+
# {
|
639
|
+
# "success": True,
|
640
|
+
# "timestamp": 1702989203989,
|
641
|
+
# "data": {
|
642
|
+
# "rows": [{
|
643
|
+
# "token": "USDC",
|
644
|
+
# "decimals": 6,
|
645
|
+
# "minimum_withdraw_amount": 0.000001,
|
646
|
+
# "token_hash": "0xd6aca1be9729c13d677335161321649cccae6a591554772516700f986f942eaa",
|
647
|
+
# "chain_details": [{
|
648
|
+
# "chain_id": 43113,
|
649
|
+
# "contract_address": "0x5d64c9cfb0197775b4b3ad9be4d3c7976e0d8dc3",
|
650
|
+
# "cross_chain_withdrawal_fee": 123,
|
651
|
+
# "decimals": 6,
|
652
|
+
# "withdraw_fee": 2
|
653
|
+
# }]
|
654
|
+
# }
|
655
|
+
# ]
|
656
|
+
# }
|
657
|
+
# }
|
658
|
+
#
|
659
|
+
data = self.safe_dict(response, 'data', {})
|
660
|
+
tokenRows = self.safe_list(data, 'rows', [])
|
661
|
+
for i in range(0, len(tokenRows)):
|
662
|
+
token = tokenRows[i]
|
663
|
+
currencyId = self.safe_string(token, 'token')
|
664
|
+
networks = self.safe_list(token, 'chain_details')
|
665
|
+
code = self.safe_currency_code(currencyId)
|
666
|
+
minPrecision = None
|
667
|
+
resultingNetworks: dict = {}
|
668
|
+
for j in range(0, len(networks)):
|
669
|
+
network = networks[j]
|
670
|
+
# TODO: transform chain id to human readable name
|
671
|
+
networkId = self.safe_string(network, 'chain_id')
|
672
|
+
precision = self.parse_precision(self.safe_string(network, 'decimals'))
|
673
|
+
if precision is not None:
|
674
|
+
minPrecision = precision if (minPrecision is None) else Precise.string_min(precision, minPrecision)
|
675
|
+
resultingNetworks[networkId] = {
|
676
|
+
'id': networkId,
|
677
|
+
'network': networkId,
|
678
|
+
'limits': {
|
679
|
+
'withdraw': {
|
680
|
+
'min': None,
|
681
|
+
'max': None,
|
682
|
+
},
|
683
|
+
'deposit': {
|
684
|
+
'min': None,
|
685
|
+
'max': None,
|
686
|
+
},
|
687
|
+
},
|
688
|
+
'active': None,
|
689
|
+
'deposit': None,
|
690
|
+
'withdraw': None,
|
691
|
+
'fee': self.safe_number(network, 'withdrawal_fee'),
|
692
|
+
'precision': self.parse_number(precision),
|
693
|
+
'info': network,
|
694
|
+
}
|
695
|
+
result[code] = self.safe_currency_structure({
|
696
|
+
'id': currencyId,
|
697
|
+
'name': currencyId,
|
698
|
+
'code': code,
|
699
|
+
'precision': self.parse_number(minPrecision),
|
700
|
+
'active': None,
|
701
|
+
'fee': None,
|
702
|
+
'networks': resultingNetworks,
|
703
|
+
'deposit': None,
|
704
|
+
'withdraw': None,
|
705
|
+
'limits': {
|
706
|
+
'deposit': {
|
707
|
+
'min': None,
|
708
|
+
'max': None,
|
709
|
+
},
|
710
|
+
'withdraw': {
|
711
|
+
'min': self.safe_number(token, 'minimum_withdraw_amount'),
|
712
|
+
'max': None,
|
713
|
+
},
|
714
|
+
},
|
715
|
+
'info': token,
|
716
|
+
})
|
717
|
+
return result
|
718
|
+
|
719
|
+
def parse_token_and_fee_temp(self, item, feeTokenKey, feeAmountKey):
|
720
|
+
feeCost = self.safe_string(item, feeAmountKey)
|
721
|
+
fee = None
|
722
|
+
if feeCost is not None:
|
723
|
+
feeCurrencyId = self.safe_string(item, feeTokenKey)
|
724
|
+
feeCurrencyCode = self.safe_currency_code(feeCurrencyId)
|
725
|
+
fee = {
|
726
|
+
'cost': feeCost,
|
727
|
+
'currency': feeCurrencyCode,
|
728
|
+
}
|
729
|
+
return fee
|
730
|
+
|
731
|
+
def parse_trade(self, trade: dict, market: Market = None) -> Trade:
|
732
|
+
#
|
733
|
+
# public/market_trades
|
734
|
+
#
|
735
|
+
# {
|
736
|
+
# "symbol": "PERP_ETH_USDC",
|
737
|
+
# "side": "SELL",
|
738
|
+
# "executed_price": 46222.35,
|
739
|
+
# "executed_quantity": 0.0012,
|
740
|
+
# "executed_timestamp": "1683878609166"
|
741
|
+
# }
|
742
|
+
#
|
743
|
+
# fetchOrderTrades, fetchOrder
|
744
|
+
#
|
745
|
+
# {
|
746
|
+
# "id": "99119876",
|
747
|
+
# "symbol": "PERP_BTC_USDC",
|
748
|
+
# "fee": "0.0024",
|
749
|
+
# "side": "BUY",
|
750
|
+
# "executed_timestamp": "1641481113084",
|
751
|
+
# "order_id": "87001234",
|
752
|
+
# "order_tag": "default", <-- self param only in "fetchOrderTrades"
|
753
|
+
# "executed_price": "1",
|
754
|
+
# "executed_quantity": "12",
|
755
|
+
# "fee_asset": "BTC",
|
756
|
+
# "is_maker": "1"
|
757
|
+
# }
|
758
|
+
#
|
759
|
+
isFromFetchOrder = ('id' in trade)
|
760
|
+
timestamp = self.safe_integer(trade, 'executed_timestamp')
|
761
|
+
marketId = self.safe_string(trade, 'symbol')
|
762
|
+
market = self.safe_market(marketId, market)
|
763
|
+
symbol = market['symbol']
|
764
|
+
price = self.safe_string(trade, 'executed_price')
|
765
|
+
amount = self.safe_string(trade, 'executed_quantity')
|
766
|
+
order_id = self.safe_string(trade, 'order_id')
|
767
|
+
fee = self.parse_token_and_fee_temp(trade, 'fee_asset', 'fee')
|
768
|
+
feeCost = self.safe_string(fee, 'cost')
|
769
|
+
if feeCost is not None:
|
770
|
+
fee['cost'] = feeCost
|
771
|
+
cost = Precise.string_mul(price, amount)
|
772
|
+
side = self.safe_string_lower(trade, 'side')
|
773
|
+
id = self.safe_string(trade, 'id')
|
774
|
+
takerOrMaker: Str = None
|
775
|
+
if isFromFetchOrder:
|
776
|
+
isMaker = self.safe_string(trade, 'is_maker') == '1'
|
777
|
+
takerOrMaker = 'maker' if isMaker else 'taker'
|
778
|
+
return self.safe_trade({
|
779
|
+
'id': id,
|
780
|
+
'timestamp': timestamp,
|
781
|
+
'datetime': self.iso8601(timestamp),
|
782
|
+
'symbol': symbol,
|
783
|
+
'side': side,
|
784
|
+
'price': price,
|
785
|
+
'amount': amount,
|
786
|
+
'cost': cost,
|
787
|
+
'order': order_id,
|
788
|
+
'takerOrMaker': takerOrMaker,
|
789
|
+
'type': None,
|
790
|
+
'fee': fee,
|
791
|
+
'info': trade,
|
792
|
+
}, market)
|
793
|
+
|
794
|
+
async def fetch_trades(self, symbol: str, since: Int = None, limit: Int = None, params={}) -> List[Trade]:
|
795
|
+
"""
|
796
|
+
get the list of most recent trades for a particular symbol
|
797
|
+
|
798
|
+
https://orderly.network/docs/build-on-evm/evm-api/restful-api/public/get-market-trades
|
799
|
+
|
800
|
+
:param str symbol: unified symbol of the market to fetch trades for
|
801
|
+
:param int [since]: timestamp in ms of the earliest trade to fetch
|
802
|
+
:param int [limit]: the maximum amount of trades to fetch
|
803
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
804
|
+
:returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
|
805
|
+
"""
|
806
|
+
await self.load_markets()
|
807
|
+
market = self.market(symbol)
|
808
|
+
request: dict = {
|
809
|
+
'symbol': market['id'],
|
810
|
+
}
|
811
|
+
if limit is not None:
|
812
|
+
request['limit'] = limit
|
813
|
+
response = await self.v1PublicGetPublicMarketTrades(self.extend(request, params))
|
814
|
+
#
|
815
|
+
# {
|
816
|
+
# "success": True,
|
817
|
+
# "timestamp": 1702989203989,
|
818
|
+
# "data": {
|
819
|
+
# "rows": [{
|
820
|
+
# "symbol": "PERP_ETH_USDC",
|
821
|
+
# "side": "BUY",
|
822
|
+
# "executed_price": 2050,
|
823
|
+
# "executed_quantity": 1,
|
824
|
+
# "executed_timestamp": 1683878609166
|
825
|
+
# }]
|
826
|
+
# }
|
827
|
+
# }
|
828
|
+
#
|
829
|
+
data = self.safe_dict(response, 'data', {})
|
830
|
+
rows = self.safe_list(data, 'rows', [])
|
831
|
+
return self.parse_trades(rows, market, since, limit)
|
832
|
+
|
833
|
+
def parse_funding_rate(self, fundingRate, market: Market = None) -> FundingRate:
|
834
|
+
#
|
835
|
+
# {
|
836
|
+
# "symbol":"PERP_AAVE_USDT",
|
837
|
+
# "est_funding_rate":-0.00003447,
|
838
|
+
# "est_funding_rate_timestamp":1653633959001,
|
839
|
+
# "last_funding_rate":-0.00002094,
|
840
|
+
# "last_funding_rate_timestamp":1653631200000,
|
841
|
+
# "next_funding_time":1653634800000,
|
842
|
+
# "sum_unitary_funding": 521.367
|
843
|
+
# }
|
844
|
+
#
|
845
|
+
symbol = self.safe_string(fundingRate, 'symbol')
|
846
|
+
market = self.market(symbol)
|
847
|
+
nextFundingTimestamp = self.safe_integer(fundingRate, 'next_funding_time')
|
848
|
+
estFundingRateTimestamp = self.safe_integer(fundingRate, 'est_funding_rate_timestamp')
|
849
|
+
lastFundingRateTimestamp = self.safe_integer(fundingRate, 'last_funding_rate_timestamp')
|
850
|
+
fundingTimeString = self.safe_string(fundingRate, 'last_funding_rate_timestamp')
|
851
|
+
nextFundingTimeString = self.safe_string(fundingRate, 'next_funding_time')
|
852
|
+
millisecondsInterval = Precise.string_sub(nextFundingTimeString, fundingTimeString)
|
853
|
+
return {
|
854
|
+
'info': fundingRate,
|
855
|
+
'symbol': market['symbol'],
|
856
|
+
'markPrice': None,
|
857
|
+
'indexPrice': None,
|
858
|
+
'interestRate': self.parse_number('0'),
|
859
|
+
'estimatedSettlePrice': None,
|
860
|
+
'timestamp': estFundingRateTimestamp,
|
861
|
+
'datetime': self.iso8601(estFundingRateTimestamp),
|
862
|
+
'fundingRate': self.safe_number(fundingRate, 'est_funding_rate'),
|
863
|
+
'fundingTimestamp': nextFundingTimestamp,
|
864
|
+
'fundingDatetime': self.iso8601(nextFundingTimestamp),
|
865
|
+
'nextFundingRate': None,
|
866
|
+
'nextFundingTimestamp': None,
|
867
|
+
'nextFundingDatetime': None,
|
868
|
+
'previousFundingRate': self.safe_number(fundingRate, 'last_funding_rate'),
|
869
|
+
'previousFundingTimestamp': lastFundingRateTimestamp,
|
870
|
+
'previousFundingDatetime': self.iso8601(lastFundingRateTimestamp),
|
871
|
+
'interval': self.parse_funding_interval(millisecondsInterval),
|
872
|
+
}
|
873
|
+
|
874
|
+
def parse_funding_interval(self, interval):
|
875
|
+
intervals: dict = {
|
876
|
+
'3600000': '1h',
|
877
|
+
'14400000': '4h',
|
878
|
+
'28800000': '8h',
|
879
|
+
'57600000': '16h',
|
880
|
+
'86400000': '24h',
|
881
|
+
}
|
882
|
+
return self.safe_string(intervals, interval, interval)
|
883
|
+
|
884
|
+
async def fetch_funding_interval(self, symbol: str, params={}) -> FundingRate:
|
885
|
+
"""
|
886
|
+
fetch the current funding rate interval
|
887
|
+
|
888
|
+
https://orderly.network/docs/build-on-evm/evm-api/restful-api/public/get-predicted-funding-rate-for-one-market
|
889
|
+
|
890
|
+
:param str symbol: unified market symbol
|
891
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
892
|
+
:returns dict: a `funding rate structure <https://docs.ccxt.com/#/?id=funding-rate-structure>`
|
893
|
+
"""
|
894
|
+
return await self.fetch_funding_rate(symbol, params)
|
895
|
+
|
896
|
+
async def fetch_funding_rate(self, symbol: str, params={}) -> FundingRate:
|
897
|
+
"""
|
898
|
+
fetch the current funding rate
|
899
|
+
|
900
|
+
https://orderly.network/docs/build-on-evm/evm-api/restful-api/public/get-predicted-funding-rate-for-one-market
|
901
|
+
|
902
|
+
:param str symbol: unified market symbol
|
903
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
904
|
+
:returns dict: a `funding rate structure <https://docs.ccxt.com/#/?id=funding-rate-structure>`
|
905
|
+
"""
|
906
|
+
await self.load_markets()
|
907
|
+
market = self.market(symbol)
|
908
|
+
request: dict = {
|
909
|
+
'symbol': market['id'],
|
910
|
+
}
|
911
|
+
response = await self.v1PublicGetPublicFundingRateSymbol(self.extend(request, params))
|
912
|
+
#
|
913
|
+
# {
|
914
|
+
# "success": True,
|
915
|
+
# "timestamp": 1702989203989,
|
916
|
+
# "data": {
|
917
|
+
# "symbol": "PERP_ETH_USDC",
|
918
|
+
# "est_funding_rate": 123,
|
919
|
+
# "est_funding_rate_timestamp": 1683880020000,
|
920
|
+
# "last_funding_rate": 0.0001,
|
921
|
+
# "last_funding_rate_timestamp": 1683878400000,
|
922
|
+
# "next_funding_time": 1683907200000,
|
923
|
+
# "sum_unitary_funding": 521.367
|
924
|
+
# }
|
925
|
+
# }
|
926
|
+
#
|
927
|
+
data = self.safe_dict(response, 'data', {})
|
928
|
+
return self.parse_funding_rate(data, market)
|
929
|
+
|
930
|
+
async def fetch_funding_rates(self, symbols: Strings = None, params={}) -> FundingRates:
|
931
|
+
"""
|
932
|
+
fetch the current funding rate for multiple markets
|
933
|
+
|
934
|
+
https://orderly.network/docs/build-on-evm/evm-api/restful-api/public/get-predicted-funding-rates-for-all-markets
|
935
|
+
|
936
|
+
:param str[] symbols: unified market symbols
|
937
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
938
|
+
:returns dict[]: an array of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-structure>`
|
939
|
+
"""
|
940
|
+
await self.load_markets()
|
941
|
+
symbols = self.market_symbols(symbols)
|
942
|
+
response = await self.v1PublicGetPublicFundingRates(params)
|
943
|
+
#
|
944
|
+
# {
|
945
|
+
# "success": True,
|
946
|
+
# "timestamp": 1702989203989,
|
947
|
+
# "data": {
|
948
|
+
# "rows": [{
|
949
|
+
# "symbol": "PERP_ETH_USDC",
|
950
|
+
# "est_funding_rate": 123,
|
951
|
+
# "est_funding_rate_timestamp": 1683880020000,
|
952
|
+
# "last_funding_rate": 0.0001,
|
953
|
+
# "last_funding_rate_timestamp": 1683878400000,
|
954
|
+
# "next_funding_time": 1683907200000,
|
955
|
+
# "sum_unitary_funding": 521.367
|
956
|
+
# }]
|
957
|
+
# }
|
958
|
+
# }
|
959
|
+
#
|
960
|
+
data = self.safe_dict(response, 'data', {})
|
961
|
+
rows = self.safe_list(data, 'rows', [])
|
962
|
+
return self.parse_funding_rates(rows, symbols)
|
963
|
+
|
964
|
+
async def fetch_funding_rate_history(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}):
|
965
|
+
"""
|
966
|
+
fetches historical funding rate prices
|
967
|
+
|
968
|
+
https://orderly.network/docs/build-on-evm/evm-api/restful-api/public/get-funding-rate-history-for-one-market
|
969
|
+
|
970
|
+
:param str symbol: unified symbol of the market to fetch the funding rate history for
|
971
|
+
:param int [since]: timestamp in ms of the earliest funding rate to fetch
|
972
|
+
:param int [limit]: the maximum amount of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-history-structure>` to fetch
|
973
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
974
|
+
:param int [params.until]: timestamp in ms of the latest funding rate
|
975
|
+
:param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
|
976
|
+
:returns dict[]: a list of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-history-structure>`
|
977
|
+
"""
|
978
|
+
await self.load_markets()
|
979
|
+
paginate = False
|
980
|
+
paginate, params = self.handle_option_and_params(params, 'fetchFundingRateHistory', 'paginate')
|
981
|
+
if paginate:
|
982
|
+
return await self.fetch_paginated_call_incremental('fetchFundingRateHistory', symbol, since, limit, params, 'page', 25)
|
983
|
+
request: dict = {}
|
984
|
+
if symbol is not None:
|
985
|
+
market = self.market(symbol)
|
986
|
+
symbol = market['symbol']
|
987
|
+
request['symbol'] = market['id']
|
988
|
+
if since is not None:
|
989
|
+
request['start_t'] = since
|
990
|
+
request, params = self.handle_until_option('end_t', request, params, 0.001)
|
991
|
+
response = await self.v1PublicGetPublicFundingRateHistory(self.extend(request, params))
|
992
|
+
#
|
993
|
+
# {
|
994
|
+
# "success": True,
|
995
|
+
# "timestamp": 1702989203989,
|
996
|
+
# "data": {
|
997
|
+
# "rows": [{
|
998
|
+
# "symbol": "PERP_ETH_USDC",
|
999
|
+
# "funding_rate": 0.0001,
|
1000
|
+
# "funding_rate_timestamp": 1684224000000,
|
1001
|
+
# "next_funding_time": 1684252800000
|
1002
|
+
# }],
|
1003
|
+
# "meta": {
|
1004
|
+
# "total": 9,
|
1005
|
+
# "records_per_page": 25,
|
1006
|
+
# "current_page": 1
|
1007
|
+
# }
|
1008
|
+
# }
|
1009
|
+
# }
|
1010
|
+
#
|
1011
|
+
data = self.safe_dict(response, 'data', {})
|
1012
|
+
result = self.safe_list(data, 'rows', [])
|
1013
|
+
rates = []
|
1014
|
+
for i in range(0, len(result)):
|
1015
|
+
entry = result[i]
|
1016
|
+
marketId = self.safe_string(entry, 'symbol')
|
1017
|
+
timestamp = self.safe_integer(entry, 'funding_rate_timestamp')
|
1018
|
+
rates.append({
|
1019
|
+
'info': entry,
|
1020
|
+
'symbol': self.safe_symbol(marketId),
|
1021
|
+
'fundingRate': self.safe_number(entry, 'funding_rate'),
|
1022
|
+
'timestamp': timestamp,
|
1023
|
+
'datetime': self.iso8601(timestamp),
|
1024
|
+
})
|
1025
|
+
sorted = self.sort_by(rates, 'timestamp')
|
1026
|
+
return self.filter_by_symbol_since_limit(sorted, symbol, since, limit)
|
1027
|
+
|
1028
|
+
async def fetch_trading_fees(self, params={}) -> TradingFees:
|
1029
|
+
"""
|
1030
|
+
fetch the trading fees for multiple markets
|
1031
|
+
|
1032
|
+
https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-account-information
|
1033
|
+
|
1034
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
1035
|
+
:returns dict: a dictionary of `fee structures <https://docs.ccxt.com/#/?id=fee-structure>` indexed by market symbols
|
1036
|
+
"""
|
1037
|
+
await self.load_markets()
|
1038
|
+
response = await self.v1PrivateGetClientInfo(params)
|
1039
|
+
#
|
1040
|
+
# {
|
1041
|
+
# "success": True,
|
1042
|
+
# "timestamp": 1702989203989,
|
1043
|
+
# "data": {
|
1044
|
+
# "account_id": "<string>",
|
1045
|
+
# "email": "test@test.com",
|
1046
|
+
# "account_mode": "FUTURES",
|
1047
|
+
# "max_leverage": 20,
|
1048
|
+
# "taker_fee_rate": 123,
|
1049
|
+
# "maker_fee_rate": 123,
|
1050
|
+
# "futures_taker_fee_rate": 123,
|
1051
|
+
# "futures_maker_fee_rate": 123,
|
1052
|
+
# "maintenance_cancel_orders": True,
|
1053
|
+
# "imr_factor": {
|
1054
|
+
# "PERP_BTC_USDC": 123,
|
1055
|
+
# "PERP_ETH_USDC": 123,
|
1056
|
+
# "PERP_NEAR_USDC": 123
|
1057
|
+
# },
|
1058
|
+
# "max_notional": {
|
1059
|
+
# "PERP_BTC_USDC": 123,
|
1060
|
+
# "PERP_ETH_USDC": 123,
|
1061
|
+
# "PERP_NEAR_USDC": 123
|
1062
|
+
# }
|
1063
|
+
# }
|
1064
|
+
# }
|
1065
|
+
#
|
1066
|
+
data = self.safe_dict(response, 'data', {})
|
1067
|
+
maker = self.safe_string(data, 'futures_maker_fee_rate')
|
1068
|
+
taker = self.safe_string(data, 'futures_taker_fee_rate')
|
1069
|
+
result: dict = {}
|
1070
|
+
for i in range(0, len(self.symbols)):
|
1071
|
+
symbol = self.symbols[i]
|
1072
|
+
result[symbol] = {
|
1073
|
+
'info': response,
|
1074
|
+
'symbol': symbol,
|
1075
|
+
'maker': self.parse_number(Precise.string_div(maker, '10000')),
|
1076
|
+
'taker': self.parse_number(Precise.string_div(taker, '10000')),
|
1077
|
+
'percentage': True,
|
1078
|
+
'tierBased': True,
|
1079
|
+
}
|
1080
|
+
return result
|
1081
|
+
|
1082
|
+
async def fetch_order_book(self, symbol: str, limit: Int = None, params={}) -> OrderBook:
|
1083
|
+
"""
|
1084
|
+
fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
|
1085
|
+
|
1086
|
+
https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/orderbook-snapshot
|
1087
|
+
|
1088
|
+
:param str symbol: unified symbol of the market to fetch the order book for
|
1089
|
+
:param int [limit]: the maximum amount of order book entries to return
|
1090
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
1091
|
+
:returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
|
1092
|
+
"""
|
1093
|
+
await self.load_markets()
|
1094
|
+
market = self.market(symbol)
|
1095
|
+
request: dict = {
|
1096
|
+
'symbol': market['id'],
|
1097
|
+
}
|
1098
|
+
if limit is not None:
|
1099
|
+
limit = min(limit, 1000)
|
1100
|
+
request['max_level'] = limit
|
1101
|
+
response = await self.v1PrivateGetOrderbookSymbol(self.extend(request, params))
|
1102
|
+
#
|
1103
|
+
# {
|
1104
|
+
# "success": True,
|
1105
|
+
# "timestamp": 1702989203989,
|
1106
|
+
# "data": {
|
1107
|
+
# "asks": [{
|
1108
|
+
# "price": 10669.4,
|
1109
|
+
# "quantity": 1.56263218
|
1110
|
+
# }],
|
1111
|
+
# "bids": [{
|
1112
|
+
# "price": 10669.4,
|
1113
|
+
# "quantity": 1.56263218
|
1114
|
+
# }],
|
1115
|
+
# "timestamp": 123
|
1116
|
+
# }
|
1117
|
+
# }
|
1118
|
+
#
|
1119
|
+
data = self.safe_dict(response, 'data', {})
|
1120
|
+
timestamp = self.safe_integer(data, 'timestamp')
|
1121
|
+
return self.parse_order_book(data, symbol, timestamp, 'bids', 'asks', 'price', 'quantity')
|
1122
|
+
|
1123
|
+
def parse_ohlcv(self, ohlcv, market: Market = None) -> list:
|
1124
|
+
return [
|
1125
|
+
self.safe_integer(ohlcv, 'start_timestamp'),
|
1126
|
+
self.safe_number(ohlcv, 'open'),
|
1127
|
+
self.safe_number(ohlcv, 'high'),
|
1128
|
+
self.safe_number(ohlcv, 'low'),
|
1129
|
+
self.safe_number(ohlcv, 'close'),
|
1130
|
+
self.safe_number(ohlcv, 'volume'),
|
1131
|
+
]
|
1132
|
+
|
1133
|
+
async def fetch_ohlcv(self, symbol: str, timeframe='1m', since: Int = None, limit: Int = None, params={}) -> List[list]:
|
1134
|
+
"""
|
1135
|
+
|
1136
|
+
https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-kline
|
1137
|
+
|
1138
|
+
fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
|
1139
|
+
:param str symbol: unified symbol of the market to fetch OHLCV data for
|
1140
|
+
:param str timeframe: the length of time each candle represents
|
1141
|
+
:param int [since]: timestamp in ms of the earliest candle to fetch
|
1142
|
+
:param int [limit]: max=1000, max=100 when since is defined and is less than(now - (999 * (timeframe in ms)))
|
1143
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
1144
|
+
:returns int[][]: A list of candles ordered, open, high, low, close, volume
|
1145
|
+
"""
|
1146
|
+
await self.load_markets()
|
1147
|
+
market = self.market(symbol)
|
1148
|
+
request: dict = {
|
1149
|
+
'symbol': market['id'],
|
1150
|
+
'type': self.safe_string(self.timeframes, timeframe, timeframe),
|
1151
|
+
}
|
1152
|
+
if limit is not None:
|
1153
|
+
request['limit'] = min(limit, 1000)
|
1154
|
+
response = await self.v1PrivateGetKline(self.extend(request, params))
|
1155
|
+
data = self.safe_dict(response, 'data', {})
|
1156
|
+
#
|
1157
|
+
# {
|
1158
|
+
# "success": True,
|
1159
|
+
# "timestamp": 1702989203989,
|
1160
|
+
# "data": {
|
1161
|
+
# "rows": [{
|
1162
|
+
# "open": 66166.23,
|
1163
|
+
# "close": 66124.56,
|
1164
|
+
# "low": 66038.06,
|
1165
|
+
# "high": 66176.97,
|
1166
|
+
# "volume": 23.45528526,
|
1167
|
+
# "amount": 1550436.21725288,
|
1168
|
+
# "symbol": "PERP_BTC_USDC",
|
1169
|
+
# "type": "1m",
|
1170
|
+
# "start_timestamp": 1636388220000,
|
1171
|
+
# "end_timestamp": 1636388280000
|
1172
|
+
# }]
|
1173
|
+
# }
|
1174
|
+
# }
|
1175
|
+
#
|
1176
|
+
rows = self.safe_list(data, 'rows', [])
|
1177
|
+
return self.parse_ohlcvs(rows, market, timeframe, since, limit)
|
1178
|
+
|
1179
|
+
def parse_order(self, order: dict, market: Market = None) -> Order:
|
1180
|
+
#
|
1181
|
+
# Possible input functions:
|
1182
|
+
# * createOrder
|
1183
|
+
# * createOrders
|
1184
|
+
# * cancelOrder
|
1185
|
+
# * fetchOrder
|
1186
|
+
# * fetchOrders
|
1187
|
+
# isFromFetchOrder = ('order_tag' in order); TO_DO
|
1188
|
+
#
|
1189
|
+
# stop order after creating it:
|
1190
|
+
# {
|
1191
|
+
# "orderId": "1578938",
|
1192
|
+
# "clientOrderId": "0",
|
1193
|
+
# "algoType": "STOP_LOSS",
|
1194
|
+
# "quantity": "0.1"
|
1195
|
+
# }
|
1196
|
+
# stop order after fetching it:
|
1197
|
+
# {
|
1198
|
+
# "algoOrderId": "1578958",
|
1199
|
+
# "clientOrderId": "0",
|
1200
|
+
# "rootAlgoOrderId": "1578958",
|
1201
|
+
# "parentAlgoOrderId": "0",
|
1202
|
+
# "symbol": "SPOT_LTC_USDT",
|
1203
|
+
# "orderTag": "default",
|
1204
|
+
# "algoType": "STOP_LOSS",
|
1205
|
+
# "side": "BUY",
|
1206
|
+
# "quantity": "0.1",
|
1207
|
+
# "isTriggered": False,
|
1208
|
+
# "triggerPrice": "100",
|
1209
|
+
# "triggerStatus": "USELESS",
|
1210
|
+
# "type": "LIMIT",
|
1211
|
+
# "rootAlgoStatus": "CANCELLED",
|
1212
|
+
# "algoStatus": "CANCELLED",
|
1213
|
+
# "triggerPriceType": "MARKET_PRICE",
|
1214
|
+
# "price": "75",
|
1215
|
+
# "triggerTime": "0",
|
1216
|
+
# "totalExecutedQuantity": "0",
|
1217
|
+
# "averageExecutedPrice": "0",
|
1218
|
+
# "totalFee": "0",
|
1219
|
+
# "feeAsset": '',
|
1220
|
+
# "reduceOnly": False,
|
1221
|
+
# "createdTime": "1686149609.744",
|
1222
|
+
# "updatedTime": "1686149903.362"
|
1223
|
+
# }
|
1224
|
+
#
|
1225
|
+
timestamp = self.safe_integer_n(order, ['timestamp', 'created_time', 'createdTime'])
|
1226
|
+
orderId = self.safe_string_n(order, ['order_id', 'orderId', 'algoOrderId'])
|
1227
|
+
clientOrderId = self.omit_zero(self.safe_string_2(order, 'client_order_id', 'clientOrderId')) # Somehow, self always returns 0 for limit order
|
1228
|
+
marketId = self.safe_string(order, 'symbol')
|
1229
|
+
market = self.safe_market(marketId, market)
|
1230
|
+
symbol = market['symbol']
|
1231
|
+
price = self.safe_string_2(order, 'order_price', 'price')
|
1232
|
+
amount = self.safe_string_2(order, 'order_quantity', 'quantity') # This is base amount
|
1233
|
+
cost = self.safe_string_2(order, 'order_amount', 'amount') # This is quote amount
|
1234
|
+
orderType = self.safe_string_lower_2(order, 'order_type', 'type')
|
1235
|
+
status = self.safe_value_2(order, 'status', 'algoStatus')
|
1236
|
+
success = self.safe_bool(order, 'success')
|
1237
|
+
if success is not None:
|
1238
|
+
status = 'NEW' if (success) else 'REJECTED'
|
1239
|
+
side = self.safe_string_lower(order, 'side')
|
1240
|
+
filled = self.omit_zero(self.safe_value_2(order, 'executed', 'totalExecutedQuantity'))
|
1241
|
+
average = self.omit_zero(self.safe_string_2(order, 'average_executed_price', 'averageExecutedPrice'))
|
1242
|
+
remaining = Precise.string_sub(cost, filled)
|
1243
|
+
fee = self.safe_value_2(order, 'total_fee', 'totalFee')
|
1244
|
+
feeCurrency = self.safe_string_2(order, 'fee_asset', 'feeAsset')
|
1245
|
+
transactions = self.safe_value(order, 'Transactions')
|
1246
|
+
triggerPrice = self.safe_number(order, 'triggerPrice')
|
1247
|
+
takeProfitPrice: Num = None
|
1248
|
+
stopLossPrice: Num = None
|
1249
|
+
childOrders = self.safe_value(order, 'childOrders')
|
1250
|
+
if childOrders is not None:
|
1251
|
+
first = self.safe_value(childOrders, 0)
|
1252
|
+
innerChildOrders = self.safe_value(first, 'childOrders', [])
|
1253
|
+
innerChildOrdersLength = len(innerChildOrders)
|
1254
|
+
if innerChildOrdersLength > 0:
|
1255
|
+
takeProfitOrder = self.safe_value(innerChildOrders, 0)
|
1256
|
+
stopLossOrder = self.safe_value(innerChildOrders, 1)
|
1257
|
+
takeProfitPrice = self.safe_number(takeProfitOrder, 'triggerPrice')
|
1258
|
+
stopLossPrice = self.safe_number(stopLossOrder, 'triggerPrice')
|
1259
|
+
lastUpdateTimestamp = self.safe_integer_2(order, 'updatedTime', 'updated_time')
|
1260
|
+
return self.safe_order({
|
1261
|
+
'id': orderId,
|
1262
|
+
'clientOrderId': clientOrderId,
|
1263
|
+
'timestamp': timestamp,
|
1264
|
+
'datetime': self.iso8601(timestamp),
|
1265
|
+
'lastTradeTimestamp': None,
|
1266
|
+
'lastUpdateTimestamp': lastUpdateTimestamp,
|
1267
|
+
'status': self.parse_order_status(status),
|
1268
|
+
'symbol': symbol,
|
1269
|
+
'type': self.parse_order_type(orderType),
|
1270
|
+
'timeInForce': self.parse_time_in_force(orderType),
|
1271
|
+
'postOnly': None, # TO_DO
|
1272
|
+
'reduceOnly': self.safe_bool(order, 'reduce_only'),
|
1273
|
+
'side': side,
|
1274
|
+
'price': price,
|
1275
|
+
'triggerPrice': triggerPrice,
|
1276
|
+
'takeProfitPrice': takeProfitPrice,
|
1277
|
+
'stopLossPrice': stopLossPrice,
|
1278
|
+
'average': average,
|
1279
|
+
'amount': amount,
|
1280
|
+
'filled': filled,
|
1281
|
+
'remaining': remaining, # TO_DO
|
1282
|
+
'cost': cost,
|
1283
|
+
'trades': transactions,
|
1284
|
+
'fee': {
|
1285
|
+
'cost': fee,
|
1286
|
+
'currency': feeCurrency,
|
1287
|
+
},
|
1288
|
+
'info': order,
|
1289
|
+
}, market)
|
1290
|
+
|
1291
|
+
def parse_time_in_force(self, timeInForce: Str):
|
1292
|
+
timeInForces: dict = {
|
1293
|
+
'ioc': 'IOC',
|
1294
|
+
'fok': 'FOK',
|
1295
|
+
'post_only': 'PO',
|
1296
|
+
}
|
1297
|
+
return self.safe_string(timeInForces, timeInForce, None)
|
1298
|
+
|
1299
|
+
def parse_order_status(self, status: Str):
|
1300
|
+
if status is not None:
|
1301
|
+
statuses: dict = {
|
1302
|
+
'NEW': 'open',
|
1303
|
+
'FILLED': 'closed',
|
1304
|
+
'CANCEL_SENT': 'canceled',
|
1305
|
+
'CANCEL_ALL_SENT': 'canceled',
|
1306
|
+
'CANCELLED': 'canceled',
|
1307
|
+
'PARTIAL_FILLED': 'open',
|
1308
|
+
'REJECTED': 'rejected',
|
1309
|
+
'INCOMPLETE': 'open',
|
1310
|
+
'COMPLETED': 'closed',
|
1311
|
+
}
|
1312
|
+
return self.safe_string(statuses, status, status)
|
1313
|
+
return status
|
1314
|
+
|
1315
|
+
def parse_order_type(self, type: Str):
|
1316
|
+
types: dict = {
|
1317
|
+
'LIMIT': 'limit',
|
1318
|
+
'MARKET': 'market',
|
1319
|
+
'POST_ONLY': 'limit',
|
1320
|
+
}
|
1321
|
+
return self.safe_string_lower(types, type, type)
|
1322
|
+
|
1323
|
+
def create_order_request(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={}):
|
1324
|
+
"""
|
1325
|
+
@ignore
|
1326
|
+
helper function to build the request
|
1327
|
+
:param str symbol: unified symbol of the market to create an order in
|
1328
|
+
:param str type: 'market' or 'limit'
|
1329
|
+
:param str side: 'buy' or 'sell'
|
1330
|
+
:param float amount: how much you want to trade in units of the base currency
|
1331
|
+
:param float [price]: the price that the order is to be fulfilled, in units of the quote currency, ignored in market orders
|
1332
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
1333
|
+
:returns dict: request to be sent to the exchange
|
1334
|
+
"""
|
1335
|
+
reduceOnly = self.safe_bool_2(params, 'reduceOnly', 'reduce_only')
|
1336
|
+
orderType = type.upper()
|
1337
|
+
market = self.market(symbol)
|
1338
|
+
orderSide = side.upper()
|
1339
|
+
request: dict = {
|
1340
|
+
'symbol': market['id'],
|
1341
|
+
'side': orderSide,
|
1342
|
+
}
|
1343
|
+
triggerPrice = self.safe_string_2(params, 'triggerPrice', 'stopPrice')
|
1344
|
+
stopLoss = self.safe_value(params, 'stopLoss')
|
1345
|
+
takeProfit = self.safe_value(params, 'takeProfit')
|
1346
|
+
algoType = self.safe_string(params, 'algoType')
|
1347
|
+
isConditional = triggerPrice is not None or stopLoss is not None or takeProfit is not None or (self.safe_value(params, 'childOrders') is not None)
|
1348
|
+
isMarket = orderType == 'MARKET'
|
1349
|
+
timeInForce = self.safe_string_lower(params, 'timeInForce')
|
1350
|
+
postOnly = self.is_post_only(isMarket, None, params)
|
1351
|
+
orderQtyKey = 'quantity' if isConditional else 'order_quantity'
|
1352
|
+
priceKey = 'price' if isConditional else 'order_price'
|
1353
|
+
typeKey = 'type' if isConditional else 'order_type'
|
1354
|
+
request[typeKey] = orderType # LIMIT/MARKET/IOC/FOK/POST_ONLY/ASK/BID
|
1355
|
+
if not isConditional:
|
1356
|
+
if postOnly:
|
1357
|
+
request['order_type'] = 'POST_ONLY'
|
1358
|
+
elif timeInForce == 'fok':
|
1359
|
+
request['order_type'] = 'FOK'
|
1360
|
+
elif timeInForce == 'ioc':
|
1361
|
+
request['order_type'] = 'IOC'
|
1362
|
+
if reduceOnly:
|
1363
|
+
request['reduce_only'] = reduceOnly
|
1364
|
+
if price is not None:
|
1365
|
+
request[priceKey] = self.price_to_precision(symbol, price)
|
1366
|
+
if isMarket and not isConditional:
|
1367
|
+
request[orderQtyKey] = self.amount_to_precision(symbol, amount)
|
1368
|
+
elif algoType != 'POSITIONAL_TP_SL':
|
1369
|
+
request[orderQtyKey] = self.amount_to_precision(symbol, amount)
|
1370
|
+
clientOrderId = self.safe_string_n(params, ['clOrdID', 'clientOrderId', 'client_order_id'])
|
1371
|
+
if clientOrderId is not None:
|
1372
|
+
request['client_order_id'] = clientOrderId
|
1373
|
+
if triggerPrice is not None:
|
1374
|
+
request['trigger_price'] = self.price_to_precision(symbol, triggerPrice)
|
1375
|
+
request['algo_type'] = 'STOP'
|
1376
|
+
elif (stopLoss is not None) or (takeProfit is not None):
|
1377
|
+
request['algo_type'] = 'TP_SL'
|
1378
|
+
outterOrder: dict = {
|
1379
|
+
'symbol': market['id'],
|
1380
|
+
'reduce_only': False,
|
1381
|
+
'algo_type': 'POSITIONAL_TP_SL',
|
1382
|
+
'child_orders': [],
|
1383
|
+
}
|
1384
|
+
childOrders = outterOrder['child_orders']
|
1385
|
+
closeSide = 'SELL' if (orderSide == 'BUY') else 'BUY'
|
1386
|
+
if stopLoss is not None:
|
1387
|
+
stopLossPrice = self.safe_number_2(stopLoss, 'triggerPrice', 'price', stopLoss)
|
1388
|
+
stopLossOrder: dict = {
|
1389
|
+
'side': closeSide,
|
1390
|
+
'algo_type': 'TP_SL',
|
1391
|
+
'trigger_price': self.price_to_precision(symbol, stopLossPrice),
|
1392
|
+
'type': 'LIMIT',
|
1393
|
+
'reduce_only': True,
|
1394
|
+
}
|
1395
|
+
childOrders.append(stopLossOrder)
|
1396
|
+
if takeProfit is not None:
|
1397
|
+
takeProfitPrice = self.safe_number_2(takeProfit, 'triggerPrice', 'price', takeProfit)
|
1398
|
+
takeProfitOrder: dict = {
|
1399
|
+
'side': closeSide,
|
1400
|
+
'algo_type': 'TP_SL',
|
1401
|
+
'trigger_price': self.price_to_precision(symbol, takeProfitPrice),
|
1402
|
+
'type': 'LIMIT',
|
1403
|
+
'reduce_only': True,
|
1404
|
+
}
|
1405
|
+
outterOrder.append(takeProfitOrder)
|
1406
|
+
request['child_orders'] = [outterOrder]
|
1407
|
+
params = self.omit(params, ['reduceOnly', 'reduce_only', 'clOrdID', 'clientOrderId', 'client_order_id', 'postOnly', 'timeInForce', 'stopPrice', 'triggerPrice', 'stopLoss', 'takeProfit'])
|
1408
|
+
return self.extend(request, params)
|
1409
|
+
|
1410
|
+
async def create_order(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={}):
|
1411
|
+
"""
|
1412
|
+
create a trade order
|
1413
|
+
|
1414
|
+
https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/create-order
|
1415
|
+
https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/create-algo-order
|
1416
|
+
|
1417
|
+
:param str symbol: unified symbol of the market to create an order in
|
1418
|
+
:param str type: 'market' or 'limit'
|
1419
|
+
:param str side: 'buy' or 'sell'
|
1420
|
+
:param float amount: how much of currency you want to trade in units of base currency
|
1421
|
+
:param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
|
1422
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
1423
|
+
:param float [params.triggerPrice]: The price a trigger order is triggered at
|
1424
|
+
:param dict [params.takeProfit]: *takeProfit object in params* containing the triggerPrice at which the attached take profit order will be triggered(perpetual swap markets only)
|
1425
|
+
:param float [params.takeProfit.triggerPrice]: take profit trigger price
|
1426
|
+
:param dict [params.stopLoss]: *stopLoss object in params* containing the triggerPrice at which the attached stop loss order will be triggered(perpetual swap markets only)
|
1427
|
+
:param float [params.stopLoss.triggerPrice]: stop loss trigger price
|
1428
|
+
:param float [params.algoType]: 'STOP'or 'TP_SL' or 'POSITIONAL_TP_SL'
|
1429
|
+
:param float [params.cost]: *spot market buy only* the quote quantity that can be used alternative for the amount
|
1430
|
+
:param str [params.clientOrderId]: a unique id for the order
|
1431
|
+
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
|
1432
|
+
"""
|
1433
|
+
await self.load_markets()
|
1434
|
+
market = self.market(symbol)
|
1435
|
+
request = self.create_order_request(symbol, type, side, amount, price, params)
|
1436
|
+
triggerPrice = self.safe_string_2(params, 'triggerPrice', 'stopPrice')
|
1437
|
+
stopLoss = self.safe_value(params, 'stopLoss')
|
1438
|
+
takeProfit = self.safe_value(params, 'takeProfit')
|
1439
|
+
isConditional = triggerPrice is not None or stopLoss is not None or takeProfit is not None or (self.safe_value(params, 'childOrders') is not None)
|
1440
|
+
response = None
|
1441
|
+
if isConditional:
|
1442
|
+
response = await self.v1PrivatePostAlgoOrder(request)
|
1443
|
+
#
|
1444
|
+
# {
|
1445
|
+
# "success": True,
|
1446
|
+
# "timestamp": 1702989203989,
|
1447
|
+
# "data": {
|
1448
|
+
# "order_id": 13,
|
1449
|
+
# "client_order_id": "testclientid",
|
1450
|
+
# "algo_type": "STOP",
|
1451
|
+
# "quantity": 100.12
|
1452
|
+
# }
|
1453
|
+
# }
|
1454
|
+
#
|
1455
|
+
else:
|
1456
|
+
response = await self.v1PrivatePostOrder(request)
|
1457
|
+
#
|
1458
|
+
# {
|
1459
|
+
# "success": True,
|
1460
|
+
# "timestamp": 1702989203989,
|
1461
|
+
# "data": {
|
1462
|
+
# "order_id": 13,
|
1463
|
+
# "client_order_id": "testclientid",
|
1464
|
+
# "order_type": "LIMIT",
|
1465
|
+
# "order_price": 100.12,
|
1466
|
+
# "order_quantity": 0.987654,
|
1467
|
+
# "order_amount": 0.8,
|
1468
|
+
# "error_message": "none"
|
1469
|
+
# }
|
1470
|
+
# }
|
1471
|
+
#
|
1472
|
+
data = self.safe_dict(response, 'data')
|
1473
|
+
data['timestamp'] = self.safe_integer(response, 'timestamp')
|
1474
|
+
order = self.parse_order(data, market)
|
1475
|
+
order['type'] = type
|
1476
|
+
return order
|
1477
|
+
|
1478
|
+
async def create_orders(self, orders: List[OrderRequest], params={}):
|
1479
|
+
"""
|
1480
|
+
*contract only* create a list of trade orders
|
1481
|
+
|
1482
|
+
https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/batch-create-order
|
1483
|
+
|
1484
|
+
:param Array orders: list of orders to create, each object should contain the parameters required by createOrder, namely symbol, type, side, amount, price and params
|
1485
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
1486
|
+
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
|
1487
|
+
"""
|
1488
|
+
await self.load_markets()
|
1489
|
+
ordersRequests = []
|
1490
|
+
for i in range(0, len(orders)):
|
1491
|
+
rawOrder = orders[i]
|
1492
|
+
marketId = self.safe_string(rawOrder, 'symbol')
|
1493
|
+
type = self.safe_string(rawOrder, 'type')
|
1494
|
+
side = self.safe_string(rawOrder, 'side')
|
1495
|
+
amount = self.safe_value(rawOrder, 'amount')
|
1496
|
+
price = self.safe_value(rawOrder, 'price')
|
1497
|
+
orderParams = self.safe_dict(rawOrder, 'params', {})
|
1498
|
+
triggerPrice = self.safe_string_2(orderParams, 'triggerPrice', 'stopPrice')
|
1499
|
+
stopLoss = self.safe_value(orderParams, 'stopLoss')
|
1500
|
+
takeProfit = self.safe_value(orderParams, 'takeProfit')
|
1501
|
+
isConditional = triggerPrice is not None or stopLoss is not None or takeProfit is not None or (self.safe_value(orderParams, 'childOrders') is not None)
|
1502
|
+
if isConditional:
|
1503
|
+
raise NotSupported(self.id + ' createOrders() only support non-stop order')
|
1504
|
+
orderRequest = self.create_order_request(marketId, type, side, amount, price, orderParams)
|
1505
|
+
ordersRequests.append(orderRequest)
|
1506
|
+
request: dict = {
|
1507
|
+
'orders': ordersRequests,
|
1508
|
+
}
|
1509
|
+
response = await self.v1PrivatePostBatchOrder(self.extend(request, params))
|
1510
|
+
#
|
1511
|
+
# {
|
1512
|
+
# "success": True,
|
1513
|
+
# "timestamp": 1702989203989,
|
1514
|
+
# "data": {
|
1515
|
+
# "rows": [{
|
1516
|
+
# "order_id": 13,
|
1517
|
+
# "client_order_id": "testclientid",
|
1518
|
+
# "order_type": "LIMIT",
|
1519
|
+
# "order_price": 100.12,
|
1520
|
+
# "order_quantity": 0.987654,
|
1521
|
+
# "order_amount": 0.8,
|
1522
|
+
# "error_message": "none"
|
1523
|
+
# }]
|
1524
|
+
# }
|
1525
|
+
# }
|
1526
|
+
#
|
1527
|
+
data = self.safe_dict(response, 'data', {})
|
1528
|
+
rows = self.safe_list(data, 'rows', [])
|
1529
|
+
return self.parse_orders(rows)
|
1530
|
+
|
1531
|
+
async def edit_order(self, id: str, symbol: str, type: OrderType, side: OrderSide, amount: Num = None, price: Num = None, params={}):
|
1532
|
+
"""
|
1533
|
+
edit a trade order
|
1534
|
+
|
1535
|
+
https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/edit-order
|
1536
|
+
https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/edit-algo-order
|
1537
|
+
|
1538
|
+
:param str id: order id
|
1539
|
+
:param str symbol: unified symbol of the market to create an order in
|
1540
|
+
:param str type: 'market' or 'limit'
|
1541
|
+
:param str side: 'buy' or 'sell'
|
1542
|
+
:param float amount: how much of currency you want to trade in units of base currency
|
1543
|
+
:param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
|
1544
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
1545
|
+
:param float [params.triggerPrice]: The price a trigger order is triggered at
|
1546
|
+
:param float [params.stopLossPrice]: price to trigger stop-loss orders
|
1547
|
+
:param float [params.takeProfitPrice]: price to trigger take-profit orders
|
1548
|
+
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
|
1549
|
+
"""
|
1550
|
+
await self.load_markets()
|
1551
|
+
market = self.market(symbol)
|
1552
|
+
request: dict = {
|
1553
|
+
'order_id': id,
|
1554
|
+
}
|
1555
|
+
triggerPrice = self.safe_string_n(params, ['triggerPrice', 'stopPrice', 'takeProfitPrice', 'stopLossPrice'])
|
1556
|
+
if triggerPrice is not None:
|
1557
|
+
request['triggerPrice'] = self.price_to_precision(symbol, triggerPrice)
|
1558
|
+
isConditional = (triggerPrice is not None) or (self.safe_value(params, 'childOrders') is not None)
|
1559
|
+
orderQtyKey = 'quantity' if isConditional else 'order_quantity'
|
1560
|
+
priceKey = 'price' if isConditional else 'order_price'
|
1561
|
+
if price is not None:
|
1562
|
+
request[priceKey] = self.price_to_precision(symbol, price)
|
1563
|
+
if amount is not None:
|
1564
|
+
request[orderQtyKey] = self.amount_to_precision(symbol, amount)
|
1565
|
+
params = self.omit(params, ['stopPrice', 'triggerPrice', 'takeProfitPrice', 'stopLossPrice', 'trailingTriggerPrice', 'trailingAmount', 'trailingPercent'])
|
1566
|
+
response = None
|
1567
|
+
if isConditional:
|
1568
|
+
response = await self.v1PrivatePutAlgoOrder(self.extend(request, params))
|
1569
|
+
else:
|
1570
|
+
request['symbol'] = market['id']
|
1571
|
+
request['side'] = side.upper()
|
1572
|
+
orderType = type.upper()
|
1573
|
+
timeInForce = self.safe_string_lower(params, 'timeInForce')
|
1574
|
+
isMarket = orderType == 'MARKET'
|
1575
|
+
postOnly = self.is_post_only(isMarket, None, params)
|
1576
|
+
if postOnly:
|
1577
|
+
request['order_type'] = 'POST_ONLY'
|
1578
|
+
elif timeInForce == 'fok':
|
1579
|
+
request['order_type'] = 'FOK'
|
1580
|
+
elif timeInForce == 'ioc':
|
1581
|
+
request['order_type'] = 'IOC'
|
1582
|
+
else:
|
1583
|
+
request['order_type'] = orderType
|
1584
|
+
clientOrderId = self.safe_string_n(params, ['clOrdID', 'clientOrderId', 'client_order_id'])
|
1585
|
+
params = self.omit(params, ['clOrdID', 'clientOrderId', 'client_order_id', 'postOnly', 'timeInForce'])
|
1586
|
+
if clientOrderId is not None:
|
1587
|
+
request['client_order_id'] = clientOrderId
|
1588
|
+
# request['side'] = side.upper()
|
1589
|
+
# request['symbol'] = market['id']
|
1590
|
+
response = await self.v1PrivatePutOrder(self.extend(request, params))
|
1591
|
+
#
|
1592
|
+
# {
|
1593
|
+
# "success": True,
|
1594
|
+
# "timestamp": 1702989203989,
|
1595
|
+
# "data": {
|
1596
|
+
# "status": "EDIT_SENT"
|
1597
|
+
# }
|
1598
|
+
# }
|
1599
|
+
#
|
1600
|
+
data = self.safe_dict(response, 'data', {})
|
1601
|
+
data['timestamp'] = self.safe_integer(response, 'timestamp')
|
1602
|
+
return self.parse_order(data, market)
|
1603
|
+
|
1604
|
+
async def cancel_order(self, id: str, symbol: Str = None, params={}):
|
1605
|
+
"""
|
1606
|
+
|
1607
|
+
https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/cancel-order
|
1608
|
+
https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/cancel-order-by-client_order_id
|
1609
|
+
https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/cancel-algo-order
|
1610
|
+
https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/cancel-algo-order-by-client_order_id
|
1611
|
+
|
1612
|
+
cancels an open order
|
1613
|
+
:param str id: order id
|
1614
|
+
:param str symbol: unified symbol of the market the order was made in
|
1615
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
1616
|
+
:param boolean [params.trigger]: whether the order is a stop/algo order
|
1617
|
+
:param str [params.clientOrderId]: a unique id for the order
|
1618
|
+
:returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
|
1619
|
+
"""
|
1620
|
+
trigger = self.safe_bool_2(params, 'stop', 'trigger', False)
|
1621
|
+
params = self.omit(params, ['stop', 'trigger'])
|
1622
|
+
if not trigger and (symbol is None):
|
1623
|
+
raise ArgumentsRequired(self.id + ' cancelOrder() requires a symbol argument')
|
1624
|
+
await self.load_markets()
|
1625
|
+
market: Market = None
|
1626
|
+
if symbol is not None:
|
1627
|
+
market = self.market(symbol)
|
1628
|
+
request: dict = {
|
1629
|
+
'symbol': market['id'],
|
1630
|
+
}
|
1631
|
+
clientOrderIdUnified = self.safe_string_2(params, 'clOrdID', 'clientOrderId')
|
1632
|
+
clientOrderIdExchangeSpecific = self.safe_string(params, 'client_order_id', clientOrderIdUnified)
|
1633
|
+
isByClientOrder = clientOrderIdExchangeSpecific is not None
|
1634
|
+
response = None
|
1635
|
+
if trigger:
|
1636
|
+
if isByClientOrder:
|
1637
|
+
request['client_order_id'] = clientOrderIdExchangeSpecific
|
1638
|
+
params = self.omit(params, ['clOrdID', 'clientOrderId', 'client_order_id'])
|
1639
|
+
response = await self.v1PrivateDeleteAlgoClientOrder(self.extend(request, params))
|
1640
|
+
else:
|
1641
|
+
request['order_id'] = id
|
1642
|
+
response = await self.v1PrivateDeleteAlgoOrder(self.extend(request, params))
|
1643
|
+
else:
|
1644
|
+
if isByClientOrder:
|
1645
|
+
request['client_order_id'] = clientOrderIdExchangeSpecific
|
1646
|
+
params = self.omit(params, ['clOrdID', 'clientOrderId', 'client_order_id'])
|
1647
|
+
response = await self.v1PrivateDeleteClientOrder(self.extend(request, params))
|
1648
|
+
else:
|
1649
|
+
request['order_id'] = id
|
1650
|
+
response = await self.v1PrivateDeleteOrder(self.extend(request, params))
|
1651
|
+
#
|
1652
|
+
# {
|
1653
|
+
# "success": True,
|
1654
|
+
# "timestamp": 1702989203989,
|
1655
|
+
# "data": {
|
1656
|
+
# "status": "CANCEL_SENT"
|
1657
|
+
# }
|
1658
|
+
# }
|
1659
|
+
#
|
1660
|
+
# {
|
1661
|
+
# "success": True,
|
1662
|
+
# "timestamp": 1702989203989,
|
1663
|
+
# "status": "CANCEL_SENT"
|
1664
|
+
# }
|
1665
|
+
#
|
1666
|
+
extendParams: dict = {'symbol': symbol}
|
1667
|
+
if isByClientOrder:
|
1668
|
+
extendParams['client_order_id'] = clientOrderIdExchangeSpecific
|
1669
|
+
else:
|
1670
|
+
extendParams['id'] = id
|
1671
|
+
if trigger:
|
1672
|
+
return self.extend(self.parse_order(response), extendParams)
|
1673
|
+
data = self.safe_dict(response, 'data', {})
|
1674
|
+
return self.extend(self.parse_order(data), extendParams)
|
1675
|
+
|
1676
|
+
async def cancel_orders(self, ids: List[str], symbol: Str = None, params={}):
|
1677
|
+
"""
|
1678
|
+
cancel multiple orders
|
1679
|
+
|
1680
|
+
https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/batch-cancel-orders
|
1681
|
+
https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/batch-cancel-orders-by-client_order_id
|
1682
|
+
|
1683
|
+
:param str[] ids: order ids
|
1684
|
+
:param str [symbol]: unified market symbol
|
1685
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
1686
|
+
:param str[] [params.client_order_ids]: max length 10 e.g. ["my_id_1","my_id_2"], encode the double quotes. No space after comma
|
1687
|
+
:returns dict: an list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
|
1688
|
+
"""
|
1689
|
+
await self.load_markets()
|
1690
|
+
clientOrderIds = self.safe_list_n(params, ['clOrdIDs', 'clientOrderIds', 'client_order_ids'])
|
1691
|
+
params = self.omit(params, ['clOrdIDs', 'clientOrderIds', 'client_order_ids'])
|
1692
|
+
request: dict = {}
|
1693
|
+
response = None
|
1694
|
+
if clientOrderIds:
|
1695
|
+
request['client_order_ids'] = ','.join(clientOrderIds)
|
1696
|
+
response = await self.v1PrivateDeleteClientBatchOrder(self.extend(request, params))
|
1697
|
+
else:
|
1698
|
+
request['order_ids'] = ','.join(ids)
|
1699
|
+
response = await self.v1PrivateDeleteBatchOrder(self.extend(request, params))
|
1700
|
+
#
|
1701
|
+
# {
|
1702
|
+
# "success": True,
|
1703
|
+
# "timestamp": 1702989203989,
|
1704
|
+
# "data": {
|
1705
|
+
# "status": "CANCEL_ALL_SENT"
|
1706
|
+
# }
|
1707
|
+
# }
|
1708
|
+
#
|
1709
|
+
return [self.safe_order({
|
1710
|
+
'info': response,
|
1711
|
+
})]
|
1712
|
+
|
1713
|
+
async def cancel_all_orders(self, symbol: Str = None, params={}):
|
1714
|
+
"""
|
1715
|
+
|
1716
|
+
https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/cancel-all-pending-algo-orders
|
1717
|
+
https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/cancel-orders-in-bulk
|
1718
|
+
|
1719
|
+
cancel all open orders in a market
|
1720
|
+
:param str symbol: unified market symbol
|
1721
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
1722
|
+
:param boolean [params.trigger]: whether the order is a stop/algo order
|
1723
|
+
:returns dict: an list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
|
1724
|
+
"""
|
1725
|
+
await self.load_markets()
|
1726
|
+
trigger = self.safe_bool_2(params, 'stop', 'trigger')
|
1727
|
+
params = self.omit(params, ['stop', 'trigger'])
|
1728
|
+
request: dict = {}
|
1729
|
+
if symbol is not None:
|
1730
|
+
market = self.market(symbol)
|
1731
|
+
request['symbol'] = market['id']
|
1732
|
+
response = None
|
1733
|
+
if trigger:
|
1734
|
+
response = await self.v1PrivateDeleteAlgoOrders(self.extend(request, params))
|
1735
|
+
else:
|
1736
|
+
response = await self.v1PrivateDeleteOrders(self.extend(request, params))
|
1737
|
+
# trigger
|
1738
|
+
# {
|
1739
|
+
# "success": True,
|
1740
|
+
# "timestamp": 1702989203989,
|
1741
|
+
# "status": "CANCEL_ALL_SENT"
|
1742
|
+
# }
|
1743
|
+
#
|
1744
|
+
# {
|
1745
|
+
# "success": True,
|
1746
|
+
# "timestamp": 1702989203989,
|
1747
|
+
# "data": {
|
1748
|
+
# "status": "CANCEL_ALL_SENT"
|
1749
|
+
# }
|
1750
|
+
# }
|
1751
|
+
#
|
1752
|
+
return [
|
1753
|
+
{
|
1754
|
+
'info': response,
|
1755
|
+
},
|
1756
|
+
]
|
1757
|
+
|
1758
|
+
async def fetch_order(self, id: str, symbol: Str = None, params={}):
|
1759
|
+
"""
|
1760
|
+
|
1761
|
+
https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-order-by-order_id
|
1762
|
+
https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-order-by-client_order_id
|
1763
|
+
https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-algo-order-by-order_id
|
1764
|
+
https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-algo-order-by-client_order_id
|
1765
|
+
|
1766
|
+
fetches information on an order made by the user
|
1767
|
+
:param str id: the order id
|
1768
|
+
:param str symbol: unified symbol of the market the order was made in
|
1769
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
1770
|
+
:param boolean [params.trigger]: whether the order is a stop/algo order
|
1771
|
+
:param str [params.clientOrderId]: a unique id for the order
|
1772
|
+
:returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
|
1773
|
+
"""
|
1774
|
+
await self.load_markets()
|
1775
|
+
market = None
|
1776
|
+
if symbol is not None:
|
1777
|
+
market = self.market(symbol)
|
1778
|
+
trigger = self.safe_bool_2(params, 'stop', 'trigger', False)
|
1779
|
+
request: dict = {}
|
1780
|
+
clientOrderId = self.safe_string_n(params, ['clOrdID', 'clientOrderId', 'client_order_id'])
|
1781
|
+
params = self.omit(params, ['stop', 'trigger', 'clOrdID', 'clientOrderId', 'client_order_id'])
|
1782
|
+
response = None
|
1783
|
+
if trigger:
|
1784
|
+
if clientOrderId:
|
1785
|
+
request['client_order_id'] = clientOrderId
|
1786
|
+
response = await self.v1PrivateGetAlgoClientOrderClientOrderId(self.extend(request, params))
|
1787
|
+
else:
|
1788
|
+
request['oid'] = id
|
1789
|
+
response = await self.v1PrivateGetAlgoOrderOid(self.extend(request, params))
|
1790
|
+
else:
|
1791
|
+
if clientOrderId:
|
1792
|
+
request['client_order_id'] = clientOrderId
|
1793
|
+
response = await self.v1PrivateGetClientOrderClientOrderId(self.extend(request, params))
|
1794
|
+
else:
|
1795
|
+
request['oid'] = id
|
1796
|
+
response = await self.v1PrivateGetOrderOid(self.extend(request, params))
|
1797
|
+
#
|
1798
|
+
# {
|
1799
|
+
# "success": True,
|
1800
|
+
# "timestamp": 1702989203989,
|
1801
|
+
# "data": {
|
1802
|
+
# "order_id": 78151,
|
1803
|
+
# "user_id": 12345,
|
1804
|
+
# "price": 0.67772,
|
1805
|
+
# "type": "LIMIT",
|
1806
|
+
# "quantity": 20,
|
1807
|
+
# "amount": 10,
|
1808
|
+
# "executed_quantity": 20,
|
1809
|
+
# "total_executed_quantity": 20,
|
1810
|
+
# "visible_quantity": 1,
|
1811
|
+
# "symbol": "PERP_BTC_USDC",
|
1812
|
+
# "side": "BUY",
|
1813
|
+
# "status": "FILLED",
|
1814
|
+
# "total_fee": 0.5,
|
1815
|
+
# "fee_asset": "BTC",
|
1816
|
+
# "client_order_id": 1,
|
1817
|
+
# "average_executed_price": 0.67772,
|
1818
|
+
# "created_time": 1653563963000,
|
1819
|
+
# "updated_time": 1653564213000,
|
1820
|
+
# "realized_pnl": 123
|
1821
|
+
# }
|
1822
|
+
# }
|
1823
|
+
#
|
1824
|
+
orders = self.safe_dict(response, 'data', response)
|
1825
|
+
return self.parse_order(orders, market)
|
1826
|
+
|
1827
|
+
async def fetch_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Order]:
|
1828
|
+
"""
|
1829
|
+
fetches information on multiple orders made by the user
|
1830
|
+
|
1831
|
+
https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-orders
|
1832
|
+
https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-algo-orders
|
1833
|
+
|
1834
|
+
:param str symbol: unified market symbol of the market orders were made in
|
1835
|
+
:param int [since]: the earliest time in ms to fetch orders for
|
1836
|
+
:param int [limit]: the maximum number of order structures to retrieve
|
1837
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
1838
|
+
:param boolean [params.trigger]: whether the order is a stop/algo order
|
1839
|
+
:param boolean [params.is_triggered]: whether the order has been triggered(False by default)
|
1840
|
+
:param str [params.side]: 'buy' or 'sell'
|
1841
|
+
:param boolean [params.paginate]: set to True if you want to fetch orders with pagination
|
1842
|
+
:param int params['until']: timestamp in ms of the latest order to fetch
|
1843
|
+
:returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
|
1844
|
+
"""
|
1845
|
+
await self.load_markets()
|
1846
|
+
paginate = False
|
1847
|
+
isTrigger = self.safe_bool_2(params, 'stop', 'trigger', False)
|
1848
|
+
maxLimit = 100 if (isTrigger) else 500
|
1849
|
+
paginate, params = self.handle_option_and_params(params, 'fetchOrders', 'paginate')
|
1850
|
+
if paginate:
|
1851
|
+
return await self.fetch_paginated_call_incremental('fetchOrders', symbol, since, limit, params, 'page', maxLimit)
|
1852
|
+
request: dict = {}
|
1853
|
+
market: Market = None
|
1854
|
+
params = self.omit(params, ['stop', 'trigger'])
|
1855
|
+
if symbol is not None:
|
1856
|
+
market = self.market(symbol)
|
1857
|
+
request['symbol'] = market['id']
|
1858
|
+
if since is not None:
|
1859
|
+
request['start_t'] = since
|
1860
|
+
if limit is not None:
|
1861
|
+
request['size'] = limit
|
1862
|
+
else:
|
1863
|
+
request['size'] = maxLimit
|
1864
|
+
if isTrigger:
|
1865
|
+
request['algo_type'] = 'STOP'
|
1866
|
+
request, params = self.handle_until_option('end_t', request, params)
|
1867
|
+
response = None
|
1868
|
+
if isTrigger:
|
1869
|
+
response = await self.v1PrivateGetAlgoOrders(self.extend(request, params))
|
1870
|
+
else:
|
1871
|
+
response = await self.v1PrivateGetOrders(self.extend(request, params))
|
1872
|
+
#
|
1873
|
+
# {
|
1874
|
+
# "success": True,
|
1875
|
+
# "timestamp": 1702989203989,
|
1876
|
+
# "data": {
|
1877
|
+
# "meta": {
|
1878
|
+
# "total": 9,
|
1879
|
+
# "records_per_page": 25,
|
1880
|
+
# "current_page": 1
|
1881
|
+
# },
|
1882
|
+
# "rows": [{
|
1883
|
+
# "order_id": 78151,
|
1884
|
+
# "user_id": 12345,
|
1885
|
+
# "price": 0.67772,
|
1886
|
+
# "type": "LIMIT",
|
1887
|
+
# "quantity": 20,
|
1888
|
+
# "amount": 10,
|
1889
|
+
# "executed_quantity": 20,
|
1890
|
+
# "total_executed_quantity": 20,
|
1891
|
+
# "visible_quantity": 1,
|
1892
|
+
# "symbol": "PERP_BTC_USDC",
|
1893
|
+
# "side": "BUY",
|
1894
|
+
# "status": "FILLED",
|
1895
|
+
# "total_fee": 0.5,
|
1896
|
+
# "fee_asset": "BTC",
|
1897
|
+
# "client_order_id": 1,
|
1898
|
+
# "average_executed_price": 0.67772,
|
1899
|
+
# "created_time": 1653563963000,
|
1900
|
+
# "updated_time": 1653564213000,
|
1901
|
+
# "realized_pnl": 123
|
1902
|
+
# }]
|
1903
|
+
# }
|
1904
|
+
# }
|
1905
|
+
#
|
1906
|
+
data = self.safe_value(response, 'data', response)
|
1907
|
+
orders = self.safe_list(data, 'rows')
|
1908
|
+
return self.parse_orders(orders, market, since, limit)
|
1909
|
+
|
1910
|
+
async def fetch_open_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Order]:
|
1911
|
+
"""
|
1912
|
+
fetches information on multiple orders made by the user
|
1913
|
+
|
1914
|
+
https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-orders
|
1915
|
+
https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-algo-orders
|
1916
|
+
|
1917
|
+
:param str symbol: unified market symbol of the market orders were made in
|
1918
|
+
:param int [since]: the earliest time in ms to fetch orders for
|
1919
|
+
:param int [limit]: the maximum number of order structures to retrieve
|
1920
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
1921
|
+
:param boolean [params.trigger]: whether the order is a stop/algo order
|
1922
|
+
:param boolean [params.is_triggered]: whether the order has been triggered(False by default)
|
1923
|
+
:param str [params.side]: 'buy' or 'sell'
|
1924
|
+
:param int params['until']: timestamp in ms of the latest order to fetch
|
1925
|
+
:param boolean [params.paginate]: set to True if you want to fetch orders with pagination
|
1926
|
+
:returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
|
1927
|
+
"""
|
1928
|
+
await self.load_markets()
|
1929
|
+
extendedParams = self.extend(params, {'status': 'INCOMPLETE'})
|
1930
|
+
return await self.fetch_orders(symbol, since, limit, extendedParams)
|
1931
|
+
|
1932
|
+
async def fetch_closed_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Order]:
|
1933
|
+
"""
|
1934
|
+
fetches information on multiple orders made by the user
|
1935
|
+
|
1936
|
+
https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-orders
|
1937
|
+
https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-algo-orders
|
1938
|
+
|
1939
|
+
:param str symbol: unified market symbol of the market orders were made in
|
1940
|
+
:param int [since]: the earliest time in ms to fetch orders for
|
1941
|
+
:param int [limit]: the maximum number of order structures to retrieve
|
1942
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
1943
|
+
:param boolean [params.trigger]: whether the order is a stop/algo order
|
1944
|
+
:param boolean [params.is_triggered]: whether the order has been triggered(False by default)
|
1945
|
+
:param str [params.side]: 'buy' or 'sell'
|
1946
|
+
:param int params['until']: timestamp in ms of the latest order to fetch
|
1947
|
+
:param boolean [params.paginate]: set to True if you want to fetch orders with pagination
|
1948
|
+
:returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
|
1949
|
+
"""
|
1950
|
+
await self.load_markets()
|
1951
|
+
extendedParams = self.extend(params, {'status': 'COMPLETED'})
|
1952
|
+
return await self.fetch_orders(symbol, since, limit, extendedParams)
|
1953
|
+
|
1954
|
+
async def fetch_order_trades(self, id: str, symbol: Str = None, since: Int = None, limit: Int = None, params={}):
|
1955
|
+
"""
|
1956
|
+
fetch all the trades made from a single order
|
1957
|
+
|
1958
|
+
https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-all-trades-of-specific-order
|
1959
|
+
|
1960
|
+
:param str id: order id
|
1961
|
+
:param str symbol: unified market symbol
|
1962
|
+
:param int [since]: the earliest time in ms to fetch trades for
|
1963
|
+
:param int [limit]: the maximum number of trades to retrieve
|
1964
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
1965
|
+
:returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
|
1966
|
+
"""
|
1967
|
+
await self.load_markets()
|
1968
|
+
market: Market = None
|
1969
|
+
if symbol is not None:
|
1970
|
+
market = self.market(symbol)
|
1971
|
+
request: dict = {
|
1972
|
+
'oid': id,
|
1973
|
+
}
|
1974
|
+
response = await self.v1PrivateGetOrderOidTrades(self.extend(request, params))
|
1975
|
+
#
|
1976
|
+
# {
|
1977
|
+
# "success": True,
|
1978
|
+
# "timestamp": 1702989203989,
|
1979
|
+
# "data": {
|
1980
|
+
# "rows": [{
|
1981
|
+
# "id": 2,
|
1982
|
+
# "symbol": "PERP_BTC_USDC",
|
1983
|
+
# "fee": 0.0001,
|
1984
|
+
# "fee_asset": "USDC",
|
1985
|
+
# "side": "BUY",
|
1986
|
+
# "order_id": 1,
|
1987
|
+
# "executed_price": 123,
|
1988
|
+
# "executed_quantity": 0.05,
|
1989
|
+
# "executed_timestamp": 1567382401000,
|
1990
|
+
# "is_maker": 1,
|
1991
|
+
# "realized_pnl": 123
|
1992
|
+
# }]
|
1993
|
+
# }
|
1994
|
+
# }
|
1995
|
+
#
|
1996
|
+
data = self.safe_dict(response, 'data', {})
|
1997
|
+
trades = self.safe_list(data, 'rows', [])
|
1998
|
+
return self.parse_trades(trades, market, since, limit, params)
|
1999
|
+
|
2000
|
+
async def fetch_my_trades(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}):
|
2001
|
+
"""
|
2002
|
+
|
2003
|
+
https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-trades
|
2004
|
+
|
2005
|
+
fetch all trades made by the user
|
2006
|
+
:param str symbol: unified market symbol
|
2007
|
+
:param int [since]: the earliest time in ms to fetch trades for
|
2008
|
+
:param int [limit]: the maximum number of trades structures to retrieve
|
2009
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
2010
|
+
:param boolean [params.paginate]: set to True if you want to fetch trades with pagination
|
2011
|
+
:param int params['until']: timestamp in ms of the latest trade to fetch
|
2012
|
+
:returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
|
2013
|
+
"""
|
2014
|
+
await self.load_markets()
|
2015
|
+
paginate = False
|
2016
|
+
paginate, params = self.handle_option_and_params(params, 'fetchMyTrades', 'paginate')
|
2017
|
+
if paginate:
|
2018
|
+
return await self.fetch_paginated_call_incremental('fetchMyTrades', symbol, since, limit, params, 'page', 500)
|
2019
|
+
request: dict = {}
|
2020
|
+
market: Market = None
|
2021
|
+
if symbol is not None:
|
2022
|
+
market = self.market(symbol)
|
2023
|
+
request['symbol'] = market['id']
|
2024
|
+
if since is not None:
|
2025
|
+
request['start_t'] = since
|
2026
|
+
if limit is not None:
|
2027
|
+
request['size'] = limit
|
2028
|
+
else:
|
2029
|
+
request['size'] = 500
|
2030
|
+
request, params = self.handle_until_option('end_t', request, params)
|
2031
|
+
response = await self.v1PrivateGetTrades(self.extend(request, params))
|
2032
|
+
#
|
2033
|
+
# {
|
2034
|
+
# "success": True,
|
2035
|
+
# "timestamp": 1702989203989,
|
2036
|
+
# "data": {
|
2037
|
+
# "meta": {
|
2038
|
+
# "total": 9,
|
2039
|
+
# "records_per_page": 25,
|
2040
|
+
# "current_page": 1
|
2041
|
+
# },
|
2042
|
+
# "rows": [{
|
2043
|
+
# "id": 2,
|
2044
|
+
# "symbol": "PERP_BTC_USDC",
|
2045
|
+
# "fee": 0.0001,
|
2046
|
+
# "fee_asset": "USDC",
|
2047
|
+
# "side": "BUY",
|
2048
|
+
# "order_id": 1,
|
2049
|
+
# "executed_price": 123,
|
2050
|
+
# "executed_quantity": 0.05,
|
2051
|
+
# "executed_timestamp": 1567382401000,
|
2052
|
+
# "is_maker": 1,
|
2053
|
+
# "realized_pnl": 123
|
2054
|
+
# }]
|
2055
|
+
# }
|
2056
|
+
# }
|
2057
|
+
#
|
2058
|
+
data = self.safe_dict(response, 'data', {})
|
2059
|
+
trades = self.safe_list(data, 'rows', [])
|
2060
|
+
return self.parse_trades(trades, market, since, limit, params)
|
2061
|
+
|
2062
|
+
def parse_balance(self, response) -> Balances:
|
2063
|
+
result: dict = {
|
2064
|
+
'info': response,
|
2065
|
+
}
|
2066
|
+
balances = self.safe_list(response, 'holding', [])
|
2067
|
+
for i in range(0, len(balances)):
|
2068
|
+
balance = balances[i]
|
2069
|
+
code = self.safe_currency_code(self.safe_string(balance, 'token'))
|
2070
|
+
account = self.account()
|
2071
|
+
account['total'] = self.safe_string(balance, 'holding')
|
2072
|
+
account['frozen'] = self.safe_string(balance, 'frozen')
|
2073
|
+
result[code] = account
|
2074
|
+
return self.safe_balance(result)
|
2075
|
+
|
2076
|
+
async def fetch_balance(self, params={}) -> Balances:
|
2077
|
+
"""
|
2078
|
+
query for balance and get the amount of funds available for trading or funds locked in orders
|
2079
|
+
|
2080
|
+
https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-current-holding
|
2081
|
+
|
2082
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
2083
|
+
:returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
|
2084
|
+
"""
|
2085
|
+
await self.load_markets()
|
2086
|
+
response = await self.v1PrivateGetClientHolding(params)
|
2087
|
+
#
|
2088
|
+
# {
|
2089
|
+
# "success": True,
|
2090
|
+
# "timestamp": 1702989203989,
|
2091
|
+
# "data": {
|
2092
|
+
# "holding": [{
|
2093
|
+
# "updated_time": 1580794149000,
|
2094
|
+
# "token": "BTC",
|
2095
|
+
# "holding": -28.000752,
|
2096
|
+
# "frozen": 123,
|
2097
|
+
# "pending_short": -2000
|
2098
|
+
# }]
|
2099
|
+
# }
|
2100
|
+
# }
|
2101
|
+
#
|
2102
|
+
data = self.safe_dict(response, 'data')
|
2103
|
+
return self.parse_balance(data)
|
2104
|
+
|
2105
|
+
async def get_asset_history_rows(self, code: Str = None, since: Int = None, limit: Int = None, params={}) -> Any:
|
2106
|
+
await self.load_markets()
|
2107
|
+
request: dict = {}
|
2108
|
+
currency: Currency = None
|
2109
|
+
if code is not None:
|
2110
|
+
currency = self.currency(code)
|
2111
|
+
request['balance_token'] = currency['id']
|
2112
|
+
if since is not None:
|
2113
|
+
request['start_t'] = since
|
2114
|
+
if limit is not None:
|
2115
|
+
request['pageSize'] = limit
|
2116
|
+
transactionType = self.safe_string(params, 'type')
|
2117
|
+
params = self.omit(params, 'type')
|
2118
|
+
if transactionType is not None:
|
2119
|
+
request['type'] = transactionType
|
2120
|
+
response = await self.v1PrivateGetAssetHistory(self.extend(request, params))
|
2121
|
+
#
|
2122
|
+
# {
|
2123
|
+
# "success": True,
|
2124
|
+
# "timestamp": 1702989203989,
|
2125
|
+
# "data": {
|
2126
|
+
# "meta": {
|
2127
|
+
# "total": 9,
|
2128
|
+
# "records_per_page": 25,
|
2129
|
+
# "current_page": 1
|
2130
|
+
# },
|
2131
|
+
# "rows": [{
|
2132
|
+
# "id": "230707030600002",
|
2133
|
+
# "tx_id": "0x4b0714c63cc7abae72bf68e84e25860b88ca651b7d27dad1e32bf4c027fa5326",
|
2134
|
+
# "side": "WITHDRAW",
|
2135
|
+
# "token": "USDC",
|
2136
|
+
# "amount": 555,
|
2137
|
+
# "fee": 123,
|
2138
|
+
# "trans_status": "FAILED",
|
2139
|
+
# "created_time": 1688699193034,
|
2140
|
+
# "updated_time": 1688699193096,
|
2141
|
+
# "chain_id": "986532"
|
2142
|
+
# }]
|
2143
|
+
# }
|
2144
|
+
# }
|
2145
|
+
#
|
2146
|
+
data = self.safe_dict(response, 'data', {})
|
2147
|
+
return [currency, self.safe_list(data, 'rows', [])]
|
2148
|
+
|
2149
|
+
def parse_ledger_entry(self, item: dict, currency: Currency = None) -> LedgerEntry:
|
2150
|
+
currencyId = self.safe_string(item, 'token')
|
2151
|
+
code = self.safe_currency_code(currencyId, currency)
|
2152
|
+
currency = self.safe_currency(currencyId, currency)
|
2153
|
+
amount = self.safe_number(item, 'amount')
|
2154
|
+
side = self.safe_string(item, 'token_side')
|
2155
|
+
direction = 'in' if (side == 'DEPOSIT') else 'out'
|
2156
|
+
timestamp = self.safe_integer(item, 'created_time')
|
2157
|
+
fee = self.parse_token_and_fee_temp(item, 'fee_token', 'fee_amount')
|
2158
|
+
return self.safe_ledger_entry({
|
2159
|
+
'id': self.safe_string(item, 'id'),
|
2160
|
+
'currency': code,
|
2161
|
+
'account': self.safe_string(item, 'account'),
|
2162
|
+
'referenceAccount': None,
|
2163
|
+
'referenceId': self.safe_string(item, 'tx_id'),
|
2164
|
+
'status': self.parse_transaction_status(self.safe_string(item, 'status')),
|
2165
|
+
'amount': amount,
|
2166
|
+
'before': None,
|
2167
|
+
'after': None,
|
2168
|
+
'fee': fee,
|
2169
|
+
'direction': direction,
|
2170
|
+
'timestamp': timestamp,
|
2171
|
+
'datetime': self.iso8601(timestamp),
|
2172
|
+
'type': self.parse_ledger_entry_type(self.safe_string(item, 'type')),
|
2173
|
+
'info': item,
|
2174
|
+
}, currency)
|
2175
|
+
|
2176
|
+
def parse_ledger_entry_type(self, type):
|
2177
|
+
types: dict = {
|
2178
|
+
'BALANCE': 'transaction', # Funds moved in/out wallet
|
2179
|
+
'COLLATERAL': 'transfer', # Funds moved between portfolios
|
2180
|
+
}
|
2181
|
+
return self.safe_string(types, type, type)
|
2182
|
+
|
2183
|
+
async def fetch_ledger(self, code: Str = None, since: Int = None, limit: Int = None, params={}) -> List[LedgerEntry]:
|
2184
|
+
"""
|
2185
|
+
fetch the history of changes, actions done by the user or operations that altered the balance of the user
|
2186
|
+
|
2187
|
+
https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-asset-history
|
2188
|
+
|
2189
|
+
:param str [code]: unified currency code, default is None
|
2190
|
+
:param int [since]: timestamp in ms of the earliest ledger entry, default is None
|
2191
|
+
:param int [limit]: max number of ledger entries to return, default is None
|
2192
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
2193
|
+
:returns dict: a `ledger structure <https://docs.ccxt.com/#/?id=ledger>`
|
2194
|
+
"""
|
2195
|
+
currencyRows = await self.get_asset_history_rows(code, since, limit, params)
|
2196
|
+
currency = self.safe_value(currencyRows, 0)
|
2197
|
+
rows = self.safe_list(currencyRows, 1)
|
2198
|
+
return self.parse_ledger(rows, currency, since, limit, params)
|
2199
|
+
|
2200
|
+
def parse_transaction(self, transaction: dict, currency: Currency = None) -> Transaction:
|
2201
|
+
# example in fetchLedger
|
2202
|
+
code = self.safe_string(transaction, 'token')
|
2203
|
+
movementDirection = self.safe_string_lower(transaction, 'token_side')
|
2204
|
+
if movementDirection == 'withdraw':
|
2205
|
+
movementDirection = 'withdrawal'
|
2206
|
+
fee = self.parse_token_and_fee_temp(transaction, 'fee_token', 'fee_amount')
|
2207
|
+
addressTo = self.safe_string(transaction, 'target_address')
|
2208
|
+
addressFrom = self.safe_string(transaction, 'source_address')
|
2209
|
+
timestamp = self.safe_integer(transaction, 'created_time')
|
2210
|
+
return {
|
2211
|
+
'info': transaction,
|
2212
|
+
'id': self.safe_string_2(transaction, 'id', 'withdraw_id'),
|
2213
|
+
'txid': self.safe_string(transaction, 'tx_id'),
|
2214
|
+
'timestamp': timestamp,
|
2215
|
+
'datetime': self.iso8601(timestamp),
|
2216
|
+
'address': None,
|
2217
|
+
'addressFrom': addressFrom,
|
2218
|
+
'addressTo': addressTo,
|
2219
|
+
'tag': self.safe_string(transaction, 'extra'),
|
2220
|
+
'tagFrom': None,
|
2221
|
+
'tagTo': None,
|
2222
|
+
'type': movementDirection,
|
2223
|
+
'amount': self.safe_number(transaction, 'amount'),
|
2224
|
+
'currency': code,
|
2225
|
+
'status': self.parse_transaction_status(self.safe_string(transaction, 'status')),
|
2226
|
+
'updated': self.safe_integer(transaction, 'updated_time'),
|
2227
|
+
'comment': None,
|
2228
|
+
'internal': None,
|
2229
|
+
'fee': fee,
|
2230
|
+
'network': None,
|
2231
|
+
}
|
2232
|
+
|
2233
|
+
def parse_transaction_status(self, status: Str):
|
2234
|
+
statuses: dict = {
|
2235
|
+
'NEW': 'pending',
|
2236
|
+
'CONFIRMING': 'pending',
|
2237
|
+
'PROCESSING': 'pending',
|
2238
|
+
'COMPLETED': 'ok',
|
2239
|
+
'CANCELED': 'canceled',
|
2240
|
+
}
|
2241
|
+
return self.safe_string(statuses, status, status)
|
2242
|
+
|
2243
|
+
async def fetch_deposits(self, code: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Transaction]:
|
2244
|
+
"""
|
2245
|
+
fetch all deposits made to an account
|
2246
|
+
|
2247
|
+
https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-asset-history
|
2248
|
+
|
2249
|
+
:param str code: unified currency code
|
2250
|
+
:param int [since]: the earliest time in ms to fetch deposits for
|
2251
|
+
:param int [limit]: the maximum number of deposits structures to retrieve
|
2252
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
2253
|
+
:returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
|
2254
|
+
"""
|
2255
|
+
request: dict = {
|
2256
|
+
'side': 'DEPOSIT',
|
2257
|
+
}
|
2258
|
+
return await self.fetch_deposits_withdrawals(code, since, limit, self.extend(request, params))
|
2259
|
+
|
2260
|
+
async def fetch_withdrawals(self, code: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Transaction]:
|
2261
|
+
"""
|
2262
|
+
fetch all withdrawals made from an account
|
2263
|
+
|
2264
|
+
https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-asset-history
|
2265
|
+
|
2266
|
+
:param str code: unified currency code
|
2267
|
+
:param int [since]: the earliest time in ms to fetch withdrawals for
|
2268
|
+
:param int [limit]: the maximum number of withdrawals structures to retrieve
|
2269
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
2270
|
+
:returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
|
2271
|
+
"""
|
2272
|
+
request: dict = {
|
2273
|
+
'side': 'WITHDRAW',
|
2274
|
+
}
|
2275
|
+
return await self.fetch_deposits_withdrawals(code, since, limit, self.extend(request, params))
|
2276
|
+
|
2277
|
+
async def fetch_deposits_withdrawals(self, code: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Transaction]:
|
2278
|
+
"""
|
2279
|
+
fetch history of deposits and withdrawals
|
2280
|
+
|
2281
|
+
https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-asset-history
|
2282
|
+
|
2283
|
+
:param str [code]: unified currency code for the currency of the deposit/withdrawals, default is None
|
2284
|
+
:param int [since]: timestamp in ms of the earliest deposit/withdrawal, default is None
|
2285
|
+
:param int [limit]: max number of deposit/withdrawals to return, default is None
|
2286
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
2287
|
+
:returns dict: a list of `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
|
2288
|
+
"""
|
2289
|
+
request: dict = {}
|
2290
|
+
currencyRows = await self.get_asset_history_rows(code, since, limit, self.extend(request, params))
|
2291
|
+
currency = self.safe_value(currencyRows, 0)
|
2292
|
+
rows = self.safe_list(currencyRows, 1)
|
2293
|
+
#
|
2294
|
+
# {
|
2295
|
+
# "rows":[],
|
2296
|
+
# "meta":{
|
2297
|
+
# "total":0,
|
2298
|
+
# "records_per_page":25,
|
2299
|
+
# "current_page":1
|
2300
|
+
# },
|
2301
|
+
# "success":true
|
2302
|
+
# }
|
2303
|
+
#
|
2304
|
+
return self.parse_transactions(rows, currency, since, limit, params)
|
2305
|
+
|
2306
|
+
async def get_withdraw_nonce(self, params={}):
|
2307
|
+
response = await self.v1PrivateGetWithdrawNonce(params)
|
2308
|
+
#
|
2309
|
+
# {
|
2310
|
+
# "success": True,
|
2311
|
+
# "timestamp": 1702989203989,
|
2312
|
+
# "data": {
|
2313
|
+
# "withdraw_nonce": 1
|
2314
|
+
# }
|
2315
|
+
# }
|
2316
|
+
#
|
2317
|
+
data = self.safe_dict(response, 'data', {})
|
2318
|
+
return self.safe_number(data, 'withdraw_nonce')
|
2319
|
+
|
2320
|
+
def hash_message(self, message):
|
2321
|
+
return '0x' + self.hash(message, 'keccak', 'hex')
|
2322
|
+
|
2323
|
+
def sign_hash(self, hash, privateKey):
|
2324
|
+
signature = self.ecdsa(hash[-64:], privateKey[-64:], 'secp256k1', None)
|
2325
|
+
r = signature['r']
|
2326
|
+
s = signature['s']
|
2327
|
+
v = self.int_to_base16(self.sum(27, signature['v']))
|
2328
|
+
return '0x' + r.rjust(64, '0') + s.rjust(64, '0') + v
|
2329
|
+
|
2330
|
+
def sign_message(self, message, privateKey):
|
2331
|
+
return self.sign_hash(self.hash_message(message), privateKey[-64:])
|
2332
|
+
|
2333
|
+
async def withdraw(self, code: str, amount: float, address: str, tag=None, params={}) -> Transaction:
|
2334
|
+
"""
|
2335
|
+
make a withdrawal
|
2336
|
+
|
2337
|
+
https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/create-withdraw-request
|
2338
|
+
|
2339
|
+
:param str code: unified currency code
|
2340
|
+
:param float amount: the amount to withdraw
|
2341
|
+
:param str address: the address to withdraw to
|
2342
|
+
:param str tag:
|
2343
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
2344
|
+
:returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
|
2345
|
+
"""
|
2346
|
+
await self.load_markets()
|
2347
|
+
self.check_address(address)
|
2348
|
+
if code is not None:
|
2349
|
+
code = code.upper()
|
2350
|
+
if code != 'USDC':
|
2351
|
+
raise NotSupported(self.id + ' withdraw() only support USDC')
|
2352
|
+
currency = self.currency(code)
|
2353
|
+
verifyingContractAddress = self.safe_string(self.options, 'verifyingContractAddress')
|
2354
|
+
chainId = self.safe_string(params, 'chainId')
|
2355
|
+
currencyNetworks = self.safe_dict(currency, 'networks', {})
|
2356
|
+
coinNetwork = self.safe_dict(currencyNetworks, chainId, {})
|
2357
|
+
coinNetworkId = self.safe_number(coinNetwork, 'id')
|
2358
|
+
if coinNetworkId is None:
|
2359
|
+
raise BadRequest(self.id + ' withdraw() require chainId parameter')
|
2360
|
+
withdrawNonce = await self.get_withdraw_nonce(params)
|
2361
|
+
nonce = self.nonce()
|
2362
|
+
domain: dict = {
|
2363
|
+
'chainId': chainId,
|
2364
|
+
'name': 'Orderly',
|
2365
|
+
'verifyingContract': verifyingContractAddress,
|
2366
|
+
'version': '1',
|
2367
|
+
}
|
2368
|
+
messageTypes: dict = {
|
2369
|
+
'Withdraw': [
|
2370
|
+
{'name': 'brokerId', 'type': 'string'},
|
2371
|
+
{'name': 'chainId', 'type': 'uint256'},
|
2372
|
+
{'name': 'receiver', 'type': 'address'},
|
2373
|
+
{'name': 'token', 'type': 'string'},
|
2374
|
+
{'name': 'amount', 'type': 'uint256'},
|
2375
|
+
{'name': 'withdrawNonce', 'type': 'uint64'},
|
2376
|
+
{'name': 'timestamp', 'type': 'uint64'},
|
2377
|
+
],
|
2378
|
+
}
|
2379
|
+
withdrawRequest: dict = {
|
2380
|
+
'brokerId': self.safe_string(self.options, 'keyBrokerId', 'mode'),
|
2381
|
+
'chainId': self.parse_to_int(chainId),
|
2382
|
+
'receiver': address,
|
2383
|
+
'token': code,
|
2384
|
+
'amount': str(amount),
|
2385
|
+
'withdrawNonce': withdrawNonce,
|
2386
|
+
'timestamp': nonce,
|
2387
|
+
}
|
2388
|
+
msg = self.eth_encode_structured_data(domain, messageTypes, withdrawRequest)
|
2389
|
+
signature = self.sign_message(msg, self.privateKey)
|
2390
|
+
request: dict = {
|
2391
|
+
'signature': signature,
|
2392
|
+
'userAddress': address,
|
2393
|
+
'verifyingContract': verifyingContractAddress,
|
2394
|
+
'message': withdrawRequest,
|
2395
|
+
}
|
2396
|
+
params = self.omit(params, 'chainId')
|
2397
|
+
response = await self.v1PrivatePostWithdrawRequest(self.extend(request, params))
|
2398
|
+
#
|
2399
|
+
# {
|
2400
|
+
# "success": True,
|
2401
|
+
# "timestamp": 1702989203989,
|
2402
|
+
# "data": {
|
2403
|
+
# "withdraw_id": 123
|
2404
|
+
# }
|
2405
|
+
# }
|
2406
|
+
#
|
2407
|
+
data = self.safe_dict(response, 'data', {})
|
2408
|
+
return self.parse_transaction(data, currency)
|
2409
|
+
|
2410
|
+
def parse_leverage(self, leverage, market=None) -> Leverage:
|
2411
|
+
leverageValue = self.safe_integer(leverage, 'max_leverage')
|
2412
|
+
return {
|
2413
|
+
'info': leverage,
|
2414
|
+
'symbol': market['symbol'],
|
2415
|
+
'marginMode': None,
|
2416
|
+
'longLeverage': leverageValue,
|
2417
|
+
'shortLeverage': leverageValue,
|
2418
|
+
}
|
2419
|
+
|
2420
|
+
async def fetch_leverage(self, symbol: str, params={}) -> Leverage:
|
2421
|
+
"""
|
2422
|
+
fetch the set leverage for a market
|
2423
|
+
|
2424
|
+
https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-account-information
|
2425
|
+
|
2426
|
+
:param str symbol: unified market symbol
|
2427
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
2428
|
+
:returns dict: a `leverage structure <https://docs.ccxt.com/#/?id=leverage-structure>`
|
2429
|
+
"""
|
2430
|
+
await self.load_markets()
|
2431
|
+
market = self.market(symbol)
|
2432
|
+
response = await self.v1PrivateGetClientInfo(params)
|
2433
|
+
#
|
2434
|
+
# {
|
2435
|
+
# "success": True,
|
2436
|
+
# "timestamp": 1702989203989,
|
2437
|
+
# "data": {
|
2438
|
+
# "account_id": "<string>",
|
2439
|
+
# "email": "test@test.com",
|
2440
|
+
# "account_mode": "FUTURES",
|
2441
|
+
# "max_leverage": 20,
|
2442
|
+
# "taker_fee_rate": 123,
|
2443
|
+
# "maker_fee_rate": 123,
|
2444
|
+
# "futures_taker_fee_rate": 123,
|
2445
|
+
# "futures_maker_fee_rate": 123,
|
2446
|
+
# "maintenance_cancel_orders": True,
|
2447
|
+
# "imr_factor": {
|
2448
|
+
# "PERP_BTC_USDC": 123,
|
2449
|
+
# "PERP_ETH_USDC": 123,
|
2450
|
+
# "PERP_NEAR_USDC": 123
|
2451
|
+
# },
|
2452
|
+
# "max_notional": {
|
2453
|
+
# "PERP_BTC_USDC": 123,
|
2454
|
+
# "PERP_ETH_USDC": 123,
|
2455
|
+
# "PERP_NEAR_USDC": 123
|
2456
|
+
# }
|
2457
|
+
# }
|
2458
|
+
# }
|
2459
|
+
#
|
2460
|
+
data = self.safe_dict(response, 'data', {})
|
2461
|
+
return self.parse_leverage(data, market)
|
2462
|
+
|
2463
|
+
async def set_leverage(self, leverage: Int, symbol: Str = None, params={}):
|
2464
|
+
"""
|
2465
|
+
set the level of leverage for a market
|
2466
|
+
|
2467
|
+
https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/update-leverage-setting
|
2468
|
+
|
2469
|
+
:param int [leverage]: the rate of leverage
|
2470
|
+
:param str [symbol]: unified market symbol
|
2471
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
2472
|
+
:returns dict: response from the exchange
|
2473
|
+
"""
|
2474
|
+
await self.load_markets()
|
2475
|
+
isMinLeverage = leverage < 1
|
2476
|
+
isMaxLeverage = leverage > 50
|
2477
|
+
if isMinLeverage or isMaxLeverage:
|
2478
|
+
raise BadRequest(self.id + ' leverage should be between 1 and 50')
|
2479
|
+
request: dict = {
|
2480
|
+
'leverage': leverage,
|
2481
|
+
}
|
2482
|
+
return await self.v1PrivatePostClientLeverage(self.extend(request, params))
|
2483
|
+
|
2484
|
+
def parse_position(self, position: dict, market: Market = None):
|
2485
|
+
#
|
2486
|
+
# {
|
2487
|
+
# "IMR_withdraw_orders": 0.1,
|
2488
|
+
# "MMR_with_orders": 0.05,
|
2489
|
+
# "average_open_price": 27908.14386047,
|
2490
|
+
# "cost_position": -139329.358492,
|
2491
|
+
# "est_liq_price": 117335.92899428,
|
2492
|
+
# "fee_24_h": 123,
|
2493
|
+
# "imr": 0.1,
|
2494
|
+
# "last_sum_unitary_funding": 70.38,
|
2495
|
+
# "mark_price": 27794.9,
|
2496
|
+
# "mmr": 0.05,
|
2497
|
+
# "pending_long_qty": 123,
|
2498
|
+
# "pending_short_qty": 123,
|
2499
|
+
# "pnl_24_h": 123,
|
2500
|
+
# "position_qty": -5,
|
2501
|
+
# "settle_price": 27865.8716984,
|
2502
|
+
# "symbol": "PERP_BTC_USDC",
|
2503
|
+
# "timestamp": 1685429350571,
|
2504
|
+
# "unsettled_pnl": 354.858492
|
2505
|
+
# }
|
2506
|
+
#
|
2507
|
+
contract = self.safe_string(position, 'symbol')
|
2508
|
+
market = self.safe_market(contract, market)
|
2509
|
+
size = self.safe_string(position, 'position_qty')
|
2510
|
+
side: Str = None
|
2511
|
+
if Precise.string_gt(size, '0'):
|
2512
|
+
side = 'long'
|
2513
|
+
else:
|
2514
|
+
side = 'short'
|
2515
|
+
contractSize = self.safe_string(market, 'contractSize')
|
2516
|
+
markPrice = self.safe_string(position, 'mark_price')
|
2517
|
+
timestamp = self.safe_integer(position, 'timestamp')
|
2518
|
+
entryPrice = self.safe_string(position, 'average_open_price')
|
2519
|
+
unrealisedPnl = self.safe_string(position, 'unsettled_pnl')
|
2520
|
+
size = Precise.string_abs(size)
|
2521
|
+
notional = Precise.string_mul(size, markPrice)
|
2522
|
+
return self.safe_position({
|
2523
|
+
'info': position,
|
2524
|
+
'id': None,
|
2525
|
+
'symbol': self.safe_string(market, 'symbol'),
|
2526
|
+
'timestamp': timestamp,
|
2527
|
+
'datetime': self.iso8601(timestamp),
|
2528
|
+
'lastUpdateTimestamp': None,
|
2529
|
+
'initialMargin': None,
|
2530
|
+
'initialMarginPercentage': None,
|
2531
|
+
'maintenanceMargin': None,
|
2532
|
+
'maintenanceMarginPercentage': None,
|
2533
|
+
'entryPrice': self.parse_number(entryPrice),
|
2534
|
+
'notional': self.parse_number(notional),
|
2535
|
+
'leverage': None,
|
2536
|
+
'unrealizedPnl': self.parse_number(unrealisedPnl),
|
2537
|
+
'contracts': self.parse_number(size),
|
2538
|
+
'contractSize': self.parse_number(contractSize),
|
2539
|
+
'marginRatio': None,
|
2540
|
+
'liquidationPrice': self.safe_number(position, 'est_liq_price'),
|
2541
|
+
'markPrice': self.parse_number(markPrice),
|
2542
|
+
'lastPrice': None,
|
2543
|
+
'collateral': None,
|
2544
|
+
'marginMode': 'cross',
|
2545
|
+
'marginType': None,
|
2546
|
+
'side': side,
|
2547
|
+
'percentage': None,
|
2548
|
+
'hedged': None,
|
2549
|
+
'stopLossPrice': None,
|
2550
|
+
'takeProfitPrice': None,
|
2551
|
+
})
|
2552
|
+
|
2553
|
+
async def fetch_position(self, symbol: Str, params={}):
|
2554
|
+
"""
|
2555
|
+
|
2556
|
+
https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-one-position-info
|
2557
|
+
|
2558
|
+
fetch data on an open position
|
2559
|
+
:param str symbol: unified market symbol of the market the position is held in
|
2560
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
2561
|
+
:returns dict: a `position structure <https://docs.ccxt.com/#/?id=position-structure>`
|
2562
|
+
"""
|
2563
|
+
await self.load_markets()
|
2564
|
+
market = self.market(symbol)
|
2565
|
+
request: dict = {
|
2566
|
+
'symbol': market['id'],
|
2567
|
+
}
|
2568
|
+
response = await self.v1PrivateGetPositionSymbol(self.extend(request, params))
|
2569
|
+
#
|
2570
|
+
# {
|
2571
|
+
# "success": True,
|
2572
|
+
# "timestamp": 1702989203989,
|
2573
|
+
# "data": {
|
2574
|
+
# "IMR_withdraw_orders": 0.1,
|
2575
|
+
# "MMR_with_orders": 0.05,
|
2576
|
+
# "average_open_price": 27908.14386047,
|
2577
|
+
# "cost_position": -139329.358492,
|
2578
|
+
# "est_liq_price": 117335.92899428,
|
2579
|
+
# "fee_24_h": 123,
|
2580
|
+
# "imr": 0.1,
|
2581
|
+
# "last_sum_unitary_funding": 70.38,
|
2582
|
+
# "mark_price": 27794.9,
|
2583
|
+
# "mmr": 0.05,
|
2584
|
+
# "pending_long_qty": 123,
|
2585
|
+
# "pending_short_qty": 123,
|
2586
|
+
# "pnl_24_h": 123,
|
2587
|
+
# "position_qty": -5,
|
2588
|
+
# "settle_price": 27865.8716984,
|
2589
|
+
# "symbol": "PERP_BTC_USDC",
|
2590
|
+
# "timestamp": 1685429350571,
|
2591
|
+
# "unsettled_pnl": 354.858492
|
2592
|
+
# }
|
2593
|
+
# }
|
2594
|
+
#
|
2595
|
+
data = self.safe_dict(response, 'data')
|
2596
|
+
return self.parse_position(data, market)
|
2597
|
+
|
2598
|
+
async def fetch_positions(self, symbols: Strings = None, params={}) -> List[Position]:
|
2599
|
+
"""
|
2600
|
+
fetch all open positions
|
2601
|
+
|
2602
|
+
https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-all-positions-info
|
2603
|
+
|
2604
|
+
:param str[] [symbols]: list of unified market symbols
|
2605
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
2606
|
+
:returns dict[]: a list of `position structure <https://docs.ccxt.com/#/?id=position-structure>`
|
2607
|
+
"""
|
2608
|
+
await self.load_markets()
|
2609
|
+
response = await self.v1PrivateGetPositions(params)
|
2610
|
+
#
|
2611
|
+
# {
|
2612
|
+
# "success": True,
|
2613
|
+
# "timestamp": 1702989203989,
|
2614
|
+
# "data": {
|
2615
|
+
# "current_margin_ratio_with_orders": 1.2385,
|
2616
|
+
# "free_collateral": 450315.09115,
|
2617
|
+
# "initial_margin_ratio": 0.1,
|
2618
|
+
# "initial_margin_ratio_with_orders": 0.1,
|
2619
|
+
# "maintenance_margin_ratio": 0.05,
|
2620
|
+
# "maintenance_margin_ratio_with_orders": 0.05,
|
2621
|
+
# "margin_ratio": 1.2385,
|
2622
|
+
# "open_margin_ratio": 1.2102,
|
2623
|
+
# "total_collateral_value": 489865.71329,
|
2624
|
+
# "total_pnl_24_h": 123,
|
2625
|
+
# "rows": [{
|
2626
|
+
# "IMR_withdraw_orders": 0.1,
|
2627
|
+
# "MMR_with_orders": 0.05,
|
2628
|
+
# "average_open_price": 27908.14386047,
|
2629
|
+
# "cost_position": -139329.358492,
|
2630
|
+
# "est_liq_price": 117335.92899428,
|
2631
|
+
# "fee_24_h": 123,
|
2632
|
+
# "imr": 0.1,
|
2633
|
+
# "last_sum_unitary_funding": 70.38,
|
2634
|
+
# "mark_price": 27794.9,
|
2635
|
+
# "mmr": 0.05,
|
2636
|
+
# "pending_long_qty": 123,
|
2637
|
+
# "pending_short_qty": 123,
|
2638
|
+
# "pnl_24_h": 123,
|
2639
|
+
# "position_qty": -5,
|
2640
|
+
# "settle_price": 27865.8716984,
|
2641
|
+
# "symbol": "PERP_BTC_USDC",
|
2642
|
+
# "timestamp": 1685429350571,
|
2643
|
+
# "unsettled_pnl": 354.858492
|
2644
|
+
# }]
|
2645
|
+
# }
|
2646
|
+
# }
|
2647
|
+
#
|
2648
|
+
result = self.safe_dict(response, 'data', {})
|
2649
|
+
positions = self.safe_list(result, 'rows', [])
|
2650
|
+
return self.parse_positions(positions, symbols)
|
2651
|
+
|
2652
|
+
def nonce(self):
|
2653
|
+
return self.milliseconds()
|
2654
|
+
|
2655
|
+
def sign(self, path, section='public', method='GET', params={}, headers=None, body=None):
|
2656
|
+
version = section[0]
|
2657
|
+
access = section[1]
|
2658
|
+
pathWithParams = self.implode_params(path, params)
|
2659
|
+
url = self.implode_hostname(self.urls['api'][access])
|
2660
|
+
url += '/' + version + '/'
|
2661
|
+
params = self.omit(params, self.extract_params(path))
|
2662
|
+
params = self.keysort(params)
|
2663
|
+
if access == 'public':
|
2664
|
+
url += pathWithParams
|
2665
|
+
if params:
|
2666
|
+
url += '?' + self.urlencode(params)
|
2667
|
+
else:
|
2668
|
+
self.check_required_credentials()
|
2669
|
+
isPostOrPut = method == 'POST' or method == 'PUT'
|
2670
|
+
isOrder = path == 'algo/order' or path == 'order' or path == 'batch-order'
|
2671
|
+
if isPostOrPut and isOrder:
|
2672
|
+
isSandboxMode = self.safe_bool(self.options, 'sandboxMode', False)
|
2673
|
+
if not isSandboxMode:
|
2674
|
+
brokerId = self.safe_string(self.options, 'brokerId', 'CCXT')
|
2675
|
+
if path == 'batch-order':
|
2676
|
+
ordersList = self.safe_list(params, 'orders', [])
|
2677
|
+
for i in range(0, len(ordersList)):
|
2678
|
+
params['orders'][i]['order_tag'] = brokerId
|
2679
|
+
else:
|
2680
|
+
params['order_tag'] = brokerId
|
2681
|
+
params = self.keysort(params)
|
2682
|
+
auth = ''
|
2683
|
+
ts = str(self.nonce())
|
2684
|
+
url += pathWithParams
|
2685
|
+
apiKey = self.apiKey
|
2686
|
+
if apiKey.find('ed25519:') < 0:
|
2687
|
+
apiKey = 'ed25519:' + apiKey
|
2688
|
+
headers = {
|
2689
|
+
'orderly-account-id': self.accountId,
|
2690
|
+
'orderly-key': apiKey,
|
2691
|
+
'orderly-timestamp': ts,
|
2692
|
+
}
|
2693
|
+
auth = ts + method + '/' + version + '/' + pathWithParams
|
2694
|
+
if method == 'POST' or method == 'PUT':
|
2695
|
+
body = self.json(params)
|
2696
|
+
auth += body
|
2697
|
+
headers['content-type'] = 'application/json'
|
2698
|
+
else:
|
2699
|
+
if params:
|
2700
|
+
url += '?' + self.urlencode(params)
|
2701
|
+
auth += '?' + self.rawencode(params)
|
2702
|
+
headers['content-type'] = 'application/x-www-form-urlencoded'
|
2703
|
+
if method == 'DELETE':
|
2704
|
+
body = ''
|
2705
|
+
secret = self.secret
|
2706
|
+
if secret.find('ed25519:') >= 0:
|
2707
|
+
parts = secret.split('ed25519:')
|
2708
|
+
secret = parts[1]
|
2709
|
+
signature = self.eddsa(self.encode(auth), self.base58_to_binary(secret), 'ed25519')
|
2710
|
+
headers['orderly-signature'] = self.urlencode_base64(self.base64_to_binary(signature))
|
2711
|
+
return {'url': url, 'method': method, 'body': body, 'headers': headers}
|
2712
|
+
|
2713
|
+
def handle_errors(self, httpCode: int, reason: str, url: str, method: str, headers: dict, body: str, response, requestHeaders, requestBody):
|
2714
|
+
if not response:
|
2715
|
+
return None # fallback to default error handler
|
2716
|
+
#
|
2717
|
+
# 400 Bad Request {"success":false,"code":-1012,"message":"Amount is required for buy market orders when margin disabled."}
|
2718
|
+
# {"code":"-1011","message":"The system is under maintenance.","success":false}
|
2719
|
+
#
|
2720
|
+
success = self.safe_bool(response, 'success')
|
2721
|
+
errorCode = self.safe_string(response, 'code')
|
2722
|
+
if not success:
|
2723
|
+
feedback = self.id + ' ' + self.json(response)
|
2724
|
+
self.throw_broadly_matched_exception(self.exceptions['broad'], body, feedback)
|
2725
|
+
self.throw_exactly_matched_exception(self.exceptions['exact'], errorCode, feedback)
|
2726
|
+
raise ExchangeError(feedback)
|
2727
|
+
return None
|