ccxt-ir 4.3.46.0.3__py2.py3-none-any.whl → 4.5.1__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.
Files changed (529) hide show
  1. ccxt/__init__.py +39 -35
  2. ccxt/abantether.py +8 -8
  3. ccxt/abstract/alpaca.py +4 -0
  4. ccxt/abstract/apex.py +31 -0
  5. ccxt/abstract/bigone.py +1 -1
  6. ccxt/abstract/binance.py +106 -48
  7. ccxt/abstract/binancecoinm.py +106 -48
  8. ccxt/abstract/binanceus.py +141 -83
  9. ccxt/abstract/binanceusdm.py +106 -48
  10. ccxt/abstract/bingx.py +50 -1
  11. ccxt/abstract/bitbank.py +5 -0
  12. ccxt/abstract/bitfinex.py +136 -65
  13. ccxt/abstract/bitflyer.py +1 -0
  14. ccxt/abstract/bitget.py +67 -0
  15. ccxt/abstract/bitmart.py +19 -1
  16. ccxt/abstract/bitopro.py +1 -0
  17. ccxt/abstract/bitrue.py +68 -68
  18. ccxt/abstract/bitstamp.py +1 -0
  19. ccxt/abstract/blofin.py +30 -0
  20. ccxt/abstract/btcbox.py +2 -0
  21. ccxt/abstract/bybit.py +28 -13
  22. ccxt/abstract/cex.py +28 -29
  23. ccxt/abstract/coinbaseexchange.py +1 -0
  24. ccxt/abstract/coinbaseinternational.py +1 -1
  25. ccxt/abstract/cryptocom.py +16 -0
  26. ccxt/abstract/cryptomus.py +20 -0
  27. ccxt/abstract/defx.py +69 -0
  28. ccxt/abstract/deribit.py +1 -0
  29. ccxt/abstract/derive.py +117 -0
  30. ccxt/abstract/digifinex.py +1 -0
  31. ccxt/abstract/ellipx.py +25 -0
  32. ccxt/abstract/foxbit.py +26 -0
  33. ccxt/abstract/gate.py +19 -0
  34. ccxt/abstract/gateio.py +19 -0
  35. ccxt/abstract/gemini.py +1 -0
  36. ccxt/abstract/hibachi.py +26 -0
  37. ccxt/abstract/hyperliquid.py +1 -1
  38. ccxt/abstract/independentreserve.py +6 -0
  39. ccxt/abstract/kraken.py +1 -0
  40. ccxt/abstract/krakenfutures.py +4 -0
  41. ccxt/abstract/kucoin.py +10 -0
  42. ccxt/abstract/kucoinfutures.py +18 -0
  43. ccxt/abstract/lbank.py +2 -1
  44. ccxt/abstract/luno.py +1 -0
  45. ccxt/abstract/mexc.py +2 -0
  46. ccxt/abstract/modetrade.py +119 -0
  47. ccxt/abstract/myokx.py +349 -0
  48. ccxt/abstract/oceanex.py +5 -0
  49. ccxt/abstract/okx.py +25 -0
  50. ccxt/abstract/okxus.py +349 -0
  51. ccxt/abstract/onetrading.py +0 -12
  52. ccxt/abstract/paradex.py +23 -0
  53. ccxt/abstract/phemex.py +2 -0
  54. ccxt/abstract/poloniex.py +36 -0
  55. ccxt/abstract/tradeogre.py +3 -1
  56. ccxt/abstract/upbit.py +51 -34
  57. ccxt/abstract/whitebit.py +16 -0
  58. ccxt/abstract/woo.py +64 -6
  59. ccxt/abstract/xt.py +10 -5
  60. ccxt/afratether.py +8 -8
  61. ccxt/alpaca.py +828 -51
  62. ccxt/apex.py +1875 -0
  63. ccxt/arzinja.py +7 -7
  64. ccxt/arzplus.py +9 -9
  65. ccxt/ascendex.py +501 -306
  66. ccxt/async_support/__init__.py +39 -35
  67. ccxt/async_support/abantether.py +8 -8
  68. ccxt/async_support/afratether.py +10 -10
  69. ccxt/async_support/alpaca.py +828 -51
  70. ccxt/async_support/apex.py +1875 -0
  71. ccxt/async_support/arzinja.py +10 -10
  72. ccxt/async_support/arzplus.py +12 -12
  73. ccxt/async_support/ascendex.py +502 -306
  74. ccxt/async_support/base/exchange.py +303 -89
  75. ccxt/async_support/base/ws/cache.py +9 -3
  76. ccxt/async_support/base/ws/client.py +173 -38
  77. ccxt/async_support/base/ws/future.py +25 -37
  78. ccxt/async_support/bequant.py +5 -3
  79. ccxt/async_support/bigone.py +279 -144
  80. ccxt/async_support/binance.py +2347 -1158
  81. ccxt/async_support/binancecoinm.py +9 -3
  82. ccxt/async_support/binanceus.py +17 -3
  83. ccxt/async_support/binanceusdm.py +9 -4
  84. ccxt/async_support/bingx.py +2962 -920
  85. ccxt/async_support/bit2c.py +147 -27
  86. ccxt/async_support/bitbank.py +151 -23
  87. ccxt/async_support/bitbns.py +104 -30
  88. ccxt/async_support/bitfinex.py +3291 -1113
  89. ccxt/async_support/bitflyer.py +202 -27
  90. ccxt/async_support/bitget.py +3683 -1538
  91. ccxt/async_support/bithumb.py +195 -38
  92. ccxt/async_support/bitimen.py +12 -12
  93. ccxt/async_support/bitir.py +38 -38
  94. ccxt/async_support/bitmart.py +1288 -350
  95. ccxt/async_support/bitmex.py +260 -75
  96. ccxt/async_support/bitopro.py +262 -62
  97. ccxt/async_support/bitpin.py +17 -16
  98. ccxt/async_support/bitrue.py +459 -290
  99. ccxt/async_support/bitso.py +199 -54
  100. ccxt/async_support/bitstamp.py +230 -96
  101. ccxt/async_support/bitteam.py +167 -25
  102. ccxt/async_support/{huobijp.py → bittrade.py} +158 -30
  103. ccxt/async_support/bitvavo.py +213 -49
  104. ccxt/async_support/blockchaincom.py +160 -46
  105. ccxt/async_support/blofin.py +502 -120
  106. ccxt/async_support/btcalpha.py +169 -31
  107. ccxt/async_support/btcbox.py +292 -23
  108. ccxt/async_support/btcmarkets.py +211 -58
  109. ccxt/async_support/btcturk.py +161 -38
  110. ccxt/async_support/bybit.py +1775 -1030
  111. ccxt/async_support/cex.py +1440 -1303
  112. ccxt/async_support/coinbase.py +724 -212
  113. ccxt/async_support/coinbaseadvanced.py +2 -1
  114. ccxt/async_support/coinbaseexchange.py +388 -89
  115. ccxt/async_support/coinbaseinternational.py +412 -57
  116. ccxt/async_support/coincatch.py +177 -78
  117. ccxt/async_support/coincheck.py +135 -19
  118. ccxt/async_support/coinex.py +606 -232
  119. ccxt/async_support/coinmate.py +189 -63
  120. ccxt/async_support/coinmetro.py +195 -54
  121. ccxt/async_support/coinone.py +158 -51
  122. ccxt/async_support/coinsph.py +336 -61
  123. ccxt/async_support/coinspot.py +151 -52
  124. ccxt/async_support/cryptocom.py +661 -111
  125. ccxt/async_support/cryptomus.py +1137 -0
  126. ccxt/async_support/defx.py +2071 -0
  127. ccxt/async_support/delta.py +299 -99
  128. ccxt/async_support/deribit.py +348 -126
  129. ccxt/async_support/derive.py +2572 -0
  130. ccxt/async_support/digifinex.py +430 -214
  131. ccxt/async_support/ellipx.py +2029 -0
  132. ccxt/async_support/eterex.py +10 -10
  133. ccxt/async_support/excoino.py +31 -31
  134. ccxt/async_support/exir.py +14 -14
  135. ccxt/async_support/exmo.py +344 -131
  136. ccxt/async_support/exnovin.py +10 -10
  137. ccxt/async_support/farhadexchange.py +12 -12
  138. ccxt/async_support/fmfwio.py +2 -1
  139. ccxt/async_support/foxbit.py +1935 -0
  140. ccxt/async_support/gate.py +1351 -529
  141. ccxt/async_support/gateio.py +2 -1
  142. ccxt/async_support/gemini.py +144 -39
  143. ccxt/async_support/hashkey.py +152 -109
  144. ccxt/async_support/hibachi.py +2080 -0
  145. ccxt/async_support/hitbtc.py +395 -167
  146. ccxt/async_support/hitobit.py +12 -12
  147. ccxt/async_support/hollaex.py +307 -119
  148. ccxt/async_support/htx.py +851 -383
  149. ccxt/async_support/huobi.py +2 -1
  150. ccxt/async_support/hyperliquid.py +1848 -536
  151. ccxt/async_support/independentreserve.py +288 -15
  152. ccxt/async_support/indodax.py +190 -33
  153. ccxt/async_support/jibitex.py +12 -12
  154. ccxt/async_support/kraken.py +795 -351
  155. ccxt/async_support/krakenfutures.py +214 -62
  156. ccxt/async_support/kucoin.py +715 -396
  157. ccxt/async_support/kucoinfutures.py +652 -89
  158. ccxt/async_support/latoken.py +217 -113
  159. ccxt/async_support/lbank.py +425 -97
  160. ccxt/async_support/luno.py +382 -35
  161. ccxt/async_support/mercado.py +113 -6
  162. ccxt/async_support/mexc.py +874 -437
  163. ccxt/async_support/modetrade.py +2818 -0
  164. ccxt/async_support/myokx.py +54 -0
  165. ccxt/async_support/ndax.py +221 -64
  166. ccxt/async_support/nobitex.py +32 -38
  167. ccxt/async_support/novadax.py +190 -34
  168. ccxt/async_support/oceanex.py +217 -28
  169. ccxt/async_support/okcoin.py +253 -145
  170. ccxt/async_support/okexchange.py +11 -11
  171. ccxt/async_support/okx.py +1088 -351
  172. ccxt/async_support/okxus.py +54 -0
  173. ccxt/async_support/ompfinex.py +32 -27
  174. ccxt/async_support/onetrading.py +213 -392
  175. ccxt/async_support/oxfun.py +245 -166
  176. ccxt/async_support/p2b.py +151 -29
  177. ccxt/async_support/paradex.py +562 -49
  178. ccxt/async_support/paymium.py +82 -19
  179. ccxt/async_support/phemex.py +713 -172
  180. ccxt/async_support/poloniex.py +1602 -283
  181. ccxt/async_support/probit.py +224 -95
  182. ccxt/async_support/ramzinex.py +34 -30
  183. ccxt/async_support/sarmayex.py +9 -9
  184. ccxt/async_support/sarrafex.py +13 -13
  185. ccxt/async_support/tabdeal.py +15 -14
  186. ccxt/async_support/tetherland.py +9 -9
  187. ccxt/async_support/timex.py +210 -51
  188. ccxt/async_support/tokocrypto.py +167 -47
  189. ccxt/async_support/tradeogre.py +266 -31
  190. ccxt/async_support/twox.py +9 -9
  191. ccxt/async_support/ubitex.py +12 -12
  192. ccxt/async_support/upbit.py +568 -165
  193. ccxt/async_support/vertex.py +160 -32
  194. ccxt/async_support/wallex.py +12 -12
  195. ccxt/async_support/wavesexchange.py +165 -30
  196. ccxt/async_support/whitebit.py +975 -127
  197. ccxt/async_support/woo.py +1918 -1016
  198. ccxt/async_support/woofipro.py +433 -141
  199. ccxt/async_support/xt.py +649 -193
  200. ccxt/async_support/yobit.py +195 -70
  201. ccxt/async_support/zaif.py +91 -15
  202. ccxt/async_support/zonda.py +151 -36
  203. ccxt/base/decimal_to_precision.py +14 -10
  204. ccxt/base/errors.py +49 -18
  205. ccxt/base/exchange.py +1556 -450
  206. ccxt/base/precise.py +10 -0
  207. ccxt/base/types.py +114 -6
  208. ccxt/bequant.py +5 -3
  209. ccxt/bigone.py +279 -144
  210. ccxt/binance.py +2347 -1158
  211. ccxt/binancecoinm.py +9 -3
  212. ccxt/binanceus.py +17 -3
  213. ccxt/binanceusdm.py +9 -4
  214. ccxt/bingx.py +2962 -920
  215. ccxt/bit2c.py +147 -27
  216. ccxt/bitbank.py +151 -23
  217. ccxt/bitbns.py +104 -30
  218. ccxt/bitfinex.py +3290 -1113
  219. ccxt/bitflyer.py +202 -27
  220. ccxt/bitget.py +3683 -1538
  221. ccxt/bithumb.py +194 -38
  222. ccxt/bitimen.py +9 -9
  223. ccxt/bitir.py +35 -35
  224. ccxt/bitmart.py +1288 -350
  225. ccxt/bitmex.py +260 -75
  226. ccxt/bitopro.py +262 -62
  227. ccxt/bitpin.py +15 -14
  228. ccxt/bitrue.py +459 -290
  229. ccxt/bitso.py +199 -54
  230. ccxt/bitstamp.py +230 -96
  231. ccxt/bitteam.py +167 -25
  232. ccxt/{huobijp.py → bittrade.py} +158 -30
  233. ccxt/bitvavo.py +213 -49
  234. ccxt/blockchaincom.py +160 -46
  235. ccxt/blofin.py +502 -120
  236. ccxt/btcalpha.py +169 -31
  237. ccxt/btcbox.py +291 -23
  238. ccxt/btcmarkets.py +211 -58
  239. ccxt/btcturk.py +161 -38
  240. ccxt/bybit.py +1775 -1030
  241. ccxt/cex.py +1439 -1303
  242. ccxt/coinbase.py +724 -212
  243. ccxt/coinbaseadvanced.py +2 -1
  244. ccxt/coinbaseexchange.py +388 -89
  245. ccxt/coinbaseinternational.py +412 -57
  246. ccxt/coincatch.py +177 -78
  247. ccxt/coincheck.py +135 -19
  248. ccxt/coinex.py +606 -232
  249. ccxt/coinmate.py +189 -63
  250. ccxt/coinmetro.py +194 -54
  251. ccxt/coinone.py +158 -51
  252. ccxt/coinsph.py +336 -61
  253. ccxt/coinspot.py +151 -52
  254. ccxt/cryptocom.py +661 -111
  255. ccxt/cryptomus.py +1137 -0
  256. ccxt/defx.py +2070 -0
  257. ccxt/delta.py +299 -99
  258. ccxt/deribit.py +348 -126
  259. ccxt/derive.py +2571 -0
  260. ccxt/digifinex.py +430 -214
  261. ccxt/ellipx.py +2029 -0
  262. ccxt/eterex.py +7 -7
  263. ccxt/excoino.py +29 -29
  264. ccxt/exir.py +11 -11
  265. ccxt/exmo.py +343 -131
  266. ccxt/exnovin.py +8 -8
  267. ccxt/farhadexchange.py +10 -10
  268. ccxt/fmfwio.py +2 -1
  269. ccxt/foxbit.py +1935 -0
  270. ccxt/gate.py +1351 -529
  271. ccxt/gateio.py +2 -1
  272. ccxt/gemini.py +144 -39
  273. ccxt/hashkey.py +152 -109
  274. ccxt/hibachi.py +2079 -0
  275. ccxt/hitbtc.py +395 -167
  276. ccxt/hitobit.py +9 -9
  277. ccxt/hollaex.py +307 -119
  278. ccxt/htx.py +851 -383
  279. ccxt/huobi.py +2 -1
  280. ccxt/hyperliquid.py +1848 -536
  281. ccxt/independentreserve.py +287 -15
  282. ccxt/indodax.py +190 -33
  283. ccxt/jibitex.py +9 -9
  284. ccxt/kraken.py +794 -351
  285. ccxt/krakenfutures.py +214 -62
  286. ccxt/kucoin.py +715 -396
  287. ccxt/kucoinfutures.py +652 -89
  288. ccxt/latoken.py +217 -113
  289. ccxt/lbank.py +425 -97
  290. ccxt/luno.py +382 -35
  291. ccxt/mercado.py +113 -6
  292. ccxt/mexc.py +873 -437
  293. ccxt/modetrade.py +2818 -0
  294. ccxt/myokx.py +54 -0
  295. ccxt/ndax.py +221 -64
  296. ccxt/nobitex.py +30 -36
  297. ccxt/novadax.py +190 -34
  298. ccxt/oceanex.py +217 -28
  299. ccxt/okcoin.py +253 -145
  300. ccxt/okexchange.py +9 -9
  301. ccxt/okx.py +1088 -351
  302. ccxt/okxus.py +54 -0
  303. ccxt/ompfinex.py +29 -24
  304. ccxt/onetrading.py +213 -392
  305. ccxt/oxfun.py +245 -166
  306. ccxt/p2b.py +151 -29
  307. ccxt/paradex.py +562 -49
  308. ccxt/paymium.py +82 -19
  309. ccxt/phemex.py +712 -172
  310. ccxt/poloniex.py +1601 -283
  311. ccxt/pro/__init__.py +76 -17
  312. ccxt/pro/alpaca.py +21 -6
  313. ccxt/pro/apex.py +984 -0
  314. ccxt/pro/ascendex.py +58 -10
  315. ccxt/pro/bequant.py +6 -1
  316. ccxt/pro/binance.py +728 -156
  317. ccxt/pro/binancecoinm.py +6 -2
  318. ccxt/pro/binanceus.py +8 -4
  319. ccxt/pro/binanceusdm.py +7 -2
  320. ccxt/pro/bingx.py +333 -142
  321. ccxt/pro/bitfinex.py +727 -262
  322. ccxt/pro/bitget.py +570 -79
  323. ccxt/pro/bithumb.py +20 -6
  324. ccxt/pro/bitmart.py +216 -87
  325. ccxt/pro/bitmex.py +47 -9
  326. ccxt/pro/bitopro.py +26 -14
  327. ccxt/pro/bitrue.py +22 -22
  328. ccxt/pro/bitstamp.py +54 -21
  329. ccxt/pro/{huobijp.py → bittrade.py} +7 -6
  330. ccxt/pro/bitvavo.py +191 -67
  331. ccxt/pro/blockchaincom.py +21 -8
  332. ccxt/pro/blofin.py +9 -1
  333. ccxt/pro/bybit.py +632 -245
  334. ccxt/pro/cex.py +59 -24
  335. ccxt/pro/coinbase.py +102 -73
  336. ccxt/pro/coinbaseadvanced.py +2 -1
  337. ccxt/pro/coinbaseexchange.py +8 -8
  338. ccxt/pro/coinbaseinternational.py +181 -25
  339. ccxt/pro/coincatch.py +6 -7
  340. ccxt/pro/coincheck.py +11 -6
  341. ccxt/pro/coinex.py +967 -665
  342. ccxt/pro/coinone.py +16 -9
  343. ccxt/pro/cryptocom.py +448 -45
  344. ccxt/pro/defx.py +831 -0
  345. ccxt/pro/deribit.py +150 -14
  346. ccxt/pro/derive.py +704 -0
  347. ccxt/pro/exmo.py +239 -6
  348. ccxt/pro/gate.py +623 -65
  349. ccxt/pro/gateio.py +2 -1
  350. ccxt/pro/gemini.py +27 -11
  351. ccxt/pro/hashkey.py +2 -2
  352. ccxt/pro/hitbtc.py +196 -91
  353. ccxt/pro/hollaex.py +23 -7
  354. ccxt/pro/htx.py +51 -14
  355. ccxt/pro/huobi.py +2 -1
  356. ccxt/pro/hyperliquid.py +591 -27
  357. ccxt/pro/independentreserve.py +9 -6
  358. ccxt/pro/kraken.py +640 -320
  359. ccxt/pro/krakenfutures.py +62 -35
  360. ccxt/pro/kucoin.py +267 -46
  361. ccxt/pro/kucoinfutures.py +165 -21
  362. ccxt/pro/lbank.py +102 -21
  363. ccxt/pro/luno.py +12 -8
  364. ccxt/pro/mexc.py +877 -111
  365. ccxt/pro/modetrade.py +1271 -0
  366. ccxt/pro/myokx.py +38 -0
  367. ccxt/pro/ndax.py +15 -2
  368. ccxt/pro/okcoin.py +23 -4
  369. ccxt/pro/okx.py +573 -98
  370. ccxt/pro/okxus.py +38 -0
  371. ccxt/pro/onetrading.py +30 -13
  372. ccxt/pro/oxfun.py +131 -27
  373. ccxt/pro/p2b.py +88 -22
  374. ccxt/pro/paradex.py +3 -3
  375. ccxt/pro/phemex.py +75 -21
  376. ccxt/pro/poloniex.py +124 -41
  377. ccxt/pro/probit.py +87 -80
  378. ccxt/pro/tradeogre.py +272 -0
  379. ccxt/pro/upbit.py +152 -12
  380. ccxt/pro/vertex.py +8 -3
  381. ccxt/pro/whitebit.py +58 -5
  382. ccxt/pro/woo.py +228 -37
  383. ccxt/pro/woofipro.py +106 -18
  384. ccxt/pro/xt.py +111 -5
  385. ccxt/probit.py +224 -95
  386. ccxt/protobuf/__init__.py +0 -0
  387. ccxt/protobuf/mexc/PrivateAccountV3Api_pb2.py +37 -0
  388. ccxt/protobuf/mexc/PrivateDealsV3Api_pb2.py +37 -0
  389. ccxt/protobuf/mexc/PrivateOrdersV3Api_pb2.py +37 -0
  390. ccxt/protobuf/mexc/PublicAggreBookTickerV3Api_pb2.py +37 -0
  391. ccxt/protobuf/mexc/PublicAggreDealsV3Api_pb2.py +39 -0
  392. ccxt/protobuf/mexc/PublicAggreDepthsV3Api_pb2.py +39 -0
  393. ccxt/protobuf/mexc/PublicBookTickerBatchV3Api_pb2.py +38 -0
  394. ccxt/protobuf/mexc/PublicBookTickerV3Api_pb2.py +37 -0
  395. ccxt/protobuf/mexc/PublicDealsV3Api_pb2.py +39 -0
  396. ccxt/protobuf/mexc/PublicIncreaseDepthsBatchV3Api_pb2.py +38 -0
  397. ccxt/protobuf/mexc/PublicIncreaseDepthsV3Api_pb2.py +39 -0
  398. ccxt/protobuf/mexc/PublicLimitDepthsV3Api_pb2.py +39 -0
  399. ccxt/protobuf/mexc/PublicMiniTickerV3Api_pb2.py +37 -0
  400. ccxt/protobuf/mexc/PublicMiniTickersV3Api_pb2.py +38 -0
  401. ccxt/protobuf/mexc/PublicSpotKlineV3Api_pb2.py +37 -0
  402. ccxt/protobuf/mexc/PushDataV3ApiWrapper_pb2.py +52 -0
  403. ccxt/protobuf/mexc/__init__.py +0 -0
  404. ccxt/ramzinex.py +32 -28
  405. ccxt/sarmayex.py +7 -7
  406. ccxt/sarrafex.py +10 -10
  407. ccxt/static_dependencies/__init__.py +1 -1
  408. ccxt/static_dependencies/lark/py.typed +0 -0
  409. ccxt/static_dependencies/marshmallow/py.typed +0 -0
  410. ccxt/static_dependencies/marshmallow_dataclass/py.typed +0 -0
  411. ccxt/static_dependencies/marshmallow_oneofschema/py.typed +0 -0
  412. ccxt/tabdeal.py +13 -12
  413. ccxt/test/tests_async.py +261 -57
  414. ccxt/test/tests_helpers.py +1 -3
  415. ccxt/test/tests_init.py +4 -3
  416. ccxt/test/tests_sync.py +261 -57
  417. ccxt/tetherland.py +7 -7
  418. ccxt/timex.py +210 -51
  419. ccxt/tokocrypto.py +167 -47
  420. ccxt/tradeogre.py +266 -31
  421. ccxt/twox.py +7 -7
  422. ccxt/ubitex.py +9 -9
  423. ccxt/upbit.py +568 -165
  424. ccxt/vertex.py +160 -32
  425. ccxt/wallex.py +9 -9
  426. ccxt/wavesexchange.py +165 -30
  427. ccxt/whitebit.py +975 -127
  428. ccxt/woo.py +1917 -1016
  429. ccxt/woofipro.py +432 -141
  430. ccxt/xt.py +649 -193
  431. ccxt/yobit.py +194 -70
  432. ccxt/zaif.py +91 -15
  433. ccxt/zonda.py +151 -36
  434. {ccxt_ir-4.3.46.0.3.dist-info → ccxt_ir-4.5.1.dist-info}/METADATA +225 -73
  435. ccxt_ir-4.5.1.dist-info/RECORD +743 -0
  436. {ccxt_ir-4.3.46.0.3.dist-info → ccxt_ir-4.5.1.dist-info}/WHEEL +1 -1
  437. ccxt/__test__.py +0 -7
  438. ccxt/abstract/ace.py +0 -15
  439. ccxt/abstract/bitbay.py +0 -53
  440. ccxt/abstract/bitcoincom.py +0 -115
  441. ccxt/abstract/bitfinex2.py +0 -139
  442. ccxt/abstract/bitpanda.py +0 -35
  443. ccxt/abstract/bl3p.py +0 -19
  444. ccxt/abstract/coinlist.py +0 -54
  445. ccxt/abstract/currencycom.py +0 -68
  446. ccxt/abstract/hitbtc3.py +0 -115
  447. ccxt/abstract/idex.py +0 -26
  448. ccxt/abstract/kuna.py +0 -182
  449. ccxt/abstract/lykke.py +0 -29
  450. ccxt/abstract/poloniexfutures.py +0 -48
  451. ccxt/abstract/wazirx.py +0 -30
  452. ccxt/ace.py +0 -1012
  453. ccxt/async_support/ace.py +0 -1012
  454. ccxt/async_support/base/ws/aiohttp_client.py +0 -125
  455. ccxt/async_support/base/ws/fast_client.py +0 -96
  456. ccxt/async_support/bitbay.py +0 -17
  457. ccxt/async_support/bitcoincom.py +0 -17
  458. ccxt/async_support/bitfinex2.py +0 -3552
  459. ccxt/async_support/bitpanda.py +0 -16
  460. ccxt/async_support/bl3p.py +0 -485
  461. ccxt/async_support/coinlist.py +0 -2243
  462. ccxt/async_support/currencycom.py +0 -1950
  463. ccxt/async_support/hitbtc3.py +0 -16
  464. ccxt/async_support/idex.py +0 -1766
  465. ccxt/async_support/kuna.py +0 -1841
  466. ccxt/async_support/lykke.py +0 -1270
  467. ccxt/async_support/poloniexfutures.py +0 -1717
  468. ccxt/async_support/wazirx.py +0 -1224
  469. ccxt/bitbay.py +0 -17
  470. ccxt/bitcoincom.py +0 -17
  471. ccxt/bitfinex2.py +0 -3552
  472. ccxt/bitpanda.py +0 -16
  473. ccxt/bl3p.py +0 -485
  474. ccxt/coinlist.py +0 -2243
  475. ccxt/currencycom.py +0 -1950
  476. ccxt/hitbtc3.py +0 -16
  477. ccxt/idex.py +0 -1766
  478. ccxt/kuna.py +0 -1841
  479. ccxt/lykke.py +0 -1270
  480. ccxt/poloniexfutures.py +0 -1717
  481. ccxt/pro/bitcoincom.py +0 -34
  482. ccxt/pro/bitfinex2.py +0 -1083
  483. ccxt/pro/bitpanda.py +0 -15
  484. ccxt/pro/currencycom.py +0 -536
  485. ccxt/pro/idex.py +0 -672
  486. ccxt/pro/poloniexfutures.py +0 -990
  487. ccxt/pro/wazirx.py +0 -749
  488. ccxt/test/base/__init__.py +0 -29
  489. ccxt/test/base/test_account.py +0 -26
  490. ccxt/test/base/test_balance.py +0 -56
  491. ccxt/test/base/test_borrow_interest.py +0 -35
  492. ccxt/test/base/test_borrow_rate.py +0 -32
  493. ccxt/test/base/test_calculate_fee.py +0 -51
  494. ccxt/test/base/test_crypto.py +0 -127
  495. ccxt/test/base/test_currency.py +0 -76
  496. ccxt/test/base/test_datetime.py +0 -109
  497. ccxt/test/base/test_decimal_to_precision.py +0 -392
  498. ccxt/test/base/test_deep_extend.py +0 -68
  499. ccxt/test/base/test_deposit_withdrawal.py +0 -50
  500. ccxt/test/base/test_exchange_datetime_functions.py +0 -76
  501. ccxt/test/base/test_funding_rate_history.py +0 -29
  502. ccxt/test/base/test_last_price.py +0 -31
  503. ccxt/test/base/test_ledger_entry.py +0 -45
  504. ccxt/test/base/test_ledger_item.py +0 -48
  505. ccxt/test/base/test_leverage_tier.py +0 -33
  506. ccxt/test/base/test_liquidation.py +0 -50
  507. ccxt/test/base/test_margin_mode.py +0 -24
  508. ccxt/test/base/test_margin_modification.py +0 -35
  509. ccxt/test/base/test_market.py +0 -193
  510. ccxt/test/base/test_number.py +0 -411
  511. ccxt/test/base/test_ohlcv.py +0 -33
  512. ccxt/test/base/test_open_interest.py +0 -32
  513. ccxt/test/base/test_order.py +0 -64
  514. ccxt/test/base/test_order_book.py +0 -69
  515. ccxt/test/base/test_position.py +0 -60
  516. ccxt/test/base/test_shared_methods.py +0 -353
  517. ccxt/test/base/test_status.py +0 -24
  518. ccxt/test/base/test_throttle.py +0 -126
  519. ccxt/test/base/test_ticker.py +0 -92
  520. ccxt/test/base/test_trade.py +0 -47
  521. ccxt/test/base/test_trading_fee.py +0 -26
  522. ccxt/test/base/test_transaction.py +0 -39
  523. ccxt/test/test_async.py +0 -1649
  524. ccxt/test/test_sync.py +0 -1648
  525. ccxt/wazirx.py +0 -1224
  526. ccxt_ir-4.3.46.0.3.dist-info/RECORD +0 -773
  527. /ccxt/abstract/{huobijp.py → bittrade.py} +0 -0
  528. {ccxt_ir-4.3.46.0.3.dist-info → ccxt_ir-4.5.1.dist-info/licenses}/LICENSE.txt +0 -0
  529. {ccxt_ir-4.3.46.0.3.dist-info → ccxt_ir-4.5.1.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,2818 @@
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': False,
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': True,
54
+ 'createMarketOrderWithCost': False,
55
+ 'createMarketSellOrderWithCost': False,
56
+ 'createOrder': True,
57
+ 'createOrderWithTakeProfitAndStopLoss': True,
58
+ 'createReduceOnlyOrder': True,
59
+ 'createStopLimitOrder': True,
60
+ 'createStopLossOrder': True,
61
+ 'createStopMarketOrder': True,
62
+ 'createStopOrder': True,
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': 'CCXTMODE',
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
+ def parse_income(self, income, market: Market = None):
1029
+ #
1030
+ # {
1031
+ # "symbol": "PERP_ETH_USDC",
1032
+ # "funding_rate": 0.00046875,
1033
+ # "mark_price": 2100,
1034
+ # "funding_fee": 0.000016,
1035
+ # "payment_type": "Pay",
1036
+ # "status": "Accrued",
1037
+ # "created_time": 1682235722003,
1038
+ # "updated_time": 1682235722003
1039
+ # }
1040
+ #
1041
+ marketId = self.safe_string(income, 'symbol')
1042
+ symbol = self.safe_symbol(marketId, market)
1043
+ amount = self.safe_string(income, 'funding_fee')
1044
+ code = self.safe_currency_code('USDC')
1045
+ timestamp = self.safe_integer(income, 'updated_time')
1046
+ rate = self.safe_number(income, 'funding_rate')
1047
+ paymentType = self.safe_string(income, 'payment_type')
1048
+ amount = Precise.string_neg(amount) if (paymentType == 'Pay') else amount
1049
+ return {
1050
+ 'info': income,
1051
+ 'symbol': symbol,
1052
+ 'code': code,
1053
+ 'timestamp': timestamp,
1054
+ 'datetime': self.iso8601(timestamp),
1055
+ 'id': None,
1056
+ 'amount': self.parse_number(amount),
1057
+ 'rate': rate,
1058
+ }
1059
+
1060
+ async def fetch_funding_history(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}):
1061
+ """
1062
+ fetch the history of funding payments paid and received on self account
1063
+
1064
+ https://orderly.network/docs/build-on-omnichain/evm-api/restful-api/private/get-funding-fee-history
1065
+
1066
+ :param str [symbol]: unified market symbol
1067
+ :param int [since]: the earliest time in ms to fetch funding history for
1068
+ :param int [limit]: the maximum number of funding history structures to retrieve
1069
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1070
+ :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)
1071
+ :returns dict: a `funding history structure <https://docs.ccxt.com/#/?id=funding-history-structure>`
1072
+ """
1073
+ await self.load_markets()
1074
+ paginate = False
1075
+ paginate, params = self.handle_option_and_params(params, 'fetchFundingHistory', 'paginate')
1076
+ if paginate:
1077
+ return await self.fetch_paginated_call_incremental('fetchFundingHistory', symbol, since, limit, params, 'page', 500)
1078
+ request: dict = {}
1079
+ market: Market = None
1080
+ if symbol is not None:
1081
+ market = self.market(symbol)
1082
+ request['symbol'] = market['id']
1083
+ if since is not None:
1084
+ request['start_t'] = since
1085
+ until = self.safe_integer(params, 'until') # unified in milliseconds
1086
+ params = self.omit(params, ['until'])
1087
+ if until is not None:
1088
+ request['end_t'] = until
1089
+ if limit is not None:
1090
+ request['size'] = min(limit, 500)
1091
+ response = await self.v1PrivateGetFundingFeeHistory(self.extend(request, params))
1092
+ #
1093
+ # {
1094
+ # "success": True,
1095
+ # "timestamp": 1702989203989,
1096
+ # "data": {
1097
+ # "meta": {
1098
+ # "total": 9,
1099
+ # "records_per_page": 25,
1100
+ # "current_page": 1
1101
+ # },
1102
+ # "rows": [{
1103
+ # "symbol": "PERP_ETH_USDC",
1104
+ # "funding_rate": 0.00046875,
1105
+ # "mark_price": 2100,
1106
+ # "funding_fee": 0.000016,
1107
+ # "payment_type": "Pay",
1108
+ # "status": "Accrued",
1109
+ # "created_time": 1682235722003,
1110
+ # "updated_time": 1682235722003
1111
+ # }]
1112
+ # }
1113
+ # }
1114
+ #
1115
+ data = self.safe_dict(response, 'data', {})
1116
+ rows = self.safe_list(data, 'rows', [])
1117
+ return self.parse_incomes(rows, market, since, limit)
1118
+
1119
+ async def fetch_trading_fees(self, params={}) -> TradingFees:
1120
+ """
1121
+ fetch the trading fees for multiple markets
1122
+
1123
+ https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-account-information
1124
+
1125
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1126
+ :returns dict: a dictionary of `fee structures <https://docs.ccxt.com/#/?id=fee-structure>` indexed by market symbols
1127
+ """
1128
+ await self.load_markets()
1129
+ response = await self.v1PrivateGetClientInfo(params)
1130
+ #
1131
+ # {
1132
+ # "success": True,
1133
+ # "timestamp": 1702989203989,
1134
+ # "data": {
1135
+ # "account_id": "<string>",
1136
+ # "email": "test@test.com",
1137
+ # "account_mode": "FUTURES",
1138
+ # "max_leverage": 20,
1139
+ # "taker_fee_rate": 123,
1140
+ # "maker_fee_rate": 123,
1141
+ # "futures_taker_fee_rate": 123,
1142
+ # "futures_maker_fee_rate": 123,
1143
+ # "maintenance_cancel_orders": True,
1144
+ # "imr_factor": {
1145
+ # "PERP_BTC_USDC": 123,
1146
+ # "PERP_ETH_USDC": 123,
1147
+ # "PERP_NEAR_USDC": 123
1148
+ # },
1149
+ # "max_notional": {
1150
+ # "PERP_BTC_USDC": 123,
1151
+ # "PERP_ETH_USDC": 123,
1152
+ # "PERP_NEAR_USDC": 123
1153
+ # }
1154
+ # }
1155
+ # }
1156
+ #
1157
+ data = self.safe_dict(response, 'data', {})
1158
+ maker = self.safe_string(data, 'futures_maker_fee_rate')
1159
+ taker = self.safe_string(data, 'futures_taker_fee_rate')
1160
+ result: dict = {}
1161
+ for i in range(0, len(self.symbols)):
1162
+ symbol = self.symbols[i]
1163
+ result[symbol] = {
1164
+ 'info': response,
1165
+ 'symbol': symbol,
1166
+ 'maker': self.parse_number(Precise.string_div(maker, '10000')),
1167
+ 'taker': self.parse_number(Precise.string_div(taker, '10000')),
1168
+ 'percentage': True,
1169
+ 'tierBased': True,
1170
+ }
1171
+ return result
1172
+
1173
+ async def fetch_order_book(self, symbol: str, limit: Int = None, params={}) -> OrderBook:
1174
+ """
1175
+ fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
1176
+
1177
+ https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/orderbook-snapshot
1178
+
1179
+ :param str symbol: unified symbol of the market to fetch the order book for
1180
+ :param int [limit]: the maximum amount of order book entries to return
1181
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1182
+ :returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
1183
+ """
1184
+ await self.load_markets()
1185
+ market = self.market(symbol)
1186
+ request: dict = {
1187
+ 'symbol': market['id'],
1188
+ }
1189
+ if limit is not None:
1190
+ limit = min(limit, 1000)
1191
+ request['max_level'] = limit
1192
+ response = await self.v1PrivateGetOrderbookSymbol(self.extend(request, params))
1193
+ #
1194
+ # {
1195
+ # "success": True,
1196
+ # "timestamp": 1702989203989,
1197
+ # "data": {
1198
+ # "asks": [{
1199
+ # "price": 10669.4,
1200
+ # "quantity": 1.56263218
1201
+ # }],
1202
+ # "bids": [{
1203
+ # "price": 10669.4,
1204
+ # "quantity": 1.56263218
1205
+ # }],
1206
+ # "timestamp": 123
1207
+ # }
1208
+ # }
1209
+ #
1210
+ data = self.safe_dict(response, 'data', {})
1211
+ timestamp = self.safe_integer(data, 'timestamp')
1212
+ return self.parse_order_book(data, symbol, timestamp, 'bids', 'asks', 'price', 'quantity')
1213
+
1214
+ def parse_ohlcv(self, ohlcv, market: Market = None) -> list:
1215
+ return [
1216
+ self.safe_integer(ohlcv, 'start_timestamp'),
1217
+ self.safe_number(ohlcv, 'open'),
1218
+ self.safe_number(ohlcv, 'high'),
1219
+ self.safe_number(ohlcv, 'low'),
1220
+ self.safe_number(ohlcv, 'close'),
1221
+ self.safe_number(ohlcv, 'volume'),
1222
+ ]
1223
+
1224
+ async def fetch_ohlcv(self, symbol: str, timeframe='1m', since: Int = None, limit: Int = None, params={}) -> List[list]:
1225
+ """
1226
+
1227
+ https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-kline
1228
+
1229
+ fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
1230
+ :param str symbol: unified symbol of the market to fetch OHLCV data for
1231
+ :param str timeframe: the length of time each candle represents
1232
+ :param int [since]: timestamp in ms of the earliest candle to fetch
1233
+ :param int [limit]: max=1000, max=100 when since is defined and is less than(now - (999 * (timeframe in ms)))
1234
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1235
+ :returns int[][]: A list of candles ordered, open, high, low, close, volume
1236
+ """
1237
+ await self.load_markets()
1238
+ market = self.market(symbol)
1239
+ request: dict = {
1240
+ 'symbol': market['id'],
1241
+ 'type': self.safe_string(self.timeframes, timeframe, timeframe),
1242
+ }
1243
+ if limit is not None:
1244
+ request['limit'] = min(limit, 1000)
1245
+ response = await self.v1PrivateGetKline(self.extend(request, params))
1246
+ data = self.safe_dict(response, 'data', {})
1247
+ #
1248
+ # {
1249
+ # "success": True,
1250
+ # "timestamp": 1702989203989,
1251
+ # "data": {
1252
+ # "rows": [{
1253
+ # "open": 66166.23,
1254
+ # "close": 66124.56,
1255
+ # "low": 66038.06,
1256
+ # "high": 66176.97,
1257
+ # "volume": 23.45528526,
1258
+ # "amount": 1550436.21725288,
1259
+ # "symbol": "PERP_BTC_USDC",
1260
+ # "type": "1m",
1261
+ # "start_timestamp": 1636388220000,
1262
+ # "end_timestamp": 1636388280000
1263
+ # }]
1264
+ # }
1265
+ # }
1266
+ #
1267
+ rows = self.safe_list(data, 'rows', [])
1268
+ return self.parse_ohlcvs(rows, market, timeframe, since, limit)
1269
+
1270
+ def parse_order(self, order: dict, market: Market = None) -> Order:
1271
+ #
1272
+ # Possible input functions:
1273
+ # * createOrder
1274
+ # * createOrders
1275
+ # * cancelOrder
1276
+ # * fetchOrder
1277
+ # * fetchOrders
1278
+ # isFromFetchOrder = ('order_tag' in order); TO_DO
1279
+ #
1280
+ # stop order after creating it:
1281
+ # {
1282
+ # "orderId": "1578938",
1283
+ # "clientOrderId": "0",
1284
+ # "algoType": "STOP_LOSS",
1285
+ # "quantity": "0.1"
1286
+ # }
1287
+ # stop order after fetching it:
1288
+ # {
1289
+ # "algoOrderId": "1578958",
1290
+ # "clientOrderId": "0",
1291
+ # "rootAlgoOrderId": "1578958",
1292
+ # "parentAlgoOrderId": "0",
1293
+ # "symbol": "SPOT_LTC_USDT",
1294
+ # "orderTag": "default",
1295
+ # "algoType": "STOP_LOSS",
1296
+ # "side": "BUY",
1297
+ # "quantity": "0.1",
1298
+ # "isTriggered": False,
1299
+ # "triggerPrice": "100",
1300
+ # "triggerStatus": "USELESS",
1301
+ # "type": "LIMIT",
1302
+ # "rootAlgoStatus": "CANCELLED",
1303
+ # "algoStatus": "CANCELLED",
1304
+ # "triggerPriceType": "MARKET_PRICE",
1305
+ # "price": "75",
1306
+ # "triggerTime": "0",
1307
+ # "totalExecutedQuantity": "0",
1308
+ # "averageExecutedPrice": "0",
1309
+ # "totalFee": "0",
1310
+ # "feeAsset": '',
1311
+ # "reduceOnly": False,
1312
+ # "createdTime": "1686149609.744",
1313
+ # "updatedTime": "1686149903.362"
1314
+ # }
1315
+ #
1316
+ timestamp = self.safe_integer_n(order, ['timestamp', 'created_time', 'createdTime'])
1317
+ orderId = self.safe_string_n(order, ['order_id', 'orderId', 'algoOrderId'])
1318
+ clientOrderId = self.omit_zero(self.safe_string_2(order, 'client_order_id', 'clientOrderId')) # Somehow, self always returns 0 for limit order
1319
+ marketId = self.safe_string(order, 'symbol')
1320
+ market = self.safe_market(marketId, market)
1321
+ symbol = market['symbol']
1322
+ price = self.safe_string_2(order, 'order_price', 'price')
1323
+ amount = self.safe_string_2(order, 'order_quantity', 'quantity') # This is base amount
1324
+ cost = self.safe_string_2(order, 'order_amount', 'amount') # This is quote amount
1325
+ orderType = self.safe_string_lower_2(order, 'order_type', 'type')
1326
+ status = self.safe_value_2(order, 'status', 'algoStatus')
1327
+ success = self.safe_bool(order, 'success')
1328
+ if success is not None:
1329
+ status = 'NEW' if (success) else 'REJECTED'
1330
+ side = self.safe_string_lower(order, 'side')
1331
+ filled = self.omit_zero(self.safe_value_2(order, 'executed', 'totalExecutedQuantity'))
1332
+ average = self.omit_zero(self.safe_string_2(order, 'average_executed_price', 'averageExecutedPrice'))
1333
+ remaining = Precise.string_sub(cost, filled)
1334
+ fee = self.safe_value_2(order, 'total_fee', 'totalFee')
1335
+ feeCurrency = self.safe_string_2(order, 'fee_asset', 'feeAsset')
1336
+ transactions = self.safe_value(order, 'Transactions')
1337
+ triggerPrice = self.safe_number(order, 'triggerPrice')
1338
+ takeProfitPrice: Num = None
1339
+ stopLossPrice: Num = None
1340
+ childOrders = self.safe_value(order, 'childOrders')
1341
+ if childOrders is not None:
1342
+ first = self.safe_value(childOrders, 0)
1343
+ innerChildOrders = self.safe_value(first, 'childOrders', [])
1344
+ innerChildOrdersLength = len(innerChildOrders)
1345
+ if innerChildOrdersLength > 0:
1346
+ takeProfitOrder = self.safe_value(innerChildOrders, 0)
1347
+ stopLossOrder = self.safe_value(innerChildOrders, 1)
1348
+ takeProfitPrice = self.safe_number(takeProfitOrder, 'triggerPrice')
1349
+ stopLossPrice = self.safe_number(stopLossOrder, 'triggerPrice')
1350
+ lastUpdateTimestamp = self.safe_integer_2(order, 'updatedTime', 'updated_time')
1351
+ return self.safe_order({
1352
+ 'id': orderId,
1353
+ 'clientOrderId': clientOrderId,
1354
+ 'timestamp': timestamp,
1355
+ 'datetime': self.iso8601(timestamp),
1356
+ 'lastTradeTimestamp': None,
1357
+ 'lastUpdateTimestamp': lastUpdateTimestamp,
1358
+ 'status': self.parse_order_status(status),
1359
+ 'symbol': symbol,
1360
+ 'type': self.parse_order_type(orderType),
1361
+ 'timeInForce': self.parse_time_in_force(orderType),
1362
+ 'postOnly': None, # TO_DO
1363
+ 'reduceOnly': self.safe_bool(order, 'reduce_only'),
1364
+ 'side': side,
1365
+ 'price': price,
1366
+ 'triggerPrice': triggerPrice,
1367
+ 'takeProfitPrice': takeProfitPrice,
1368
+ 'stopLossPrice': stopLossPrice,
1369
+ 'average': average,
1370
+ 'amount': amount,
1371
+ 'filled': filled,
1372
+ 'remaining': remaining, # TO_DO
1373
+ 'cost': cost,
1374
+ 'trades': transactions,
1375
+ 'fee': {
1376
+ 'cost': fee,
1377
+ 'currency': feeCurrency,
1378
+ },
1379
+ 'info': order,
1380
+ }, market)
1381
+
1382
+ def parse_time_in_force(self, timeInForce: Str):
1383
+ timeInForces: dict = {
1384
+ 'ioc': 'IOC',
1385
+ 'fok': 'FOK',
1386
+ 'post_only': 'PO',
1387
+ }
1388
+ return self.safe_string(timeInForces, timeInForce, None)
1389
+
1390
+ def parse_order_status(self, status: Str):
1391
+ if status is not None:
1392
+ statuses: dict = {
1393
+ 'NEW': 'open',
1394
+ 'FILLED': 'closed',
1395
+ 'CANCEL_SENT': 'canceled',
1396
+ 'CANCEL_ALL_SENT': 'canceled',
1397
+ 'CANCELLED': 'canceled',
1398
+ 'PARTIAL_FILLED': 'open',
1399
+ 'REJECTED': 'rejected',
1400
+ 'INCOMPLETE': 'open',
1401
+ 'COMPLETED': 'closed',
1402
+ }
1403
+ return self.safe_string(statuses, status, status)
1404
+ return status
1405
+
1406
+ def parse_order_type(self, type: Str):
1407
+ types: dict = {
1408
+ 'LIMIT': 'limit',
1409
+ 'MARKET': 'market',
1410
+ 'POST_ONLY': 'limit',
1411
+ }
1412
+ return self.safe_string_lower(types, type, type)
1413
+
1414
+ def create_order_request(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={}):
1415
+ """
1416
+ @ignore
1417
+ helper function to build the request
1418
+ :param str symbol: unified symbol of the market to create an order in
1419
+ :param str type: 'market' or 'limit'
1420
+ :param str side: 'buy' or 'sell'
1421
+ :param float amount: how much you want to trade in units of the base currency
1422
+ :param float [price]: the price that the order is to be fulfilled, in units of the quote currency, ignored in market orders
1423
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1424
+ :returns dict: request to be sent to the exchange
1425
+ """
1426
+ reduceOnly = self.safe_bool_2(params, 'reduceOnly', 'reduce_only')
1427
+ orderType = type.upper()
1428
+ market = self.market(symbol)
1429
+ orderSide = side.upper()
1430
+ request: dict = {
1431
+ 'symbol': market['id'],
1432
+ 'side': orderSide,
1433
+ }
1434
+ triggerPrice = self.safe_string_2(params, 'triggerPrice', 'stopPrice')
1435
+ stopLoss = self.safe_value(params, 'stopLoss')
1436
+ takeProfit = self.safe_value(params, 'takeProfit')
1437
+ algoType = self.safe_string(params, 'algoType')
1438
+ isConditional = triggerPrice is not None or stopLoss is not None or takeProfit is not None or (self.safe_value(params, 'childOrders') is not None)
1439
+ isMarket = orderType == 'MARKET'
1440
+ timeInForce = self.safe_string_lower(params, 'timeInForce')
1441
+ postOnly = self.is_post_only(isMarket, None, params)
1442
+ orderQtyKey = 'quantity' if isConditional else 'order_quantity'
1443
+ priceKey = 'price' if isConditional else 'order_price'
1444
+ typeKey = 'type' if isConditional else 'order_type'
1445
+ request[typeKey] = orderType # LIMIT/MARKET/IOC/FOK/POST_ONLY/ASK/BID
1446
+ if not isConditional:
1447
+ if postOnly:
1448
+ request['order_type'] = 'POST_ONLY'
1449
+ elif timeInForce == 'fok':
1450
+ request['order_type'] = 'FOK'
1451
+ elif timeInForce == 'ioc':
1452
+ request['order_type'] = 'IOC'
1453
+ if reduceOnly:
1454
+ request['reduce_only'] = reduceOnly
1455
+ if price is not None:
1456
+ request[priceKey] = self.price_to_precision(symbol, price)
1457
+ if isMarket and not isConditional:
1458
+ request[orderQtyKey] = self.amount_to_precision(symbol, amount)
1459
+ elif algoType != 'POSITIONAL_TP_SL':
1460
+ request[orderQtyKey] = self.amount_to_precision(symbol, amount)
1461
+ clientOrderId = self.safe_string_n(params, ['clOrdID', 'clientOrderId', 'client_order_id'])
1462
+ if clientOrderId is not None:
1463
+ request['client_order_id'] = clientOrderId
1464
+ if triggerPrice is not None:
1465
+ request['trigger_price'] = self.price_to_precision(symbol, triggerPrice)
1466
+ request['algo_type'] = 'STOP'
1467
+ elif (stopLoss is not None) or (takeProfit is not None):
1468
+ request['algo_type'] = 'TP_SL'
1469
+ outterOrder: dict = {
1470
+ 'symbol': market['id'],
1471
+ 'reduce_only': False,
1472
+ 'algo_type': 'POSITIONAL_TP_SL',
1473
+ 'child_orders': [],
1474
+ }
1475
+ childOrders = outterOrder['child_orders']
1476
+ closeSide = 'SELL' if (orderSide == 'BUY') else 'BUY'
1477
+ if stopLoss is not None:
1478
+ stopLossPrice = self.safe_number_2(stopLoss, 'triggerPrice', 'price', stopLoss)
1479
+ stopLossOrder: dict = {
1480
+ 'side': closeSide,
1481
+ 'algo_type': 'TP_SL',
1482
+ 'trigger_price': self.price_to_precision(symbol, stopLossPrice),
1483
+ 'type': 'LIMIT',
1484
+ 'reduce_only': True,
1485
+ }
1486
+ childOrders.append(stopLossOrder)
1487
+ if takeProfit is not None:
1488
+ takeProfitPrice = self.safe_number_2(takeProfit, 'triggerPrice', 'price', takeProfit)
1489
+ takeProfitOrder: dict = {
1490
+ 'side': closeSide,
1491
+ 'algo_type': 'TP_SL',
1492
+ 'trigger_price': self.price_to_precision(symbol, takeProfitPrice),
1493
+ 'type': 'LIMIT',
1494
+ 'reduce_only': True,
1495
+ }
1496
+ outterOrder.append(takeProfitOrder)
1497
+ request['child_orders'] = [outterOrder]
1498
+ params = self.omit(params, ['reduceOnly', 'reduce_only', 'clOrdID', 'clientOrderId', 'client_order_id', 'postOnly', 'timeInForce', 'stopPrice', 'triggerPrice', 'stopLoss', 'takeProfit'])
1499
+ return self.extend(request, params)
1500
+
1501
+ async def create_order(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={}):
1502
+ """
1503
+ create a trade order
1504
+
1505
+ https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/create-order
1506
+ https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/create-algo-order
1507
+
1508
+ :param str symbol: unified symbol of the market to create an order in
1509
+ :param str type: 'market' or 'limit'
1510
+ :param str side: 'buy' or 'sell'
1511
+ :param float amount: how much of currency you want to trade in units of base currency
1512
+ :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
1513
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1514
+ :param float [params.triggerPrice]: The price a trigger order is triggered at
1515
+ :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)
1516
+ :param float [params.takeProfit.triggerPrice]: take profit trigger price
1517
+ :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)
1518
+ :param float [params.stopLoss.triggerPrice]: stop loss trigger price
1519
+ :param float [params.algoType]: 'STOP'or 'TP_SL' or 'POSITIONAL_TP_SL'
1520
+ :param float [params.cost]: *spot market buy only* the quote quantity that can be used alternative for the amount
1521
+ :param str [params.clientOrderId]: a unique id for the order
1522
+ :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
1523
+ """
1524
+ await self.load_markets()
1525
+ market = self.market(symbol)
1526
+ request = self.create_order_request(symbol, type, side, amount, price, params)
1527
+ triggerPrice = self.safe_string_2(params, 'triggerPrice', 'stopPrice')
1528
+ stopLoss = self.safe_value(params, 'stopLoss')
1529
+ takeProfit = self.safe_value(params, 'takeProfit')
1530
+ isConditional = triggerPrice is not None or stopLoss is not None or takeProfit is not None or (self.safe_value(params, 'childOrders') is not None)
1531
+ response = None
1532
+ if isConditional:
1533
+ response = await self.v1PrivatePostAlgoOrder(request)
1534
+ #
1535
+ # {
1536
+ # "success": True,
1537
+ # "timestamp": 1702989203989,
1538
+ # "data": {
1539
+ # "order_id": 13,
1540
+ # "client_order_id": "testclientid",
1541
+ # "algo_type": "STOP",
1542
+ # "quantity": 100.12
1543
+ # }
1544
+ # }
1545
+ #
1546
+ else:
1547
+ response = await self.v1PrivatePostOrder(request)
1548
+ #
1549
+ # {
1550
+ # "success": True,
1551
+ # "timestamp": 1702989203989,
1552
+ # "data": {
1553
+ # "order_id": 13,
1554
+ # "client_order_id": "testclientid",
1555
+ # "order_type": "LIMIT",
1556
+ # "order_price": 100.12,
1557
+ # "order_quantity": 0.987654,
1558
+ # "order_amount": 0.8,
1559
+ # "error_message": "none"
1560
+ # }
1561
+ # }
1562
+ #
1563
+ data = self.safe_dict(response, 'data')
1564
+ data['timestamp'] = self.safe_integer(response, 'timestamp')
1565
+ order = self.parse_order(data, market)
1566
+ order['type'] = type
1567
+ return order
1568
+
1569
+ async def create_orders(self, orders: List[OrderRequest], params={}):
1570
+ """
1571
+ *contract only* create a list of trade orders
1572
+
1573
+ https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/batch-create-order
1574
+
1575
+ :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
1576
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1577
+ :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
1578
+ """
1579
+ await self.load_markets()
1580
+ ordersRequests = []
1581
+ for i in range(0, len(orders)):
1582
+ rawOrder = orders[i]
1583
+ marketId = self.safe_string(rawOrder, 'symbol')
1584
+ type = self.safe_string(rawOrder, 'type')
1585
+ side = self.safe_string(rawOrder, 'side')
1586
+ amount = self.safe_value(rawOrder, 'amount')
1587
+ price = self.safe_value(rawOrder, 'price')
1588
+ orderParams = self.safe_dict(rawOrder, 'params', {})
1589
+ triggerPrice = self.safe_string_2(orderParams, 'triggerPrice', 'stopPrice')
1590
+ stopLoss = self.safe_value(orderParams, 'stopLoss')
1591
+ takeProfit = self.safe_value(orderParams, 'takeProfit')
1592
+ isConditional = triggerPrice is not None or stopLoss is not None or takeProfit is not None or (self.safe_value(orderParams, 'childOrders') is not None)
1593
+ if isConditional:
1594
+ raise NotSupported(self.id + ' createOrders() only support non-stop order')
1595
+ orderRequest = self.create_order_request(marketId, type, side, amount, price, orderParams)
1596
+ ordersRequests.append(orderRequest)
1597
+ request: dict = {
1598
+ 'orders': ordersRequests,
1599
+ }
1600
+ response = await self.v1PrivatePostBatchOrder(self.extend(request, params))
1601
+ #
1602
+ # {
1603
+ # "success": True,
1604
+ # "timestamp": 1702989203989,
1605
+ # "data": {
1606
+ # "rows": [{
1607
+ # "order_id": 13,
1608
+ # "client_order_id": "testclientid",
1609
+ # "order_type": "LIMIT",
1610
+ # "order_price": 100.12,
1611
+ # "order_quantity": 0.987654,
1612
+ # "order_amount": 0.8,
1613
+ # "error_message": "none"
1614
+ # }]
1615
+ # }
1616
+ # }
1617
+ #
1618
+ data = self.safe_dict(response, 'data', {})
1619
+ rows = self.safe_list(data, 'rows', [])
1620
+ return self.parse_orders(rows)
1621
+
1622
+ async def edit_order(self, id: str, symbol: str, type: OrderType, side: OrderSide, amount: Num = None, price: Num = None, params={}):
1623
+ """
1624
+ edit a trade order
1625
+
1626
+ https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/edit-order
1627
+ https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/edit-algo-order
1628
+
1629
+ :param str id: order id
1630
+ :param str symbol: unified symbol of the market to create an order in
1631
+ :param str type: 'market' or 'limit'
1632
+ :param str side: 'buy' or 'sell'
1633
+ :param float amount: how much of currency you want to trade in units of base currency
1634
+ :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
1635
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1636
+ :param float [params.triggerPrice]: The price a trigger order is triggered at
1637
+ :param float [params.stopLossPrice]: price to trigger stop-loss orders
1638
+ :param float [params.takeProfitPrice]: price to trigger take-profit orders
1639
+ :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
1640
+ """
1641
+ await self.load_markets()
1642
+ market = self.market(symbol)
1643
+ request: dict = {
1644
+ 'order_id': id,
1645
+ }
1646
+ triggerPrice = self.safe_string_n(params, ['triggerPrice', 'stopPrice', 'takeProfitPrice', 'stopLossPrice'])
1647
+ if triggerPrice is not None:
1648
+ request['triggerPrice'] = self.price_to_precision(symbol, triggerPrice)
1649
+ isConditional = (triggerPrice is not None) or (self.safe_value(params, 'childOrders') is not None)
1650
+ orderQtyKey = 'quantity' if isConditional else 'order_quantity'
1651
+ priceKey = 'price' if isConditional else 'order_price'
1652
+ if price is not None:
1653
+ request[priceKey] = self.price_to_precision(symbol, price)
1654
+ if amount is not None:
1655
+ request[orderQtyKey] = self.amount_to_precision(symbol, amount)
1656
+ params = self.omit(params, ['stopPrice', 'triggerPrice', 'takeProfitPrice', 'stopLossPrice', 'trailingTriggerPrice', 'trailingAmount', 'trailingPercent'])
1657
+ response = None
1658
+ if isConditional:
1659
+ response = await self.v1PrivatePutAlgoOrder(self.extend(request, params))
1660
+ else:
1661
+ request['symbol'] = market['id']
1662
+ request['side'] = side.upper()
1663
+ orderType = type.upper()
1664
+ timeInForce = self.safe_string_lower(params, 'timeInForce')
1665
+ isMarket = orderType == 'MARKET'
1666
+ postOnly = self.is_post_only(isMarket, None, params)
1667
+ if postOnly:
1668
+ request['order_type'] = 'POST_ONLY'
1669
+ elif timeInForce == 'fok':
1670
+ request['order_type'] = 'FOK'
1671
+ elif timeInForce == 'ioc':
1672
+ request['order_type'] = 'IOC'
1673
+ else:
1674
+ request['order_type'] = orderType
1675
+ clientOrderId = self.safe_string_n(params, ['clOrdID', 'clientOrderId', 'client_order_id'])
1676
+ params = self.omit(params, ['clOrdID', 'clientOrderId', 'client_order_id', 'postOnly', 'timeInForce'])
1677
+ if clientOrderId is not None:
1678
+ request['client_order_id'] = clientOrderId
1679
+ # request['side'] = side.upper()
1680
+ # request['symbol'] = market['id']
1681
+ response = await self.v1PrivatePutOrder(self.extend(request, params))
1682
+ #
1683
+ # {
1684
+ # "success": True,
1685
+ # "timestamp": 1702989203989,
1686
+ # "data": {
1687
+ # "status": "EDIT_SENT"
1688
+ # }
1689
+ # }
1690
+ #
1691
+ data = self.safe_dict(response, 'data', {})
1692
+ data['timestamp'] = self.safe_integer(response, 'timestamp')
1693
+ return self.parse_order(data, market)
1694
+
1695
+ async def cancel_order(self, id: str, symbol: Str = None, params={}):
1696
+ """
1697
+
1698
+ https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/cancel-order
1699
+ https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/cancel-order-by-client_order_id
1700
+ https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/cancel-algo-order
1701
+ https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/cancel-algo-order-by-client_order_id
1702
+
1703
+ cancels an open order
1704
+ :param str id: order id
1705
+ :param str symbol: unified symbol of the market the order was made in
1706
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1707
+ :param boolean [params.trigger]: whether the order is a stop/algo order
1708
+ :param str [params.clientOrderId]: a unique id for the order
1709
+ :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
1710
+ """
1711
+ trigger = self.safe_bool_2(params, 'stop', 'trigger', False)
1712
+ params = self.omit(params, ['stop', 'trigger'])
1713
+ if not trigger and (symbol is None):
1714
+ raise ArgumentsRequired(self.id + ' cancelOrder() requires a symbol argument')
1715
+ await self.load_markets()
1716
+ market: Market = None
1717
+ if symbol is not None:
1718
+ market = self.market(symbol)
1719
+ request: dict = {
1720
+ 'symbol': market['id'],
1721
+ }
1722
+ clientOrderIdUnified = self.safe_string_2(params, 'clOrdID', 'clientOrderId')
1723
+ clientOrderIdExchangeSpecific = self.safe_string(params, 'client_order_id', clientOrderIdUnified)
1724
+ isByClientOrder = clientOrderIdExchangeSpecific is not None
1725
+ response = None
1726
+ if trigger:
1727
+ if isByClientOrder:
1728
+ request['client_order_id'] = clientOrderIdExchangeSpecific
1729
+ params = self.omit(params, ['clOrdID', 'clientOrderId', 'client_order_id'])
1730
+ response = await self.v1PrivateDeleteAlgoClientOrder(self.extend(request, params))
1731
+ else:
1732
+ request['order_id'] = id
1733
+ response = await self.v1PrivateDeleteAlgoOrder(self.extend(request, params))
1734
+ else:
1735
+ if isByClientOrder:
1736
+ request['client_order_id'] = clientOrderIdExchangeSpecific
1737
+ params = self.omit(params, ['clOrdID', 'clientOrderId', 'client_order_id'])
1738
+ response = await self.v1PrivateDeleteClientOrder(self.extend(request, params))
1739
+ else:
1740
+ request['order_id'] = id
1741
+ response = await self.v1PrivateDeleteOrder(self.extend(request, params))
1742
+ #
1743
+ # {
1744
+ # "success": True,
1745
+ # "timestamp": 1702989203988,
1746
+ # "data": {
1747
+ # "status": "CANCEL_SENT"
1748
+ # }
1749
+ # }
1750
+ #
1751
+ # {
1752
+ # "success": True,
1753
+ # "timestamp": 1702989203988,
1754
+ # "status": "CANCEL_SENT"
1755
+ # }
1756
+ #
1757
+ extendParams: dict = {'symbol': symbol}
1758
+ if isByClientOrder:
1759
+ extendParams['client_order_id'] = clientOrderIdExchangeSpecific
1760
+ else:
1761
+ extendParams['id'] = id
1762
+ if trigger:
1763
+ return self.extend(self.parse_order(response), extendParams)
1764
+ data = self.safe_dict(response, 'data', {})
1765
+ return self.extend(self.parse_order(data), extendParams)
1766
+
1767
+ async def cancel_orders(self, ids: List[str], symbol: Str = None, params={}):
1768
+ """
1769
+ cancel multiple orders
1770
+
1771
+ https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/batch-cancel-orders
1772
+ https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/batch-cancel-orders-by-client_order_id
1773
+
1774
+ :param str[] ids: order ids
1775
+ :param str [symbol]: unified market symbol
1776
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1777
+ :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
1778
+ :returns dict: an list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
1779
+ """
1780
+ await self.load_markets()
1781
+ clientOrderIds = self.safe_list_n(params, ['clOrdIDs', 'clientOrderIds', 'client_order_ids'])
1782
+ params = self.omit(params, ['clOrdIDs', 'clientOrderIds', 'client_order_ids'])
1783
+ request: dict = {}
1784
+ response = None
1785
+ if clientOrderIds:
1786
+ request['client_order_ids'] = ','.join(clientOrderIds)
1787
+ response = await self.v1PrivateDeleteClientBatchOrder(self.extend(request, params))
1788
+ else:
1789
+ request['order_ids'] = ','.join(ids)
1790
+ response = await self.v1PrivateDeleteBatchOrder(self.extend(request, params))
1791
+ #
1792
+ # {
1793
+ # "success": True,
1794
+ # "timestamp": 1702989203989,
1795
+ # "data": {
1796
+ # "status": "CANCEL_ALL_SENT"
1797
+ # }
1798
+ # }
1799
+ #
1800
+ return [self.safe_order({
1801
+ 'info': response,
1802
+ })]
1803
+
1804
+ async def cancel_all_orders(self, symbol: Str = None, params={}):
1805
+ """
1806
+
1807
+ https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/cancel-all-pending-algo-orders
1808
+ https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/cancel-orders-in-bulk
1809
+
1810
+ cancel all open orders in a market
1811
+ :param str symbol: unified market symbol
1812
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1813
+ :param boolean [params.trigger]: whether the order is a stop/algo order
1814
+ :returns dict: an list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
1815
+ """
1816
+ await self.load_markets()
1817
+ trigger = self.safe_bool_2(params, 'stop', 'trigger')
1818
+ params = self.omit(params, ['stop', 'trigger'])
1819
+ request: dict = {}
1820
+ if symbol is not None:
1821
+ market = self.market(symbol)
1822
+ request['symbol'] = market['id']
1823
+ response = None
1824
+ if trigger:
1825
+ response = await self.v1PrivateDeleteAlgoOrders(self.extend(request, params))
1826
+ else:
1827
+ response = await self.v1PrivateDeleteOrders(self.extend(request, params))
1828
+ # trigger
1829
+ # {
1830
+ # "success": True,
1831
+ # "timestamp": 1702989203989,
1832
+ # "status": "CANCEL_ALL_SENT"
1833
+ # }
1834
+ #
1835
+ # {
1836
+ # "success": True,
1837
+ # "timestamp": 1702989203989,
1838
+ # "data": {
1839
+ # "status": "CANCEL_ALL_SENT"
1840
+ # }
1841
+ # }
1842
+ #
1843
+ return [
1844
+ self.safe_order({
1845
+ 'info': response,
1846
+ }),
1847
+ ]
1848
+
1849
+ async def fetch_order(self, id: str, symbol: Str = None, params={}):
1850
+ """
1851
+
1852
+ https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-order-by-order_id
1853
+ https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-order-by-client_order_id
1854
+ https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-algo-order-by-order_id
1855
+ https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-algo-order-by-client_order_id
1856
+
1857
+ fetches information on an order made by the user
1858
+ :param str id: the order id
1859
+ :param str symbol: unified symbol of the market the order was made in
1860
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1861
+ :param boolean [params.trigger]: whether the order is a stop/algo order
1862
+ :param str [params.clientOrderId]: a unique id for the order
1863
+ :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
1864
+ """
1865
+ await self.load_markets()
1866
+ market = None
1867
+ if symbol is not None:
1868
+ market = self.market(symbol)
1869
+ trigger = self.safe_bool_2(params, 'stop', 'trigger', False)
1870
+ request: dict = {}
1871
+ clientOrderId = self.safe_string_n(params, ['clOrdID', 'clientOrderId', 'client_order_id'])
1872
+ params = self.omit(params, ['stop', 'trigger', 'clOrdID', 'clientOrderId', 'client_order_id'])
1873
+ response = None
1874
+ if trigger:
1875
+ if clientOrderId:
1876
+ request['client_order_id'] = clientOrderId
1877
+ response = await self.v1PrivateGetAlgoClientOrderClientOrderId(self.extend(request, params))
1878
+ else:
1879
+ request['oid'] = id
1880
+ response = await self.v1PrivateGetAlgoOrderOid(self.extend(request, params))
1881
+ else:
1882
+ if clientOrderId:
1883
+ request['client_order_id'] = clientOrderId
1884
+ response = await self.v1PrivateGetClientOrderClientOrderId(self.extend(request, params))
1885
+ else:
1886
+ request['oid'] = id
1887
+ response = await self.v1PrivateGetOrderOid(self.extend(request, params))
1888
+ #
1889
+ # {
1890
+ # "success": True,
1891
+ # "timestamp": 1702989203989,
1892
+ # "data": {
1893
+ # "order_id": 78151,
1894
+ # "user_id": 12345,
1895
+ # "price": 0.67772,
1896
+ # "type": "LIMIT",
1897
+ # "quantity": 20,
1898
+ # "amount": 10,
1899
+ # "executed_quantity": 20,
1900
+ # "total_executed_quantity": 20,
1901
+ # "visible_quantity": 1,
1902
+ # "symbol": "PERP_BTC_USDC",
1903
+ # "side": "BUY",
1904
+ # "status": "FILLED",
1905
+ # "total_fee": 0.5,
1906
+ # "fee_asset": "BTC",
1907
+ # "client_order_id": 1,
1908
+ # "average_executed_price": 0.67772,
1909
+ # "created_time": 1653563963000,
1910
+ # "updated_time": 1653564213000,
1911
+ # "realized_pnl": 123
1912
+ # }
1913
+ # }
1914
+ #
1915
+ orders = self.safe_dict(response, 'data', response)
1916
+ return self.parse_order(orders, market)
1917
+
1918
+ async def fetch_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Order]:
1919
+ """
1920
+ fetches information on multiple orders made by the user
1921
+
1922
+ https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-orders
1923
+ https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-algo-orders
1924
+
1925
+ :param str symbol: unified market symbol of the market orders were made in
1926
+ :param int [since]: the earliest time in ms to fetch orders for
1927
+ :param int [limit]: the maximum number of order structures to retrieve
1928
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1929
+ :param boolean [params.trigger]: whether the order is a stop/algo order
1930
+ :param boolean [params.is_triggered]: whether the order has been triggered(False by default)
1931
+ :param str [params.side]: 'buy' or 'sell'
1932
+ :param boolean [params.paginate]: set to True if you want to fetch orders with pagination
1933
+ :param int params['until']: timestamp in ms of the latest order to fetch
1934
+ :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
1935
+ """
1936
+ await self.load_markets()
1937
+ paginate = False
1938
+ isTrigger = self.safe_bool_2(params, 'stop', 'trigger', False)
1939
+ maxLimit = 100 if (isTrigger) else 500
1940
+ paginate, params = self.handle_option_and_params(params, 'fetchOrders', 'paginate')
1941
+ if paginate:
1942
+ return await self.fetch_paginated_call_incremental('fetchOrders', symbol, since, limit, params, 'page', maxLimit)
1943
+ request: dict = {}
1944
+ market: Market = None
1945
+ params = self.omit(params, ['stop', 'trigger'])
1946
+ if symbol is not None:
1947
+ market = self.market(symbol)
1948
+ request['symbol'] = market['id']
1949
+ if since is not None:
1950
+ request['start_t'] = since
1951
+ if limit is not None:
1952
+ request['size'] = limit
1953
+ else:
1954
+ request['size'] = maxLimit
1955
+ if isTrigger:
1956
+ request['algo_type'] = 'STOP'
1957
+ request, params = self.handle_until_option('end_t', request, params)
1958
+ response = None
1959
+ if isTrigger:
1960
+ response = await self.v1PrivateGetAlgoOrders(self.extend(request, params))
1961
+ else:
1962
+ response = await self.v1PrivateGetOrders(self.extend(request, params))
1963
+ #
1964
+ # {
1965
+ # "success": True,
1966
+ # "timestamp": 1702989203989,
1967
+ # "data": {
1968
+ # "meta": {
1969
+ # "total": 9,
1970
+ # "records_per_page": 25,
1971
+ # "current_page": 1
1972
+ # },
1973
+ # "rows": [{
1974
+ # "order_id": 78151,
1975
+ # "user_id": 12345,
1976
+ # "price": 0.67772,
1977
+ # "type": "LIMIT",
1978
+ # "quantity": 20,
1979
+ # "amount": 10,
1980
+ # "executed_quantity": 20,
1981
+ # "total_executed_quantity": 20,
1982
+ # "visible_quantity": 1,
1983
+ # "symbol": "PERP_BTC_USDC",
1984
+ # "side": "BUY",
1985
+ # "status": "FILLED",
1986
+ # "total_fee": 0.5,
1987
+ # "fee_asset": "BTC",
1988
+ # "client_order_id": 1,
1989
+ # "average_executed_price": 0.67772,
1990
+ # "created_time": 1653563963000,
1991
+ # "updated_time": 1653564213000,
1992
+ # "realized_pnl": 123
1993
+ # }]
1994
+ # }
1995
+ # }
1996
+ #
1997
+ data = self.safe_value(response, 'data', response)
1998
+ orders = self.safe_list(data, 'rows')
1999
+ return self.parse_orders(orders, market, since, limit)
2000
+
2001
+ async def fetch_open_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Order]:
2002
+ """
2003
+ fetches information on multiple orders made by the user
2004
+
2005
+ https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-orders
2006
+ https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-algo-orders
2007
+
2008
+ :param str symbol: unified market symbol of the market orders were made in
2009
+ :param int [since]: the earliest time in ms to fetch orders for
2010
+ :param int [limit]: the maximum number of order structures to retrieve
2011
+ :param dict [params]: extra parameters specific to the exchange API endpoint
2012
+ :param boolean [params.trigger]: whether the order is a stop/algo order
2013
+ :param boolean [params.is_triggered]: whether the order has been triggered(False by default)
2014
+ :param str [params.side]: 'buy' or 'sell'
2015
+ :param int params['until']: timestamp in ms of the latest order to fetch
2016
+ :param boolean [params.paginate]: set to True if you want to fetch orders with pagination
2017
+ :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
2018
+ """
2019
+ await self.load_markets()
2020
+ extendedParams = self.extend(params, {'status': 'INCOMPLETE'})
2021
+ return await self.fetch_orders(symbol, since, limit, extendedParams)
2022
+
2023
+ async def fetch_closed_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Order]:
2024
+ """
2025
+ fetches information on multiple orders made by the user
2026
+
2027
+ https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-orders
2028
+ https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-algo-orders
2029
+
2030
+ :param str symbol: unified market symbol of the market orders were made in
2031
+ :param int [since]: the earliest time in ms to fetch orders for
2032
+ :param int [limit]: the maximum number of order structures to retrieve
2033
+ :param dict [params]: extra parameters specific to the exchange API endpoint
2034
+ :param boolean [params.trigger]: whether the order is a stop/algo order
2035
+ :param boolean [params.is_triggered]: whether the order has been triggered(False by default)
2036
+ :param str [params.side]: 'buy' or 'sell'
2037
+ :param int params['until']: timestamp in ms of the latest order to fetch
2038
+ :param boolean [params.paginate]: set to True if you want to fetch orders with pagination
2039
+ :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
2040
+ """
2041
+ await self.load_markets()
2042
+ extendedParams = self.extend(params, {'status': 'COMPLETED'})
2043
+ return await self.fetch_orders(symbol, since, limit, extendedParams)
2044
+
2045
+ async def fetch_order_trades(self, id: str, symbol: Str = None, since: Int = None, limit: Int = None, params={}):
2046
+ """
2047
+ fetch all the trades made from a single order
2048
+
2049
+ https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-all-trades-of-specific-order
2050
+
2051
+ :param str id: order id
2052
+ :param str symbol: unified market symbol
2053
+ :param int [since]: the earliest time in ms to fetch trades for
2054
+ :param int [limit]: the maximum number of trades to retrieve
2055
+ :param dict [params]: extra parameters specific to the exchange API endpoint
2056
+ :returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
2057
+ """
2058
+ await self.load_markets()
2059
+ market: Market = None
2060
+ if symbol is not None:
2061
+ market = self.market(symbol)
2062
+ request: dict = {
2063
+ 'oid': id,
2064
+ }
2065
+ response = await self.v1PrivateGetOrderOidTrades(self.extend(request, params))
2066
+ #
2067
+ # {
2068
+ # "success": True,
2069
+ # "timestamp": 1702989203989,
2070
+ # "data": {
2071
+ # "rows": [{
2072
+ # "id": 2,
2073
+ # "symbol": "PERP_BTC_USDC",
2074
+ # "fee": 0.0001,
2075
+ # "fee_asset": "USDC",
2076
+ # "side": "BUY",
2077
+ # "order_id": 1,
2078
+ # "executed_price": 123,
2079
+ # "executed_quantity": 0.05,
2080
+ # "executed_timestamp": 1567382401000,
2081
+ # "is_maker": 1,
2082
+ # "realized_pnl": 123
2083
+ # }]
2084
+ # }
2085
+ # }
2086
+ #
2087
+ data = self.safe_dict(response, 'data', {})
2088
+ trades = self.safe_list(data, 'rows', [])
2089
+ return self.parse_trades(trades, market, since, limit, params)
2090
+
2091
+ async def fetch_my_trades(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}):
2092
+ """
2093
+
2094
+ https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-trades
2095
+
2096
+ fetch all trades made by the user
2097
+ :param str symbol: unified market symbol
2098
+ :param int [since]: the earliest time in ms to fetch trades for
2099
+ :param int [limit]: the maximum number of trades structures to retrieve
2100
+ :param dict [params]: extra parameters specific to the exchange API endpoint
2101
+ :param boolean [params.paginate]: set to True if you want to fetch trades with pagination
2102
+ :param int params['until']: timestamp in ms of the latest trade to fetch
2103
+ :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
2104
+ """
2105
+ await self.load_markets()
2106
+ paginate = False
2107
+ paginate, params = self.handle_option_and_params(params, 'fetchMyTrades', 'paginate')
2108
+ if paginate:
2109
+ return await self.fetch_paginated_call_incremental('fetchMyTrades', symbol, since, limit, params, 'page', 500)
2110
+ request: dict = {}
2111
+ market: Market = None
2112
+ if symbol is not None:
2113
+ market = self.market(symbol)
2114
+ request['symbol'] = market['id']
2115
+ if since is not None:
2116
+ request['start_t'] = since
2117
+ if limit is not None:
2118
+ request['size'] = limit
2119
+ else:
2120
+ request['size'] = 500
2121
+ request, params = self.handle_until_option('end_t', request, params)
2122
+ response = await self.v1PrivateGetTrades(self.extend(request, params))
2123
+ #
2124
+ # {
2125
+ # "success": True,
2126
+ # "timestamp": 1702989203989,
2127
+ # "data": {
2128
+ # "meta": {
2129
+ # "total": 9,
2130
+ # "records_per_page": 25,
2131
+ # "current_page": 1
2132
+ # },
2133
+ # "rows": [{
2134
+ # "id": 2,
2135
+ # "symbol": "PERP_BTC_USDC",
2136
+ # "fee": 0.0001,
2137
+ # "fee_asset": "USDC",
2138
+ # "side": "BUY",
2139
+ # "order_id": 1,
2140
+ # "executed_price": 123,
2141
+ # "executed_quantity": 0.05,
2142
+ # "executed_timestamp": 1567382401000,
2143
+ # "is_maker": 1,
2144
+ # "realized_pnl": 123
2145
+ # }]
2146
+ # }
2147
+ # }
2148
+ #
2149
+ data = self.safe_dict(response, 'data', {})
2150
+ trades = self.safe_list(data, 'rows', [])
2151
+ return self.parse_trades(trades, market, since, limit, params)
2152
+
2153
+ def parse_balance(self, response) -> Balances:
2154
+ result: dict = {
2155
+ 'info': response,
2156
+ }
2157
+ balances = self.safe_list(response, 'holding', [])
2158
+ for i in range(0, len(balances)):
2159
+ balance = balances[i]
2160
+ code = self.safe_currency_code(self.safe_string(balance, 'token'))
2161
+ account = self.account()
2162
+ account['total'] = self.safe_string(balance, 'holding')
2163
+ account['used'] = self.safe_string(balance, 'frozen')
2164
+ result[code] = account
2165
+ return self.safe_balance(result)
2166
+
2167
+ async def fetch_balance(self, params={}) -> Balances:
2168
+ """
2169
+ query for balance and get the amount of funds available for trading or funds locked in orders
2170
+
2171
+ https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-current-holding
2172
+
2173
+ :param dict [params]: extra parameters specific to the exchange API endpoint
2174
+ :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
2175
+ """
2176
+ await self.load_markets()
2177
+ response = await self.v1PrivateGetClientHolding(params)
2178
+ #
2179
+ # {
2180
+ # "success": True,
2181
+ # "timestamp": 1702989203989,
2182
+ # "data": {
2183
+ # "holding": [{
2184
+ # "updated_time": 1580794149000,
2185
+ # "token": "BTC",
2186
+ # "holding": -28.000752,
2187
+ # "frozen": 123,
2188
+ # "pending_short": -2000
2189
+ # }]
2190
+ # }
2191
+ # }
2192
+ #
2193
+ data = self.safe_dict(response, 'data')
2194
+ return self.parse_balance(data)
2195
+
2196
+ async def get_asset_history_rows(self, code: Str = None, since: Int = None, limit: Int = None, params={}) -> Any:
2197
+ await self.load_markets()
2198
+ request: dict = {}
2199
+ currency: Currency = None
2200
+ if code is not None:
2201
+ currency = self.currency(code)
2202
+ request['balance_token'] = currency['id']
2203
+ if since is not None:
2204
+ request['start_t'] = since
2205
+ if limit is not None:
2206
+ request['pageSize'] = limit
2207
+ transactionType = self.safe_string(params, 'type')
2208
+ params = self.omit(params, 'type')
2209
+ if transactionType is not None:
2210
+ request['type'] = transactionType
2211
+ response = await self.v1PrivateGetAssetHistory(self.extend(request, params))
2212
+ #
2213
+ # {
2214
+ # "success": True,
2215
+ # "timestamp": 1702989203989,
2216
+ # "data": {
2217
+ # "meta": {
2218
+ # "total": 9,
2219
+ # "records_per_page": 25,
2220
+ # "current_page": 1
2221
+ # },
2222
+ # "rows": [{
2223
+ # "id": "230707030600002",
2224
+ # "tx_id": "0x4b0714c63cc7abae72bf68e84e25860b88ca651b7d27dad1e32bf4c027fa5326",
2225
+ # "side": "WITHDRAW",
2226
+ # "token": "USDC",
2227
+ # "amount": 555,
2228
+ # "fee": 123,
2229
+ # "trans_status": "FAILED",
2230
+ # "created_time": 1688699193034,
2231
+ # "updated_time": 1688699193096,
2232
+ # "chain_id": "986532"
2233
+ # }]
2234
+ # }
2235
+ # }
2236
+ #
2237
+ data = self.safe_dict(response, 'data', {})
2238
+ return [currency, self.safe_list(data, 'rows', [])]
2239
+
2240
+ def parse_ledger_entry(self, item: dict, currency: Currency = None) -> LedgerEntry:
2241
+ currencyId = self.safe_string(item, 'token')
2242
+ code = self.safe_currency_code(currencyId, currency)
2243
+ currency = self.safe_currency(currencyId, currency)
2244
+ amount = self.safe_number(item, 'amount')
2245
+ side = self.safe_string(item, 'token_side')
2246
+ direction = 'in' if (side == 'DEPOSIT') else 'out'
2247
+ timestamp = self.safe_integer(item, 'created_time')
2248
+ fee = self.parse_token_and_fee_temp(item, 'fee_token', 'fee_amount')
2249
+ return self.safe_ledger_entry({
2250
+ 'id': self.safe_string(item, 'id'),
2251
+ 'currency': code,
2252
+ 'account': self.safe_string(item, 'account'),
2253
+ 'referenceAccount': None,
2254
+ 'referenceId': self.safe_string(item, 'tx_id'),
2255
+ 'status': self.parse_transaction_status(self.safe_string(item, 'status')),
2256
+ 'amount': amount,
2257
+ 'before': None,
2258
+ 'after': None,
2259
+ 'fee': fee,
2260
+ 'direction': direction,
2261
+ 'timestamp': timestamp,
2262
+ 'datetime': self.iso8601(timestamp),
2263
+ 'type': self.parse_ledger_entry_type(self.safe_string(item, 'type')),
2264
+ 'info': item,
2265
+ }, currency)
2266
+
2267
+ def parse_ledger_entry_type(self, type):
2268
+ types: dict = {
2269
+ 'BALANCE': 'transaction', # Funds moved in/out wallet
2270
+ 'COLLATERAL': 'transfer', # Funds moved between portfolios
2271
+ }
2272
+ return self.safe_string(types, type, type)
2273
+
2274
+ async def fetch_ledger(self, code: Str = None, since: Int = None, limit: Int = None, params={}) -> List[LedgerEntry]:
2275
+ """
2276
+ fetch the history of changes, actions done by the user or operations that altered the balance of the user
2277
+
2278
+ https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-asset-history
2279
+
2280
+ :param str [code]: unified currency code, default is None
2281
+ :param int [since]: timestamp in ms of the earliest ledger entry, default is None
2282
+ :param int [limit]: max number of ledger entries to return, default is None
2283
+ :param dict [params]: extra parameters specific to the exchange API endpoint
2284
+ :returns dict: a `ledger structure <https://docs.ccxt.com/#/?id=ledger>`
2285
+ """
2286
+ currencyRows = await self.get_asset_history_rows(code, since, limit, params)
2287
+ currency = self.safe_value(currencyRows, 0)
2288
+ rows = self.safe_list(currencyRows, 1)
2289
+ return self.parse_ledger(rows, currency, since, limit, params)
2290
+
2291
+ def parse_transaction(self, transaction: dict, currency: Currency = None) -> Transaction:
2292
+ # example in fetchLedger
2293
+ code = self.safe_string(transaction, 'token')
2294
+ movementDirection = self.safe_string_lower(transaction, 'token_side')
2295
+ if movementDirection == 'withdraw':
2296
+ movementDirection = 'withdrawal'
2297
+ fee = self.parse_token_and_fee_temp(transaction, 'fee_token', 'fee_amount')
2298
+ addressTo = self.safe_string(transaction, 'target_address')
2299
+ addressFrom = self.safe_string(transaction, 'source_address')
2300
+ timestamp = self.safe_integer(transaction, 'created_time')
2301
+ return {
2302
+ 'info': transaction,
2303
+ 'id': self.safe_string_2(transaction, 'id', 'withdraw_id'),
2304
+ 'txid': self.safe_string(transaction, 'tx_id'),
2305
+ 'timestamp': timestamp,
2306
+ 'datetime': self.iso8601(timestamp),
2307
+ 'address': None,
2308
+ 'addressFrom': addressFrom,
2309
+ 'addressTo': addressTo,
2310
+ 'tag': self.safe_string(transaction, 'extra'),
2311
+ 'tagFrom': None,
2312
+ 'tagTo': None,
2313
+ 'type': movementDirection,
2314
+ 'amount': self.safe_number(transaction, 'amount'),
2315
+ 'currency': code,
2316
+ 'status': self.parse_transaction_status(self.safe_string(transaction, 'status')),
2317
+ 'updated': self.safe_integer(transaction, 'updated_time'),
2318
+ 'comment': None,
2319
+ 'internal': None,
2320
+ 'fee': fee,
2321
+ 'network': None,
2322
+ }
2323
+
2324
+ def parse_transaction_status(self, status: Str):
2325
+ statuses: dict = {
2326
+ 'NEW': 'pending',
2327
+ 'CONFIRMING': 'pending',
2328
+ 'PROCESSING': 'pending',
2329
+ 'COMPLETED': 'ok',
2330
+ 'CANCELED': 'canceled',
2331
+ }
2332
+ return self.safe_string(statuses, status, status)
2333
+
2334
+ async def fetch_deposits(self, code: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Transaction]:
2335
+ """
2336
+ fetch all deposits made to an account
2337
+
2338
+ https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-asset-history
2339
+
2340
+ :param str code: unified currency code
2341
+ :param int [since]: the earliest time in ms to fetch deposits for
2342
+ :param int [limit]: the maximum number of deposits structures to retrieve
2343
+ :param dict [params]: extra parameters specific to the exchange API endpoint
2344
+ :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
2345
+ """
2346
+ request: dict = {
2347
+ 'side': 'DEPOSIT',
2348
+ }
2349
+ return await self.fetch_deposits_withdrawals(code, since, limit, self.extend(request, params))
2350
+
2351
+ async def fetch_withdrawals(self, code: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Transaction]:
2352
+ """
2353
+ fetch all withdrawals made from an account
2354
+
2355
+ https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-asset-history
2356
+
2357
+ :param str code: unified currency code
2358
+ :param int [since]: the earliest time in ms to fetch withdrawals for
2359
+ :param int [limit]: the maximum number of withdrawals structures to retrieve
2360
+ :param dict [params]: extra parameters specific to the exchange API endpoint
2361
+ :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
2362
+ """
2363
+ request: dict = {
2364
+ 'side': 'WITHDRAW',
2365
+ }
2366
+ return await self.fetch_deposits_withdrawals(code, since, limit, self.extend(request, params))
2367
+
2368
+ async def fetch_deposits_withdrawals(self, code: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Transaction]:
2369
+ """
2370
+ fetch history of deposits and withdrawals
2371
+
2372
+ https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-asset-history
2373
+
2374
+ :param str [code]: unified currency code for the currency of the deposit/withdrawals, default is None
2375
+ :param int [since]: timestamp in ms of the earliest deposit/withdrawal, default is None
2376
+ :param int [limit]: max number of deposit/withdrawals to return, default is None
2377
+ :param dict [params]: extra parameters specific to the exchange API endpoint
2378
+ :returns dict: a list of `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
2379
+ """
2380
+ request: dict = {}
2381
+ currencyRows = await self.get_asset_history_rows(code, since, limit, self.extend(request, params))
2382
+ currency = self.safe_value(currencyRows, 0)
2383
+ rows = self.safe_list(currencyRows, 1)
2384
+ #
2385
+ # {
2386
+ # "rows":[],
2387
+ # "meta":{
2388
+ # "total":0,
2389
+ # "records_per_page":25,
2390
+ # "current_page":1
2391
+ # },
2392
+ # "success":true
2393
+ # }
2394
+ #
2395
+ return self.parse_transactions(rows, currency, since, limit, params)
2396
+
2397
+ async def get_withdraw_nonce(self, params={}):
2398
+ response = await self.v1PrivateGetWithdrawNonce(params)
2399
+ #
2400
+ # {
2401
+ # "success": True,
2402
+ # "timestamp": 1702989203989,
2403
+ # "data": {
2404
+ # "withdraw_nonce": 1
2405
+ # }
2406
+ # }
2407
+ #
2408
+ data = self.safe_dict(response, 'data', {})
2409
+ return self.safe_number(data, 'withdraw_nonce')
2410
+
2411
+ def hash_message(self, message):
2412
+ return '0x' + self.hash(message, 'keccak', 'hex')
2413
+
2414
+ def sign_hash(self, hash, privateKey):
2415
+ signature = self.ecdsa(hash[-64:], privateKey[-64:], 'secp256k1', None)
2416
+ r = signature['r']
2417
+ s = signature['s']
2418
+ v = self.int_to_base16(self.sum(27, signature['v']))
2419
+ return '0x' + r.rjust(64, '0') + s.rjust(64, '0') + v
2420
+
2421
+ def sign_message(self, message, privateKey):
2422
+ return self.sign_hash(self.hash_message(message), privateKey[-64:])
2423
+
2424
+ async def withdraw(self, code: str, amount: float, address: str, tag: Str = None, params={}) -> Transaction:
2425
+ """
2426
+ make a withdrawal
2427
+
2428
+ https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/create-withdraw-request
2429
+
2430
+ :param str code: unified currency code
2431
+ :param float amount: the amount to withdraw
2432
+ :param str address: the address to withdraw to
2433
+ :param str tag:
2434
+ :param dict [params]: extra parameters specific to the exchange API endpoint
2435
+ :returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
2436
+ """
2437
+ await self.load_markets()
2438
+ self.check_address(address)
2439
+ if code is not None:
2440
+ code = code.upper()
2441
+ if code != 'USDC':
2442
+ raise NotSupported(self.id + ' withdraw() only support USDC')
2443
+ currency = self.currency(code)
2444
+ verifyingContractAddress = self.safe_string(self.options, 'verifyingContractAddress')
2445
+ chainId = self.safe_string(params, 'chainId')
2446
+ currencyNetworks = self.safe_dict(currency, 'networks', {})
2447
+ coinNetwork = self.safe_dict(currencyNetworks, chainId, {})
2448
+ coinNetworkId = self.safe_number(coinNetwork, 'id')
2449
+ if coinNetworkId is None:
2450
+ raise BadRequest(self.id + ' withdraw() require chainId parameter')
2451
+ withdrawNonce = await self.get_withdraw_nonce(params)
2452
+ nonce = self.nonce()
2453
+ domain: dict = {
2454
+ 'chainId': chainId,
2455
+ 'name': 'Orderly',
2456
+ 'verifyingContract': verifyingContractAddress,
2457
+ 'version': '1',
2458
+ }
2459
+ messageTypes: dict = {
2460
+ 'Withdraw': [
2461
+ {'name': 'brokerId', 'type': 'string'},
2462
+ {'name': 'chainId', 'type': 'uint256'},
2463
+ {'name': 'receiver', 'type': 'address'},
2464
+ {'name': 'token', 'type': 'string'},
2465
+ {'name': 'amount', 'type': 'uint256'},
2466
+ {'name': 'withdrawNonce', 'type': 'uint64'},
2467
+ {'name': 'timestamp', 'type': 'uint64'},
2468
+ ],
2469
+ }
2470
+ withdrawRequest: dict = {
2471
+ 'brokerId': self.safe_string(self.options, 'keyBrokerId', 'mode'),
2472
+ 'chainId': self.parse_to_int(chainId),
2473
+ 'receiver': address,
2474
+ 'token': code,
2475
+ 'amount': str(amount),
2476
+ 'withdrawNonce': withdrawNonce,
2477
+ 'timestamp': nonce,
2478
+ }
2479
+ msg = self.eth_encode_structured_data(domain, messageTypes, withdrawRequest)
2480
+ signature = self.sign_message(msg, self.privateKey)
2481
+ request: dict = {
2482
+ 'signature': signature,
2483
+ 'userAddress': address,
2484
+ 'verifyingContract': verifyingContractAddress,
2485
+ 'message': withdrawRequest,
2486
+ }
2487
+ params = self.omit(params, 'chainId')
2488
+ response = await self.v1PrivatePostWithdrawRequest(self.extend(request, params))
2489
+ #
2490
+ # {
2491
+ # "success": True,
2492
+ # "timestamp": 1702989203989,
2493
+ # "data": {
2494
+ # "withdraw_id": 123
2495
+ # }
2496
+ # }
2497
+ #
2498
+ data = self.safe_dict(response, 'data', {})
2499
+ return self.parse_transaction(data, currency)
2500
+
2501
+ def parse_leverage(self, leverage, market=None) -> Leverage:
2502
+ leverageValue = self.safe_integer(leverage, 'max_leverage')
2503
+ return {
2504
+ 'info': leverage,
2505
+ 'symbol': market['symbol'],
2506
+ 'marginMode': None,
2507
+ 'longLeverage': leverageValue,
2508
+ 'shortLeverage': leverageValue,
2509
+ }
2510
+
2511
+ async def fetch_leverage(self, symbol: str, params={}) -> Leverage:
2512
+ """
2513
+ fetch the set leverage for a market
2514
+
2515
+ https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-account-information
2516
+
2517
+ :param str symbol: unified market symbol
2518
+ :param dict [params]: extra parameters specific to the exchange API endpoint
2519
+ :returns dict: a `leverage structure <https://docs.ccxt.com/#/?id=leverage-structure>`
2520
+ """
2521
+ await self.load_markets()
2522
+ market = self.market(symbol)
2523
+ response = await self.v1PrivateGetClientInfo(params)
2524
+ #
2525
+ # {
2526
+ # "success": True,
2527
+ # "timestamp": 1702989203989,
2528
+ # "data": {
2529
+ # "account_id": "<string>",
2530
+ # "email": "test@test.com",
2531
+ # "account_mode": "FUTURES",
2532
+ # "max_leverage": 20,
2533
+ # "taker_fee_rate": 123,
2534
+ # "maker_fee_rate": 123,
2535
+ # "futures_taker_fee_rate": 123,
2536
+ # "futures_maker_fee_rate": 123,
2537
+ # "maintenance_cancel_orders": True,
2538
+ # "imr_factor": {
2539
+ # "PERP_BTC_USDC": 123,
2540
+ # "PERP_ETH_USDC": 123,
2541
+ # "PERP_NEAR_USDC": 123
2542
+ # },
2543
+ # "max_notional": {
2544
+ # "PERP_BTC_USDC": 123,
2545
+ # "PERP_ETH_USDC": 123,
2546
+ # "PERP_NEAR_USDC": 123
2547
+ # }
2548
+ # }
2549
+ # }
2550
+ #
2551
+ data = self.safe_dict(response, 'data', {})
2552
+ return self.parse_leverage(data, market)
2553
+
2554
+ async def set_leverage(self, leverage: int, symbol: Str = None, params={}):
2555
+ """
2556
+ set the level of leverage for a market
2557
+
2558
+ https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/update-leverage-setting
2559
+
2560
+ :param int [leverage]: the rate of leverage
2561
+ :param str [symbol]: unified market symbol
2562
+ :param dict [params]: extra parameters specific to the exchange API endpoint
2563
+ :returns dict: response from the exchange
2564
+ """
2565
+ await self.load_markets()
2566
+ isMinLeverage = leverage < 1
2567
+ isMaxLeverage = leverage > 50
2568
+ if isMinLeverage or isMaxLeverage:
2569
+ raise BadRequest(self.id + ' leverage should be between 1 and 50')
2570
+ request: dict = {
2571
+ 'leverage': leverage,
2572
+ }
2573
+ return await self.v1PrivatePostClientLeverage(self.extend(request, params))
2574
+
2575
+ def parse_position(self, position: dict, market: Market = None):
2576
+ #
2577
+ # {
2578
+ # "IMR_withdraw_orders": 0.1,
2579
+ # "MMR_with_orders": 0.05,
2580
+ # "average_open_price": 27908.14386047,
2581
+ # "cost_position": -139329.358492,
2582
+ # "est_liq_price": 117335.92899428,
2583
+ # "fee_24_h": 123,
2584
+ # "imr": 0.1,
2585
+ # "last_sum_unitary_funding": 70.38,
2586
+ # "mark_price": 27794.9,
2587
+ # "mmr": 0.05,
2588
+ # "pending_long_qty": 123,
2589
+ # "pending_short_qty": 123,
2590
+ # "pnl_24_h": 123,
2591
+ # "position_qty": -5,
2592
+ # "settle_price": 27865.8716984,
2593
+ # "symbol": "PERP_BTC_USDC",
2594
+ # "timestamp": 1685429350571,
2595
+ # "unsettled_pnl": 354.858492
2596
+ # }
2597
+ #
2598
+ contract = self.safe_string(position, 'symbol')
2599
+ market = self.safe_market(contract, market)
2600
+ size = self.safe_string(position, 'position_qty')
2601
+ side: Str = None
2602
+ if Precise.string_gt(size, '0'):
2603
+ side = 'long'
2604
+ else:
2605
+ side = 'short'
2606
+ contractSize = self.safe_string(market, 'contractSize')
2607
+ markPrice = self.safe_string(position, 'mark_price')
2608
+ timestamp = self.safe_integer(position, 'timestamp')
2609
+ entryPrice = self.safe_string(position, 'average_open_price')
2610
+ unrealisedPnl = self.safe_string(position, 'unsettled_pnl')
2611
+ size = Precise.string_abs(size)
2612
+ notional = Precise.string_mul(size, markPrice)
2613
+ return self.safe_position({
2614
+ 'info': position,
2615
+ 'id': None,
2616
+ 'symbol': self.safe_string(market, 'symbol'),
2617
+ 'timestamp': timestamp,
2618
+ 'datetime': self.iso8601(timestamp),
2619
+ 'lastUpdateTimestamp': None,
2620
+ 'initialMargin': None,
2621
+ 'initialMarginPercentage': None,
2622
+ 'maintenanceMargin': None,
2623
+ 'maintenanceMarginPercentage': None,
2624
+ 'entryPrice': self.parse_number(entryPrice),
2625
+ 'notional': self.parse_number(notional),
2626
+ 'leverage': None,
2627
+ 'unrealizedPnl': self.parse_number(unrealisedPnl),
2628
+ 'contracts': self.parse_number(size),
2629
+ 'contractSize': self.parse_number(contractSize),
2630
+ 'marginRatio': None,
2631
+ 'liquidationPrice': self.safe_number(position, 'est_liq_price'),
2632
+ 'markPrice': self.parse_number(markPrice),
2633
+ 'lastPrice': None,
2634
+ 'collateral': None,
2635
+ 'marginMode': 'cross',
2636
+ 'marginType': None,
2637
+ 'side': side,
2638
+ 'percentage': None,
2639
+ 'hedged': None,
2640
+ 'stopLossPrice': None,
2641
+ 'takeProfitPrice': None,
2642
+ })
2643
+
2644
+ async def fetch_position(self, symbol: Str, params={}):
2645
+ """
2646
+
2647
+ https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-one-position-info
2648
+
2649
+ fetch data on an open position
2650
+ :param str symbol: unified market symbol of the market the position is held in
2651
+ :param dict [params]: extra parameters specific to the exchange API endpoint
2652
+ :returns dict: a `position structure <https://docs.ccxt.com/#/?id=position-structure>`
2653
+ """
2654
+ await self.load_markets()
2655
+ market = self.market(symbol)
2656
+ request: dict = {
2657
+ 'symbol': market['id'],
2658
+ }
2659
+ response = await self.v1PrivateGetPositionSymbol(self.extend(request, params))
2660
+ #
2661
+ # {
2662
+ # "success": True,
2663
+ # "timestamp": 1702989203989,
2664
+ # "data": {
2665
+ # "IMR_withdraw_orders": 0.1,
2666
+ # "MMR_with_orders": 0.05,
2667
+ # "average_open_price": 27908.14386047,
2668
+ # "cost_position": -139329.358492,
2669
+ # "est_liq_price": 117335.92899428,
2670
+ # "fee_24_h": 123,
2671
+ # "imr": 0.1,
2672
+ # "last_sum_unitary_funding": 70.38,
2673
+ # "mark_price": 27794.9,
2674
+ # "mmr": 0.05,
2675
+ # "pending_long_qty": 123,
2676
+ # "pending_short_qty": 123,
2677
+ # "pnl_24_h": 123,
2678
+ # "position_qty": -5,
2679
+ # "settle_price": 27865.8716984,
2680
+ # "symbol": "PERP_BTC_USDC",
2681
+ # "timestamp": 1685429350571,
2682
+ # "unsettled_pnl": 354.858492
2683
+ # }
2684
+ # }
2685
+ #
2686
+ data = self.safe_dict(response, 'data')
2687
+ return self.parse_position(data, market)
2688
+
2689
+ async def fetch_positions(self, symbols: Strings = None, params={}) -> List[Position]:
2690
+ """
2691
+ fetch all open positions
2692
+
2693
+ https://orderly.network/docs/build-on-evm/evm-api/restful-api/private/get-all-positions-info
2694
+
2695
+ :param str[] [symbols]: list of unified market symbols
2696
+ :param dict [params]: extra parameters specific to the exchange API endpoint
2697
+ :returns dict[]: a list of `position structure <https://docs.ccxt.com/#/?id=position-structure>`
2698
+ """
2699
+ await self.load_markets()
2700
+ response = await self.v1PrivateGetPositions(params)
2701
+ #
2702
+ # {
2703
+ # "success": True,
2704
+ # "timestamp": 1702989203989,
2705
+ # "data": {
2706
+ # "current_margin_ratio_with_orders": 1.2385,
2707
+ # "free_collateral": 450315.09115,
2708
+ # "initial_margin_ratio": 0.1,
2709
+ # "initial_margin_ratio_with_orders": 0.1,
2710
+ # "maintenance_margin_ratio": 0.05,
2711
+ # "maintenance_margin_ratio_with_orders": 0.05,
2712
+ # "margin_ratio": 1.2385,
2713
+ # "open_margin_ratio": 1.2102,
2714
+ # "total_collateral_value": 489865.71329,
2715
+ # "total_pnl_24_h": 123,
2716
+ # "rows": [{
2717
+ # "IMR_withdraw_orders": 0.1,
2718
+ # "MMR_with_orders": 0.05,
2719
+ # "average_open_price": 27908.14386047,
2720
+ # "cost_position": -139329.358492,
2721
+ # "est_liq_price": 117335.92899428,
2722
+ # "fee_24_h": 123,
2723
+ # "imr": 0.1,
2724
+ # "last_sum_unitary_funding": 70.38,
2725
+ # "mark_price": 27794.9,
2726
+ # "mmr": 0.05,
2727
+ # "pending_long_qty": 123,
2728
+ # "pending_short_qty": 123,
2729
+ # "pnl_24_h": 123,
2730
+ # "position_qty": -5,
2731
+ # "settle_price": 27865.8716984,
2732
+ # "symbol": "PERP_BTC_USDC",
2733
+ # "timestamp": 1685429350571,
2734
+ # "unsettled_pnl": 354.858492
2735
+ # }]
2736
+ # }
2737
+ # }
2738
+ #
2739
+ result = self.safe_dict(response, 'data', {})
2740
+ positions = self.safe_list(result, 'rows', [])
2741
+ return self.parse_positions(positions, symbols)
2742
+
2743
+ def nonce(self):
2744
+ return self.milliseconds()
2745
+
2746
+ def sign(self, path, section='public', method='GET', params={}, headers=None, body=None):
2747
+ version = section[0]
2748
+ access = section[1]
2749
+ pathWithParams = self.implode_params(path, params)
2750
+ url = self.implode_hostname(self.urls['api'][access])
2751
+ url += '/' + version + '/'
2752
+ params = self.omit(params, self.extract_params(path))
2753
+ params = self.keysort(params)
2754
+ if access == 'public':
2755
+ url += pathWithParams
2756
+ if params:
2757
+ url += '?' + self.urlencode(params)
2758
+ else:
2759
+ self.check_required_credentials()
2760
+ isPostOrPut = method == 'POST' or method == 'PUT'
2761
+ isOrder = path == 'algo/order' or path == 'order' or path == 'batch-order'
2762
+ if isPostOrPut and isOrder:
2763
+ isSandboxMode = self.safe_bool(self.options, 'sandboxMode', False)
2764
+ if not isSandboxMode:
2765
+ brokerId = self.safe_string(self.options, 'brokerId', 'CCXTMODE')
2766
+ if path == 'batch-order':
2767
+ ordersList = self.safe_list(params, 'orders', [])
2768
+ for i in range(0, len(ordersList)):
2769
+ params['orders'][i]['order_tag'] = brokerId
2770
+ else:
2771
+ params['order_tag'] = brokerId
2772
+ params = self.keysort(params)
2773
+ auth = ''
2774
+ ts = str(self.nonce())
2775
+ url += pathWithParams
2776
+ apiKey = self.apiKey
2777
+ if apiKey.find('ed25519:') < 0:
2778
+ apiKey = 'ed25519:' + apiKey
2779
+ headers = {
2780
+ 'orderly-account-id': self.accountId,
2781
+ 'orderly-key': apiKey,
2782
+ 'orderly-timestamp': ts,
2783
+ }
2784
+ auth = ts + method + '/' + version + '/' + pathWithParams
2785
+ if method == 'POST' or method == 'PUT':
2786
+ body = self.json(params)
2787
+ auth += body
2788
+ headers['content-type'] = 'application/json'
2789
+ else:
2790
+ if params:
2791
+ url += '?' + self.urlencode(params)
2792
+ auth += '?' + self.rawencode(params)
2793
+ headers['content-type'] = 'application/x-www-form-urlencoded'
2794
+ if method == 'DELETE':
2795
+ body = ''
2796
+ secret = self.secret
2797
+ if secret.find('ed25519:') >= 0:
2798
+ parts = secret.split('ed25519:')
2799
+ secret = parts[1]
2800
+ signature = self.eddsa(self.encode(auth), self.base58_to_binary(secret), 'ed25519')
2801
+ headers['orderly-signature'] = self.urlencode_base64(self.base64_to_binary(signature))
2802
+ return {'url': url, 'method': method, 'body': body, 'headers': headers}
2803
+
2804
+ def handle_errors(self, httpCode: int, reason: str, url: str, method: str, headers: dict, body: str, response, requestHeaders, requestBody):
2805
+ if not response:
2806
+ return None # fallback to default error handler
2807
+ #
2808
+ # 400 Bad Request {"success":false,"code":-1012,"message":"Amount is required for buy market orders when margin disabled."}
2809
+ # {"code":"-1011","message":"The system is under maintenance.","success":false}
2810
+ #
2811
+ success = self.safe_bool(response, 'success')
2812
+ errorCode = self.safe_string(response, 'code')
2813
+ if not success:
2814
+ feedback = self.id + ' ' + self.json(response)
2815
+ self.throw_broadly_matched_exception(self.exceptions['broad'], body, feedback)
2816
+ self.throw_exactly_matched_exception(self.exceptions['exact'], errorCode, feedback)
2817
+ raise ExchangeError(feedback)
2818
+ return None