ccxt-ir 4.3.46.0.3__py2.py3-none-any.whl → 4.5.1__py2.py3-none-any.whl

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