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
@@ -0,0 +1,2066 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ # PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
4
+ # https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
5
+
6
+ from ccxt.async_support.base.exchange import Exchange
7
+ from ccxt.abstract.defx import ImplicitAPI
8
+ import asyncio
9
+ import hashlib
10
+ from ccxt.base.types import Balances, Currency, Int, LedgerEntry, Leverage, Market, Num, Order, OrderBook, OrderSide, OrderType, Position, Str, Strings, Ticker, Tickers, FundingRate, Trade, Transaction
11
+ from typing import List
12
+ from ccxt.base.errors import ExchangeError
13
+ from ccxt.base.errors import AuthenticationError
14
+ from ccxt.base.errors import ArgumentsRequired
15
+ from ccxt.base.errors import BadRequest
16
+ from ccxt.base.errors import InvalidOrder
17
+ from ccxt.base.errors import NotSupported
18
+ from ccxt.base.decimal_to_precision import TICK_SIZE
19
+ from ccxt.base.precise import Precise
20
+
21
+
22
+ class defx(Exchange, ImplicitAPI):
23
+
24
+ def describe(self):
25
+ return self.deep_extend(super(defx, self).describe(), {
26
+ 'id': 'defx',
27
+ 'name': 'Defx X',
28
+ # 'countries': [''],
29
+ 'rateLimit': 100,
30
+ 'version': 'v1',
31
+ 'certified': False,
32
+ 'pro': False,
33
+ 'hostname': 'defx.com',
34
+ 'dex': True,
35
+ 'has': {
36
+ 'CORS': None,
37
+ 'spot': False,
38
+ 'margin': False,
39
+ 'swap': True,
40
+ 'future': False,
41
+ 'option': False,
42
+ 'addMargin': True,
43
+ 'cancelAllOrders': True,
44
+ 'cancelAllOrdersAfter': False,
45
+ 'cancelOrder': True,
46
+ 'cancelWithdraw': False,
47
+ 'closeAllPositions': True,
48
+ 'closePosition': True,
49
+ 'createConvertTrade': False,
50
+ 'createDepositAddress': False,
51
+ 'createMarketBuyOrderWithCost': False,
52
+ 'createMarketOrder': False,
53
+ 'createMarketOrderWithCost': False,
54
+ 'createMarketSellOrderWithCost': False,
55
+ 'createOrder': True,
56
+ 'createOrderWithTakeProfitAndStopLoss': True,
57
+ 'createReduceOnlyOrder': True,
58
+ 'createStopLimitOrder': False,
59
+ 'createStopLossOrder': False,
60
+ 'createStopMarketOrder': False,
61
+ 'createStopOrder': False,
62
+ 'createTakeProfitOrder': True,
63
+ 'createTrailingAmountOrder': False,
64
+ 'createTrailingPercentOrder': False,
65
+ 'createTriggerOrder': True,
66
+ 'fetchAccounts': False,
67
+ 'fetchBalance': True,
68
+ 'fetchCanceledOrders': True,
69
+ 'fetchClosedOrder': False,
70
+ 'fetchClosedOrders': True,
71
+ 'fetchConvertCurrencies': False,
72
+ 'fetchConvertQuote': False,
73
+ 'fetchConvertTrade': False,
74
+ 'fetchConvertTradeHistory': False,
75
+ 'fetchCurrencies': False,
76
+ 'fetchDepositAddress': False,
77
+ 'fetchDepositAddresses': False,
78
+ 'fetchDepositAddressesByNetwork': False,
79
+ 'fetchDeposits': False,
80
+ 'fetchDepositsWithdrawals': False,
81
+ 'fetchFundingHistory': False,
82
+ 'fetchFundingInterval': False,
83
+ 'fetchFundingIntervals': False,
84
+ 'fetchFundingRate': True,
85
+ 'fetchFundingRateHistory': False,
86
+ 'fetchFundingRates': False,
87
+ 'fetchIndexOHLCV': False,
88
+ 'fetchLedger': True,
89
+ 'fetchLeverage': False,
90
+ 'fetchMarginAdjustmentHistory': False,
91
+ 'fetchMarginMode': False,
92
+ 'fetchMarkets': True,
93
+ 'fetchMarkOHLCV': False,
94
+ 'fetchMarkPrice': False,
95
+ 'fetchMarkPrices': False,
96
+ 'fetchMyTrades': True,
97
+ 'fetchOHLCV': True,
98
+ 'fetchOpenInterestHistory': False,
99
+ 'fetchOpenOrder': False,
100
+ 'fetchOpenOrders': True,
101
+ 'fetchOrder': True,
102
+ 'fetchOrderBook': True,
103
+ 'fetchOrders': True,
104
+ 'fetchOrderTrades': False,
105
+ 'fetchPosition': True,
106
+ 'fetchPositionHistory': False,
107
+ 'fetchPositionMode': False,
108
+ 'fetchPositions': True,
109
+ 'fetchPositionsHistory': False,
110
+ 'fetchPremiumIndexOHLCV': False,
111
+ 'fetchStatus': True,
112
+ 'fetchTicker': True,
113
+ 'fetchTickers': True,
114
+ 'fetchTime': True,
115
+ 'fetchTrades': True,
116
+ 'fetchTradingFee': False,
117
+ 'fetchTradingFees': False,
118
+ 'fetchTransactions': False,
119
+ 'fetchTransfers': False,
120
+ 'fetchWithdrawals': False,
121
+ 'reduceMargin': False,
122
+ 'sandbox': True,
123
+ 'setLeverage': True,
124
+ 'setMargin': False,
125
+ 'setPositionMode': False,
126
+ 'transfer': False,
127
+ 'withdraw': True,
128
+ },
129
+ 'timeframes': {
130
+ '1m': '1m',
131
+ '3m': '3m',
132
+ '5m': '5m',
133
+ '15m': '15m',
134
+ '30m': '30m',
135
+ '1h': '1h',
136
+ '2h': '2h',
137
+ '4h': '4h',
138
+ '12h': '12h',
139
+ '1d': '1d',
140
+ '1w': '1w',
141
+ '1M': '1M',
142
+ },
143
+ 'urls': {
144
+ 'logo': 'https://github.com/user-attachments/assets/4e92bace-d7a9-45ea-92be-122168dc87e4',
145
+ 'api': {
146
+ 'public': 'https://api.{hostname}',
147
+ 'private': 'https://api.{hostname}',
148
+ },
149
+ 'test': {
150
+ 'public': 'https://api.testnet.{hostname}',
151
+ 'private': 'https://api.testnet.{hostname}',
152
+ },
153
+ 'www': 'https://defx.com/home',
154
+ 'doc': [
155
+ 'https://docs.defx.com/docs',
156
+ 'https://api-docs.defx.com/',
157
+ ],
158
+ 'fees': [
159
+ '',
160
+ ],
161
+ 'referral': {
162
+ 'url': 'https://app.defx.com/join/6I2CZ7',
163
+ },
164
+ },
165
+ 'api': {
166
+ 'v1': {
167
+ 'public': {
168
+ 'get': {
169
+ 'healthcheck/ping': 1,
170
+ 'symbols/{symbol}/ohlc': 1,
171
+ 'symbols/{symbol}/trades': 1,
172
+ 'symbols/{symbol}/prices': 1,
173
+ 'symbols/{symbol}/ticker/24hr': 1,
174
+ 'symbols/{symbol}/depth/{level}/{slab}': 1,
175
+ 'ticker/24HrAgg': 1,
176
+ 'c/markets': 1,
177
+ 'c/markets/metadata': 1,
178
+ 'analytics/market/stats/newUsers': 1,
179
+ 'analytics/market/stats/tvl': 1,
180
+ 'analytics/market/stats/volumeByInstrument': 1,
181
+ 'analytics/market/stats/liquidation': 1,
182
+ 'analytics/market/stats/totalVolume': 1,
183
+ 'analytics/market/stats/openInterest': 1,
184
+ 'analytics/market/stats/totalTrades': 1,
185
+ 'analytics/market/stats/basis': 1,
186
+ 'analytics/market/stats/insuranceFund': 1,
187
+ 'analytics/market/stats/longAndShortRatio': 1,
188
+ 'analytics/market/stats/fundingRate': 1,
189
+ 'analytics/market/overview': 1,
190
+ 'explorer/search': 1,
191
+ 'explorer/transactions': 1,
192
+ 'explorer/blocks': 1,
193
+ },
194
+ },
195
+ 'private': {
196
+ 'get': {
197
+ 'api/order/{orderId}': 1,
198
+ 'api/orders': 1,
199
+ 'api/orders/oco/{parentOrderId}': 1,
200
+ 'api/trades': 1,
201
+ 'api/position/active': 1,
202
+ 'api/users/metadata/leverage': 1,
203
+ 'api/users/metadata/feeMultiplier': 1,
204
+ 'api/users/metadata/slippage': 1,
205
+ 'api/users/referral': 1,
206
+ 'api/users/apikeys': 1,
207
+ 'connection-signature-message/evm': 1,
208
+ 'api/users/profile/wallets': 1,
209
+ 'api/notifications': 1,
210
+ 'api/wallet/balance': 1,
211
+ 'api/wallet/transactions': 1,
212
+ 'api/analytics/user/overview': 1,
213
+ 'api/analytics/user/pnl': 1,
214
+ 'api/analytics/points/overview': 1,
215
+ 'api/analytics/points/history': 1,
216
+ },
217
+ 'post': {
218
+ 'api/order': 1,
219
+ 'api/position/oco': 1,
220
+ 'api/users/socket/listenKeys': 1,
221
+ 'api/users/metadata/leverage': 1,
222
+ 'api/users/metadata/feeMultiplier': 1,
223
+ 'api/users/metadata/slippage': 1,
224
+ 'api/users/referral/recordReferralSignup': 1,
225
+ 'api/users/apikeys': 1,
226
+ 'api/users/profile/wallets': 1,
227
+ 'api/transfers/withdrawal': 1,
228
+ 'api/transfers/bridge/withdrawal': 1,
229
+ },
230
+ 'put': {
231
+ 'api/position/updatePositionMargin': 1,
232
+ 'api/users/socket/listenKeys/{listenKey}': 1,
233
+ 'api/users/apikeys/{accessKey}/status': 1,
234
+ 'api/users/referral': 1,
235
+ },
236
+ 'patch': {
237
+ 'api/users/apikeys/{accessKey}': 1,
238
+ },
239
+ 'delete': {
240
+ 'api/orders/allOpen': 1,
241
+ 'api/order/{orderId}': 1,
242
+ 'api/position/{positionId}': 1,
243
+ 'api/position/all': 1,
244
+ 'api/users/socket/listenKeys/{listenKey}': 1,
245
+ 'api/users/apikeys/{accessKey}': 1,
246
+ },
247
+ },
248
+ },
249
+ },
250
+ 'fees': {
251
+ 'trading': {
252
+ 'tierBased': True,
253
+ 'percentage': True,
254
+ 'maker': self.parse_number('0.0002'),
255
+ 'taker': self.parse_number('0.0005'),
256
+ },
257
+ },
258
+ 'options': {
259
+ 'sandboxMode': False,
260
+ },
261
+ 'features': {
262
+ 'spot': None,
263
+ 'forDerivatives': {
264
+ 'sandbox': True,
265
+ 'createOrder': {
266
+ 'marginMode': False,
267
+ 'triggerPrice': True,
268
+ # todo implement
269
+ 'triggerPriceType': {
270
+ 'last': True,
271
+ 'mark': True,
272
+ 'index': False,
273
+ },
274
+ 'triggerDirection': False,
275
+ 'stopLossPrice': False, # todo
276
+ 'takeProfitPrice': False, # todo
277
+ 'attachedStopLossTakeProfit': None,
278
+ 'timeInForce': {
279
+ 'IOC': True,
280
+ 'FOK': True,
281
+ 'PO': True,
282
+ 'GTD': False,
283
+ },
284
+ 'hedged': False,
285
+ 'selfTradePrevention': False,
286
+ 'trailing': False,
287
+ 'iceberg': False,
288
+ 'leverage': False,
289
+ 'marketBuyByCost': False,
290
+ 'marketBuyRequiresPrice': False,
291
+ },
292
+ 'createOrders': None,
293
+ 'fetchMyTrades': {
294
+ 'marginMode': False,
295
+ 'limit': 1000,
296
+ 'daysBack': None,
297
+ 'untilDays': None,
298
+ },
299
+ 'fetchOrder': {
300
+ 'marginMode': False,
301
+ 'trigger': False,
302
+ 'trailing': False,
303
+ },
304
+ 'fetchOpenOrders': {
305
+ 'marginMode': True,
306
+ 'limit': 100,
307
+ 'trigger': False,
308
+ 'trailing': False,
309
+ },
310
+ 'fetchOrders': {
311
+ 'marginMode': False,
312
+ 'limit': 500,
313
+ 'daysBack': 100000,
314
+ 'untilDays': 100000,
315
+ 'trigger': False,
316
+ 'trailing': False,
317
+ },
318
+ 'fetchClosedOrders': {
319
+ 'marginMode': False,
320
+ 'limit': 500,
321
+ 'daysBack': 100000,
322
+ 'daysBackCanceled': 1,
323
+ 'untilDays': 100000,
324
+ 'trigger': False,
325
+ 'trailing': False,
326
+ },
327
+ 'fetchOHLCV': {
328
+ 'limit': 1000,
329
+ },
330
+ },
331
+ 'swap': {
332
+ 'linear': {
333
+ 'extends': 'forDerivatives',
334
+ },
335
+ 'inverse': None,
336
+ },
337
+ 'future': {
338
+ 'linear': None,
339
+ 'inverse': None,
340
+ },
341
+ },
342
+ 'commonCurrencies': {},
343
+ 'exceptions': {
344
+ 'exact': {
345
+ '404': BadRequest, # {"errorCode":404,"errorMessage":"Not Found"}
346
+ 'missing_auth_signature': AuthenticationError, # {"msg":"Missing auth signature","code":"missing_auth_signature"}
347
+ 'order_rejected': InvalidOrder, # {"success":false,"err":{"msg":"Order has already been rejected","code":"order_rejected"}}
348
+ 'invalid_order_id': InvalidOrder, # {"success":false,"err":{"msg":"Invalid order id","code":"invalid_order_id"}}
349
+ 'filter_lotsize_maxqty': InvalidOrder, # {"errorCode":"filter_lotsize_maxqty","errorMessage":"LOT_SIZE filter failed, quantity more than maxQty","errorData":{"maxQty":"5000.00"}}
350
+ 'filter_notional_min': InvalidOrder, # {"errorCode":"filter_notional_min","errorMessage":"NOTIONAL filter failed, Notional value of quote asset less than minNotional","errorData":{"minNotional":"100.00000000"}}
351
+ 'failed_index_price_up_multiplier_filter': InvalidOrder, # {"errorCode":"failed_index_price_up_multiplier_filter","errorMessage":"failed_index_price_up_multiplier_filter","errorData":{"maxPrice":"307.81241042"}}
352
+ 'no_open_orders': InvalidOrder, # {"errorMessage":"No open orders found","errorCode":"no_open_orders"}
353
+ 'active_position_not_found': InvalidOrder, # {"errorCode":"active_position_not_found","errorMessage":"Active position not found"}
354
+ 'position_inactive': InvalidOrder, # {"errorCode":"position_inactive","errorMessage":"Position is already inactive"}
355
+ 'invalid_position_id': InvalidOrder, # {"errorCode":"invalid_position_id","errorMessage":"Position id is invalid"}
356
+ 'Internal server error': ExchangeError, # {"msg":"Internal server error","code":"internal_server_error"}
357
+ },
358
+ 'broad': {
359
+ 'Bad Request': BadRequest, # {"errorMessage":"Bad Request","data":[{"param":"symbol","message":"\"symbol\" must be one of [ETH_USDC, BTC_USDC, BNB_USDC, SOL_USDC, DOGE_USDC, TON_USDC, AVAX_USDC, WIF_USDC, KPEPE_USDC, KSHIB_USDC, KBONK_USDC, MOODENG_USDC, POPCAT_USDC, MOTHER_USDC]"}]}
360
+ },
361
+ },
362
+ 'precisionMode': TICK_SIZE,
363
+ })
364
+
365
+ async def fetch_status(self, params={}):
366
+ """
367
+ the latest known information on the availability of the exchange API
368
+
369
+ https://api-docs.defx.com/#4b03bb3b-a0fa-4dfb-b96c-237bde0ce9e6
370
+
371
+ :param dict [params]: extra parameters specific to the exchange API endpoint
372
+ :returns dict: a `status structure <https://docs.ccxt.com/#/?id=exchange-status-structure>`
373
+ """
374
+ response = await self.v1PublicGetHealthcheckPing(params)
375
+ #
376
+ # {
377
+ # "success": True,
378
+ # "t": 1709705048323,
379
+ # "v": "0.0.7",
380
+ # "msg": "A programmer’s wife tells him, “While you’re at the grocery store, buy some eggs.” He never comes back."
381
+ # }
382
+ #
383
+ status = None
384
+ success = self.safe_bool(response, 'success')
385
+ if success:
386
+ status = 'ok'
387
+ else:
388
+ status = 'error'
389
+ return {
390
+ 'status': status,
391
+ 'updated': None,
392
+ 'eta': None,
393
+ 'url': None,
394
+ 'info': response,
395
+ }
396
+
397
+ async def fetch_time(self, params={}):
398
+ """
399
+ fetches the current integer timestamp in milliseconds from the exchange server
400
+
401
+ https://api-docs.defx.com/#4b03bb3b-a0fa-4dfb-b96c-237bde0ce9e6
402
+
403
+ :param dict [params]: extra parameters specific to the exchange API endpoint
404
+ :returns int: the current integer timestamp in milliseconds from the exchange server
405
+ """
406
+ response = await self.v1PublicGetHealthcheckPing(params)
407
+ #
408
+ # {
409
+ # "success": True,
410
+ # "t": 1709705048323,
411
+ # "v": "0.0.7",
412
+ # "msg": "A programmer’s wife tells him, “While you’re at the grocery store, buy some eggs.” He never comes back."
413
+ # }
414
+ #
415
+ return self.safe_integer(response, 't')
416
+
417
+ async def fetch_markets(self, params={}) -> List[Market]:
418
+ """
419
+ retrieves data on all markets for defx
420
+
421
+ https://api-docs.defx.com/#73cce0c8-f842-4891-9145-01bb6d61324d
422
+ https://api-docs.defx.com/#24fd4e5b-840e-451e-99e0-7fea47c7f371
423
+
424
+ :param dict [params]: extra parameters specific to the exchange API endpoint
425
+ :returns dict[]: an array of objects representing market data
426
+ """
427
+ request = {
428
+ 'type': 'perps',
429
+ }
430
+ promises = [
431
+ self.v1PublicGetCMarkets(self.extend(request, params)),
432
+ self.v1PublicGetCMarketsMetadata(self.extend(request, params)),
433
+ ]
434
+ responses = await asyncio.gather(*promises)
435
+ #
436
+ # {
437
+ # "data": [
438
+ # {
439
+ # "market": "DOGE_USDC",
440
+ # "candleWindows": [
441
+ # "1m",
442
+ # "3m",
443
+ # "5m",
444
+ # "15m",
445
+ # "30m",
446
+ # "1h",
447
+ # "2h",
448
+ # "4h",
449
+ # "12h",
450
+ # "1d",
451
+ # "1w",
452
+ # "1M"
453
+ # ],
454
+ # "depthSlabs": [
455
+ # "0.00001",
456
+ # "0.00005",
457
+ # "0.0001",
458
+ # "0.001",
459
+ # "0.01"
460
+ # ],
461
+ # "filters": [
462
+ # {
463
+ # "filterType": "LOT_SIZE",
464
+ # "minQty": "1.00000",
465
+ # "maxQty": "1500000.00000",
466
+ # "stepSize": "1.00000"
467
+ # },
468
+ # {
469
+ # "filterType": "MARKET_LOT_SIZE",
470
+ # "minQty": "1.00000",
471
+ # "maxQty": "750000.00000",
472
+ # "stepSize": "1.00000"
473
+ # },
474
+ # {
475
+ # "filterType": "PRICE_FILTER",
476
+ # "minPrice": "0.00244000",
477
+ # "maxPrice": "30.00000000",
478
+ # "tickSize": "0.00001"
479
+ # },
480
+ # {
481
+ # "filterType": "NOTIONAL",
482
+ # "minNotional": "100.00000000"
483
+ # },
484
+ # {
485
+ # "filterType": "PERCENT_PRICE_BY_SIDE",
486
+ # "bidMultiplierUp": "1.5",
487
+ # "bidMultiplierDown": "0.5",
488
+ # "askMultiplierUp": "1.5",
489
+ # "askMultiplierDown": "0.5"
490
+ # },
491
+ # {
492
+ # "filterType": "INDEX_PRICE_FILTER",
493
+ # "multiplierUp": "1.3",
494
+ # "multiplierDown": "0.7"
495
+ # }
496
+ # ],
497
+ # "cappedLeverage": "25",
498
+ # "maintenanceMarginTiers": [
499
+ # {
500
+ # "tier": "1",
501
+ # "minMaintenanceMargin": "0",
502
+ # "maxMaintenanceMargin": "2500",
503
+ # "leverage": "25"
504
+ # },
505
+ # {
506
+ # "tier": "2",
507
+ # "minMaintenanceMargin": "2500",
508
+ # "maxMaintenanceMargin": "12500",
509
+ # "leverage": "20"
510
+ # },
511
+ # {
512
+ # "tier": "3",
513
+ # "minMaintenanceMargin": "12500",
514
+ # "maxMaintenanceMargin": "25000",
515
+ # "leverage": "15"
516
+ # },
517
+ # {
518
+ # "tier": "4",
519
+ # "minMaintenanceMargin": "25000",
520
+ # "maxMaintenanceMargin": "50000",
521
+ # "leverage": "10"
522
+ # },
523
+ # {
524
+ # "tier": "5",
525
+ # "minMaintenanceMargin": "50000",
526
+ # "maxMaintenanceMargin": "75000",
527
+ # "leverage": "8"
528
+ # },
529
+ # {
530
+ # "tier": "6",
531
+ # "minMaintenanceMargin": "75000",
532
+ # "maxMaintenanceMargin": "125000",
533
+ # "leverage": "7"
534
+ # },
535
+ # {
536
+ # "tier": "7",
537
+ # "minMaintenanceMargin": "125000",
538
+ # "maxMaintenanceMargin": "187500",
539
+ # "leverage": "5"
540
+ # },
541
+ # {
542
+ # "tier": "8",
543
+ # "minMaintenanceMargin": "187500",
544
+ # "maxMaintenanceMargin": "250000",
545
+ # "leverage": "3"
546
+ # },
547
+ # {
548
+ # "tier": "9",
549
+ # "minMaintenanceMargin": "250000",
550
+ # "maxMaintenanceMargin": "375000",
551
+ # "leverage": "2"
552
+ # },
553
+ # {
554
+ # "tier": "10",
555
+ # "minMaintenanceMargin": "375000",
556
+ # "maxMaintenanceMargin": "500000",
557
+ # "leverage": "1"
558
+ # }
559
+ # ],
560
+ # "fees": {
561
+ # "maker": "0.08",
562
+ # "taker": "0.1"
563
+ # }
564
+ # },
565
+ # ]
566
+ # }
567
+ #
568
+ activeMarkets = self.safe_list(responses[0], 'data')
569
+ activeMarketsByType = self.index_by(activeMarkets, 'market')
570
+ marketMetadatas = self.safe_list(responses[1], 'data')
571
+ for i in range(0, len(marketMetadatas)):
572
+ marketId = marketMetadatas[i]['market']
573
+ status = None
574
+ if marketId in activeMarketsByType:
575
+ status = activeMarketsByType[marketId]['status']
576
+ marketMetadatas[i]['status'] = status
577
+ return self.parse_markets(marketMetadatas)
578
+
579
+ def parse_market(self, market: dict) -> Market:
580
+ marketId = self.safe_string(market, 'market')
581
+ parts = marketId.split('_')
582
+ baseId = self.safe_string(parts, 0)
583
+ quoteId = self.safe_string(parts, 1)
584
+ base = self.safe_currency_code(baseId)
585
+ quote = self.safe_currency_code(quoteId)
586
+ symbol = base + '/' + quote + ':' + quote
587
+ filters = self.safe_list(market, 'filters', [])
588
+ fees = self.safe_dict(market, 'fees', {})
589
+ filtersByType = self.index_by(filters, 'filterType')
590
+ priceFilter = self.safe_dict(filtersByType, 'PRICE_FILTER', {})
591
+ lotFilter = self.safe_dict(filtersByType, 'LOT_SIZE', {})
592
+ marketLotFilter = self.safe_dict(filtersByType, 'MARKET_LOT_SIZE', {})
593
+ notionalFilter = self.safe_dict(filtersByType, 'NOTIONAL', {})
594
+ return {
595
+ 'id': marketId,
596
+ 'symbol': symbol,
597
+ 'base': base,
598
+ 'quote': quote,
599
+ 'settle': quote,
600
+ 'baseId': baseId,
601
+ 'quoteId': quoteId,
602
+ 'settleId': quoteId,
603
+ 'type': 'swap',
604
+ 'spot': False,
605
+ 'margin': False,
606
+ 'swap': True,
607
+ 'future': False,
608
+ 'option': False,
609
+ 'active': self.safe_string(market, 'status', '') == 'active',
610
+ 'contract': True,
611
+ 'linear': True,
612
+ 'inverse': None,
613
+ 'taker': self.safe_number(fees, 'taker'),
614
+ 'maker': self.safe_number(fees, 'maker'),
615
+ 'contractSize': self.parse_number('1'),
616
+ 'expiry': None,
617
+ 'expiryDatetime': None,
618
+ 'strike': None,
619
+ 'optionType': None,
620
+ 'precision': {
621
+ 'amount': self.safe_number(lotFilter, 'stepSize'),
622
+ 'price': self.safe_number(priceFilter, 'tickSize'),
623
+ },
624
+ 'limits': {
625
+ 'leverage': {
626
+ 'min': None,
627
+ 'max': self.safe_number(market, 'cappedLeverage'),
628
+ },
629
+ 'amount': {
630
+ 'min': self.safe_number(lotFilter, 'minQty'),
631
+ 'max': self.safe_number(lotFilter, 'maxQty'),
632
+ },
633
+ 'price': {
634
+ 'min': self.safe_number(priceFilter, 'minPrice'),
635
+ 'max': self.safe_number(priceFilter, 'maxPrice'),
636
+ },
637
+ 'cost': {
638
+ 'min': self.safe_number(notionalFilter, 'minNotional'),
639
+ 'max': None,
640
+ },
641
+ 'market': {
642
+ 'min': self.safe_number(marketLotFilter, 'minQty'),
643
+ 'max': self.safe_number(marketLotFilter, 'maxQty'),
644
+ },
645
+ },
646
+ 'created': None,
647
+ 'info': market,
648
+ }
649
+
650
+ async def fetch_ticker(self, symbol: str, params={}) -> Ticker:
651
+ """
652
+ fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
653
+
654
+ https://api-docs.defx.com/#fe6f81d0-2f3a-4eee-976f-c8fc8f4c5d56
655
+
656
+ :param str symbol: unified symbol of the market to fetch the ticker for
657
+ :param dict [params]: extra parameters specific to the exchange API endpoint
658
+ :returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
659
+ """
660
+ await self.load_markets()
661
+ market = self.market(symbol)
662
+ request: dict = {
663
+ 'symbol': market['id'],
664
+ }
665
+ response = await self.v1PublicGetSymbolsSymbolTicker24hr(self.extend(request, params))
666
+ #
667
+ # {
668
+ # "symbol": "BTC_USDC",
669
+ # "priceChange": "0",
670
+ # "priceChangePercent": "0",
671
+ # "weightedAvgPrice": "0",
672
+ # "lastPrice": "2.00",
673
+ # "lastQty": "10.000",
674
+ # "bestBidPrice": "1646.00",
675
+ # "bestBidQty": "10.000",
676
+ # "bestAskPrice": "1646.00",
677
+ # "bestAskQty": "10.000",
678
+ # "openPrice": "0.00",
679
+ # "highPrice": "0.00",
680
+ # "lowPrice": "0.00",
681
+ # "volume": "0.000",
682
+ # "quoteVolume": "0.00",
683
+ # "openTime": 1700142658697,
684
+ # "closeTime": 1700142658697,
685
+ # "openInterestBase": "1.000",
686
+ # "openInterestQuote": "0.43112300"
687
+ # }
688
+ #
689
+ return self.parse_ticker(response, market)
690
+
691
+ async def fetch_tickers(self, symbols: Strings = None, params={}) -> Tickers:
692
+ """
693
+ fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
694
+
695
+ https://api-docs.defx.com/#8c61cfbd-40d9-410e-b014-f5b36eba51d1
696
+
697
+ :param str[]|None symbols: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
698
+ :param dict [params]: extra parameters specific to the exchange API endpoint
699
+ :returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
700
+ """
701
+ await self.load_markets()
702
+ market = None
703
+ if symbols is not None:
704
+ symbols = self.market_symbols(symbols)
705
+ firstSymbol = self.safe_string(symbols, 0)
706
+ if firstSymbol is not None:
707
+ market = self.market(firstSymbol)
708
+ type = None
709
+ type, params = self.handle_market_type_and_params('fetchTickers', market, params)
710
+ if type == 'spot':
711
+ raise NotSupported(self.id + ' fetchTickers() is not supported for ' + type + ' markets')
712
+ response = await self.v1PublicGetTicker24HrAgg(params)
713
+ #
714
+ # {
715
+ # "ETH_USDC": {
716
+ # "priceChange": "0",
717
+ # "priceChangePercent": "0",
718
+ # "openPrice": "1646.15",
719
+ # "highPrice": "1646.15",
720
+ # "lowPrice": "1646.15",
721
+ # "lastPrice": "1646.15",
722
+ # "quoteVolume": "13.17",
723
+ # "volume": "0.008",
724
+ # "markPrice": "1645.15"
725
+ # }
726
+ # }
727
+ #
728
+ return self.parse_tickers(response, symbols)
729
+
730
+ def parse_ticker(self, ticker: dict, market: Market = None) -> Ticker:
731
+ #
732
+ # fetchTicker
733
+ #
734
+ # {
735
+ # "symbol": "BTC_USDC",
736
+ # "priceChange": "0",
737
+ # "priceChangePercent": "0",
738
+ # "weightedAvgPrice": "0",
739
+ # "lastPrice": "2.00",
740
+ # "lastQty": "10.000",
741
+ # "bestBidPrice": "1646.00",
742
+ # "bestBidQty": "10.000",
743
+ # "bestAskPrice": "1646.00",
744
+ # "bestAskQty": "10.000",
745
+ # "openPrice": "0.00",
746
+ # "highPrice": "0.00",
747
+ # "lowPrice": "0.00",
748
+ # "volume": "0.000",
749
+ # "quoteVolume": "0.00",
750
+ # "openTime": 1700142658697,
751
+ # "closeTime": 1700142658697,
752
+ # "openInterestBase": "1.000",
753
+ # "openInterestQuote": "0.43112300"
754
+ # }
755
+ #
756
+ # fetchTickers
757
+ #
758
+ # "ETH_USDC": {
759
+ # "priceChange": "0",
760
+ # "priceChangePercent": "0",
761
+ # "openPrice": "1646.15",
762
+ # "highPrice": "1646.15",
763
+ # "lowPrice": "1646.15",
764
+ # "lastPrice": "1646.15",
765
+ # "quoteVolume": "13.17",
766
+ # "volume": "0.008",
767
+ # "markPrice": "1645.15"
768
+ # }
769
+ #
770
+ # fetchMarkPrice
771
+ #
772
+ # {
773
+ # "markPrice": "100.00",
774
+ # "indexPrice": "100.00",
775
+ # "ltp": "101.34",
776
+ # "movingFundingRate": "0.08",
777
+ # "payoutFundingRate": "-0.03",
778
+ # "nextFundingPayout": 1711555532146
779
+ # }
780
+ #
781
+ marketId = self.safe_string(ticker, 'symbol')
782
+ if marketId is not None:
783
+ market = self.market(marketId)
784
+ symbol = market['symbol']
785
+ open = self.safe_string(ticker, 'openPrice')
786
+ high = self.safe_string(ticker, 'highPrice')
787
+ low = self.safe_string(ticker, 'lowPrice')
788
+ close = self.safe_string(ticker, 'lastPrice')
789
+ quoteVolume = self.safe_string(ticker, 'quoteVolume')
790
+ baseVolume = self.safe_string(ticker, 'volume')
791
+ percentage = self.safe_string(ticker, 'priceChangePercent')
792
+ change = self.safe_string(ticker, 'priceChange')
793
+ ts = self.safe_integer(ticker, 'closeTime')
794
+ if ts == 0:
795
+ ts = None
796
+ datetime = self.iso8601(ts)
797
+ bid = self.safe_string(ticker, 'bestBidPrice')
798
+ bidVolume = self.safe_string(ticker, 'bestBidQty')
799
+ ask = self.safe_string(ticker, 'bestAskPrice')
800
+ askVolume = self.safe_string(ticker, 'bestAskQty')
801
+ return self.safe_ticker({
802
+ 'symbol': symbol,
803
+ 'timestamp': ts,
804
+ 'datetime': datetime,
805
+ 'high': high,
806
+ 'low': low,
807
+ 'bid': bid,
808
+ 'bidVolume': bidVolume,
809
+ 'ask': ask,
810
+ 'askVolume': askVolume,
811
+ 'vwap': None,
812
+ 'open': open,
813
+ 'close': close,
814
+ 'last': None,
815
+ 'previousClose': None,
816
+ 'change': change,
817
+ 'percentage': percentage,
818
+ 'average': None,
819
+ 'baseVolume': baseVolume,
820
+ 'quoteVolume': quoteVolume,
821
+ 'markPrice': self.safe_string(ticker, 'markPrice'),
822
+ 'indexPrice': self.safe_string(ticker, 'indexPrice'),
823
+ 'info': ticker,
824
+ }, market)
825
+
826
+ async def fetch_ohlcv(self, symbol: str, timeframe='1m', since: Int = None, limit: Int = None, params={}) -> List[list]:
827
+ """
828
+
829
+ https://api-docs.defx.com/#54b71951-1472-4670-b5af-4c2dc41e73d0
830
+
831
+ fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
832
+ :param str symbol: unified symbol of the market to fetch OHLCV data for
833
+ :param str timeframe: the length of time each candle represents
834
+ :param int [since]: timestamp in ms of the earliest candle to fetch
835
+ :param int [limit]: max=1000, max=100 when since is defined and is less than(now - (999 * (timeframe in ms)))
836
+ :param dict [params]: extra parameters specific to the exchange API endpoint
837
+ :param int [params.until]: the latest time in ms to fetch orders for
838
+ :returns int[][]: A list of candles ordered, open, high, low, close, volume
839
+ """
840
+ await self.load_markets()
841
+ market = self.market(symbol)
842
+ maxLimit = 1000
843
+ if limit is None:
844
+ limit = maxLimit
845
+ limit = min(maxLimit, limit)
846
+ request: dict = {
847
+ 'symbol': market['id'],
848
+ 'interval': self.safe_string(self.timeframes, timeframe, timeframe),
849
+ 'limit': limit,
850
+ }
851
+ until = self.safe_integer_2(params, 'until', 'till')
852
+ params = self.omit(params, ['until', 'till'])
853
+ request['endTime'] = self.milliseconds() if (until is None) else until
854
+ if since is None:
855
+ request['startTime'] = 0
856
+ else:
857
+ request['startTime'] = since
858
+ if until is None:
859
+ timeframeInSeconds = self.parse_timeframe(timeframe)
860
+ timeframeInMilliseconds = timeframeInSeconds * 1000
861
+ totalTimeframeInMilliseconds = limit * timeframeInMilliseconds
862
+ request['endTime'] = self.sum(since, totalTimeframeInMilliseconds)
863
+ response = await self.v1PublicGetSymbolsSymbolOhlc(self.extend(request, params))
864
+ #
865
+ # [
866
+ # {
867
+ # "symbol": "BTC_USDC",
868
+ # "open": "0.00",
869
+ # "high": "0.00",
870
+ # "low": "0.00",
871
+ # "close": "0.00",
872
+ # "volume": "0.000",
873
+ # "quoteAssetVolume": "0.00",
874
+ # "takerBuyAssetVolume": "0.000",
875
+ # "takerBuyQuoteAssetVolume": "0.00",
876
+ # "numberOfTrades": 0,
877
+ # "start": 1702453663894,
878
+ # "end": 1702453663894,
879
+ # "isClosed": True
880
+ # }
881
+ # ]
882
+ #
883
+ return self.parse_ohlcvs(response, market, timeframe, since, limit)
884
+
885
+ def parse_ohlcv(self, ohlcv, market: Market = None) -> list:
886
+ # example response in fetchOHLCV
887
+ return [
888
+ self.safe_integer(ohlcv, 'start'),
889
+ self.safe_number(ohlcv, 'open'),
890
+ self.safe_number(ohlcv, 'high'),
891
+ self.safe_number(ohlcv, 'low'),
892
+ self.safe_number(ohlcv, 'close'),
893
+ self.safe_number(ohlcv, 'volume'),
894
+ ]
895
+
896
+ async def fetch_trades(self, symbol: str, since: Int = None, limit: Int = None, params={}) -> List[Trade]:
897
+ """
898
+ get the list of most recent trades for a particular symbol
899
+
900
+ https://api-docs.defx.com/#5865452f-ea32-4f13-bfbc-03af5f5574fd
901
+
902
+ :param str symbol: unified symbol of the market to fetch trades for
903
+ :param int [since]: timestamp in ms of the earliest trade to fetch
904
+ :param int [limit]: the maximum amount of trades to fetch
905
+ :param dict [params]: extra parameters specific to the exchange API endpoint
906
+ :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
907
+ """
908
+ await self.load_markets()
909
+ market = self.market(symbol)
910
+ maxLimit = 50
911
+ if limit is None:
912
+ limit = maxLimit
913
+ limit = min(maxLimit, limit)
914
+ request: dict = {
915
+ 'symbol': market['id'],
916
+ 'limit': limit,
917
+ }
918
+ response = await self.v1PublicGetSymbolsSymbolTrades(self.extend(request, params))
919
+ #
920
+ # [
921
+ # {
922
+ # "buyerMaker": "false",
923
+ # "price": "2.0000",
924
+ # "qty": "10.0000",
925
+ # "symbol": "BTC_USDC",
926
+ # "timestamp": "1702453663894"
927
+ # }
928
+ # ]
929
+ #
930
+ return self.parse_trades(response, market, since, limit)
931
+
932
+ async def fetch_my_trades(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Trade]:
933
+ """
934
+ fetch all trades made by the user
935
+
936
+ https://api-docs.defx.com/#06b5b33c-2fc6-48de-896c-fc316f5871a7
937
+
938
+ :param str symbol: unified symbol of the market to fetch trades for
939
+ :param int [since]: timestamp in ms of the earliest trade to fetch
940
+ :param int [limit]: the maximum amount of trades to fetch
941
+ :param dict [params]: extra parameters specific to the exchange API endpoint
942
+ :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
943
+ """
944
+ await self.load_markets()
945
+ request: dict = {}
946
+ if symbol is not None:
947
+ market = self.market(symbol)
948
+ request['symbols'] = market['id']
949
+ if limit is not None:
950
+ maxLimit = 100
951
+ limit = min(maxLimit, limit)
952
+ request['pageSize'] = limit
953
+ response = await self.v1PrivateGetApiTrades(self.extend(request, params))
954
+ #
955
+ # {
956
+ # "data": [
957
+ # {
958
+ # "id": "0192f665-c05b-7ba0-a080-8b6c99083489",
959
+ # "orderId": "757730811259651728",
960
+ # "time": "2024-11-04T08:58:36.474Z",
961
+ # "symbol": "SOL_USDC",
962
+ # "side": "SELL",
963
+ # "price": "160.43600000",
964
+ # "qty": "1.00",
965
+ # "fee": "0.08823980",
966
+ # "role": "TAKER",
967
+ # "pnl": "0.00000000"
968
+ # }
969
+ # ]
970
+ # }
971
+ #
972
+ data = self.safe_list(response, 'data', [])
973
+ return self.parse_trades(data, None, since, limit)
974
+
975
+ def parse_trade(self, trade: dict, market: Market = None) -> Trade:
976
+ #
977
+ # fetchTrades
978
+ # {
979
+ # "buyerMaker": "false",
980
+ # "price": "2.0000",
981
+ # "qty": "10.0000",
982
+ # "symbol": "BTC_USDC",
983
+ # "timestamp": "1702453663894"
984
+ # }
985
+ #
986
+ # fetchMyTrades
987
+ # {
988
+ # "id": "0192f665-c05b-7ba0-a080-8b6c99083489",
989
+ # "orderId": "757730811259651728",
990
+ # "time": "2024-11-04T08:58:36.474Z",
991
+ # "symbol": "SOL_USDC",
992
+ # "side": "SELL",
993
+ # "price": "160.43600000",
994
+ # "qty": "1.00",
995
+ # "fee": "0.08823980",
996
+ # "role": "TAKER",
997
+ # "pnl": "0.00000000"
998
+ # }
999
+ #
1000
+ time = self.safe_string(trade, 'time')
1001
+ timestamp = self.safe_integer(trade, 'timestamp', self.parse8601(time))
1002
+ marketId = self.safe_string(trade, 'symbol')
1003
+ market = self.safe_market(marketId, market)
1004
+ symbol = market['symbol']
1005
+ price = self.safe_string(trade, 'price')
1006
+ amount = self.safe_string(trade, 'qty')
1007
+ id = self.safe_string(trade, 'id')
1008
+ oid = self.safe_string(trade, 'orderId')
1009
+ takerOrMaker = self.safe_string_lower(trade, 'role')
1010
+ buyerMaker = self.safe_bool(trade, 'buyerMaker')
1011
+ side = self.safe_string_lower(trade, 'side')
1012
+ if buyerMaker is not None:
1013
+ if buyerMaker:
1014
+ side = 'sell'
1015
+ else:
1016
+ side = 'buy'
1017
+ return self.safe_trade({
1018
+ 'id': id,
1019
+ 'timestamp': timestamp,
1020
+ 'datetime': self.iso8601(timestamp),
1021
+ 'symbol': symbol,
1022
+ 'side': side,
1023
+ 'price': price,
1024
+ 'amount': amount,
1025
+ 'cost': None,
1026
+ 'order': oid,
1027
+ 'takerOrMaker': takerOrMaker,
1028
+ 'type': None,
1029
+ 'fee': {
1030
+ 'cost': self.safe_string(trade, 'fee'),
1031
+ 'currency': 'USDC',
1032
+ },
1033
+ 'info': trade,
1034
+ }, market)
1035
+
1036
+ async def fetch_order_book(self, symbol: str, limit: Int = None, params={}) -> OrderBook:
1037
+ """
1038
+ fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
1039
+
1040
+ https://api-docs.defx.com/#6c1a2971-8325-4e7d-9962-e0bfcaacf9c4
1041
+
1042
+ :param str symbol: unified symbol of the market to fetch the order book for
1043
+ :param int [limit]: the maximum amount of order book entries to return
1044
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1045
+ :param str [params.slab]: slab from market.info.depthSlabs
1046
+ :returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
1047
+ """
1048
+ await self.load_markets()
1049
+ market = self.market(symbol)
1050
+ if limit is None:
1051
+ limit = 10 # limit must be one of [5, 10, 20]
1052
+ marketInfo = self.safe_dict(market, 'info', {})
1053
+ slab = self.safe_list(marketInfo, 'depthSlabs', [])
1054
+ request: dict = {
1055
+ 'symbol': market['id'],
1056
+ 'level': limit,
1057
+ 'slab': self.safe_string(slab, 0),
1058
+ }
1059
+ response = await self.v1PublicGetSymbolsSymbolDepthLevelSlab(self.extend(request, params))
1060
+ #
1061
+ # {
1062
+ # "symbol": "ETH_USDC",
1063
+ # "level": "5",
1064
+ # "slab": "1",
1065
+ # "lastTradeTimestamp": "1708313446812",
1066
+ # "timestamp": "1708313446812",
1067
+ # "bids": [
1068
+ # {
1069
+ # "price": "1646.16",
1070
+ # "qty": "0.001"
1071
+ # }
1072
+ # ],
1073
+ # "asks": [
1074
+ # {
1075
+ # "price": "1646.16",
1076
+ # "qty": "0.001"
1077
+ # }
1078
+ # ]
1079
+ # }
1080
+ #
1081
+ timestamp = self.safe_integer(response, 'timestamp')
1082
+ return self.parse_order_book(response, symbol, timestamp, 'bids', 'asks', 'price', 'qty')
1083
+
1084
+ async def fetch_mark_price(self, symbol: str, params={}) -> Ticker:
1085
+ """
1086
+ fetches mark price for the market
1087
+
1088
+ https://api-docs.defx.com/#12168192-4e7b-4458-a001-e8b80961f0b7
1089
+
1090
+ :param str symbol: unified symbol of the market to fetch the ticker for
1091
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1092
+ :param str [params.subType]: "linear" or "inverse"
1093
+ :returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
1094
+ """
1095
+ await self.load_markets()
1096
+ market = self.market(symbol)
1097
+ request = {
1098
+ 'symbol': market['id'],
1099
+ }
1100
+ response = await self.v1PublicGetSymbolsSymbolPrices(self.extend(request, params))
1101
+ #
1102
+ # {
1103
+ # "markPrice": "100.00",
1104
+ # "indexPrice": "100.00",
1105
+ # "ltp": "101.34",
1106
+ # "movingFundingRate": "0.08",
1107
+ # "payoutFundingRate": "-0.03",
1108
+ # "nextFundingPayout": 1711555532146
1109
+ # }
1110
+ #
1111
+ return self.parse_ticker(response, market)
1112
+
1113
+ async def fetch_funding_rate(self, symbol: str, params={}) -> FundingRate:
1114
+ """
1115
+ fetch the current funding rate
1116
+
1117
+ https://api-docs.defx.com/#12168192-4e7b-4458-a001-e8b80961f0b7
1118
+
1119
+ :param str symbol: unified market symbol
1120
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1121
+ :returns dict: a `funding rate structure <https://docs.ccxt.com/#/?id=funding-rate-structure>`
1122
+ """
1123
+ await self.load_markets()
1124
+ market = self.market(symbol)
1125
+ request = {
1126
+ 'symbol': market['id'],
1127
+ }
1128
+ response = await self.v1PublicGetSymbolsSymbolPrices(self.extend(request, params))
1129
+ #
1130
+ # {
1131
+ # "markPrice": "100.00",
1132
+ # "indexPrice": "100.00",
1133
+ # "ltp": "101.34",
1134
+ # "movingFundingRate": "0.08",
1135
+ # "payoutFundingRate": "-0.03",
1136
+ # "nextFundingPayout": 1711555532146
1137
+ # }
1138
+ #
1139
+ return self.parse_funding_rate(response, market)
1140
+
1141
+ def parse_funding_rate(self, contract, market: Market = None) -> FundingRate:
1142
+ #
1143
+ # {
1144
+ # "markPrice": "100.00",
1145
+ # "indexPrice": "100.00",
1146
+ # "ltp": "101.34",
1147
+ # "movingFundingRate": "0.08",
1148
+ # "payoutFundingRate": "-0.03",
1149
+ # "nextFundingPayout": 1711555532146
1150
+ # }
1151
+ #
1152
+ markPrice = self.safe_number(contract, 'markPrice')
1153
+ indexPrice = self.safe_number(contract, 'indexPrice')
1154
+ fundingRate = self.safe_number(contract, 'payoutFundingRate')
1155
+ fundingTime = self.safe_integer(contract, 'nextFundingPayout')
1156
+ return {
1157
+ 'info': contract,
1158
+ 'symbol': market['symbol'],
1159
+ 'markPrice': markPrice,
1160
+ 'indexPrice': indexPrice,
1161
+ 'interestRate': None,
1162
+ 'estimatedSettlePrice': None,
1163
+ 'timestamp': None,
1164
+ 'datetime': None,
1165
+ 'fundingRate': fundingRate,
1166
+ 'fundingTimestamp': fundingTime,
1167
+ 'fundingDatetime': self.iso8601(fundingTime),
1168
+ 'nextFundingRate': None,
1169
+ 'nextFundingTimestamp': None,
1170
+ 'nextFundingDatetime': None,
1171
+ 'previousFundingRate': None,
1172
+ 'previousFundingTimestamp': None,
1173
+ 'previousFundingDatetime': None,
1174
+ 'interval': None,
1175
+ }
1176
+
1177
+ async def fetch_balance(self, params={}) -> Balances:
1178
+ """
1179
+ query for balance and get the amount of funds available for trading or funds locked in orders
1180
+
1181
+ https://api-docs.defx.com/#26414338-14f7-40a1-b246-f8ea8571493f
1182
+
1183
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1184
+ :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
1185
+ """
1186
+ await self.load_markets()
1187
+ response = await self.v1PrivateGetApiWalletBalance(params)
1188
+ #
1189
+ # {
1190
+ # "assets": [
1191
+ # {
1192
+ # "asset": "USDC",
1193
+ # "balance": "0.000"
1194
+ # }
1195
+ # ]
1196
+ # }
1197
+ #
1198
+ data = self.safe_list(response, 'assets')
1199
+ return self.parse_balance(data)
1200
+
1201
+ def parse_balance(self, balances) -> Balances:
1202
+ result: dict = {
1203
+ 'info': balances,
1204
+ }
1205
+ for i in range(0, len(balances)):
1206
+ balance = balances[i]
1207
+ code = self.safe_currency_code(self.safe_string(balance, 'asset'))
1208
+ account = self.account()
1209
+ account['total'] = self.safe_string(balance, 'balance')
1210
+ result[code] = account
1211
+ return self.safe_balance(result)
1212
+
1213
+ async def create_order(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={}):
1214
+ """
1215
+ create a trade order
1216
+
1217
+ https://api-docs.defx.com/#ba222d88-8856-4d3c-87a9-7cec07bb2622
1218
+
1219
+ :param str symbol: unified symbol of the market to create an order in
1220
+ :param str type: 'market' or 'limit'
1221
+ :param str side: 'buy' or 'sell'
1222
+ :param float amount: how much of currency you want to trade in units of base currency
1223
+ :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
1224
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1225
+ :param float [params.triggerPrice]: The price a trigger order is triggered at
1226
+ :param str [params.reduceOnly]: for swap and future reduceOnly is a string 'true' or 'false' that cant be sent with close position set to True or in hedge mode. For spot margin and option reduceOnly is a boolean.
1227
+ :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
1228
+ """
1229
+ await self.load_markets()
1230
+ market = self.market(symbol)
1231
+ reduceOnly = self.safe_bool_2(params, 'reduceOnly', 'reduce_only')
1232
+ params = self.omit(params, ['reduceOnly', 'reduce_only'])
1233
+ orderType = type.upper()
1234
+ orderSide = side.upper()
1235
+ request: dict = {
1236
+ 'symbol': market['id'],
1237
+ 'side': orderSide,
1238
+ 'type': orderType,
1239
+ }
1240
+ takeProfitPrice = self.safe_string(params, 'takeProfitPrice')
1241
+ triggerPrice = self.safe_string_2(params, 'stopPrice', 'triggerPrice')
1242
+ isMarket = orderType == 'MARKET'
1243
+ isLimit = orderType == 'LIMIT'
1244
+ timeInForce = self.safe_string_upper(params, 'timeInForce')
1245
+ if timeInForce is not None:
1246
+ # GTC, IOC, FOK, AON
1247
+ request['timeInForce'] = timeInForce
1248
+ else:
1249
+ if isLimit:
1250
+ request['timeInForce'] = 'GTC'
1251
+ if reduceOnly:
1252
+ request['reduceOnly'] = reduceOnly
1253
+ clientOrderId = self.safe_string(params, 'clientOrderId')
1254
+ if clientOrderId is not None:
1255
+ request['newClientOrderId'] = clientOrderId
1256
+ if triggerPrice is not None or takeProfitPrice is not None:
1257
+ request['workingType'] = 'MARK_PRICE'
1258
+ if takeProfitPrice is not None:
1259
+ request['stopPrice'] = self.price_to_precision(symbol, takeProfitPrice)
1260
+ if isMarket:
1261
+ request['type'] = 'TAKE_PROFIT_MARKET'
1262
+ else:
1263
+ request['type'] = 'TAKE_PROFIT_LIMIT'
1264
+ else:
1265
+ request['stopPrice'] = self.price_to_precision(symbol, triggerPrice)
1266
+ if isMarket:
1267
+ request['type'] = 'STOP_MARKET'
1268
+ else:
1269
+ request['type'] = 'STOP_LIMIT'
1270
+ if isLimit and price is not None:
1271
+ request['price'] = self.price_to_precision(symbol, price)
1272
+ request['quantity'] = self.amount_to_precision(symbol, amount)
1273
+ params = self.omit(params, ['clOrdID', 'clientOrderId', 'client_order_id', 'postOnly', 'timeInForce', 'stopPrice', 'triggerPrice', 'takeProfitPrice'])
1274
+ response = await self.v1PrivatePostApiOrder(self.extend(request, params))
1275
+ #
1276
+ # {
1277
+ # "success": True,
1278
+ # "data": {
1279
+ # "orderId": "",
1280
+ # "clientOrderId": "",
1281
+ # "cumulativeQty": "",
1282
+ # "cumulativeQuote": "",
1283
+ # "executedQty": "",
1284
+ # "avgPrice": "",
1285
+ # "origQty": "",
1286
+ # "price": "",
1287
+ # "reduceOnly": True,
1288
+ # "side": "",
1289
+ # "status": "",
1290
+ # "symbol": "",
1291
+ # "timeInForce": "",
1292
+ # "type": "",
1293
+ # "workingType": ""
1294
+ # }
1295
+ # }
1296
+ #
1297
+ data = self.safe_dict(response, 'data')
1298
+ return self.parse_order(data, market)
1299
+
1300
+ def parse_order_status(self, status: Str):
1301
+ if status is not None:
1302
+ statuses: dict = {
1303
+ 'NEW': 'open',
1304
+ 'OPEN': 'open',
1305
+ 'CANCELLED': 'canceled',
1306
+ 'REJECTED': 'rejected',
1307
+ 'FILLED': 'closed',
1308
+ }
1309
+ return self.safe_string(statuses, status, status)
1310
+ return status
1311
+
1312
+ def parse_order(self, order: dict, market: Market = None) -> Order:
1313
+ #
1314
+ # {
1315
+ # "orderId": "746472647227344528",
1316
+ # "createdAt": "2024-10-25T16:49:31.077Z",
1317
+ # "updatedAt": "2024-10-25T16:49:31.378Z",
1318
+ # "clientOrderId": "0192c495-49c3-71ee-b3d3-7442a2090807",
1319
+ # "reduceOnly": False,
1320
+ # "side": "SELL",
1321
+ # "status": "FILLED",
1322
+ # "symbol": "SOL_USDC",
1323
+ # "timeInForce": "GTC",
1324
+ # "type": "MARKET",
1325
+ # "origQty": "0.80",
1326
+ # "executedQty": "0.80",
1327
+ # "cumulativeQuote": "137.87440000",
1328
+ # "avgPrice": "172.34300000",
1329
+ # "totalPnL": "0.00000000",
1330
+ # "totalFee": "0.07583092",
1331
+ # "workingType": null,
1332
+ # "postOnly": False,
1333
+ # "linkedOrderParentType": null,
1334
+ # "isTriggered": False,
1335
+ # "slippagePercentage": "5"
1336
+ # }
1337
+ #
1338
+ orderId = self.safe_string(order, 'orderId')
1339
+ clientOrderId = self.safe_string(order, 'clientOrderId')
1340
+ marketId = self.safe_string(order, 'symbol')
1341
+ market = self.safe_market(marketId, market)
1342
+ symbol = market['symbol']
1343
+ price = self.safe_string(order, 'price')
1344
+ amount = self.safe_string(order, 'origQty')
1345
+ orderType = self.safe_string_lower(order, 'type')
1346
+ status = self.safe_string(order, 'status')
1347
+ side = self.safe_string_lower(order, 'side')
1348
+ filled = self.omit_zero(self.safe_string(order, 'executedQty'))
1349
+ average = self.omit_zero(self.safe_string(order, 'avgPrice'))
1350
+ timeInForce = self.safe_string_lower(order, 'timeInForce')
1351
+ takeProfitPrice: Str = None
1352
+ triggerPrice: Str = None
1353
+ if orderType is not None:
1354
+ if orderType.find('take_profit') >= 0:
1355
+ takeProfitPrice = self.safe_string(order, 'stopPrice')
1356
+ else:
1357
+ triggerPrice = self.safe_string(order, 'stopPrice')
1358
+ timestamp = self.parse8601(self.safe_string(order, 'createdAt'))
1359
+ lastTradeTimestamp = self.parse8601(self.safe_string(order, 'updatedAt'))
1360
+ return self.safe_order({
1361
+ 'id': orderId,
1362
+ 'clientOrderId': clientOrderId,
1363
+ 'timestamp': timestamp,
1364
+ 'datetime': self.iso8601(timestamp),
1365
+ 'lastTradeTimestamp': lastTradeTimestamp,
1366
+ 'lastUpdateTimestamp': lastTradeTimestamp,
1367
+ 'status': self.parse_order_status(status),
1368
+ 'symbol': symbol,
1369
+ 'type': orderType,
1370
+ 'timeInForce': timeInForce,
1371
+ 'postOnly': self.safe_bool(order, 'postOnly'),
1372
+ 'reduceOnly': self.safe_bool(order, 'reduceOnly'),
1373
+ 'side': side,
1374
+ 'price': price,
1375
+ 'triggerPrice': triggerPrice,
1376
+ 'takeProfitPrice': takeProfitPrice,
1377
+ 'stopLossPrice': None,
1378
+ 'average': average,
1379
+ 'amount': amount,
1380
+ 'filled': filled,
1381
+ 'remaining': None,
1382
+ 'cost': None,
1383
+ 'trades': None,
1384
+ 'fee': {
1385
+ 'cost': self.safe_string(order, 'totalFee'),
1386
+ 'currency': 'USDC',
1387
+ },
1388
+ 'info': order,
1389
+ }, market)
1390
+
1391
+ async def cancel_order(self, id: str, symbol: Str = None, params={}):
1392
+ """
1393
+
1394
+ https://api-docs.defx.com/#09186f23-f8d1-4993-acf4-9974d8a6ddb0
1395
+
1396
+ cancels an open order
1397
+ :param str id: order id
1398
+ :param str symbol: unified symbol of the market the order was made in
1399
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1400
+ :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
1401
+ """
1402
+ await self.load_markets()
1403
+ request: dict = {
1404
+ 'orderId': id,
1405
+ 'idType': 'orderId',
1406
+ }
1407
+ clientOrderId = self.safe_string_n(params, ['clOrdID', 'clientOrderId', 'client_order_id'])
1408
+ isByClientOrder = clientOrderId is not None
1409
+ if isByClientOrder:
1410
+ if symbol is None:
1411
+ raise ArgumentsRequired(self.id + ' cancelOrder() requires a symbol argument')
1412
+ market = self.market(symbol)
1413
+ request['orderId'] = clientOrderId
1414
+ request['idType'] = 'clientOrderId'
1415
+ request['symbol'] = market['id']
1416
+ params = self.omit(params, ['clOrdID', 'clientOrderId', 'client_order_id'])
1417
+ response = await self.v1PrivateDeleteApiOrderOrderId(self.extend(request, params))
1418
+ #
1419
+ # {
1420
+ # "success": True
1421
+ # }
1422
+ #
1423
+ extendParams: dict = {'symbol': symbol}
1424
+ if isByClientOrder:
1425
+ extendParams['clientOrderId'] = clientOrderId
1426
+ else:
1427
+ extendParams['id'] = id
1428
+ return self.extend(self.parse_order(response), extendParams)
1429
+
1430
+ async def cancel_all_orders(self, symbol: Str = None, params={}):
1431
+ """
1432
+ cancel all open orders
1433
+
1434
+ https://api-docs.defx.com/#db5531da-3692-4a53-841f-6ad6495f823a
1435
+
1436
+ :param str symbol: unified market symbol, only orders in the market of self symbol are cancelled when symbol is not None
1437
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1438
+ :returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
1439
+ """
1440
+ await self.load_markets()
1441
+ market = self.market(symbol)
1442
+ request: dict = {
1443
+ 'symbols': [market['id']],
1444
+ }
1445
+ response = await self.v1PrivateDeleteApiOrdersAllOpen(self.extend(request, params))
1446
+ #
1447
+ # {
1448
+ # "data": {
1449
+ # "msg": "The operation of cancel all open order is done."
1450
+ # }
1451
+ # }
1452
+ #
1453
+ return response
1454
+
1455
+ async def fetch_position(self, symbol: str, params={}):
1456
+ """
1457
+ fetch data on a single open contract trade position
1458
+
1459
+ https://api-docs.defx.com/#d89dbb86-9aba-4f59-ac5d-a97ff25ea80e
1460
+
1461
+ :param str symbol: unified market symbol of the market the position is held in, default is None
1462
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1463
+ :returns dict: a `position structure <https://docs.ccxt.com/#/?id=position-structure>`
1464
+ """
1465
+ if symbol is None:
1466
+ raise ArgumentsRequired(self.id + ' fetchPosition() requires a symbol argument')
1467
+ await self.load_markets()
1468
+ market = self.market(symbol)
1469
+ request: dict = {
1470
+ 'symbol': market['id'],
1471
+ }
1472
+ response = await self.v1PrivateGetApiPositionActive(self.extend(request, params))
1473
+ #
1474
+ # {
1475
+ # "data": [
1476
+ # {
1477
+ # "positionId": "0192c495-4a68-70ee-9081-9d368bd16dfc",
1478
+ # "symbol": "SOL_USDC",
1479
+ # "positionSide": "SHORT",
1480
+ # "entryPrice": "172.34300000",
1481
+ # "quantity": "0.80",
1482
+ # "marginAmount": "20.11561173",
1483
+ # "marginAsset": "USDC",
1484
+ # "pnl": "0.00000000"
1485
+ # }
1486
+ # ]
1487
+ # }
1488
+ #
1489
+ data = self.safe_list(response, 'data', [])
1490
+ first = self.safe_dict(data, 0, {})
1491
+ return self.parse_position(first, market)
1492
+
1493
+ async def fetch_positions(self, symbols: Strings = None, params={}):
1494
+ """
1495
+ fetch all open positions
1496
+
1497
+ https://api-docs.defx.com/#d89dbb86-9aba-4f59-ac5d-a97ff25ea80e
1498
+
1499
+ :param str[] [symbols]: list of unified market symbols
1500
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1501
+ :returns dict[]: a list of `position structure <https://docs.ccxt.com/#/?id=position-structure>`
1502
+ """
1503
+ await self.load_markets()
1504
+ response = await self.v1PrivateGetApiPositionActive(params)
1505
+ #
1506
+ # {
1507
+ # "data": [
1508
+ # {
1509
+ # "positionId": "0192c495-4a68-70ee-9081-9d368bd16dfc",
1510
+ # "symbol": "SOL_USDC",
1511
+ # "positionSide": "SHORT",
1512
+ # "entryPrice": "172.34300000",
1513
+ # "quantity": "0.80",
1514
+ # "marginAmount": "20.11561173",
1515
+ # "marginAsset": "USDC",
1516
+ # "pnl": "0.00000000"
1517
+ # }
1518
+ # ]
1519
+ # }
1520
+ #
1521
+ positions = self.safe_list(response, 'data', [])
1522
+ return self.parse_positions(positions, symbols)
1523
+
1524
+ def parse_position(self, position: dict, market: Market = None):
1525
+ #
1526
+ # {
1527
+ # "positionId": "0192c495-4a68-70ee-9081-9d368bd16dfc",
1528
+ # "symbol": "SOL_USDC",
1529
+ # "positionSide": "SHORT",
1530
+ # "entryPrice": "172.34300000",
1531
+ # "quantity": "0.80",
1532
+ # "marginAmount": "20.11561173",
1533
+ # "marginAsset": "USDC",
1534
+ # "pnl": "0.00000000"
1535
+ # }
1536
+ #
1537
+ marketId = self.safe_string(position, 'symbol')
1538
+ market = self.safe_market(marketId, market)
1539
+ size = Precise.string_abs(self.safe_string(position, 'quantity'))
1540
+ side = self.safe_string_lower(position, 'positionSide')
1541
+ unrealisedPnl = self.omit_zero(self.safe_string(position, 'pnl'))
1542
+ entryPrice = self.omit_zero(self.safe_string(position, 'entryPrice'))
1543
+ initialMargin = self.safe_string(position, 'marginAmount')
1544
+ return self.safe_position({
1545
+ 'info': position,
1546
+ 'id': self.safe_string(position, 'positionId'),
1547
+ 'symbol': market['symbol'],
1548
+ 'timestamp': None,
1549
+ 'datetime': None,
1550
+ 'lastUpdateTimestamp': None,
1551
+ 'initialMargin': self.parse_number(initialMargin),
1552
+ 'initialMarginPercentage': None,
1553
+ 'maintenanceMargin': None,
1554
+ 'maintenanceMarginPercentage': None,
1555
+ 'entryPrice': self.parse_number(entryPrice),
1556
+ 'notional': None,
1557
+ 'leverage': None,
1558
+ 'unrealizedPnl': self.parse_number(unrealisedPnl),
1559
+ 'realizedPnl': None,
1560
+ 'contracts': self.parse_number(size),
1561
+ 'contractSize': self.safe_number(market, 'contractSize'),
1562
+ 'marginRatio': None,
1563
+ 'liquidationPrice': None,
1564
+ 'markPrice': None,
1565
+ 'lastPrice': None,
1566
+ 'collateral': None,
1567
+ 'marginMode': None,
1568
+ 'side': side,
1569
+ 'percentage': None,
1570
+ 'stopLossPrice': None,
1571
+ 'takeProfitPrice': None,
1572
+ 'hedged': None,
1573
+ })
1574
+
1575
+ async def fetch_order(self, id: str, symbol: Str = None, params={}):
1576
+ """
1577
+ fetches information on an order made by the user
1578
+
1579
+ https://api-docs.defx.com/#44f82dd5-26b3-4e1f-b4aa-88ceddd65237
1580
+
1581
+ :param str id: the order id
1582
+ :param str symbol: unified symbol of the market the order was made in
1583
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1584
+ :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
1585
+ """
1586
+ await self.load_markets()
1587
+ request: dict = {
1588
+ 'orderId': id,
1589
+ 'idType': 'orderId',
1590
+ }
1591
+ clientOrderId = self.safe_string_n(params, ['clOrdID', 'clientOrderId', 'client_order_id'])
1592
+ params = self.omit(params, ['clOrdID', 'clientOrderId', 'client_order_id'])
1593
+ if clientOrderId is not None:
1594
+ if symbol is None:
1595
+ raise ArgumentsRequired(self.id + ' fetchOrder() requires a symbol argument')
1596
+ market = self.market(symbol)
1597
+ request['orderId'] = clientOrderId
1598
+ request['idType'] = 'clientOrderId'
1599
+ request['symbol'] = market['id']
1600
+ response = await self.v1PrivateGetApiOrderOrderId(self.extend(request, params))
1601
+ #
1602
+ # {
1603
+ # "success": True,
1604
+ # "data": {
1605
+ # "orderId": "555068654076559792",
1606
+ # "createdAt": "2024-05-08T05:45:42.148Z",
1607
+ # "updatedAt": "2024-05-08T05:45:42.166Z",
1608
+ # "clientOrderId": "dummyClientOrderId",
1609
+ # "reduceOnly": False,
1610
+ # "side": "SELL",
1611
+ # "status": "REJECTED",
1612
+ # "symbol": "BTC_USDC",
1613
+ # "timeInForce": "GTC",
1614
+ # "type": "TAKE_PROFIT_MARKET",
1615
+ # "origQty": "1.000",
1616
+ # "executedQty": "0.000",
1617
+ # "cumulativeQuote": "0.00",
1618
+ # "avgPrice": "0.00",
1619
+ # "stopPrice": "65000.00",
1620
+ # "totalPnL": "0.00",
1621
+ # "workingType": "MARK_PRICE",
1622
+ # "postOnly": False
1623
+ # }
1624
+ # }
1625
+ #
1626
+ data = self.safe_dict(response, 'data')
1627
+ return self.parse_order(data)
1628
+
1629
+ async def fetch_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Order]:
1630
+ """
1631
+ fetches information on multiple orders made by the user
1632
+
1633
+ https://api-docs.defx.com/#ab200038-8acb-4170-b05e-4fcb4cc13751
1634
+
1635
+ :param str symbol: unified market symbol
1636
+ :param int [since]: the earliest time in ms to fetch open orders for
1637
+ :param int [limit]: the maximum number of open order structures to retrieve
1638
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1639
+ :param int [params.until]: the latest time in ms to fetch orders for
1640
+ :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
1641
+ """
1642
+ await self.load_markets()
1643
+ request: dict = {}
1644
+ if symbol is not None:
1645
+ market = self.market(symbol)
1646
+ request['symbols'] = market['id']
1647
+ until = self.safe_integer(params, 'until')
1648
+ if until is not None:
1649
+ params = self.omit(params, 'until')
1650
+ request['end'] = self.iso8601(until)
1651
+ if since is not None:
1652
+ request['start'] = self.iso8601(since)
1653
+ if limit is not None:
1654
+ maxLimit = 100
1655
+ limit = min(maxLimit, limit)
1656
+ request['pageSize'] = limit
1657
+ response = await self.v1PrivateGetApiOrders(self.extend(request, params))
1658
+ #
1659
+ # {
1660
+ # "data": [
1661
+ # {
1662
+ # "orderId": "746472647227344528",
1663
+ # "createdAt": "2024-10-25T16:49:31.077Z",
1664
+ # "updatedAt": "2024-10-25T16:49:31.378Z",
1665
+ # "clientOrderId": "0192c495-49c3-71ee-b3d3-7442a2090807",
1666
+ # "reduceOnly": False,
1667
+ # "side": "SELL",
1668
+ # "status": "FILLED",
1669
+ # "symbol": "SOL_USDC",
1670
+ # "timeInForce": "GTC",
1671
+ # "type": "MARKET",
1672
+ # "origQty": "0.80",
1673
+ # "executedQty": "0.80",
1674
+ # "cumulativeQuote": "137.87440000",
1675
+ # "avgPrice": "172.34300000",
1676
+ # "totalPnL": "0.00000000",
1677
+ # "totalFee": "0.07583092",
1678
+ # "workingType": null,
1679
+ # "postOnly": False,
1680
+ # "linkedOrderParentType": null,
1681
+ # "isTriggered": False,
1682
+ # "slippagePercentage": 5
1683
+ # }
1684
+ # ]
1685
+ # }
1686
+ #
1687
+ data = self.safe_list(response, 'data', [])
1688
+ return self.parse_orders(data, None, since, limit)
1689
+
1690
+ async def fetch_open_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Order]:
1691
+ """
1692
+ fetch all unfilled currently open orders
1693
+
1694
+ https://api-docs.defx.com/#ab200038-8acb-4170-b05e-4fcb4cc13751
1695
+
1696
+ :param str symbol: unified market symbol
1697
+ :param int [since]: the earliest time in ms to fetch open orders for
1698
+ :param int [limit]: the maximum number of open order structures to retrieve
1699
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1700
+ :param int [params.until]: the latest time in ms to fetch orders for
1701
+ :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
1702
+ """
1703
+ req = {
1704
+ 'statuses': 'OPEN',
1705
+ }
1706
+ return await self.fetch_orders(symbol, since, limit, self.extend(req, params))
1707
+
1708
+ async def fetch_closed_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Order]:
1709
+ """
1710
+ fetches information on multiple closed orders made by the user
1711
+
1712
+ https://api-docs.defx.com/#ab200038-8acb-4170-b05e-4fcb4cc13751
1713
+
1714
+ :param str symbol: unified market symbol
1715
+ :param int [since]: the earliest time in ms to fetch open orders for
1716
+ :param int [limit]: the maximum number of open order structures to retrieve
1717
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1718
+ :param int [params.until]: the latest time in ms to fetch orders for
1719
+ :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
1720
+ """
1721
+ req = {
1722
+ 'statuses': 'FILLED',
1723
+ }
1724
+ return await self.fetch_orders(symbol, since, limit, self.extend(req, params))
1725
+
1726
+ async def fetch_canceled_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Order]:
1727
+ """
1728
+ fetches information on multiple canceled orders made by the user
1729
+
1730
+ https://api-docs.defx.com/#ab200038-8acb-4170-b05e-4fcb4cc13751
1731
+
1732
+ :param str symbol: unified market symbol
1733
+ :param int [since]: the earliest time in ms to fetch open orders for
1734
+ :param int [limit]: the maximum number of open order structures to retrieve
1735
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1736
+ :param int [params.until]: the latest time in ms to fetch orders for
1737
+ :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
1738
+ """
1739
+ req = {
1740
+ 'statuses': 'CANCELED',
1741
+ }
1742
+ return await self.fetch_orders(symbol, since, limit, self.extend(req, params))
1743
+
1744
+ async def close_position(self, symbol: str, side: OrderSide = None, params={}) -> Order:
1745
+ """
1746
+ closes an open position for a market
1747
+
1748
+ https://api-docs.defx.com/#b2c08074-c4d9-4e50-b637-0d6c498fa29e
1749
+
1750
+ :param str symbol: unified CCXT market symbol
1751
+ :param str [side]: one-way mode: 'buy' or 'sell', hedge-mode: 'long' or 'short'
1752
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1753
+ :param str [params.positionId]: the position id you want to close
1754
+ :param str [params.type]: 'MARKET' or 'LIMIT'
1755
+ :param str [params.quantity]: how much of currency you want to trade in units of base currency
1756
+ :param str [params.price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
1757
+ :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
1758
+ """
1759
+ await self.load_markets()
1760
+ positionId = self.safe_string(params, 'positionId')
1761
+ if positionId is None:
1762
+ raise ArgumentsRequired(self.id + ' closePosition() requires a positionId')
1763
+ type = self.safe_string_upper(params, 'type')
1764
+ if type is None:
1765
+ raise ArgumentsRequired(self.id + ' closePosition() requires a type')
1766
+ quantity = self.safe_string(params, 'quantity')
1767
+ if quantity is None:
1768
+ raise ArgumentsRequired(self.id + ' closePosition() requires a quantity')
1769
+ request: dict = {
1770
+ 'positionId': positionId,
1771
+ 'type': type,
1772
+ 'quantity': quantity,
1773
+ }
1774
+ if type != 'MARKET':
1775
+ price = self.safe_string(params, 'price')
1776
+ if price is None:
1777
+ raise ArgumentsRequired(self.id + ' closePosition() requires a price')
1778
+ request['price'] = price
1779
+ params = self.omit(params, ['positionId', 'type', 'quantity', 'price'])
1780
+ response = await self.v1PrivateDeleteApiPositionPositionId(self.extend(request, params))
1781
+ #
1782
+ # {}
1783
+ #
1784
+ return response
1785
+
1786
+ async def close_all_positions(self, params={}) -> List[Position]:
1787
+ """
1788
+ closes all open positions for a market type
1789
+
1790
+ https://api-docs.defx.com/#d6f63b43-100e-47a9-998c-8b6c0c72d204
1791
+
1792
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1793
+ :returns dict[]: A list of `position structures <https://docs.ccxt.com/#/?id=position-structure>`
1794
+ """
1795
+ await self.load_markets()
1796
+ response = await self.v1PrivateDeleteApiPositionAll(params)
1797
+ #
1798
+ # {
1799
+ # "data": [
1800
+ # {
1801
+ # "positionId": "d6ca1a27-28ad-47ae-b244-0bda5ac37b2b",
1802
+ # "success": True
1803
+ # }
1804
+ # ]
1805
+ # }
1806
+ #
1807
+ data = self.safe_list(response, 'data', [])
1808
+ return self.parse_positions(data, None, params)
1809
+
1810
+ async def fetch_ledger(self, code: Str = None, since: Int = None, limit: Int = None, params={}) -> List[LedgerEntry]:
1811
+ """
1812
+ fetch the history of changes, actions done by the user or operations that altered the balance of the user
1813
+
1814
+ https://api-docs.defx.com/#38cc8974-794f-48c0-b959-db045a0ee565
1815
+
1816
+ :param str [code]: unified currency code
1817
+ :param int [since]: timestamp in ms of the earliest ledger entry
1818
+ :param int [limit]: max number of ledger entries to return
1819
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1820
+ :param int [params.until]: timestamp in ms of the latest ledger entry
1821
+ :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)
1822
+ :returns dict: a `ledger structure <https://docs.ccxt.com/#/?id=ledger>`
1823
+ """
1824
+ await self.load_markets()
1825
+ paginate = False
1826
+ paginate, params = self.handle_option_and_params(params, 'fetchLedger', 'paginate')
1827
+ if paginate:
1828
+ return await self.fetch_paginated_call_dynamic('fetchLedger', code, since, limit, params)
1829
+ request: dict = {}
1830
+ if since is not None:
1831
+ request['start'] = since
1832
+ else:
1833
+ request['start'] = 0
1834
+ until = self.safe_integer(params, 'until')
1835
+ if until is not None:
1836
+ params = self.omit(params, 'until')
1837
+ request['end'] = until
1838
+ else:
1839
+ request['end'] = self.milliseconds()
1840
+ response = await self.v1PrivateGetApiWalletTransactions(self.extend(request, params))
1841
+ data = self.safe_list(response, 'transactions', [])
1842
+ return self.parse_ledger(data, None, since, limit)
1843
+
1844
+ def parse_ledger_entry(self, item: dict, currency: Currency = None) -> LedgerEntry:
1845
+ #
1846
+ # {
1847
+ # "id": "01JCSZS6H5VQND3GF5P98SJ29C",
1848
+ # "timestamp": 1731744012054,
1849
+ # "type": "FundingFee",
1850
+ # "amount": "0.02189287",
1851
+ # "asset": "USDC",
1852
+ # "operation": "CREDIT"
1853
+ # }
1854
+ #
1855
+ amount = self.safe_string(item, 'amount')
1856
+ currencyId = self.safe_string(item, 'asset')
1857
+ code = self.safe_currency_code(currencyId, currency)
1858
+ currency = self.safe_currency(currencyId, currency)
1859
+ timestamp = self.safe_integer(item, 'timestamp')
1860
+ type = self.safe_string(item, 'type')
1861
+ return self.safe_ledger_entry({
1862
+ 'info': item,
1863
+ 'id': self.safe_string(item, 'id'),
1864
+ 'direction': None,
1865
+ 'account': None,
1866
+ 'referenceAccount': None,
1867
+ 'referenceId': None,
1868
+ 'type': self.parse_ledger_entry_type(type),
1869
+ 'currency': code,
1870
+ 'amount': self.parse_number(amount),
1871
+ 'timestamp': timestamp,
1872
+ 'datetime': self.iso8601(timestamp),
1873
+ 'before': None,
1874
+ 'after': None,
1875
+ 'status': None,
1876
+ 'fee': None,
1877
+ }, currency)
1878
+
1879
+ def parse_ledger_entry_type(self, type):
1880
+ ledgerType: dict = {
1881
+ 'FundingFee': 'fee',
1882
+ 'FeeRebate': 'fee',
1883
+ 'FeeKickback': 'fee',
1884
+ 'RealizedPnl': 'trade',
1885
+ 'LiquidationClearance': 'trade',
1886
+ 'Transfer': 'transfer',
1887
+ 'ReferralPayout': 'referral',
1888
+ 'Commission': 'commission',
1889
+ }
1890
+ return self.safe_string(ledgerType, type, type)
1891
+
1892
+ async def withdraw(self, code: str, amount: float, address: str, tag=None, params={}):
1893
+ """
1894
+ make a withdrawal
1895
+
1896
+ https://api-docs.defx.com/#2600f503-63ed-4672-b8f6-69ea5f03203b
1897
+
1898
+ :param str code: unified currency code
1899
+ :param float amount: the amount to withdraw
1900
+ :param str address: the address to withdraw to
1901
+ :param str tag:
1902
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1903
+ :returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
1904
+ """
1905
+ await self.load_markets()
1906
+ currency = self.currency(code)
1907
+ request: dict = {
1908
+ 'amount': self.currency_to_precision(code, amount),
1909
+ 'asset': currency['id'],
1910
+ # 'network': 'ARB_SEPOLIA',
1911
+ # 'chainId': '421614',
1912
+ }
1913
+ response = await self.v1PrivatePostApiTransfersBridgeWithdrawal(self.extend(request, params))
1914
+ #
1915
+ # {
1916
+ # "transactionId": "0x301e5851e5aefa733abfbc8b30817ca3b61601e0ddf1df8c59656fb888b0bc9c"
1917
+ # }
1918
+ #
1919
+ return self.parse_transaction(response, currency)
1920
+
1921
+ def parse_transaction(self, transaction: dict, currency: Currency = None) -> Transaction:
1922
+ #
1923
+ # withdraw
1924
+ #
1925
+ # {
1926
+ # "transactionId": "0x301e5851e5aefa733abfbc8b30817ca3b61601e0ddf1df8c59656fb888b0bc9c"
1927
+ # }
1928
+ #
1929
+ txid = self.safe_string(transaction, 'transactionId')
1930
+ return {
1931
+ 'info': transaction,
1932
+ 'id': None,
1933
+ 'txid': txid,
1934
+ 'timestamp': None,
1935
+ 'datetime': None,
1936
+ 'network': None,
1937
+ 'address': None,
1938
+ 'addressTo': None,
1939
+ 'addressFrom': None,
1940
+ 'tag': None,
1941
+ 'tagTo': None,
1942
+ 'tagFrom': None,
1943
+ 'type': None,
1944
+ 'amount': None,
1945
+ 'currency': self.safe_currency_code(None, currency),
1946
+ 'status': None,
1947
+ 'updated': None,
1948
+ 'internal': None,
1949
+ 'comment': None,
1950
+ 'fee': None,
1951
+ }
1952
+
1953
+ async def set_leverage(self, leverage: Int, symbol: Str = None, params={}):
1954
+ """
1955
+ set the level of leverage for a market
1956
+
1957
+ https://api-docs.defx.com/#4cb4ecc4-6c61-4194-8353-be67faaf7ca7
1958
+
1959
+ :param float leverage: the rate of leverage
1960
+ :param str symbol: unified market symbol
1961
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1962
+ :returns dict: response from the exchange
1963
+ """
1964
+ if symbol is None:
1965
+ raise ArgumentsRequired(self.id + ' setLeverage() requires a symbol argument')
1966
+ await self.load_markets()
1967
+ request: dict = {
1968
+ 'leverage': self.number_to_string(leverage),
1969
+ }
1970
+ market = self.market(symbol)
1971
+ request['symbol'] = market['id']
1972
+ response = await self.v1PrivatePostApiUsersMetadataLeverage(self.extend(request, params))
1973
+ #
1974
+ # {
1975
+ # "success": True,
1976
+ # "data": {
1977
+ # "leverage": "11",
1978
+ # "symbol": "BTC_USDC"
1979
+ # }
1980
+ # }
1981
+ #
1982
+ data = self.safe_dict(response, 'data', {})
1983
+ return self.parse_leverage(data, market)
1984
+
1985
+ def parse_leverage(self, leverage: dict, market: Market = None) -> Leverage:
1986
+ #
1987
+ # "data": {
1988
+ # "leverage": "11",
1989
+ # "symbol": "BTC_USDC"
1990
+ # }
1991
+ #
1992
+ marketId = self.safe_string(leverage, 'symbol')
1993
+ leverageValue = self.safe_integer(leverage, 'leverage')
1994
+ return {
1995
+ 'info': leverage,
1996
+ 'symbol': self.safe_symbol(marketId, market),
1997
+ 'marginMode': None,
1998
+ 'longLeverage': leverageValue,
1999
+ 'shortLeverage': leverageValue,
2000
+ }
2001
+
2002
+ def nonce(self):
2003
+ return self.milliseconds()
2004
+
2005
+ def sign(self, path, section='public', method='GET', params={}, headers=None, body=None):
2006
+ version = section[0]
2007
+ access = section[1]
2008
+ pathWithParams = self.implode_params(path, params)
2009
+ url = self.implode_hostname(self.urls['api'][access])
2010
+ url += '/' + version + '/'
2011
+ params = self.omit(params, self.extract_params(path))
2012
+ params = self.keysort(params)
2013
+ if access == 'public':
2014
+ url += 'open/' + pathWithParams
2015
+ if params:
2016
+ url += '?' + self.rawencode(params)
2017
+ else:
2018
+ self.check_required_credentials()
2019
+ headers = {'X-DEFX-SOURCE': 'ccxt'}
2020
+ url += 'auth/' + pathWithParams
2021
+ nonce = str(self.milliseconds())
2022
+ payload = nonce
2023
+ if method == 'GET' or path == 'api/order/{orderId}':
2024
+ payload += self.rawencode(params)
2025
+ if params:
2026
+ url += '?' + self.rawencode(params)
2027
+ else:
2028
+ if params is not None:
2029
+ body = self.json(params)
2030
+ payload += body
2031
+ headers['Content-Type'] = 'application/json'
2032
+ signature = self.hmac(self.encode(payload), self.encode(self.secret), hashlib.sha256)
2033
+ headers['X-DEFX-APIKEY'] = self.apiKey
2034
+ headers['X-DEFX-TIMESTAMP'] = nonce
2035
+ headers['X-DEFX-SIGNATURE'] = signature
2036
+ return {'url': url, 'method': method, 'body': body, 'headers': headers}
2037
+
2038
+ def handle_errors(self, httpCode: int, reason: str, url: str, method: str, headers: dict, body: str, response, requestHeaders, requestBody):
2039
+ if not response:
2040
+ return None # fallback to default error handler
2041
+ # {"errorCode":404,"errorMessage":"Not Found"}
2042
+ # {"msg":"Missing auth signature","code":"missing_auth_signature"}
2043
+ # {"success":false,"err":{"msg":"Invalid order id","code":"invalid_order_id"}}
2044
+ success = self.safe_bool(response, 'success')
2045
+ err = self.safe_dict(response, 'err', response)
2046
+ errorCode = self.safe_string_2(err, 'errorCode', 'code')
2047
+ if not success:
2048
+ feedback = self.id + ' ' + self.json(response)
2049
+ self.throw_broadly_matched_exception(self.exceptions['broad'], body, feedback)
2050
+ self.throw_exactly_matched_exception(self.exceptions['exact'], errorCode, feedback)
2051
+ return None
2052
+
2053
+ def default_network_code_for_currency(self, code):
2054
+ currencyItem = self.currency(code)
2055
+ networks = currencyItem['networks']
2056
+ networkKeys = list(networks.keys())
2057
+ for i in range(0, len(networkKeys)):
2058
+ network = networkKeys[i]
2059
+ if network == 'ETH':
2060
+ return network
2061
+ # if it was not returned according to above options, then return the first network of currency
2062
+ return self.safe_value(networkKeys, 0)
2063
+
2064
+ def set_sandbox_mode(self, enable: bool):
2065
+ super(defx, self).set_sandbox_mode(enable)
2066
+ self.options['sandboxMode'] = enable