ccxt 4.2.77__py2.py3-none-any.whl → 4.4.49__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 +24 -0
  44. ccxt/abstract/kucoinfutures.py +34 -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 +3030 -1087
  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 +3205 -937
  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 +238 -49
  89. ccxt/async_support/bitget.py +1525 -573
  90. ccxt/async_support/bithumb.py +199 -65
  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 +392 -148
  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 +2231 -1193
  107. ccxt/async_support/cex.py +1409 -1329
  108. ccxt/async_support/coinbase.py +1454 -287
  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 +223 -97
  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 +404 -109
  125. ccxt/async_support/deribit.py +639 -323
  126. ccxt/async_support/digifinex.py +465 -233
  127. ccxt/async_support/ellipx.py +1887 -0
  128. ccxt/async_support/exmo.py +317 -128
  129. ccxt/async_support/gate.py +1472 -463
  130. ccxt/async_support/gemini.py +206 -84
  131. ccxt/async_support/hashkey.py +4164 -0
  132. ccxt/async_support/hitbtc.py +433 -178
  133. ccxt/async_support/hollaex.py +207 -83
  134. ccxt/async_support/htx.py +1095 -563
  135. ccxt/async_support/huobijp.py +178 -56
  136. ccxt/async_support/hyperliquid.py +1678 -292
  137. ccxt/async_support/idex.py +219 -95
  138. ccxt/async_support/independentreserve.py +300 -31
  139. ccxt/async_support/indodax.py +226 -62
  140. ccxt/async_support/kraken.py +871 -354
  141. ccxt/async_support/krakenfutures.py +324 -100
  142. ccxt/async_support/kucoin.py +917 -357
  143. ccxt/async_support/kucoinfutures.py +1004 -149
  144. ccxt/async_support/kuna.py +198 -107
  145. ccxt/async_support/latoken.py +199 -79
  146. ccxt/async_support/lbank.py +360 -113
  147. ccxt/async_support/luno.py +185 -62
  148. ccxt/async_support/lykke.py +168 -55
  149. ccxt/async_support/mercado.py +101 -29
  150. ccxt/async_support/mexc.py +995 -429
  151. ccxt/async_support/myokx.py +53 -0
  152. ccxt/async_support/ndax.py +234 -82
  153. ccxt/async_support/novadax.py +195 -75
  154. ccxt/async_support/oceanex.py +244 -59
  155. ccxt/async_support/okcoin.py +301 -165
  156. ccxt/async_support/okx.py +1776 -454
  157. ccxt/async_support/onetrading.py +198 -414
  158. ccxt/async_support/oxfun.py +2898 -0
  159. ccxt/async_support/p2b.py +142 -52
  160. ccxt/async_support/paradex.py +2085 -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 +1137 -296
  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 +1722 -480
  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 +3030 -1087
  187. ccxt/binancecoinm.py +2 -1
  188. ccxt/binanceus.py +12 -1
  189. ccxt/binanceusdm.py +3 -1
  190. ccxt/bingx.py +3205 -937
  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 +238 -49
  197. ccxt/bitget.py +1525 -573
  198. ccxt/bithumb.py +198 -65
  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 +392 -148
  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 +2231 -1193
  215. ccxt/cex.py +1408 -1329
  216. ccxt/coinbase.py +1454 -287
  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 +223 -97
  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 +404 -109
  233. ccxt/deribit.py +639 -323
  234. ccxt/digifinex.py +465 -233
  235. ccxt/ellipx.py +1887 -0
  236. ccxt/exmo.py +317 -128
  237. ccxt/gate.py +1472 -463
  238. ccxt/gemini.py +206 -84
  239. ccxt/hashkey.py +4164 -0
  240. ccxt/hitbtc.py +433 -178
  241. ccxt/hollaex.py +207 -83
  242. ccxt/htx.py +1095 -563
  243. ccxt/huobijp.py +178 -56
  244. ccxt/hyperliquid.py +1677 -292
  245. ccxt/idex.py +219 -95
  246. ccxt/independentreserve.py +299 -31
  247. ccxt/indodax.py +226 -62
  248. ccxt/kraken.py +871 -354
  249. ccxt/krakenfutures.py +324 -100
  250. ccxt/kucoin.py +917 -357
  251. ccxt/kucoinfutures.py +1004 -149
  252. ccxt/kuna.py +198 -107
  253. ccxt/latoken.py +199 -79
  254. ccxt/lbank.py +360 -113
  255. ccxt/luno.py +185 -62
  256. ccxt/lykke.py +168 -55
  257. ccxt/mercado.py +101 -29
  258. ccxt/mexc.py +994 -429
  259. ccxt/myokx.py +53 -0
  260. ccxt/ndax.py +234 -82
  261. ccxt/novadax.py +195 -75
  262. ccxt/oceanex.py +244 -59
  263. ccxt/okcoin.py +301 -165
  264. ccxt/okx.py +1776 -454
  265. ccxt/onetrading.py +198 -414
  266. ccxt/oxfun.py +2897 -0
  267. ccxt/p2b.py +142 -52
  268. ccxt/paradex.py +2085 -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 +62 -14
  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 +143 -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 +203 -81
  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 +965 -665
  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 +167 -31
  309. ccxt/pro/exmo.py +252 -20
  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 +92 -33
  336. ccxt/pro/poloniex.py +128 -49
  337. ccxt/pro/poloniexfutures.py +53 -32
  338. ccxt/pro/probit.py +92 -85
  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 +437 -65
  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} +456 -391
  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} +456 -393
  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 +1137 -296
  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.49.dist-info/LICENSE.txt +21 -0
  496. ccxt-4.4.49.dist-info/METADATA +646 -0
  497. ccxt-4.4.49.dist-info/RECORD +669 -0
  498. {ccxt-4.2.77.dist-info → ccxt-4.4.49.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.77.dist-info/METADATA +0 -626
  545. ccxt-4.2.77.dist-info/RECORD +0 -534
  546. {ccxt-4.2.77.dist-info → ccxt-4.4.49.dist-info}/top_level.txt +0 -0
ccxt/paradex.py ADDED
@@ -0,0 +1,2085 @@
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.paradex import ImplicitAPI
8
+ from ccxt.base.types import Balances, Currency, Int, Market, Num, Order, OrderBook, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, Transaction
9
+ from typing import List
10
+ from ccxt.base.errors import ExchangeError
11
+ from ccxt.base.errors import AuthenticationError
12
+ from ccxt.base.errors import PermissionDenied
13
+ from ccxt.base.errors import ArgumentsRequired
14
+ from ccxt.base.errors import BadRequest
15
+ from ccxt.base.errors import OperationRejected
16
+ from ccxt.base.errors import InvalidOrder
17
+ from ccxt.base.decimal_to_precision import TICK_SIZE
18
+ from ccxt.base.precise import Precise
19
+
20
+
21
+ class paradex(Exchange, ImplicitAPI):
22
+
23
+ def describe(self):
24
+ return self.deep_extend(super(paradex, self).describe(), {
25
+ 'id': 'paradex',
26
+ 'name': 'Paradex',
27
+ 'countries': [],
28
+ 'version': 'v1',
29
+ 'rateLimit': 50,
30
+ 'certified': False,
31
+ 'pro': True,
32
+ 'dex': True,
33
+ 'has': {
34
+ 'CORS': None,
35
+ 'spot': False,
36
+ 'margin': False,
37
+ 'swap': True,
38
+ 'future': False,
39
+ 'option': False,
40
+ 'addMargin': False,
41
+ 'borrowCrossMargin': False,
42
+ 'borrowIsolatedMargin': False,
43
+ 'cancelAllOrders': True,
44
+ 'cancelAllOrdersAfter': False,
45
+ 'cancelOrder': False,
46
+ 'cancelOrders': False,
47
+ 'cancelOrdersForSymbols': False,
48
+ 'closeAllPositions': False,
49
+ 'closePosition': False,
50
+ 'createMarketBuyOrderWithCost': False,
51
+ 'createMarketOrderWithCost': False,
52
+ 'createMarketSellOrderWithCost': False,
53
+ 'createOrder': True,
54
+ 'createOrders': False,
55
+ 'createReduceOnlyOrder': False,
56
+ 'createStopOrder': True,
57
+ 'createTriggerOrder': True,
58
+ 'editOrder': False,
59
+ 'fetchAccounts': False,
60
+ 'fetchBalance': True,
61
+ 'fetchBorrowInterest': False,
62
+ 'fetchBorrowRateHistories': False,
63
+ 'fetchBorrowRateHistory': False,
64
+ 'fetchCanceledOrders': False,
65
+ 'fetchClosedOrders': False,
66
+ 'fetchCrossBorrowRate': False,
67
+ 'fetchCrossBorrowRates': False,
68
+ 'fetchCurrencies': False,
69
+ 'fetchDepositAddress': False,
70
+ 'fetchDepositAddresses': False,
71
+ 'fetchDeposits': True,
72
+ 'fetchDepositWithdrawFee': False,
73
+ 'fetchDepositWithdrawFees': False,
74
+ 'fetchFundingHistory': False,
75
+ 'fetchFundingRate': False,
76
+ 'fetchFundingRateHistory': False,
77
+ 'fetchFundingRates': False,
78
+ 'fetchIndexOHLCV': False,
79
+ 'fetchIsolatedBorrowRate': False,
80
+ 'fetchIsolatedBorrowRates': False,
81
+ 'fetchLedger': False,
82
+ 'fetchLeverage': False,
83
+ 'fetchLeverageTiers': False,
84
+ 'fetchLiquidations': True,
85
+ 'fetchMarginMode': None,
86
+ 'fetchMarketLeverageTiers': False,
87
+ 'fetchMarkets': True,
88
+ 'fetchMarkOHLCV': False,
89
+ 'fetchMyLiquidations': False,
90
+ 'fetchMyTrades': True,
91
+ 'fetchOHLCV': True,
92
+ 'fetchOpenInterest': True,
93
+ 'fetchOpenInterestHistory': False,
94
+ 'fetchOpenOrders': True,
95
+ 'fetchOrder': True,
96
+ 'fetchOrderBook': True,
97
+ 'fetchOrders': True,
98
+ 'fetchOrderTrades': False,
99
+ 'fetchPosition': True,
100
+ 'fetchPositionMode': False,
101
+ 'fetchPositions': True,
102
+ 'fetchPositionsRisk': False,
103
+ 'fetchPremiumIndexOHLCV': False,
104
+ 'fetchStatus': True,
105
+ 'fetchTicker': True,
106
+ 'fetchTickers': True,
107
+ 'fetchTime': True,
108
+ 'fetchTrades': True,
109
+ 'fetchTradingFee': False,
110
+ 'fetchTradingFees': False,
111
+ 'fetchTransfer': False,
112
+ 'fetchTransfers': False,
113
+ 'fetchWithdrawal': False,
114
+ 'fetchWithdrawals': True,
115
+ 'reduceMargin': False,
116
+ 'repayCrossMargin': False,
117
+ 'repayIsolatedMargin': False,
118
+ 'sandbox': True,
119
+ 'setLeverage': False,
120
+ 'setMarginMode': False,
121
+ 'setPositionMode': False,
122
+ 'transfer': False,
123
+ 'withdraw': False,
124
+ },
125
+ 'timeframes': {
126
+ '1m': 1,
127
+ '3m': 3,
128
+ '5m': 5,
129
+ '15m': 15,
130
+ '30m': 30,
131
+ '1h': 60,
132
+ },
133
+ 'hostname': 'paradex.trade',
134
+ 'urls': {
135
+ 'logo': 'https://github.com/user-attachments/assets/84628770-784e-4ec4-a759-ec2fbb2244ea',
136
+ 'api': {
137
+ 'v1': 'https://api.prod.{hostname}/v1',
138
+ },
139
+ 'test': {
140
+ 'v1': 'https://api.testnet.{hostname}/v1',
141
+ },
142
+ 'www': 'https://www.paradex.trade/',
143
+ 'doc': 'https://docs.api.testnet.paradex.trade/',
144
+ 'fees': 'https://docs.paradex.trade/getting-started/trading-fees',
145
+ 'referral': 'https://app.paradex.trade/r/ccxt24',
146
+ },
147
+ 'api': {
148
+ 'public': {
149
+ 'get': {
150
+ 'bbo/{market}': 1,
151
+ 'funding/data': 1,
152
+ 'markets': 1,
153
+ 'markets/klines': 1,
154
+ 'markets/summary': 1,
155
+ 'orderbook/{market}': 1,
156
+ 'insurance': 1,
157
+ 'referrals/config': 1,
158
+ 'system/config': 1,
159
+ 'system/state': 1,
160
+ 'system/time': 1,
161
+ 'trades': 1,
162
+ },
163
+ },
164
+ 'private': {
165
+ 'get': {
166
+ 'account': 1,
167
+ 'account/profile': 1,
168
+ 'balance': 1,
169
+ 'fills': 1,
170
+ 'funding/payments': 1,
171
+ 'positions': 1,
172
+ 'tradebusts': 1,
173
+ 'transactions': 1,
174
+ 'liquidations': 1,
175
+ 'orders': 1,
176
+ 'orders-history': 1,
177
+ 'orders/by_client_id/{client_id}': 1,
178
+ 'orders/{order_id}': 1,
179
+ 'points_data/{market}/{program}': 1,
180
+ 'referrals/summary': 1,
181
+ 'transfers': 1,
182
+ },
183
+ 'post': {
184
+ 'account/profile/referral_code': 1,
185
+ 'account/profile/username': 1,
186
+ 'auth': 1,
187
+ 'onboarding': 1,
188
+ 'orders': 1,
189
+ },
190
+ 'delete': {
191
+ 'orders': 1,
192
+ 'orders/by_client_id/{client_id}': 1,
193
+ 'orders/{order_id}': 1,
194
+ },
195
+ },
196
+ },
197
+ 'fees': {
198
+ 'swap': {
199
+ 'taker': self.parse_number('0.0002'),
200
+ 'maker': self.parse_number('0.0002'),
201
+ },
202
+ 'spot': {
203
+ 'taker': self.parse_number('0.0002'),
204
+ 'maker': self.parse_number('0.0002'),
205
+ },
206
+ },
207
+ 'requiredCredentials': {
208
+ 'apiKey': False,
209
+ 'secret': False,
210
+ 'walletAddress': True,
211
+ 'privateKey': True,
212
+ },
213
+ 'exceptions': {
214
+ 'exact': {
215
+ 'VALIDATION_ERROR': AuthenticationError,
216
+ 'BINDING_ERROR': OperationRejected,
217
+ 'INTERNAL_ERROR': ExchangeError,
218
+ 'NOT_FOUND': BadRequest,
219
+ 'SERVICE_UNAVAILABLE': ExchangeError,
220
+ 'INVALID_REQUEST_PARAMETER': BadRequest,
221
+ 'ORDER_ID_NOT_FOUND': InvalidOrder,
222
+ 'ORDER_IS_CLOSED': InvalidOrder,
223
+ 'ORDER_IS_NOT_OPEN_YET': InvalidOrder,
224
+ 'CLIENT_ORDER_ID_NOT_FOUND': InvalidOrder,
225
+ 'DUPLICATED_CLIENT_ID': InvalidOrder,
226
+ 'INVALID_PRICE_PRECISION': OperationRejected,
227
+ 'INVALID_SYMBOL': OperationRejected,
228
+ 'INVALID_TOKEN': OperationRejected,
229
+ 'INVALID_ETHEREUM_ADDRESS': OperationRejected,
230
+ 'INVALID_ETHEREUM_SIGNATURE': OperationRejected,
231
+ 'INVALID_STARKNET_ADDRESS': OperationRejected,
232
+ 'INVALID_STARKNET_SIGNATURE': OperationRejected,
233
+ 'STARKNET_SIGNATURE_VERIFICATION_FAILED': AuthenticationError,
234
+ 'BAD_STARKNET_REQUEST': BadRequest,
235
+ 'ETHEREUM_SIGNER_MISMATCH': BadRequest,
236
+ 'ETHEREUM_HASH_MISMATCH': BadRequest,
237
+ 'NOT_ONBOARDED': BadRequest,
238
+ 'INVALID_TIMESTAMP': BadRequest,
239
+ 'INVALID_SIGNATURE_EXPIRATION': AuthenticationError,
240
+ 'ACCOUNT_NOT_FOUND': AuthenticationError,
241
+ 'INVALID_ORDER_SIGNATURE': AuthenticationError,
242
+ 'PUBLIC_KEY_INVALID': BadRequest,
243
+ 'UNAUTHORIZED_ETHEREUM_ADDRESS': BadRequest,
244
+ 'ETHEREUM_ADDRESS_ALREADY_ONBOARDED': BadRequest,
245
+ 'MARKET_NOT_FOUND': BadRequest,
246
+ 'ALLOWLIST_ENTRY_NOT_FOUND': BadRequest,
247
+ 'USERNAME_IN_USE': AuthenticationError,
248
+ 'GEO_IP_BLOCK': PermissionDenied,
249
+ 'ETHEREUM_ADDRESS_BLOCKED': PermissionDenied,
250
+ 'PROGRAM_NOT_FOUND': BadRequest,
251
+ 'INVALID_DASHBOARD': OperationRejected,
252
+ 'MARKET_NOT_OPEN': BadRequest,
253
+ 'INVALID_REFERRAL_CODE': OperationRejected,
254
+ 'PARENT_ADDRESS_ALREADY_ONBOARDED': BadRequest,
255
+ 'INVALID_PARENT_ACCOUNT': OperationRejected,
256
+ 'INVALID_VAULT_OPERATOR_CHAIN': OperationRejected,
257
+ 'VAULT_OPERATOR_ALREADY_ONBOARDED': OperationRejected,
258
+ 'VAULT_NAME_IN_USE': OperationRejected,
259
+ 'BATCH_SIZE_OUT_OF_RANGE': OperationRejected,
260
+ 'ISOLATED_MARKET_ACCOUNT_MISMATCH': OperationRejected,
261
+ 'POINTS_SUMMARY_NOT_FOUND': OperationRejected,
262
+ '-32700': BadRequest, # Parse error
263
+ '-32600': BadRequest, # Invalid request
264
+ '-32601': BadRequest, # Method not found
265
+ '-32602': BadRequest, # Invalid parameterss
266
+ '-32603': ExchangeError, # Internal error
267
+ '100': BadRequest, # Method error
268
+ '40110': AuthenticationError, # Malformed Bearer Token
269
+ '40111': AuthenticationError, # Invalid Bearer Token
270
+ '40112': PermissionDenied, # Geo IP blocked
271
+ },
272
+ 'broad': {
273
+ 'missing or malformed jwt': AuthenticationError,
274
+ },
275
+ },
276
+ 'precisionMode': TICK_SIZE,
277
+ 'commonCurrencies': {
278
+ },
279
+ 'options': {
280
+ 'paradexAccount': None, # add {"privateKey": A, "publicKey": B, "address": C}
281
+ 'broker': 'CCXT',
282
+ },
283
+ 'features': {
284
+ 'spot': None,
285
+ 'forSwap': {
286
+ 'sandbox': True,
287
+ 'createOrder': {
288
+ 'marginMode': False,
289
+ 'triggerPrice': True,
290
+ 'triggerDirection': True, # todo
291
+ 'triggerPriceType': None,
292
+ 'stopLossPrice': False, # todo
293
+ 'takeProfitPrice': False, # todo
294
+ 'attachedStopLossTakeProfit': None,
295
+ 'timeInForce': {
296
+ 'IOC': True,
297
+ 'FOK': False,
298
+ 'PO': True,
299
+ 'GTD': False,
300
+ },
301
+ 'hedged': False,
302
+ 'trailing': False,
303
+ 'leverage': False,
304
+ 'marketBuyByCost': False,
305
+ 'marketBuyRequiresPrice': False,
306
+ 'selfTradePrevention': True, # todo
307
+ 'iceberg': False,
308
+ },
309
+ 'createOrders': None, # todo
310
+ 'fetchMyTrades': {
311
+ 'marginMode': False,
312
+ 'limit': 100, # todo
313
+ 'daysBack': 100000, # todo
314
+ 'untilDays': 100000, # todo
315
+ },
316
+ 'fetchOrder': {
317
+ 'marginMode': False,
318
+ 'trigger': False,
319
+ 'trailing': False,
320
+ },
321
+ 'fetchOpenOrders': {
322
+ 'marginMode': False,
323
+ 'limit': 100, # todo
324
+ 'trigger': False,
325
+ 'trailing': False,
326
+ },
327
+ 'fetchOrders': {
328
+ 'marginMode': False,
329
+ 'limit': 100,
330
+ 'daysBack': 100000, # todo
331
+ 'untilDays': 100000, # todo
332
+ 'trigger': False,
333
+ 'trailing': False,
334
+ },
335
+ 'fetchClosedOrders': None, # todo
336
+ 'fetchOHLCV': {
337
+ 'limit': None, # todo by from/to
338
+ },
339
+ },
340
+ 'swap': {
341
+ 'linear': {
342
+ 'extends': 'forSwap',
343
+ },
344
+ 'inverse': None,
345
+ },
346
+ 'future': {
347
+ 'linear': None,
348
+ 'inverse': None,
349
+ },
350
+ },
351
+ })
352
+
353
+ def fetch_time(self, params={}):
354
+ """
355
+ fetches the current integer timestamp in milliseconds from the exchange server
356
+
357
+ https://docs.api.testnet.paradex.trade/#get-system-time-unix-milliseconds
358
+
359
+ :param dict [params]: extra parameters specific to the exchange API endpoint
360
+ :returns int: the current integer timestamp in milliseconds from the exchange server
361
+ """
362
+ response = self.publicGetSystemTime(params)
363
+ #
364
+ # {
365
+ # "server_time": "1681493415023"
366
+ # }
367
+ #
368
+ return self.safe_integer(response, 'server_time')
369
+
370
+ def fetch_status(self, params={}):
371
+ """
372
+ the latest known information on the availability of the exchange API
373
+
374
+ https://docs.api.testnet.paradex.trade/#get-system-state
375
+
376
+ :param dict [params]: extra parameters specific to the exchange API endpoint
377
+ :returns dict: a `status structure <https://docs.ccxt.com/#/?id=exchange-status-structure>`
378
+ """
379
+ response = self.publicGetSystemState(params)
380
+ #
381
+ # {
382
+ # "status": "ok"
383
+ # }
384
+ #
385
+ status = self.safe_string(response, 'status')
386
+ return {
387
+ 'status': 'ok' if (status == 'ok') else 'maintenance',
388
+ 'updated': None,
389
+ 'eta': None,
390
+ 'url': None,
391
+ 'info': response,
392
+ }
393
+
394
+ def fetch_markets(self, params={}) -> List[Market]:
395
+ """
396
+ retrieves data on all markets for bitget
397
+
398
+ https://docs.api.testnet.paradex.trade/#list-available-markets
399
+
400
+ :param dict [params]: extra parameters specific to the exchange API endpoint
401
+ :returns dict[]: an array of objects representing market data
402
+ """
403
+ response = self.publicGetMarkets(params)
404
+ #
405
+ # {
406
+ # "results": [
407
+ # {
408
+ # "symbol": "BODEN-USD-PERP",
409
+ # "base_currency": "BODEN",
410
+ # "quote_currency": "USD",
411
+ # "settlement_currency": "USDC",
412
+ # "order_size_increment": "1",
413
+ # "price_tick_size": "0.00001",
414
+ # "min_notional": "200",
415
+ # "open_at": 1717065600000,
416
+ # "expiry_at": 0,
417
+ # "asset_kind": "PERP",
418
+ # "position_limit": "2000000",
419
+ # "price_bands_width": "0.2",
420
+ # "max_open_orders": 50,
421
+ # "max_funding_rate": "0.05",
422
+ # "delta1_cross_margin_params": {
423
+ # "imf_base": "0.2",
424
+ # "imf_shift": "180000",
425
+ # "imf_factor": "0.00071",
426
+ # "mmf_factor": "0.5"
427
+ # },
428
+ # "price_feed_id": "9LScEHse1ioZt2rUuhwiN6bmYnqpMqvZkQJDNUpxVHN5",
429
+ # "oracle_ewma_factor": "0.14999987905913592",
430
+ # "max_order_size": "520000",
431
+ # "max_funding_rate_change": "0.0005",
432
+ # "max_tob_spread": "0.2"
433
+ # }
434
+ # ]
435
+ # }
436
+ #
437
+ data = self.safe_list(response, 'results')
438
+ return self.parse_markets(data)
439
+
440
+ def parse_market(self, market: dict) -> Market:
441
+ #
442
+ # {
443
+ # "symbol": "BODEN-USD-PERP",
444
+ # "base_currency": "BODEN",
445
+ # "quote_currency": "USD",
446
+ # "settlement_currency": "USDC",
447
+ # "order_size_increment": "1",
448
+ # "price_tick_size": "0.00001",
449
+ # "min_notional": "200",
450
+ # "open_at": 1717065600000,
451
+ # "expiry_at": 0,
452
+ # "asset_kind": "PERP",
453
+ # "position_limit": "2000000",
454
+ # "price_bands_width": "0.2",
455
+ # "max_open_orders": 50,
456
+ # "max_funding_rate": "0.05",
457
+ # "delta1_cross_margin_params": {
458
+ # "imf_base": "0.2",
459
+ # "imf_shift": "180000",
460
+ # "imf_factor": "0.00071",
461
+ # "mmf_factor": "0.5"
462
+ # },
463
+ # "price_feed_id": "9LScEHse1ioZt2rUuhwiN6bmYnqpMqvZkQJDNUpxVHN5",
464
+ # "oracle_ewma_factor": "0.14999987905913592",
465
+ # "max_order_size": "520000",
466
+ # "max_funding_rate_change": "0.0005",
467
+ # "max_tob_spread": "0.2"
468
+ # }
469
+ #
470
+ marketId = self.safe_string(market, 'symbol')
471
+ quoteId = self.safe_string(market, 'quote_currency')
472
+ baseId = self.safe_string(market, 'base_currency')
473
+ quote = self.safe_currency_code(quoteId)
474
+ base = self.safe_currency_code(baseId)
475
+ settleId = self.safe_string(market, 'settlement_currency')
476
+ settle = self.safe_currency_code(settleId)
477
+ symbol = base + '/' + quote + ':' + settle
478
+ expiry = self.safe_integer(market, 'expiry_at')
479
+ takerFee = self.parse_number('0.0003')
480
+ makerFee = self.parse_number('-0.00005')
481
+ return self.safe_market_structure({
482
+ 'id': marketId,
483
+ 'symbol': symbol,
484
+ 'base': base,
485
+ 'quote': quote,
486
+ 'settle': settle,
487
+ 'baseId': baseId,
488
+ 'quoteId': quoteId,
489
+ 'settleId': settleId,
490
+ 'type': 'swap',
491
+ 'spot': False,
492
+ 'margin': None,
493
+ 'swap': True,
494
+ 'future': False,
495
+ 'option': False,
496
+ 'active': self.safe_bool(market, 'enableTrading'),
497
+ 'contract': True,
498
+ 'linear': True,
499
+ 'inverse': None,
500
+ 'taker': takerFee,
501
+ 'maker': makerFee,
502
+ 'contractSize': self.parse_number('1'),
503
+ 'expiry': None if (expiry == 0) else expiry,
504
+ 'expiryDatetime': None if (expiry == 0) else self.iso8601(expiry),
505
+ 'strike': None,
506
+ 'optionType': None,
507
+ 'precision': {
508
+ 'amount': self.safe_number(market, 'order_size_increment'),
509
+ 'price': self.safe_number(market, 'price_tick_size'),
510
+ },
511
+ 'limits': {
512
+ 'leverage': {
513
+ 'min': None,
514
+ 'max': None,
515
+ },
516
+ 'amount': {
517
+ 'min': None,
518
+ 'max': self.safe_number(market, 'max_order_size'),
519
+ },
520
+ 'price': {
521
+ 'min': None,
522
+ 'max': None,
523
+ },
524
+ 'cost': {
525
+ 'min': self.safe_number(market, 'min_notional'),
526
+ 'max': None,
527
+ },
528
+ },
529
+ 'created': None,
530
+ 'info': market,
531
+ })
532
+
533
+ def fetch_ohlcv(self, symbol: str, timeframe='1m', since: Int = None, limit: Int = None, params={}) -> List[list]:
534
+ """
535
+ fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
536
+
537
+ https://docs.api.testnet.paradex.trade/#ohlcv-for-a-symbol
538
+
539
+ :param str symbol: unified symbol of the market to fetch OHLCV data for
540
+ :param str timeframe: the length of time each candle represents
541
+ :param int [since]: timestamp in ms of the earliest candle to fetch
542
+ :param int [limit]: the maximum amount of candles to fetch
543
+ :param dict [params]: extra parameters specific to the exchange API endpoint
544
+ :param int [params.until]: timestamp in ms of the latest candle to fetch
545
+ :returns int[][]: A list of candles ordered, open, high, low, close, volume
546
+ """
547
+ self.load_markets()
548
+ market = self.market(symbol)
549
+ request: dict = {
550
+ 'resolution': self.safe_string(self.timeframes, timeframe, timeframe),
551
+ 'symbol': market['id'],
552
+ }
553
+ now = self.milliseconds()
554
+ duration = self.parse_timeframe(timeframe)
555
+ until = self.safe_integer_2(params, 'until', 'till', now)
556
+ params = self.omit(params, ['until', 'till'])
557
+ if since is not None:
558
+ request['start_at'] = since
559
+ if limit is not None:
560
+ request['end_at'] = self.sum(since, duration * (limit + 1) * 1000) - 1
561
+ else:
562
+ request['end_at'] = until
563
+ else:
564
+ request['end_at'] = until
565
+ if limit is not None:
566
+ request['start_at'] = until - duration * (limit + 1) * 1000 + 1
567
+ else:
568
+ request['start_at'] = until - duration * 101 * 1000 + 1
569
+ response = self.publicGetMarketsKlines(self.extend(request, params))
570
+ #
571
+ # {
572
+ # "results": [
573
+ # [
574
+ # 1720071900000,
575
+ # 58961.3,
576
+ # 58961.3,
577
+ # 58961.3,
578
+ # 58961.3,
579
+ # 1591
580
+ # ]
581
+ # ]
582
+ # }
583
+ #
584
+ data = self.safe_list(response, 'results', [])
585
+ return self.parse_ohlcvs(data, market, timeframe, since, limit)
586
+
587
+ def parse_ohlcv(self, ohlcv, market: Market = None) -> list:
588
+ #
589
+ # [
590
+ # 1720071900000,
591
+ # 58961.3,
592
+ # 58961.3,
593
+ # 58961.3,
594
+ # 58961.3,
595
+ # 1591
596
+ # ]
597
+ #
598
+ return [
599
+ self.safe_integer(ohlcv, 0),
600
+ self.safe_number(ohlcv, 1),
601
+ self.safe_number(ohlcv, 2),
602
+ self.safe_number(ohlcv, 3),
603
+ self.safe_number(ohlcv, 4),
604
+ self.safe_number(ohlcv, 5),
605
+ ]
606
+
607
+ def fetch_tickers(self, symbols: Strings = None, params={}) -> Tickers:
608
+ """
609
+ fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
610
+
611
+ https://docs.api.testnet.paradex.trade/#list-available-markets-summary
612
+
613
+ :param str[]|None symbols: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
614
+ :param dict [params]: extra parameters specific to the exchange API endpoint
615
+ :returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
616
+ """
617
+ self.load_markets()
618
+ symbols = self.market_symbols(symbols)
619
+ request: dict = {}
620
+ if symbols is not None:
621
+ if isinstance(symbols, list):
622
+ request['market'] = self.market_id(symbols[0])
623
+ else:
624
+ request['market'] = self.market_id(symbols)
625
+ else:
626
+ request['market'] = 'ALL'
627
+ response = self.publicGetMarketsSummary(self.extend(request, params))
628
+ #
629
+ # {
630
+ # "results": [
631
+ # {
632
+ # "symbol": "BTC-USD-PERP",
633
+ # "oracle_price": "68465.17449906",
634
+ # "mark_price": "68465.17449906",
635
+ # "last_traded_price": "68495.1",
636
+ # "bid": "68477.6",
637
+ # "ask": "69578.2",
638
+ # "volume_24h": "5815541.397939004",
639
+ # "total_volume": "584031465.525259686",
640
+ # "created_at": 1718170156580,
641
+ # "underlying_price": "67367.37268422",
642
+ # "open_interest": "162.272",
643
+ # "funding_rate": "0.01629574927887",
644
+ # "price_change_rate_24h": "0.009032"
645
+ # }
646
+ # ]
647
+ # }
648
+ #
649
+ data = self.safe_list(response, 'results', [])
650
+ return self.parse_tickers(data, symbols)
651
+
652
+ def fetch_ticker(self, symbol: str, params={}) -> Ticker:
653
+ """
654
+ fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
655
+
656
+ https://docs.api.testnet.paradex.trade/#list-available-markets-summary
657
+
658
+ :param str symbol: unified symbol of the market to fetch the ticker for
659
+ :param dict [params]: extra parameters specific to the exchange API endpoint
660
+ :returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
661
+ """
662
+ self.load_markets()
663
+ market = self.market(symbol)
664
+ request: dict = {
665
+ 'market': market['id'],
666
+ }
667
+ response = self.publicGetMarketsSummary(self.extend(request, params))
668
+ #
669
+ # {
670
+ # "results": [
671
+ # {
672
+ # "symbol": "BTC-USD-PERP",
673
+ # "oracle_price": "68465.17449906",
674
+ # "mark_price": "68465.17449906",
675
+ # "last_traded_price": "68495.1",
676
+ # "bid": "68477.6",
677
+ # "ask": "69578.2",
678
+ # "volume_24h": "5815541.397939004",
679
+ # "total_volume": "584031465.525259686",
680
+ # "created_at": 1718170156580,
681
+ # "underlying_price": "67367.37268422",
682
+ # "open_interest": "162.272",
683
+ # "funding_rate": "0.01629574927887",
684
+ # "price_change_rate_24h": "0.009032"
685
+ # }
686
+ # ]
687
+ # }
688
+ #
689
+ data = self.safe_list(response, 'results', [])
690
+ ticker = self.safe_dict(data, 0, {})
691
+ return self.parse_ticker(ticker, market)
692
+
693
+ def parse_ticker(self, ticker: dict, market: Market = None) -> Ticker:
694
+ #
695
+ # {
696
+ # "symbol": "BTC-USD-PERP",
697
+ # "oracle_price": "68465.17449906",
698
+ # "mark_price": "68465.17449906",
699
+ # "last_traded_price": "68495.1",
700
+ # "bid": "68477.6",
701
+ # "ask": "69578.2",
702
+ # "volume_24h": "5815541.397939004",
703
+ # "total_volume": "584031465.525259686",
704
+ # "created_at": 1718170156580,
705
+ # "underlying_price": "67367.37268422",
706
+ # "open_interest": "162.272",
707
+ # "funding_rate": "0.01629574927887",
708
+ # "price_change_rate_24h": "0.009032"
709
+ # }
710
+ #
711
+ percentage = self.safe_string(ticker, 'price_change_rate_24h')
712
+ if percentage is not None:
713
+ percentage = Precise.string_mul(percentage, '100')
714
+ last = self.safe_string(ticker, 'last_traded_price')
715
+ marketId = self.safe_string(ticker, 'symbol')
716
+ market = self.safe_market(marketId, market)
717
+ symbol = market['symbol']
718
+ timestamp = self.safe_integer(ticker, 'created_at')
719
+ return self.safe_ticker({
720
+ 'symbol': symbol,
721
+ 'timestamp': timestamp,
722
+ 'datetime': self.iso8601(timestamp),
723
+ 'high': None,
724
+ 'low': None,
725
+ 'bid': self.safe_string(ticker, 'bid'),
726
+ 'bidVolume': None,
727
+ 'ask': self.safe_string(ticker, 'ask'),
728
+ 'askVolume': None,
729
+ 'vwap': None,
730
+ 'open': None,
731
+ 'close': last,
732
+ 'last': last,
733
+ 'previousClose': None,
734
+ 'change': None,
735
+ 'percentage': percentage,
736
+ 'average': None,
737
+ 'baseVolume': None,
738
+ 'quoteVolume': self.safe_string(ticker, 'volume_24h'),
739
+ 'markPrice': self.safe_string(ticker, 'mark_price'),
740
+ 'info': ticker,
741
+ }, market)
742
+
743
+ def fetch_order_book(self, symbol: str, limit: Int = None, params={}) -> OrderBook:
744
+ """
745
+ fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
746
+
747
+ https://docs.api.testnet.paradex.trade/#get-market-orderbook
748
+
749
+ :param str symbol: unified symbol of the market to fetch the order book for
750
+ :param int [limit]: the maximum amount of order book entries to return
751
+ :param dict [params]: extra parameters specific to the exchange API endpoint
752
+ :returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
753
+ """
754
+ self.load_markets()
755
+ market = self.market(symbol)
756
+ request: dict = {'market': market['id']}
757
+ response = self.publicGetOrderbookMarket(self.extend(request, params))
758
+ #
759
+ # {
760
+ # "market": "BTC-USD-PERP",
761
+ # "seq_no": 14115975,
762
+ # "last_updated_at": 1718172538340,
763
+ # "asks": [
764
+ # [
765
+ # "69578.2",
766
+ # "3.019"
767
+ # ]
768
+ # ],
769
+ # "bids": [
770
+ # [
771
+ # "68477.6",
772
+ # "0.1"
773
+ # ]
774
+ # ]
775
+ # }
776
+ #
777
+ if limit is not None:
778
+ request['depth'] = limit
779
+ timestamp = self.safe_integer(response, 'last_updated_at')
780
+ orderbook = self.parse_order_book(response, market['symbol'], timestamp)
781
+ orderbook['nonce'] = self.safe_integer(response, 'seq_no')
782
+ return orderbook
783
+
784
+ def fetch_trades(self, symbol: str, since: Int = None, limit: Int = None, params={}) -> List[Trade]:
785
+ """
786
+ get the list of most recent trades for a particular symbol
787
+
788
+ https://docs.api.testnet.paradex.trade/#trade-tape
789
+
790
+ :param str symbol: unified symbol of the market to fetch trades for
791
+ :param int [since]: timestamp in ms of the earliest trade to fetch
792
+ :param int [limit]: the maximum amount of trades to fetch
793
+ :param dict [params]: extra parameters specific to the exchange API endpoint
794
+ :param int [params.until]: the latest time in ms to fetch trades for
795
+ :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times
796
+ :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
797
+ """
798
+ self.load_markets()
799
+ paginate = False
800
+ paginate, params = self.handle_option_and_params(params, 'fetchTrades', 'paginate')
801
+ if paginate:
802
+ return self.fetch_paginated_call_cursor('fetchTrades', symbol, since, limit, params, 'next', 'cursor', None, 100)
803
+ market = self.market(symbol)
804
+ request: dict = {
805
+ 'market': market['id'],
806
+ }
807
+ if limit is not None:
808
+ request['page_size'] = limit
809
+ if since is not None:
810
+ request['start_at'] = since
811
+ request, params = self.handle_until_option('end_at', request, params)
812
+ response = self.publicGetTrades(self.extend(request, params))
813
+ #
814
+ # {
815
+ # "next": "...",
816
+ # "prev": "...",
817
+ # "results": [
818
+ # {
819
+ # "id": "1718154353750201703989430001",
820
+ # "market": "BTC-USD-PERP",
821
+ # "side": "BUY",
822
+ # "size": "0.026",
823
+ # "price": "69578.2",
824
+ # "created_at": 1718154353750,
825
+ # "trade_type": "FILL"
826
+ # }
827
+ # ]
828
+ # }
829
+ #
830
+ trades = self.safe_list(response, 'results', [])
831
+ for i in range(0, len(trades)):
832
+ trades[i]['next'] = self.safe_string(response, 'next')
833
+ return self.parse_trades(trades, market, since, limit)
834
+
835
+ def parse_trade(self, trade: dict, market: Market = None) -> Trade:
836
+ #
837
+ # fetchTrades(public)
838
+ #
839
+ # {
840
+ # "id": "1718154353750201703989430001",
841
+ # "market": "BTC-USD-PERP",
842
+ # "side": "BUY",
843
+ # "size": "0.026",
844
+ # "price": "69578.2",
845
+ # "created_at": 1718154353750,
846
+ # "trade_type": "FILL"
847
+ # }
848
+ #
849
+ # fetchMyTrades(private)
850
+ #
851
+ # {
852
+ # "id": "1718947571560201703986670001",
853
+ # "side": "BUY",
854
+ # "liquidity": "TAKER",
855
+ # "market": "BTC-USD-PERP",
856
+ # "order_id": "1718947571540201703992340000",
857
+ # "price": "64852.9",
858
+ # "size": "0.01",
859
+ # "fee": "0.1945587",
860
+ # "fee_currency": "USDC",
861
+ # "created_at": 1718947571569,
862
+ # "remaining_size": "0",
863
+ # "client_id": "",
864
+ # "fill_type": "FILL"
865
+ # }
866
+ #
867
+ marketId = self.safe_string(trade, 'market')
868
+ market = self.safe_market(marketId, market)
869
+ id = self.safe_string(trade, 'id')
870
+ timestamp = self.safe_integer(trade, 'created_at')
871
+ priceString = self.safe_string(trade, 'price')
872
+ amountString = self.safe_string(trade, 'size')
873
+ side = self.safe_string_lower(trade, 'side')
874
+ liability = self.safe_string_lower(trade, 'liquidity', 'taker')
875
+ isTaker = liability == 'taker'
876
+ takerOrMaker = 'taker' if (isTaker) else 'maker'
877
+ currencyId = self.safe_string(trade, 'fee_currency')
878
+ code = self.safe_currency_code(currencyId)
879
+ return self.safe_trade({
880
+ 'info': trade,
881
+ 'id': id,
882
+ 'order': self.safe_string(trade, 'order_id'),
883
+ 'timestamp': timestamp,
884
+ 'datetime': self.iso8601(timestamp),
885
+ 'symbol': market['symbol'],
886
+ 'type': None,
887
+ 'takerOrMaker': takerOrMaker,
888
+ 'side': side,
889
+ 'price': priceString,
890
+ 'amount': amountString,
891
+ 'cost': None,
892
+ 'fee': {
893
+ 'cost': self.safe_string(trade, 'fee'),
894
+ 'currency': code,
895
+ 'rate': None,
896
+ },
897
+ }, market)
898
+
899
+ def fetch_open_interest(self, symbol: str, params={}):
900
+ """
901
+ retrieves the open interest of a contract trading pair
902
+
903
+ https://docs.api.testnet.paradex.trade/#list-available-markets-summary
904
+
905
+ :param str symbol: unified CCXT market symbol
906
+ :param dict [params]: exchange specific parameters
907
+ :returns dict} an open interest structure{@link https://docs.ccxt.com/#/?id=open-interest-structure:
908
+ """
909
+ self.load_markets()
910
+ market = self.market(symbol)
911
+ if not market['contract']:
912
+ raise BadRequest(self.id + ' fetchOpenInterest() supports contract markets only')
913
+ request: dict = {
914
+ 'market': market['id'],
915
+ }
916
+ response = self.publicGetMarketsSummary(self.extend(request, params))
917
+ #
918
+ # {
919
+ # "results": [
920
+ # {
921
+ # "symbol": "BTC-USD-PERP",
922
+ # "oracle_price": "68465.17449906",
923
+ # "mark_price": "68465.17449906",
924
+ # "last_traded_price": "68495.1",
925
+ # "bid": "68477.6",
926
+ # "ask": "69578.2",
927
+ # "volume_24h": "5815541.397939004",
928
+ # "total_volume": "584031465.525259686",
929
+ # "created_at": 1718170156580,
930
+ # "underlying_price": "67367.37268422",
931
+ # "open_interest": "162.272",
932
+ # "funding_rate": "0.01629574927887",
933
+ # "price_change_rate_24h": "0.009032"
934
+ # }
935
+ # ]
936
+ # }
937
+ #
938
+ data = self.safe_list(response, 'results', [])
939
+ interest = self.safe_dict(data, 0, {})
940
+ return self.parse_open_interest(interest, market)
941
+
942
+ def parse_open_interest(self, interest, market: Market = None):
943
+ #
944
+ # {
945
+ # "symbol": "BTC-USD-PERP",
946
+ # "oracle_price": "68465.17449906",
947
+ # "mark_price": "68465.17449906",
948
+ # "last_traded_price": "68495.1",
949
+ # "bid": "68477.6",
950
+ # "ask": "69578.2",
951
+ # "volume_24h": "5815541.397939004",
952
+ # "total_volume": "584031465.525259686",
953
+ # "created_at": 1718170156580,
954
+ # "underlying_price": "67367.37268422",
955
+ # "open_interest": "162.272",
956
+ # "funding_rate": "0.01629574927887",
957
+ # "price_change_rate_24h": "0.009032"
958
+ # }
959
+ #
960
+ timestamp = self.safe_integer(interest, 'created_at')
961
+ marketId = self.safe_string(interest, 'symbol')
962
+ market = self.safe_market(marketId, market)
963
+ symbol = market['symbol']
964
+ return self.safe_open_interest({
965
+ 'symbol': symbol,
966
+ 'openInterestAmount': self.safe_string(interest, 'open_interest'),
967
+ 'openInterestValue': None,
968
+ 'timestamp': timestamp,
969
+ 'datetime': self.iso8601(timestamp),
970
+ 'info': interest,
971
+ }, market)
972
+
973
+ def hash_message(self, message):
974
+ return '0x' + self.hash(message, 'keccak', 'hex')
975
+
976
+ def sign_hash(self, hash, privateKey):
977
+ signature = self.ecdsa(hash[-64:], privateKey[-64:], 'secp256k1', None)
978
+ r = signature['r']
979
+ s = signature['s']
980
+ v = self.int_to_base16(self.sum(27, signature['v']))
981
+ return '0x' + r.rjust(64, '0') + s.rjust(64, '0') + v
982
+
983
+ def sign_message(self, message, privateKey):
984
+ return self.sign_hash(self.hash_message(message), privateKey[-64:])
985
+
986
+ def get_system_config(self):
987
+ cachedConfig: dict = self.safe_dict(self.options, 'systemConfig')
988
+ if cachedConfig is not None:
989
+ return cachedConfig
990
+ response = self.publicGetSystemConfig()
991
+ #
992
+ # {
993
+ # "starknet_gateway_url": "https://potc-testnet-sepolia.starknet.io",
994
+ # "starknet_fullnode_rpc_url": "https://pathfinder.api.testnet.paradex.trade/rpc/v0_7",
995
+ # "starknet_chain_id": "PRIVATE_SN_POTC_SEPOLIA",
996
+ # "block_explorer_url": "https://voyager.testnet.paradex.trade/",
997
+ # "paraclear_address": "0x286003f7c7bfc3f94e8f0af48b48302e7aee2fb13c23b141479ba00832ef2c6",
998
+ # "paraclear_decimals": 8,
999
+ # "paraclear_account_proxy_hash": "0x3530cc4759d78042f1b543bf797f5f3d647cde0388c33734cf91b7f7b9314a9",
1000
+ # "paraclear_account_hash": "0x41cb0280ebadaa75f996d8d92c6f265f6d040bb3ba442e5f86a554f1765244e",
1001
+ # "oracle_address": "0x2c6a867917ef858d6b193a0ff9e62b46d0dc760366920d631715d58baeaca1f",
1002
+ # "bridged_tokens": [
1003
+ # {
1004
+ # "name": "TEST USDC",
1005
+ # "symbol": "USDC",
1006
+ # "decimals": 6,
1007
+ # "l1_token_address": "0x29A873159D5e14AcBd63913D4A7E2df04570c666",
1008
+ # "l1_bridge_address": "0x8586e05adc0C35aa11609023d4Ae6075Cb813b4C",
1009
+ # "l2_token_address": "0x6f373b346561036d98ea10fb3e60d2f459c872b1933b50b21fe6ef4fda3b75e",
1010
+ # "l2_bridge_address": "0x46e9237f5408b5f899e72125dd69bd55485a287aaf24663d3ebe00d237fc7ef"
1011
+ # }
1012
+ # ],
1013
+ # "l1_core_contract_address": "0x582CC5d9b509391232cd544cDF9da036e55833Af",
1014
+ # "l1_operator_address": "0x11bACdFbBcd3Febe5e8CEAa75E0Ef6444d9B45FB",
1015
+ # "l1_chain_id": "11155111",
1016
+ # "liquidation_fee": "0.2"
1017
+ # }
1018
+ #
1019
+ self.options['systemConfig'] = response
1020
+ return response
1021
+
1022
+ def prepare_paradex_domain(self, l1=False):
1023
+ systemConfig = self.get_system_config()
1024
+ if l1 is True:
1025
+ return {
1026
+ 'name': 'Paradex',
1027
+ 'chainId': systemConfig['l1_chain_id'],
1028
+ 'version': '1',
1029
+ }
1030
+ return {
1031
+ 'name': 'Paradex',
1032
+ 'chainId': systemConfig['starknet_chain_id'],
1033
+ 'version': 1,
1034
+ }
1035
+
1036
+ def retrieve_account(self):
1037
+ cachedAccount: dict = self.safe_dict(self.options, 'paradexAccount')
1038
+ if cachedAccount is not None:
1039
+ return cachedAccount
1040
+ self.check_required_credentials()
1041
+ systemConfig = self.get_system_config()
1042
+ domain = self.prepare_paradex_domain(True)
1043
+ messageTypes = {
1044
+ 'Constant': [
1045
+ {'name': 'action', 'type': 'string'},
1046
+ ],
1047
+ }
1048
+ message = {
1049
+ 'action': 'STARK Key',
1050
+ }
1051
+ msg = self.eth_encode_structured_data(domain, messageTypes, message)
1052
+ signature = self.sign_message(msg, self.privateKey)
1053
+ account = self.retrieve_stark_account(
1054
+ signature,
1055
+ systemConfig['paraclear_account_hash'],
1056
+ systemConfig['paraclear_account_proxy_hash']
1057
+ )
1058
+ self.options['paradexAccount'] = account
1059
+ return account
1060
+
1061
+ def onboarding(self, params={}):
1062
+ account = self.retrieve_account()
1063
+ req = {
1064
+ 'action': 'Onboarding',
1065
+ }
1066
+ domain = self.prepare_paradex_domain()
1067
+ messageTypes = {
1068
+ 'Constant': [
1069
+ {'name': 'action', 'type': 'felt'},
1070
+ ],
1071
+ }
1072
+ msg = self.starknet_encode_structured_data(domain, messageTypes, req, account['address'])
1073
+ signature = self.starknet_sign(msg, account['privateKey'])
1074
+ params['signature'] = signature
1075
+ params['account'] = account['address']
1076
+ params['public_key'] = account['publicKey']
1077
+ response = self.privatePostOnboarding(params)
1078
+ return response
1079
+
1080
+ def authenticate_rest(self, params={}):
1081
+ cachedToken = self.safe_string(self.options, 'authToken')
1082
+ now = self.nonce()
1083
+ if cachedToken is not None:
1084
+ cachedExpires = self.safe_integer(self.options, 'expires')
1085
+ if now < cachedExpires:
1086
+ return cachedToken
1087
+ account = self.retrieve_account()
1088
+ # https://docs.paradex.trade/api-reference/general-information/authentication
1089
+ expires = now + 180
1090
+ req = {
1091
+ 'method': 'POST',
1092
+ 'path': '/v1/auth',
1093
+ 'body': '',
1094
+ 'timestamp': now,
1095
+ 'expiration': expires,
1096
+ }
1097
+ domain = self.prepare_paradex_domain()
1098
+ messageTypes = {
1099
+ 'Request': [
1100
+ {'name': 'method', 'type': 'felt'},
1101
+ {'name': 'path', 'type': 'felt'},
1102
+ {'name': 'body', 'type': 'felt'},
1103
+ {'name': 'timestamp', 'type': 'felt'},
1104
+ {'name': 'expiration', 'type': 'felt'},
1105
+ ],
1106
+ }
1107
+ msg = self.starknet_encode_structured_data(domain, messageTypes, req, account['address'])
1108
+ signature = self.starknet_sign(msg, account['privateKey'])
1109
+ params['signature'] = signature
1110
+ params['account'] = account['address']
1111
+ params['timestamp'] = req['timestamp']
1112
+ params['expiration'] = req['expiration']
1113
+ response = self.privatePostAuth(params)
1114
+ #
1115
+ # {
1116
+ # jwt_token: "ooooccxtooootoooootheoooomoonooooo"
1117
+ # }
1118
+ #
1119
+ token = self.safe_string(response, 'jwt_token')
1120
+ self.options['authToken'] = token
1121
+ self.options['expires'] = expires
1122
+ return token
1123
+
1124
+ def parse_order(self, order: dict, market: Market = None) -> Order:
1125
+ #
1126
+ # {
1127
+ # "account": "0x4638e3041366aa71720be63e32e53e1223316c7f0d56f7aa617542ed1e7512x",
1128
+ # "avg_fill_price": "26000",
1129
+ # "client_id": "x1234",
1130
+ # "cancel_reason": "NOT_ENOUGH_MARGIN",
1131
+ # "created_at": 1681493746016,
1132
+ # "flags": [
1133
+ # "REDUCE_ONLY"
1134
+ # ],
1135
+ # "id": "123456",
1136
+ # "instruction": "GTC",
1137
+ # "last_updated_at": 1681493746016,
1138
+ # "market": "BTC-USD-PERP",
1139
+ # "price": "26000",
1140
+ # "published_at": 1681493746016,
1141
+ # "received_at": 1681493746016,
1142
+ # "remaining_size": "0",
1143
+ # "seq_no": 1681471234972000000,
1144
+ # "side": "BUY",
1145
+ # "size": "0.05",
1146
+ # "status": "NEW",
1147
+ # "stp": "EXPIRE_MAKER",
1148
+ # "timestamp": 1681493746016,
1149
+ # "trigger_price": "26000",
1150
+ # "type": "MARKET"
1151
+ # }
1152
+ #
1153
+ timestamp = self.safe_integer(order, 'created_at')
1154
+ orderId = self.safe_string(order, 'id')
1155
+ clientOrderId = self.omit_zero(self.safe_string(order, 'client_id'))
1156
+ marketId = self.safe_string(order, 'market')
1157
+ market = self.safe_market(marketId, market)
1158
+ symbol = market['symbol']
1159
+ price = self.safe_string(order, 'price')
1160
+ amount = self.safe_string(order, 'size')
1161
+ orderType = self.safe_string(order, 'type')
1162
+ status = self.safe_string(order, 'status')
1163
+ side = self.safe_string_lower(order, 'side')
1164
+ average = self.omit_zero(self.safe_string(order, 'avg_fill_price'))
1165
+ remaining = self.omit_zero(self.safe_string(order, 'remaining_size'))
1166
+ lastUpdateTimestamp = self.safe_integer(order, 'last_updated_at')
1167
+ return self.safe_order({
1168
+ 'id': orderId,
1169
+ 'clientOrderId': clientOrderId,
1170
+ 'timestamp': timestamp,
1171
+ 'datetime': self.iso8601(timestamp),
1172
+ 'lastTradeTimestamp': None,
1173
+ 'lastUpdateTimestamp': lastUpdateTimestamp,
1174
+ 'status': self.parse_order_status(status),
1175
+ 'symbol': symbol,
1176
+ 'type': self.parse_order_type(orderType),
1177
+ 'timeInForce': self.parse_time_in_force(self.safe_string(order, 'instrunction')),
1178
+ 'postOnly': None,
1179
+ 'reduceOnly': None,
1180
+ 'side': side,
1181
+ 'price': price,
1182
+ 'triggerPrice': self.safe_string(order, 'trigger_price'),
1183
+ 'takeProfitPrice': None,
1184
+ 'stopLossPrice': None,
1185
+ 'average': average,
1186
+ 'amount': amount,
1187
+ 'filled': None,
1188
+ 'remaining': remaining,
1189
+ 'cost': None,
1190
+ 'trades': None,
1191
+ 'fee': {
1192
+ 'cost': None,
1193
+ 'currency': None,
1194
+ },
1195
+ 'info': order,
1196
+ }, market)
1197
+
1198
+ def parse_time_in_force(self, timeInForce: Str):
1199
+ timeInForces: dict = {
1200
+ 'IOC': 'IOC',
1201
+ 'GTC': 'GTC',
1202
+ 'POST_ONLY': 'PO',
1203
+ }
1204
+ return self.safe_string(timeInForces, timeInForce, None)
1205
+
1206
+ def parse_order_status(self, status: Str):
1207
+ if status is not None:
1208
+ statuses: dict = {
1209
+ 'NEW': 'open',
1210
+ 'UNTRIGGERED': 'open',
1211
+ 'OPEN': 'open',
1212
+ 'CLOSED': 'closed',
1213
+ }
1214
+ return self.safe_string(statuses, status, status)
1215
+ return status
1216
+
1217
+ def parse_order_type(self, type: Str):
1218
+ types: dict = {
1219
+ 'LIMIT': 'limit',
1220
+ 'MARKET': 'market',
1221
+ 'STOP_LIMIT': 'limit',
1222
+ 'STOP_MARKET': 'market',
1223
+ }
1224
+ return self.safe_string_lower(types, type, type)
1225
+
1226
+ def convert_short_string(self, str: str):
1227
+ # TODO: add stringToBase16 in exchange
1228
+ return '0x' + self.binary_to_base16(self.base64_to_binary(self.string_to_base64(str)))
1229
+
1230
+ def scale_number(self, num: str):
1231
+ return Precise.string_mul(num, '100000000')
1232
+
1233
+ def create_order(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={}):
1234
+ """
1235
+ create a trade order
1236
+
1237
+ https://docs.api.prod.paradex.trade/#create-order
1238
+
1239
+ :param str symbol: unified symbol of the market to create an order in
1240
+ :param str type: 'market' or 'limit'
1241
+ :param str side: 'buy' or 'sell'
1242
+ :param float amount: how much of currency you want to trade in units of base currency
1243
+ :param float [price]: the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
1244
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1245
+ :param float [params.stopPrice]: alias for triggerPrice
1246
+ :param float [params.triggerPrice]: The price a trigger order is triggered at
1247
+ :param str [params.timeInForce]: "GTC", "IOC", or "POST_ONLY"
1248
+ :param bool [params.postOnly]: True or False
1249
+ :param bool [params.reduceOnly]: Ensures that the executed order does not flip the opened position.
1250
+ :param str [params.clientOrderId]: a unique id for the order
1251
+ :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
1252
+ """
1253
+ self.authenticate_rest()
1254
+ self.load_markets()
1255
+ market = self.market(symbol)
1256
+ reduceOnly = self.safe_bool_2(params, 'reduceOnly', 'reduce_only')
1257
+ orderType = type.upper()
1258
+ orderSide = side.upper()
1259
+ request: dict = {
1260
+ 'market': market['id'],
1261
+ 'side': orderSide,
1262
+ 'type': orderType, # LIMIT/MARKET/STOP_LIMIT/STOP_MARKET
1263
+ 'size': self.amount_to_precision(symbol, amount),
1264
+ }
1265
+ triggerPrice = self.safe_string_2(params, 'triggerPrice', 'stopPrice')
1266
+ isMarket = orderType == 'MARKET'
1267
+ timeInForce = self.safe_string_upper(params, 'timeInForce')
1268
+ postOnly = self.is_post_only(isMarket, None, params)
1269
+ if not isMarket:
1270
+ if postOnly:
1271
+ request['instruction'] = 'POST_ONLY'
1272
+ elif timeInForce == 'ioc':
1273
+ request['instruction'] = 'IOC'
1274
+ if reduceOnly:
1275
+ request['flags'] = [
1276
+ 'REDUCE_ONLY',
1277
+ ]
1278
+ if price is not None:
1279
+ request['price'] = self.price_to_precision(symbol, price)
1280
+ clientOrderId = self.safe_string_n(params, ['clOrdID', 'clientOrderId', 'client_order_id'])
1281
+ if clientOrderId is not None:
1282
+ request['client_id'] = clientOrderId
1283
+ if triggerPrice is not None:
1284
+ if isMarket:
1285
+ request['type'] = 'STOP_MARKET'
1286
+ else:
1287
+ request['type'] = 'STOP_LIMIT'
1288
+ request['trigger_price'] = self.price_to_precision(symbol, triggerPrice)
1289
+ params = self.omit(params, ['reduceOnly', 'reduce_only', 'clOrdID', 'clientOrderId', 'client_order_id', 'postOnly', 'timeInForce', 'stopPrice', 'triggerPrice'])
1290
+ account = self.retrieve_account()
1291
+ now = self.nonce()
1292
+ orderReq = {
1293
+ 'timestamp': now * 1000,
1294
+ 'market': self.convert_short_string(request['market']),
1295
+ 'side': '1' if (orderSide == 'BUY') else '2',
1296
+ 'orderType': self.convert_short_string(request['type']),
1297
+ 'size': self.scale_number(request['size']),
1298
+ 'price': '0' if (isMarket) else self.scale_number(request['price']),
1299
+ }
1300
+ domain = self.prepare_paradex_domain()
1301
+ messageTypes = {
1302
+ 'Order': [
1303
+ {'name': 'timestamp', 'type': 'felt'},
1304
+ {'name': 'market', 'type': 'felt'},
1305
+ {'name': 'side', 'type': 'felt'},
1306
+ {'name': 'orderType', 'type': 'felt'},
1307
+ {'name': 'size', 'type': 'felt'},
1308
+ {'name': 'price', 'type': 'felt'},
1309
+ ],
1310
+ }
1311
+ msg = self.starknet_encode_structured_data(domain, messageTypes, orderReq, account['address'])
1312
+ signature = self.starknet_sign(msg, account['privateKey'])
1313
+ request['signature'] = signature
1314
+ request['signature_timestamp'] = orderReq['timestamp']
1315
+ response = self.privatePostOrders(self.extend(request, params))
1316
+ #
1317
+ # {
1318
+ # "account": "0x4638e3041366aa71720be63e32e53e1223316c7f0d56f7aa617542ed1e7512x",
1319
+ # "avg_fill_price": "26000",
1320
+ # "cancel_reason": "NOT_ENOUGH_MARGIN",
1321
+ # "client_id": "x1234",
1322
+ # "created_at": 1681493746016,
1323
+ # "flags": [
1324
+ # "REDUCE_ONLY"
1325
+ # ],
1326
+ # "id": "123456",
1327
+ # "instruction": "GTC",
1328
+ # "last_updated_at": 1681493746016,
1329
+ # "market": "BTC-USD-PERP",
1330
+ # "price": "26000",
1331
+ # "published_at": 1681493746016,
1332
+ # "received_at": 1681493746016,
1333
+ # "remaining_size": "0",
1334
+ # "seq_no": 1681471234972000000,
1335
+ # "side": "BUY",
1336
+ # "size": "0.05",
1337
+ # "status": "NEW",
1338
+ # "stp": "EXPIRE_MAKER",
1339
+ # "timestamp": 1681493746016,
1340
+ # "trigger_price": "26000",
1341
+ # "type": "MARKET"
1342
+ # }
1343
+ #
1344
+ order = self.parse_order(response, market)
1345
+ return order
1346
+
1347
+ def cancel_order(self, id: str, symbol: Str = None, params={}):
1348
+ """
1349
+ cancels an open order
1350
+
1351
+ https://docs.api.prod.paradex.trade/#cancel-order
1352
+ https://docs.api.prod.paradex.trade/#cancel-open-order-by-client-order-id
1353
+
1354
+ :param str id: order id
1355
+ :param str symbol: unified symbol of the market the order was made in
1356
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1357
+ :param str [params.clientOrderId]: a unique id for the order
1358
+ :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
1359
+ """
1360
+ self.authenticate_rest()
1361
+ self.load_markets()
1362
+ request: dict = {}
1363
+ clientOrderId = self.safe_string_n(params, ['clOrdID', 'clientOrderId', 'client_order_id'])
1364
+ response = None
1365
+ if clientOrderId is not None:
1366
+ request['client_id'] = clientOrderId
1367
+ response = self.privateDeleteOrdersByClientIdClientId(self.extend(request, params))
1368
+ else:
1369
+ request['order_id'] = id
1370
+ response = self.privateDeleteOrdersOrderId(self.extend(request, params))
1371
+ #
1372
+ # if success, no response...
1373
+ #
1374
+ return self.parse_order(response)
1375
+
1376
+ def cancel_all_orders(self, symbol: Str = None, params={}):
1377
+ """
1378
+ cancel all open orders in a market
1379
+
1380
+ https://docs.api.prod.paradex.trade/#cancel-all-open-orders
1381
+
1382
+ :param str symbol: unified market symbol of the market to cancel orders in
1383
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1384
+ :returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
1385
+ """
1386
+ if symbol is None:
1387
+ raise ArgumentsRequired(self.id + ' cancelAllOrders() requires a symbol argument')
1388
+ self.authenticate_rest()
1389
+ self.load_markets()
1390
+ market = self.market(symbol)
1391
+ request: dict = {
1392
+ 'market': market['id'],
1393
+ }
1394
+ response = self.privateDeleteOrders(self.extend(request, params))
1395
+ #
1396
+ # if success, no response...
1397
+ #
1398
+ return response
1399
+
1400
+ def fetch_order(self, id: str, symbol: Str = None, params={}):
1401
+ """
1402
+ fetches information on an order made by the user
1403
+
1404
+ https://docs.api.prod.paradex.trade/#get-order
1405
+ https://docs.api.prod.paradex.trade/#get-order-by-client-id
1406
+
1407
+ :param str id: the order id
1408
+ :param str symbol: unified symbol of the market the order was made in
1409
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1410
+ :param str [params.clientOrderId]: a unique id for the order
1411
+ :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
1412
+ """
1413
+ self.authenticate_rest()
1414
+ self.load_markets()
1415
+ request: dict = {}
1416
+ clientOrderId = self.safe_string_n(params, ['clOrdID', 'clientOrderId', 'client_order_id'])
1417
+ params = self.omit(params, ['clOrdID', 'clientOrderId', 'client_order_id'])
1418
+ response = None
1419
+ if clientOrderId is not None:
1420
+ request['client_id'] = clientOrderId
1421
+ response = self.privateGetOrdersByClientIdClientId(self.extend(request, params))
1422
+ else:
1423
+ request['order_id'] = id
1424
+ response = self.privateGetOrdersOrderId(self.extend(request, params))
1425
+ #
1426
+ # {
1427
+ # "id": "1718941725080201704028870000",
1428
+ # "account": "0x49ddd7a564c978f6e4089ff8355b56a42b7e2d48ba282cb5aad60f04bea0ec3",
1429
+ # "market": "BTC-USD-PERP",
1430
+ # "side": "SELL",
1431
+ # "type": "LIMIT",
1432
+ # "size": "10.153",
1433
+ # "remaining_size": "10.153",
1434
+ # "price": "70784.5",
1435
+ # "status": "CLOSED",
1436
+ # "created_at": 1718941725082,
1437
+ # "last_updated_at": 1718958002991,
1438
+ # "timestamp": 1718941724678,
1439
+ # "cancel_reason": "USER_CANCELED",
1440
+ # "client_id": "",
1441
+ # "seq_no": 1718958002991595738,
1442
+ # "instruction": "GTC",
1443
+ # "avg_fill_price": "",
1444
+ # "stp": "EXPIRE_TAKER",
1445
+ # "received_at": 1718958510959,
1446
+ # "published_at": 1718958510960,
1447
+ # "flags": [],
1448
+ # "trigger_price": "0"
1449
+ # }
1450
+ #
1451
+ return self.parse_order(response)
1452
+
1453
+ def fetch_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Order]:
1454
+ """
1455
+ fetches information on multiple orders made by the user
1456
+
1457
+ https://docs.api.prod.paradex.trade/#get-orders
1458
+
1459
+ :param str symbol: unified market symbol of the market orders were made in
1460
+ :param int [since]: the earliest time in ms to fetch orders for
1461
+ :param int [limit]: the maximum number of order structures to retrieve
1462
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1463
+ :param str [params.side]: 'buy' or 'sell'
1464
+ :param boolean [params.paginate]: set to True if you want to fetch orders with pagination
1465
+ :param int params['until']: timestamp in ms of the latest order to fetch
1466
+ :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
1467
+ """
1468
+ self.authenticate_rest()
1469
+ self.load_markets()
1470
+ paginate = False
1471
+ paginate, params = self.handle_option_and_params(params, 'fetchOrders', 'paginate')
1472
+ if paginate:
1473
+ return self.fetch_paginated_call_cursor('fetchOrders', symbol, since, limit, params, 'next', 'cursor', None, 50)
1474
+ request: dict = {}
1475
+ market: Market = None
1476
+ if symbol is not None:
1477
+ market = self.market(symbol)
1478
+ request['market'] = market['id']
1479
+ if since is not None:
1480
+ request['start_at'] = since
1481
+ if limit is not None:
1482
+ request['page_size'] = limit
1483
+ request, params = self.handle_until_option('end_at', request, params)
1484
+ response = self.privateGetOrdersHistory(self.extend(request, params))
1485
+ #
1486
+ # {
1487
+ # "next": "eyJmaWx0ZXIiMsIm1hcmtlciI6eyJtYXJrZXIiOiIxNjc1NjUwMDE3NDMxMTAxNjk5N=",
1488
+ # "prev": "eyJmaWx0ZXIiOnsiTGltaXQiOjkwfSwidGltZSI6MTY4MTY3OTgzNzk3MTMwOTk1MywibWFya2VyIjp7Im1zMjExMD==",
1489
+ # "results": [
1490
+ # {
1491
+ # "account": "0x4638e3041366aa71720be63e32e53e1223316c7f0d56f7aa617542ed1e7512x",
1492
+ # "avg_fill_price": "26000",
1493
+ # "cancel_reason": "NOT_ENOUGH_MARGIN",
1494
+ # "client_id": "x1234",
1495
+ # "created_at": 1681493746016,
1496
+ # "flags": [
1497
+ # "REDUCE_ONLY"
1498
+ # ],
1499
+ # "id": "123456",
1500
+ # "instruction": "GTC",
1501
+ # "last_updated_at": 1681493746016,
1502
+ # "market": "BTC-USD-PERP",
1503
+ # "price": "26000",
1504
+ # "published_at": 1681493746016,
1505
+ # "received_at": 1681493746016,
1506
+ # "remaining_size": "0",
1507
+ # "seq_no": 1681471234972000000,
1508
+ # "side": "BUY",
1509
+ # "size": "0.05",
1510
+ # "status": "NEW",
1511
+ # "stp": "EXPIRE_MAKER",
1512
+ # "timestamp": 1681493746016,
1513
+ # "trigger_price": "26000",
1514
+ # "type": "MARKET"
1515
+ # }
1516
+ # ]
1517
+ # }
1518
+ #
1519
+ orders = self.safe_list(response, 'results', [])
1520
+ paginationCursor = self.safe_string(response, 'next')
1521
+ ordersLength = len(orders)
1522
+ if (paginationCursor is not None) and (ordersLength > 0):
1523
+ first = orders[0]
1524
+ first['next'] = paginationCursor
1525
+ orders[0] = first
1526
+ return self.parse_orders(orders, market, since, limit)
1527
+
1528
+ def fetch_open_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Order]:
1529
+ """
1530
+ fetches information on multiple orders made by the user
1531
+
1532
+ https://docs.api.prod.paradex.trade/#paradex-rest-api-orders
1533
+
1534
+ :param str symbol: unified market symbol of the market orders were made in
1535
+ :param int [since]: the earliest time in ms to fetch orders for
1536
+ :param int [limit]: the maximum number of order structures to retrieve
1537
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1538
+ :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
1539
+ """
1540
+ self.authenticate_rest()
1541
+ self.load_markets()
1542
+ request: dict = {}
1543
+ market: Market = None
1544
+ if symbol is not None:
1545
+ market = self.market(symbol)
1546
+ request['market'] = market['id']
1547
+ response = self.privateGetOrders(self.extend(request, params))
1548
+ #
1549
+ # {
1550
+ # "results": [
1551
+ # {
1552
+ # "account": "0x4638e3041366aa71720be63e32e53e1223316c7f0d56f7aa617542ed1e7512x",
1553
+ # "avg_fill_price": "26000",
1554
+ # "client_id": "x1234",
1555
+ # "cancel_reason": "NOT_ENOUGH_MARGIN",
1556
+ # "created_at": 1681493746016,
1557
+ # "flags": [
1558
+ # "REDUCE_ONLY"
1559
+ # ],
1560
+ # "id": "123456",
1561
+ # "instruction": "GTC",
1562
+ # "last_updated_at": 1681493746016,
1563
+ # "market": "BTC-USD-PERP",
1564
+ # "price": "26000",
1565
+ # "published_at": 1681493746016,
1566
+ # "received_at": 1681493746016,
1567
+ # "remaining_size": "0",
1568
+ # "seq_no": 1681471234972000000,
1569
+ # "side": "BUY",
1570
+ # "size": "0.05",
1571
+ # "status": "NEW",
1572
+ # "stp": "EXPIRE_MAKER",
1573
+ # "timestamp": 1681493746016,
1574
+ # "trigger_price": "26000",
1575
+ # "type": "MARKET"
1576
+ # }
1577
+ # ]
1578
+ # }
1579
+ #
1580
+ orders = self.safe_list(response, 'results', [])
1581
+ return self.parse_orders(orders, market, since, limit)
1582
+
1583
+ def fetch_balance(self, params={}) -> Balances:
1584
+ """
1585
+ query for balance and get the amount of funds available for trading or funds locked in orders
1586
+
1587
+ https://docs.api.prod.paradex.trade/#list-balances
1588
+
1589
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1590
+ :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
1591
+ """
1592
+ self.authenticate_rest()
1593
+ self.load_markets()
1594
+ response = self.privateGetBalance()
1595
+ #
1596
+ # {
1597
+ # "results": [
1598
+ # {
1599
+ # "token": "USDC",
1600
+ # "size": "99980.2382266290601",
1601
+ # "last_updated_at": 1718529757240
1602
+ # }
1603
+ # ]
1604
+ # }
1605
+ #
1606
+ data = self.safe_list(response, 'results', [])
1607
+ return self.parse_balance(data)
1608
+
1609
+ def parse_balance(self, response) -> Balances:
1610
+ result: dict = {'info': response}
1611
+ for i in range(0, len(response)):
1612
+ balance = self.safe_dict(response, i, {})
1613
+ currencyId = self.safe_string(balance, 'token')
1614
+ code = self.safe_currency_code(currencyId)
1615
+ account = self.account()
1616
+ account['total'] = self.safe_string(balance, 'size')
1617
+ result[code] = account
1618
+ return self.safe_balance(result)
1619
+
1620
+ def fetch_my_trades(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}):
1621
+ """
1622
+ fetch all trades made by the user
1623
+
1624
+ https://docs.api.prod.paradex.trade/#list-fills
1625
+
1626
+ :param str symbol: unified market symbol
1627
+ :param int [since]: the earliest time in ms to fetch trades for
1628
+ :param int [limit]: the maximum number of trades structures to retrieve
1629
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1630
+ :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
1631
+ :param int [params.until]: the latest time in ms to fetch entries for
1632
+ :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
1633
+ """
1634
+ self.authenticate_rest()
1635
+ self.load_markets()
1636
+ paginate = False
1637
+ paginate, params = self.handle_option_and_params(params, 'fetchMyTrades', 'paginate')
1638
+ if paginate:
1639
+ return self.fetch_paginated_call_cursor('fetchMyTrades', symbol, since, limit, params, 'next', 'cursor', None, 100)
1640
+ request: dict = {}
1641
+ market: Market = None
1642
+ if symbol is not None:
1643
+ market = self.market(symbol)
1644
+ request['market'] = market['id']
1645
+ if limit is not None:
1646
+ request['page_size'] = limit
1647
+ if since is not None:
1648
+ request['start_at'] = since
1649
+ request, params = self.handle_until_option('end_at', request, params)
1650
+ response = self.privateGetFills(self.extend(request, params))
1651
+ #
1652
+ # {
1653
+ # "next": null,
1654
+ # "prev": null,
1655
+ # "results": [
1656
+ # {
1657
+ # "id": "1718947571560201703986670001",
1658
+ # "side": "BUY",
1659
+ # "liquidity": "TAKER",
1660
+ # "market": "BTC-USD-PERP",
1661
+ # "order_id": "1718947571540201703992340000",
1662
+ # "price": "64852.9",
1663
+ # "size": "0.01",
1664
+ # "fee": "0.1945587",
1665
+ # "fee_currency": "USDC",
1666
+ # "created_at": 1718947571569,
1667
+ # "remaining_size": "0",
1668
+ # "client_id": "",
1669
+ # "fill_type": "FILL"
1670
+ # }
1671
+ # ]
1672
+ # }
1673
+ #
1674
+ trades = self.safe_list(response, 'results', [])
1675
+ for i in range(0, len(trades)):
1676
+ trades[i]['next'] = self.safe_string(response, 'next')
1677
+ return self.parse_trades(trades, market, since, limit)
1678
+
1679
+ def fetch_position(self, symbol: str, params={}):
1680
+ """
1681
+ fetch data on an open position
1682
+
1683
+ https://docs.api.prod.paradex.trade/#list-open-positions
1684
+
1685
+ :param str symbol: unified market symbol of the market the position is held in
1686
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1687
+ :returns dict: a `position structure <https://docs.ccxt.com/#/?id=position-structure>`
1688
+ """
1689
+ self.authenticate_rest()
1690
+ self.load_markets()
1691
+ market = self.market(symbol)
1692
+ positions = self.fetch_positions([market['symbol']], params)
1693
+ return self.safe_dict(positions, 0, {})
1694
+
1695
+ def fetch_positions(self, symbols: Strings = None, params={}):
1696
+ """
1697
+ fetch all open positions
1698
+
1699
+ https://docs.api.prod.paradex.trade/#list-open-positions
1700
+
1701
+ :param str[] [symbols]: list of unified market symbols
1702
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1703
+ :returns dict[]: a list of `position structure <https://docs.ccxt.com/#/?id=position-structure>`
1704
+ """
1705
+ self.authenticate_rest()
1706
+ self.load_markets()
1707
+ symbols = self.market_symbols(symbols)
1708
+ response = self.privateGetPositions()
1709
+ #
1710
+ # {
1711
+ # "results": [
1712
+ # {
1713
+ # "id": "0x49ddd7a564c978f6e4089ff8355b56a42b7e2d48ba282cb5aad60f04bea0ec3-BTC-USD-PERP",
1714
+ # "market": "BTC-USD-PERP",
1715
+ # "status": "OPEN",
1716
+ # "side": "LONG",
1717
+ # "size": "0.01",
1718
+ # "average_entry_price": "64839.96053748",
1719
+ # "average_entry_price_usd": "64852.9",
1720
+ # "realized_pnl": "0",
1721
+ # "unrealized_pnl": "-2.39677214",
1722
+ # "unrealized_funding_pnl": "-0.11214013",
1723
+ # "cost": "648.39960537",
1724
+ # "cost_usd": "648.529",
1725
+ # "cached_funding_index": "35202.1002351",
1726
+ # "last_updated_at": 1718950074249,
1727
+ # "last_fill_id": "1718947571560201703986670001",
1728
+ # "seq_no": 1718950074249176253,
1729
+ # "liquidation_price": ""
1730
+ # }
1731
+ # ]
1732
+ # }
1733
+ #
1734
+ data = self.safe_list(response, 'results', [])
1735
+ return self.parse_positions(data, symbols)
1736
+
1737
+ def parse_position(self, position: dict, market: Market = None):
1738
+ #
1739
+ # {
1740
+ # "id": "0x49ddd7a564c978f6e4089ff8355b56a42b7e2d48ba282cb5aad60f04bea0ec3-BTC-USD-PERP",
1741
+ # "market": "BTC-USD-PERP",
1742
+ # "status": "OPEN",
1743
+ # "side": "LONG",
1744
+ # "size": "0.01",
1745
+ # "average_entry_price": "64839.96053748",
1746
+ # "average_entry_price_usd": "64852.9",
1747
+ # "realized_pnl": "0",
1748
+ # "unrealized_pnl": "-2.39677214",
1749
+ # "unrealized_funding_pnl": "-0.11214013",
1750
+ # "cost": "648.39960537",
1751
+ # "cost_usd": "648.529",
1752
+ # "cached_funding_index": "35202.1002351",
1753
+ # "last_updated_at": 1718950074249,
1754
+ # "last_fill_id": "1718947571560201703986670001",
1755
+ # "seq_no": 1718950074249176253,
1756
+ # "liquidation_price": ""
1757
+ # }
1758
+ #
1759
+ marketId = self.safe_string(position, 'market')
1760
+ market = self.safe_market(marketId, market)
1761
+ symbol = market['symbol']
1762
+ side = self.safe_string_lower(position, 'side')
1763
+ quantity = self.safe_string(position, 'size')
1764
+ if side != 'long':
1765
+ quantity = Precise.string_mul('-1', quantity)
1766
+ timestamp = self.safe_integer(position, 'time')
1767
+ return self.safe_position({
1768
+ 'info': position,
1769
+ 'id': self.safe_string(position, 'id'),
1770
+ 'symbol': symbol,
1771
+ 'entryPrice': self.safe_string(position, 'average_entry_price'),
1772
+ 'markPrice': None,
1773
+ 'notional': None,
1774
+ 'collateral': self.safe_string(position, 'cost'),
1775
+ 'unrealizedPnl': self.safe_string(position, 'unrealized_pnl'),
1776
+ 'side': side,
1777
+ 'contracts': self.parse_number(quantity),
1778
+ 'contractSize': None,
1779
+ 'timestamp': timestamp,
1780
+ 'datetime': self.iso8601(timestamp),
1781
+ 'hedged': None,
1782
+ 'maintenanceMargin': None,
1783
+ 'maintenanceMarginPercentage': None,
1784
+ 'initialMargin': None,
1785
+ 'initialMarginPercentage': None,
1786
+ 'leverage': None,
1787
+ 'liquidationPrice': None,
1788
+ 'marginRatio': None,
1789
+ 'marginMode': None,
1790
+ 'percentage': None,
1791
+ })
1792
+
1793
+ def fetch_liquidations(self, symbol: str, since: Int = None, limit: Int = None, params={}):
1794
+ """
1795
+ retrieves the public liquidations of a trading pair
1796
+
1797
+ https://docs.api.prod.paradex.trade/#list-liquidations
1798
+
1799
+ :param str symbol: unified CCXT market symbol
1800
+ :param int [since]: the earliest time in ms to fetch liquidations for
1801
+ :param int [limit]: the maximum number of liquidation structures to retrieve
1802
+ :param dict [params]: exchange specific parameters for the huobi api endpoint
1803
+ :param int [params.until]: timestamp in ms of the latest liquidation
1804
+ :returns dict: an array of `liquidation structures <https://docs.ccxt.com/#/?id=liquidation-structure>`
1805
+ """
1806
+ self.authenticate_rest()
1807
+ request: dict = {}
1808
+ if since is not None:
1809
+ request['from'] = since
1810
+ else:
1811
+ request['from'] = 1
1812
+ market = self.market(symbol)
1813
+ request, params = self.handle_until_option('to', request, params)
1814
+ response = self.privateGetLiquidations(self.extend(request, params))
1815
+ #
1816
+ # {
1817
+ # "results": [
1818
+ # {
1819
+ # "created_at": 1697213130097,
1820
+ # "id": "0x123456789"
1821
+ # }
1822
+ # ]
1823
+ # }
1824
+ #
1825
+ data = self.safe_list(response, 'results', [])
1826
+ return self.parse_liquidations(data, market, since, limit)
1827
+
1828
+ def parse_liquidation(self, liquidation, market: Market = None):
1829
+ #
1830
+ # {
1831
+ # "created_at": 1697213130097,
1832
+ # "id": "0x123456789"
1833
+ # }
1834
+ #
1835
+ timestamp = self.safe_integer(liquidation, 'created_at')
1836
+ return self.safe_liquidation({
1837
+ 'info': liquidation,
1838
+ 'symbol': None,
1839
+ 'contracts': None,
1840
+ 'contractSize': None,
1841
+ 'price': None,
1842
+ 'baseValue': None,
1843
+ 'quoteValue': None,
1844
+ 'timestamp': timestamp,
1845
+ 'datetime': self.iso8601(timestamp),
1846
+ })
1847
+
1848
+ def fetch_deposits(self, code: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Transaction]:
1849
+ """
1850
+ fetch all deposits made to an account
1851
+
1852
+ https://docs.api.prod.paradex.trade/#paradex-rest-api-transfers
1853
+
1854
+ :param str code: unified currency code
1855
+ :param int [since]: the earliest time in ms to fetch deposits for
1856
+ :param int [limit]: the maximum number of deposits structures to retrieve
1857
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1858
+ :param int [params.until]: the latest time in ms to fetch entries for
1859
+ :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)
1860
+ :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
1861
+ """
1862
+ self.authenticate_rest()
1863
+ self.load_markets()
1864
+ paginate = False
1865
+ paginate, params = self.handle_option_and_params(params, 'fetchDeposits', 'paginate')
1866
+ if paginate:
1867
+ return self.fetch_paginated_call_cursor('fetchDeposits', code, since, limit, params, 'next', 'cursor', None, 100)
1868
+ request: dict = {}
1869
+ if limit is not None:
1870
+ request['page_size'] = limit
1871
+ if since is not None:
1872
+ request['start_at'] = since
1873
+ request, params = self.handle_until_option('end_at', request, params)
1874
+ response = self.privateGetTransfers(self.extend(request, params))
1875
+ #
1876
+ # {
1877
+ # "next": null,
1878
+ # "prev": null,
1879
+ # "results": [
1880
+ # {
1881
+ # "id": "1718940471200201703989430000",
1882
+ # "account": "0x49ddd7a564c978f6e4089ff8355b56a42b7e2d48ba282cb5aad60f04bea0ec3",
1883
+ # "kind": "DEPOSIT",
1884
+ # "status": "COMPLETED",
1885
+ # "amount": "100000",
1886
+ # "token": "USDC",
1887
+ # "created_at": 1718940471208,
1888
+ # "last_updated_at": 1718941455546,
1889
+ # "txn_hash": "0x73a415ca558a97bbdcd1c43e52b45f1e0486a0a84b3bb4958035ad6c59cb866",
1890
+ # "external_txn_hash": "",
1891
+ # "socialized_loss_factor": ""
1892
+ # }
1893
+ # ]
1894
+ # }
1895
+ #
1896
+ rows = self.safe_list(response, 'results', [])
1897
+ deposits = []
1898
+ for i in range(0, len(rows)):
1899
+ row = rows[i]
1900
+ if row['kind'] == 'DEPOSIT':
1901
+ deposits.append(row)
1902
+ return self.parse_transactions(deposits, None, since, limit)
1903
+
1904
+ def fetch_withdrawals(self, code: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Transaction]:
1905
+ """
1906
+ fetch all withdrawals made from an account
1907
+
1908
+ https://docs.api.prod.paradex.trade/#paradex-rest-api-transfers
1909
+
1910
+ :param str code: unified currency code
1911
+ :param int [since]: the earliest time in ms to fetch withdrawals for
1912
+ :param int [limit]: the maximum number of withdrawals structures to retrieve
1913
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1914
+ :param int [params.until]: the latest time in ms to fetch withdrawals for
1915
+ :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)
1916
+ :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
1917
+ """
1918
+ self.authenticate_rest()
1919
+ self.load_markets()
1920
+ paginate = False
1921
+ paginate, params = self.handle_option_and_params(params, 'fetchWithdrawals', 'paginate')
1922
+ if paginate:
1923
+ return self.fetch_paginated_call_cursor('fetchWithdrawals', code, since, limit, params, 'next', 'cursor', None, 100)
1924
+ request: dict = {}
1925
+ if limit is not None:
1926
+ request['page_size'] = limit
1927
+ if since is not None:
1928
+ request['start_at'] = since
1929
+ request, params = self.handle_until_option('end_at', request, params)
1930
+ response = self.privateGetTransfers(self.extend(request, params))
1931
+ #
1932
+ # {
1933
+ # "next": null,
1934
+ # "prev": null,
1935
+ # "results": [
1936
+ # {
1937
+ # "id": "1718940471200201703989430000",
1938
+ # "account": "0x49ddd7a564c978f6e4089ff8355b56a42b7e2d48ba282cb5aad60f04bea0ec3",
1939
+ # "kind": "DEPOSIT",
1940
+ # "status": "COMPLETED",
1941
+ # "amount": "100000",
1942
+ # "token": "USDC",
1943
+ # "created_at": 1718940471208,
1944
+ # "last_updated_at": 1718941455546,
1945
+ # "txn_hash": "0x73a415ca558a97bbdcd1c43e52b45f1e0486a0a84b3bb4958035ad6c59cb866",
1946
+ # "external_txn_hash": "",
1947
+ # "socialized_loss_factor": ""
1948
+ # }
1949
+ # ]
1950
+ # }
1951
+ #
1952
+ rows = self.safe_list(response, 'results', [])
1953
+ deposits = []
1954
+ for i in range(0, len(rows)):
1955
+ row = rows[i]
1956
+ if row['kind'] == 'WITHDRAWAL':
1957
+ deposits.append(row)
1958
+ return self.parse_transactions(deposits, None, since, limit)
1959
+
1960
+ def parse_transaction(self, transaction: dict, currency: Currency = None) -> Transaction:
1961
+ #
1962
+ # fetchDeposits & fetchWithdrawals
1963
+ #
1964
+ # {
1965
+ # "id": "1718940471200201703989430000",
1966
+ # "account": "0x49ddd7a564c978f6e4089ff8355b56a42b7e2d48ba282cb5aad60f04bea0ec3",
1967
+ # "kind": "DEPOSIT",
1968
+ # "status": "COMPLETED",
1969
+ # "amount": "100000",
1970
+ # "token": "USDC",
1971
+ # "created_at": 1718940471208,
1972
+ # "last_updated_at": 1718941455546,
1973
+ # "txn_hash": "0x73a415ca558a97bbdcd1c43e52b45f1e0486a0a84b3bb4958035ad6c59cb866",
1974
+ # "external_txn_hash": "",
1975
+ # "socialized_loss_factor": ""
1976
+ # }
1977
+ #
1978
+ id = self.safe_string(transaction, 'id')
1979
+ address = self.safe_string(transaction, 'account')
1980
+ txid = self.safe_string(transaction, 'txn_hash')
1981
+ currencyId = self.safe_string(transaction, 'token')
1982
+ code = self.safe_currency_code(currencyId, currency)
1983
+ timestamp = self.safe_integer(transaction, 'created_at')
1984
+ updated = self.safe_integer(transaction, 'last_updated_at')
1985
+ type = self.safe_string(transaction, 'kind')
1986
+ type = 'deposit' if (type == 'DEPOSIT') else 'withdrawal'
1987
+ status = self.parse_transaction_status(self.safe_string(transaction, 'status'))
1988
+ amount = self.safe_number(transaction, 'amount')
1989
+ return {
1990
+ 'info': transaction,
1991
+ 'id': id,
1992
+ 'txid': txid,
1993
+ 'timestamp': timestamp,
1994
+ 'datetime': self.iso8601(timestamp),
1995
+ 'network': None,
1996
+ 'address': address,
1997
+ 'addressTo': address,
1998
+ 'addressFrom': None,
1999
+ 'tag': None,
2000
+ 'tagTo': None,
2001
+ 'tagFrom': None,
2002
+ 'type': type,
2003
+ 'amount': amount,
2004
+ 'currency': code,
2005
+ 'status': status,
2006
+ 'updated': updated,
2007
+ 'internal': None,
2008
+ 'comment': None,
2009
+ 'fee': None,
2010
+ }
2011
+
2012
+ def parse_transaction_status(self, status: Str):
2013
+ statuses: dict = {
2014
+ 'PENDING': 'pending',
2015
+ 'AVAILABLE': 'pending',
2016
+ 'COMPLETED': 'ok',
2017
+ 'FAILED': 'failed',
2018
+ }
2019
+ return self.safe_string(statuses, status, status)
2020
+
2021
+ def sign(self, path, api='public', method='GET', params={}, headers=None, body=None):
2022
+ url = self.implode_hostname(self.urls['api'][self.version]) + '/' + self.implode_params(path, params)
2023
+ query = self.omit(params, self.extract_params(path))
2024
+ if api == 'public':
2025
+ if query:
2026
+ url += '?' + self.urlencode(query)
2027
+ elif api == 'private':
2028
+ headers = {
2029
+ 'Accept': 'application/json',
2030
+ 'PARADEX-PARTNER': self.safe_string(self.options, 'broker', 'CCXT'),
2031
+ }
2032
+ # TODO: optimize
2033
+ if path == 'auth':
2034
+ headers['PARADEX-STARKNET-ACCOUNT'] = query['account']
2035
+ headers['PARADEX-STARKNET-SIGNATURE'] = query['signature']
2036
+ headers['PARADEX-TIMESTAMP'] = str(query['timestamp'])
2037
+ headers['PARADEX-SIGNATURE-EXPIRATION'] = str(query['expiration'])
2038
+ elif path == 'onboarding':
2039
+ headers['PARADEX-ETHEREUM-ACCOUNT'] = self.walletAddress
2040
+ headers['PARADEX-STARKNET-ACCOUNT'] = query['account']
2041
+ headers['PARADEX-STARKNET-SIGNATURE'] = query['signature']
2042
+ headers['PARADEX-TIMESTAMP'] = str(self.nonce())
2043
+ headers['Content-Type'] = 'application/json'
2044
+ body = self.json({
2045
+ 'public_key': query['public_key'],
2046
+ })
2047
+ else:
2048
+ token = self.options['authToken']
2049
+ headers['Authorization'] = 'Bearer ' + token
2050
+ if method == 'POST':
2051
+ headers['Content-Type'] = 'application/json'
2052
+ body = self.json(query)
2053
+ else:
2054
+ url = url + '?' + self.urlencode(query)
2055
+ # headers = {
2056
+ # 'Accept': 'application/json',
2057
+ # 'Authorization': 'Bearer ' + self.apiKey,
2058
+ # }
2059
+ # if method == 'POST':
2060
+ # body = self.json(query)
2061
+ # headers['Content-Type'] = 'application/json'
2062
+ # else:
2063
+ # if query:
2064
+ # url += '?' + self.urlencode(query)
2065
+ # }
2066
+ # }
2067
+ return {'url': url, 'method': method, 'body': body, 'headers': headers}
2068
+
2069
+ def handle_errors(self, httpCode: int, reason: str, url: str, method: str, headers: dict, body: str, response, requestHeaders, requestBody):
2070
+ if not response:
2071
+ return None # fallback to default error handler
2072
+ #
2073
+ # {
2074
+ # "data": null,
2075
+ # "error": "NOT_ONBOARDED",
2076
+ # "message": "User has never called /onboarding endpoint"
2077
+ # }
2078
+ #
2079
+ errorCode = self.safe_string(response, 'error')
2080
+ if errorCode is not None:
2081
+ feedback = self.id + ' ' + body
2082
+ self.throw_broadly_matched_exception(self.exceptions['broad'], body, feedback)
2083
+ self.throw_exactly_matched_exception(self.exceptions['exact'], errorCode, feedback)
2084
+ raise ExchangeError(feedback) # unknown message
2085
+ return None