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