ccxt-ir 4.3.46.0.3__py2.py3-none-any.whl → 4.5.0__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 +7 -7
  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 +9 -9
  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 +31 -37
  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 +25 -24
  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 +30 -27
  183. ccxt/async_support/sarmayex.py +9 -9
  184. ccxt/async_support/sarrafex.py +13 -13
  185. ccxt/async_support/tabdeal.py +14 -13
  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 +29 -35
  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 +22 -21
  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 +28 -25
  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 +12 -11
  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.0.dist-info}/METADATA +225 -73
  435. ccxt_ir-4.5.0.dist-info/RECORD +743 -0
  436. {ccxt_ir-4.3.46.0.3.dist-info → ccxt_ir-4.5.0.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.0.dist-info/licenses}/LICENSE.txt +0 -0
  529. {ccxt_ir-4.3.46.0.3.dist-info → ccxt_ir-4.5.0.dist-info}/top_level.txt +0 -0
@@ -1,1717 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- # PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
4
- # https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
5
-
6
- from ccxt.async_support.base.exchange import Exchange
7
- from ccxt.abstract.poloniexfutures import ImplicitAPI
8
- import hashlib
9
- from ccxt.base.types import Balances, Int, Market, Num, Order, OrderBook, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade
10
- from typing import List
11
- from ccxt.base.errors import AuthenticationError
12
- from ccxt.base.errors import AccountSuspended
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 OrderNotFound
17
- from ccxt.base.errors import NotSupported
18
- from ccxt.base.errors import RateLimitExceeded
19
- from ccxt.base.errors import ExchangeNotAvailable
20
- from ccxt.base.errors import InvalidNonce
21
- from ccxt.base.decimal_to_precision import TICK_SIZE
22
- from ccxt.base.precise import Precise
23
-
24
-
25
- class poloniexfutures(Exchange, ImplicitAPI):
26
-
27
- def describe(self):
28
- return self.deep_extend(super(poloniexfutures, self).describe(), {
29
- 'id': 'poloniexfutures',
30
- 'name': 'Poloniex Futures',
31
- 'countries': ['US'],
32
- # 30 requests per second
33
- 'rateLimit': 33.3,
34
- 'certified': False,
35
- 'pro': True,
36
- 'version': 'v1',
37
- 'has': {
38
- 'CORS': None,
39
- 'spot': False,
40
- 'margin': True,
41
- 'swap': True,
42
- 'future': False,
43
- 'option': None,
44
- 'createOrder': True,
45
- 'fetchBalance': True,
46
- 'fetchClosedOrders': True,
47
- 'fetchCurrencies': False,
48
- 'fetchDepositAddress': False,
49
- 'fetchDepositAddresses': False,
50
- 'fetchDepositAddressesByNetwork': False,
51
- 'fetchFundingRate': True,
52
- 'fetchFundingRateHistory': False,
53
- 'fetchL3OrderBook': True,
54
- 'fetchMarkets': True,
55
- 'fetchMyTrades': True,
56
- 'fetchOHLCV': True,
57
- 'fetchOpenOrders': True,
58
- 'fetchOrder': True,
59
- 'fetchOrderBook': True,
60
- 'fetchOrdersByStatus': True,
61
- 'fetchPositions': True,
62
- 'fetchTicker': True,
63
- 'fetchTickers': True,
64
- 'fetchTime': True,
65
- 'fetchTrades': True,
66
- 'setMarginMode': True,
67
- },
68
- 'timeframes': {
69
- '1m': 1,
70
- '5m': 5,
71
- '15m': 15,
72
- '30m': 30,
73
- '1h': 60,
74
- '2h': 120,
75
- '4h': 480,
76
- '12h': 720,
77
- '1d': 1440,
78
- '1w': 10080,
79
- },
80
- 'urls': {
81
- 'logo': 'https://user-images.githubusercontent.com/1294454/27766817-e9456312-5ee6-11e7-9b3c-b628ca5626a5.jpg',
82
- 'api': {
83
- 'public': 'https://futures-api.poloniex.com',
84
- 'private': 'https://futures-api.poloniex.com',
85
- },
86
- 'www': 'https://www.poloniex.com',
87
- 'doc': 'https://futures-docs.poloniex.com',
88
- 'fees': 'https://poloniex.com/fee-schedule',
89
- 'referral': 'https://poloniex.com/signup?c=UBFZJRPJ',
90
- },
91
- 'api': {
92
- 'public': {
93
- 'get': {
94
- 'contracts/active': 10,
95
- 'contracts/{symbol}': 10,
96
- 'ticker': 10,
97
- 'tickers': 10, # v2
98
- 'level2/snapshot': 180.002,
99
- 'level2/depth': 180.002,
100
- 'level2/message/query': 180.002,
101
- 'level3/snapshot': 180.002, # v2
102
- 'trade/history': 10,
103
- 'interest/query': 10,
104
- 'index/query': 10,
105
- 'mark-price/{symbol}/current': 10,
106
- 'premium/query': 10,
107
- 'funding-rate/{symbol}/current': 10,
108
- 'timestamp': 10,
109
- 'status': 10,
110
- 'kline/query': 10,
111
- },
112
- 'post': {
113
- 'bullet-public': 10,
114
- },
115
- },
116
- 'private': {
117
- 'get': {
118
- 'account-overview': 1,
119
- 'transaction-history': 1,
120
- 'maxActiveOrders': 1,
121
- 'maxRiskLimit': 1,
122
- 'userFeeRate': 1,
123
- 'marginType/query': 1,
124
- 'orders': 1,
125
- 'stopOrders': 1,
126
- 'recentDoneOrders': 1,
127
- 'orders/{order-id}': 1,
128
- 'clientOrderId/{clientOid}': 1,
129
- 'fills': 1,
130
- 'openOrderStatistics': 1,
131
- 'position': 1.5,
132
- 'positions': 1.5,
133
- 'funding-history': 1,
134
- },
135
- 'post': {
136
- 'orders': 1.5,
137
- 'batchOrders': 1.5,
138
- 'position/margin/auto-deposit-status': 1.5,
139
- 'position/margin/deposit-margin': 1.5,
140
- 'position/margin/withdraw-margin': 1.5,
141
- 'bullet-private': 1,
142
- 'marginType/change': 1,
143
- },
144
- 'delete': {
145
- 'orders/{order-id}': 1.5,
146
- 'orders': 150.016,
147
- 'stopOrders': 150.016,
148
- },
149
- },
150
- },
151
- 'precisionMode': TICK_SIZE,
152
- 'fees': {
153
- 'trading': {
154
- 'tierBased': False,
155
- 'percentage': True,
156
- 'taker': self.parse_number('0.00075'),
157
- 'maker': self.parse_number('0.0001'),
158
- },
159
- 'funding': {
160
- 'tierBased': False,
161
- 'percentage': False,
162
- 'withdraw': {},
163
- 'deposit': {},
164
- },
165
- },
166
- 'commonCurrencies': {
167
- },
168
- 'requiredCredentials': {
169
- 'apiKey': True,
170
- 'secret': True,
171
- 'password': True,
172
- },
173
- 'options': {
174
- 'networks': {
175
- 'OMNI': 'omni',
176
- 'ERC20': 'eth',
177
- 'TRC20': 'trx',
178
- },
179
- 'versions': {
180
- 'public': {
181
- 'GET': {
182
- 'ticker': 'v2',
183
- 'tickers': 'v2',
184
- 'level3/snapshot': 'v2',
185
- },
186
- },
187
- },
188
- },
189
- 'exceptions': {
190
- 'exact': {
191
- '400': BadRequest, # Bad Request -- Invalid request format
192
- '401': AuthenticationError, # Unauthorized -- Invalid API Key
193
- '403': NotSupported, # Forbidden -- The request is forbidden
194
- '404': NotSupported, # Not Found -- The specified resource could not be found
195
- '405': NotSupported, # Method Not Allowed -- You tried to access the resource with an invalid method.
196
- '415': BadRequest, # Content-Type -- application/json
197
- '429': RateLimitExceeded, # Too Many Requests -- Access limit breached
198
- '500': ExchangeNotAvailable, # Internal Server Error -- We had a problem with our server. Try again later.
199
- '503': ExchangeNotAvailable, # Service Unavailable -- We're temporarily offline for maintenance. Please try again later.
200
- '400001': AuthenticationError, # Any of KC-API-KEY, KC-API-SIGN, KC-API-TIMESTAMP, KC-API-PASSPHRASE is missing in your request header.
201
- '400002': InvalidNonce, # KC-API-TIMESTAMP Invalid -- Time differs from server time by more than 5 seconds
202
- '400003': AuthenticationError, # KC-API-KEY not exists
203
- '400004': AuthenticationError, # KC-API-PASSPHRASE error
204
- '400005': AuthenticationError, # Signature error -- Please check your signature
205
- '400006': AuthenticationError, # The IP address is not in the API whitelist
206
- '400007': AuthenticationError, # Access Denied -- Your API key does not have sufficient permissions to access the URI
207
- '404000': NotSupported, # URL Not Found -- The requested resource could not be found
208
- '400100': BadRequest, # Parameter Error -- You tried to access the resource with invalid parameters
209
- '411100': AccountSuspended, # User is frozen -- Please contact us via support center
210
- '500000': ExchangeNotAvailable, # Internal Server Error -- We had a problem with our server. Try again later.
211
- },
212
- 'broad': {
213
- 'Position does not exist': OrderNotFound, # {"code":"200000", "msg":"Position does not exist"}
214
- },
215
- },
216
- })
217
-
218
- async def fetch_markets(self, params={}) -> List[Market]:
219
- """
220
- retrieves data on all markets for poloniexfutures
221
- :see: https://futures-docs.poloniex.com/#symbol-2
222
- :param dict [params]: extra parameters specific to the exchange API endpoint
223
- :returns dict[]: an array of objects representing market data
224
- """
225
- response = await self.publicGetContractsActive(params)
226
- #
227
- # {
228
- # "code": "200000",
229
- # "data": [
230
- # {
231
- # "symbol": "APTUSDTPERP",
232
- # "takerFixFee": "0E-10",
233
- # "nextFundingRateTime": "20145603",
234
- # "makerFixFee": "0E-10",
235
- # "type": "FFWCSX",
236
- # "predictedFundingFeeRate": "0.000000",
237
- # "turnoverOf24h": "386037.46704292",
238
- # "initialMargin": "0.05",
239
- # "isDeleverage": True,
240
- # "createdAt": "1666681959000",
241
- # "fundingBaseSymbol": ".APTINT8H",
242
- # "lowPriceOf24h": "4.34499979019165",
243
- # "lastTradePrice": "4.4090000000",
244
- # "indexPriceTickSize": "0.001",
245
- # "fairMethod": "FundingRate",
246
- # "takerFeeRate": "0.00040",
247
- # "order": "102",
248
- # "updatedAt": "1671076377000",
249
- # "displaySettleCurrency": "USDT",
250
- # "indexPrice": "4.418",
251
- # "multiplier": "1.0",
252
- # "maxLeverage": "20",
253
- # "fundingQuoteSymbol": ".USDTINT8H",
254
- # "quoteCurrency": "USDT",
255
- # "maxOrderQty": "1000000",
256
- # "maxPrice": "1000000.0000000000",
257
- # "maintainMargin": "0.025",
258
- # "status": "Open",
259
- # "displayNameMap": [Object],
260
- # "openInterest": "2367",
261
- # "highPriceOf24h": "4.763999938964844",
262
- # "fundingFeeRate": "0.000000",
263
- # "volumeOf24h": "83540.00000000",
264
- # "riskStep": "500000",
265
- # "isQuanto": True,
266
- # "maxRiskLimit": "20000",
267
- # "rootSymbol": "USDT",
268
- # "baseCurrency": "APT",
269
- # "firstOpenDate": "1666701000000",
270
- # "tickSize": "0.001",
271
- # "markMethod": "FairPrice",
272
- # "indexSymbol": ".PAPTUSDT",
273
- # "markPrice": "4.418",
274
- # "minRiskLimit": "1000000",
275
- # "settlementFixFee": "0E-10",
276
- # "settlementSymbol": '',
277
- # "priceChgPctOf24h": "-0.0704",
278
- # "fundingRateSymbol": ".APTUSDTPERPFPI8H",
279
- # "makerFeeRate": "0.00010",
280
- # "isInverse": False,
281
- # "lotSize": "1",
282
- # "settleCurrency": "USDT",
283
- # "settlementFeeRate": "0.0"
284
- # },
285
- # ]
286
- # }
287
- #
288
- data = self.safe_value(response, 'data', [])
289
- return self.parse_markets(data)
290
-
291
- def parse_market(self, market: dict) -> Market:
292
- id = self.safe_string(market, 'symbol')
293
- baseId = self.safe_string(market, 'baseCurrency')
294
- quoteId = self.safe_string(market, 'quoteCurrency')
295
- settleId = self.safe_string(market, 'rootSymbol')
296
- base = self.safe_currency_code(baseId)
297
- quote = self.safe_currency_code(quoteId)
298
- settle = self.safe_currency_code(settleId)
299
- symbol = base + '/' + quote + ':' + settle
300
- inverse = self.safe_value(market, 'isInverse')
301
- status = self.safe_string(market, 'status')
302
- multiplier = self.safe_string(market, 'multiplier')
303
- tickSize = self.safe_number(market, 'indexPriceTickSize')
304
- lotSize = self.safe_number(market, 'lotSize')
305
- limitAmountMax = self.safe_number(market, 'maxOrderQty')
306
- limitPriceMax = self.safe_number(market, 'maxPrice')
307
- return {
308
- 'id': id,
309
- 'symbol': symbol,
310
- 'base': base,
311
- 'quote': quote,
312
- 'settle': settle,
313
- 'baseId': baseId,
314
- 'quoteId': quoteId,
315
- 'settleId': settleId,
316
- 'type': 'swap',
317
- 'spot': False,
318
- 'margin': False,
319
- 'swap': True,
320
- 'future': False,
321
- 'option': False,
322
- 'active': (status == 'Open'),
323
- 'contract': True,
324
- 'linear': not inverse,
325
- 'inverse': inverse,
326
- 'taker': self.safe_number(market, 'takerFeeRate'),
327
- 'maker': self.safe_number(market, 'makerFeeRate'),
328
- 'contractSize': self.parse_number(Precise.string_abs(multiplier)),
329
- 'expiry': None,
330
- 'expiryDatetime': None,
331
- 'strike': None,
332
- 'optionType': None,
333
- 'precision': {
334
- 'amount': lotSize,
335
- 'price': tickSize,
336
- },
337
- 'limits': {
338
- 'leverage': {
339
- 'min': self.parse_number('1'),
340
- 'max': self.safe_number(market, 'maxLeverage'),
341
- },
342
- 'amount': {
343
- 'min': lotSize,
344
- 'max': limitAmountMax,
345
- },
346
- 'price': {
347
- 'min': tickSize,
348
- 'max': limitPriceMax,
349
- },
350
- 'cost': {
351
- 'min': None,
352
- 'max': None,
353
- },
354
- },
355
- 'created': self.safe_integer(market, 'firstOpenDate'),
356
- 'info': market,
357
- }
358
-
359
- def parse_ticker(self, ticker: dict, market: Market = None) -> Ticker:
360
- #
361
- # {
362
- # "symbol": "BTCUSDTPERP", # Market of the symbol
363
- # "sequence": 45, # Sequence number which is used to judge the continuity of the pushed messages
364
- # "side": "sell", # Transaction side of the last traded taker order
365
- # "price": 3600.00, # Filled price
366
- # "size": 16, # Filled quantity
367
- # "tradeId": "5c9dcf4170744d6f5a3d32fb", # Order ID
368
- # "bestBidSize": 795, # Best bid size
369
- # "bestBidPrice": 3200.00, # Best bid
370
- # "bestAskPrice": 3600.00, # Best ask size
371
- # "bestAskSize": 284, # Best ask
372
- # "ts": 1553846081210004941 # Filled time - nanosecond
373
- # }
374
- #
375
- # {
376
- # "volume": 30449670, #24h Volume
377
- # "turnover": 845169919063, #24h Turnover
378
- # "lastPrice": 3551, #Last price
379
- # "priceChgPct": 0.0043, #24h Change
380
- # "ts": 1547697294838004923 #Snapshot time(nanosecond)
381
- # }
382
- #
383
- marketId = self.safe_string(ticker, 'symbol')
384
- symbol = self.safe_symbol(marketId, market)
385
- timestampString = self.safe_string(ticker, 'ts')
386
- multiplier = None
387
- if len(timestampString) == 16:
388
- # 16 digits: https://app.travis-ci.com/github/ccxt/ccxt/builds/270587157#L5454
389
- multiplier = 0.001
390
- elif len(timestampString) == 17:
391
- # 17 digits: https://app.travis-ci.com/github/ccxt/ccxt/builds/269959181#L4011
392
- multiplier = 0.0001
393
- elif len(timestampString) == 18:
394
- multiplier = 0.00001
395
- else:
396
- # 19 length default
397
- multiplier = 0.000001
398
- timestamp = self.safe_integer_product(ticker, 'ts', multiplier)
399
- last = self.safe_string_2(ticker, 'price', 'lastPrice')
400
- percentage = Precise.string_mul(self.safe_string(ticker, 'priceChgPct'), '100')
401
- return self.safe_ticker({
402
- 'symbol': symbol,
403
- 'timestamp': timestamp,
404
- 'datetime': self.iso8601(timestamp),
405
- 'high': None,
406
- 'low': None,
407
- 'bid': self.safe_string(ticker, 'bestBidPrice'),
408
- 'bidVolume': self.safe_string(ticker, 'bestBidSize'),
409
- 'ask': self.safe_string(ticker, 'bestAskPrice'),
410
- 'askVolume': self.safe_string(ticker, 'bestAskSize'),
411
- 'vwap': None,
412
- 'open': None,
413
- 'close': last,
414
- 'last': last,
415
- 'previousClose': None,
416
- 'change': None,
417
- 'percentage': percentage,
418
- 'average': None,
419
- 'baseVolume': self.safe_string_2(ticker, 'size', 'volume'),
420
- 'quoteVolume': self.safe_string(ticker, 'turnover'),
421
- 'info': ticker,
422
- }, market)
423
-
424
- async def fetch_ticker(self, symbol: str, params={}) -> Ticker:
425
- """
426
- fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
427
- :see: https://futures-docs.poloniex.com/#get-real-time-ticker-2-0
428
- :param str symbol: unified symbol of the market to fetch the ticker for
429
- :param dict [params]: extra parameters specific to the exchange API endpoint
430
- :returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
431
- """
432
- await self.load_markets()
433
- market = self.market(symbol)
434
- request: dict = {
435
- 'symbol': market['id'],
436
- }
437
- response = await self.publicGetTicker(self.extend(request, params))
438
- #
439
- # {
440
- # "code": "200000",
441
- # "data": {
442
- # "sequence": "11574719",
443
- # "symbol": "BTCUSDTPERP",
444
- # "side": "sell",
445
- # "size": "1",
446
- # "price": "16990.1",
447
- # "bestBidSize": "3",
448
- # "bestBidPrice": "16990.1",
449
- # "bestAskPrice": "16991.0",
450
- # "tradeId": "639c8a529fd7cf0001af4157",
451
- # "bestAskSize": "505",
452
- # "ts": "1671203410721232337"
453
- # }
454
- # }
455
- #
456
- return self.parse_ticker(self.safe_value(response, 'data', {}), market)
457
-
458
- async def fetch_tickers(self, symbols: Strings = None, params={}) -> Tickers:
459
- """
460
- fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
461
- :see: https://futures-docs.poloniex.com/#get-real-time-ticker-of-all-symbols
462
- :param str[]|None symbols: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
463
- :param dict [params]: extra parameters specific to the exchange API endpoint
464
- :returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
465
- """
466
- await self.load_markets()
467
- response = await self.publicGetTickers(params)
468
- data = self.safe_list(response, 'data', [])
469
- return self.parse_tickers(data, symbols)
470
-
471
- async def fetch_order_book(self, symbol: str, limit: Int = None, params={}) -> OrderBook:
472
- """
473
- fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
474
- :see: https://futures-docs.poloniex.com/#get-full-order-book-level-2
475
- :see: https://futures-docs.poloniex.com/#get-full-order-book-level-3
476
- :param str symbol: unified symbol of the market to fetch the order book for
477
- :param int [limit]: the maximum amount of order book entries to return
478
- :param dict [params]: extra parameters specific to the exchange API endpoint
479
- :returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
480
- """
481
- await self.load_markets()
482
- level = self.safe_number(params, 'level')
483
- params = self.omit(params, 'level')
484
- if level is not None and level != 2 and level != 3:
485
- raise BadRequest(self.id + ' fetchOrderBook() can only return level 2 & 3')
486
- market = self.market(symbol)
487
- request: dict = {
488
- 'symbol': market['id'],
489
- }
490
- response = None
491
- if level == 3:
492
- response = await self.publicGetLevel3Snapshot(self.extend(request, params))
493
- else:
494
- response = await self.publicGetLevel2Snapshot(self.extend(request, params))
495
- # L2
496
- #
497
- # {
498
- # "code": "200000",
499
- # "data": {
500
- # "symbol": "BTCUSDTPERP",
501
- # "sequence": 1669149851334,
502
- # "asks": [
503
- # [
504
- # 16952,
505
- # 12
506
- # ],
507
- # ],
508
- # "bids": [
509
- # [
510
- # 16951.9,
511
- # 13
512
- # ],
513
- # ],
514
- # }
515
- #
516
- # L3
517
- #
518
- # {
519
- # "code": "200000",
520
- # "data": {
521
- # "symbol": "BTCUSDTPERP",
522
- # "sequence": 1669149851334,
523
- # "asks": [
524
- # [
525
- # "639c95388cba5100084eabce",
526
- # "16952.0",
527
- # "1",
528
- # 1671206200542484700
529
- # ],
530
- # ],
531
- # "bids": [
532
- # [
533
- # "626659d83385c200072e690b",
534
- # "17.0",
535
- # "1000",
536
- # 1650874840161291000
537
- # ],
538
- # ],
539
- # }
540
- #
541
- data = self.safe_value(response, 'data', {})
542
- timestamp = self.safe_integer_product(data, 'ts', 0.000001)
543
- orderbook = None
544
- if level == 3:
545
- orderbook = self.parse_order_book(data, market['symbol'], timestamp, 'bids', 'asks', 1, 2)
546
- else:
547
- orderbook = self.parse_order_book(data, market['symbol'], timestamp, 'bids', 'asks', 0, 1)
548
- orderbook['nonce'] = self.safe_integer(data, 'sequence')
549
- return orderbook
550
-
551
- async def fetch_l3_order_book(self, symbol: str, limit: Int = None, params={}):
552
- """
553
- fetches level 3 information on open orders with bid(buy) and ask(sell) prices, volumes and other data
554
- :see: https://futures-docs.poloniex.com/#get-full-order-book-level-3
555
- :param str symbol: unified market symbol
556
- :param int [limit]: max number of orders to return, default is None
557
- :param dict [params]: extra parameters specific to the exchange API endpoint
558
- :returns dict: an `order book structure <https://docs.ccxt.com/#/?id=order-book-structure>`
559
- """
560
- await self.load_markets()
561
- market = self.market(symbol)
562
- return self.fetch_order_book(market['id'], None, {'level': 3})
563
-
564
- def parse_trade(self, trade: dict, market: Market = None) -> Trade:
565
- #
566
- # fetchTrades(public)
567
- #
568
- # {
569
- # "sequence": 11827985,
570
- # "side": "buy",
571
- # "size": 101,
572
- # "price": "16864.0000000000",
573
- # "takerOrderId": "639c986f0ac2470007be75ee",
574
- # "makerOrderId": "639c986fa69d280007b76111",
575
- # "tradeId": "639c986f9fd7cf0001afd7ee",
576
- # "ts": 1671207023485924400
577
- # }
578
- #
579
- # fetchMyTrades
580
- #
581
- # {
582
- # "symbol": "BTCUSDTPERP", #Ticker symbol of the contract
583
- # "tradeId": "5ce24c1f0c19fc3c58edc47c", #Trade ID
584
- # "orderId": "5ce24c16b210233c36ee321d", # Order ID
585
- # "side": "sell", #Transaction side
586
- # "liquidity": "taker", #Liquidity- taker or maker
587
- # "price": "8302", #Filled price
588
- # "size": 10, #Filled amount
589
- # "value": "0.001204529", #Order value
590
- # "feeRate": "0.0005", #Floating fees
591
- # "fixFee": "0.00000006", #Fixed fees
592
- # "feeCurrency": "XBT", #Charging currency
593
- # "stop": "", #A mark to the stop order type
594
- # "fee": "0.0000012022", #Transaction fee
595
- # "orderType": "limit", #Order type
596
- # "tradeType": "trade", #Trade type(trade, liquidation, ADL or settlement)
597
- # "createdAt": 1558334496000, #Time the order created
598
- # "settleCurrency": "XBT", #settlement currency
599
- # "tradeTime": 1558334496000000000 #trade time in nanosecond
600
- # }
601
- #
602
- marketId = self.safe_string(trade, 'symbol')
603
- market = self.safe_market(marketId, market, '-')
604
- id = self.safe_string(trade, 'tradeId')
605
- orderId = self.safe_string(trade, 'orderId')
606
- takerOrMaker = self.safe_string(trade, 'liquidity')
607
- timestamp = self.safe_integer(trade, 'ts')
608
- if timestamp is not None:
609
- timestamp = self.parse_to_int(timestamp / 1000000)
610
- else:
611
- timestamp = self.safe_integer(trade, 'createdAt')
612
- # if it's a historical v1 trade, the exchange returns timestamp in seconds
613
- if ('dealValue' in trade) and (timestamp is not None):
614
- timestamp = timestamp * 1000
615
- priceString = self.safe_string(trade, 'price')
616
- amountString = self.safe_string(trade, 'size')
617
- side = self.safe_string(trade, 'side')
618
- fee = None
619
- feeCostString = self.safe_string(trade, 'fee')
620
- if feeCostString is not None:
621
- feeCurrencyId = self.safe_string(trade, 'feeCurrency')
622
- feeCurrency = self.safe_currency_code(feeCurrencyId)
623
- if feeCurrency is None:
624
- feeCurrency = market['quote'] if (side == 'sell') else market['base']
625
- fee = {
626
- 'cost': feeCostString,
627
- 'currency': feeCurrency,
628
- 'rate': self.safe_string(trade, 'feeRate'),
629
- }
630
- type = self.safe_string(trade, 'orderType')
631
- if type == 'match':
632
- type = None
633
- costString = self.safe_string(trade, 'value')
634
- return self.safe_trade({
635
- 'info': trade,
636
- 'id': id,
637
- 'order': orderId,
638
- 'timestamp': timestamp,
639
- 'datetime': self.iso8601(timestamp),
640
- 'symbol': market['symbol'],
641
- 'type': type,
642
- 'takerOrMaker': takerOrMaker,
643
- 'side': side,
644
- 'price': priceString,
645
- 'amount': amountString,
646
- 'cost': costString,
647
- 'fee': fee,
648
- }, market)
649
-
650
- async def fetch_trades(self, symbol: str, since: Int = None, limit: Int = None, params={}) -> List[Trade]:
651
- """
652
- get the list of most recent trades for a particular symbol
653
- :see: https://futures-docs.poloniex.com/#historical-data
654
- :param str symbol: unified symbol of the market to fetch trades for
655
- :param int [since]: timestamp in ms of the earliest trade to fetch
656
- :param int [limit]: the maximum amount of trades to fetch
657
- :param dict [params]: extra parameters specific to the exchange API endpoint
658
- :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
659
- """
660
- await self.load_markets()
661
- market = self.market(symbol)
662
- request: dict = {
663
- 'symbol': market['id'],
664
- }
665
- response = await self.publicGetTradeHistory(self.extend(request, params))
666
- #
667
- # {
668
- # "code": "200000",
669
- # "data": [
670
- # {
671
- # "sequence": 11827985,
672
- # "side": "buy",
673
- # "size": 101,
674
- # "price": "16864.0000000000",
675
- # "takerOrderId": "639c986f0ac2470007be75ee",
676
- # "makerOrderId": "639c986fa69d280007b76111",
677
- # "tradeId": "639c986f9fd7cf0001afd7ee",
678
- # "ts": 1671207023485924400
679
- # },
680
- # }
681
- #
682
- trades = self.safe_list(response, 'data', [])
683
- return self.parse_trades(trades, market, since, limit)
684
-
685
- async def fetch_time(self, params={}):
686
- """
687
- fetches the current integer timestamp in milliseconds from the poloniexfutures server
688
- :see: https://futures-docs.poloniex.com/#time
689
- :param dict [params]: extra parameters specific to the exchange API endpoint
690
- :returns int: the current integer timestamp in milliseconds from the poloniexfutures server
691
- """
692
- response = await self.publicGetTimestamp(params)
693
- #
694
- # {
695
- # "code":"200000",
696
- # "msg":"success",
697
- # "data":1546837113087
698
- # }
699
- #
700
- return self.safe_integer(response, 'data')
701
-
702
- async def fetch_ohlcv(self, symbol: str, timeframe='1m', since: Int = None, limit: Int = None, params={}) -> List[list]:
703
- """
704
- fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
705
- :see: https://futures-docs.poloniex.com/#k-chart
706
- :param str symbol: unified symbol of the market to fetch OHLCV data for
707
- :param str timeframe: the length of time each candle represents
708
- :param int [since]: timestamp in ms of the earliest candle to fetch
709
- :param int [limit]: the maximum amount of candles to fetch
710
- :param dict [params]: extra parameters specific to the exchange API endpoint
711
- :returns int[][]: A list of candles ordered, open, high, low, close, volume
712
- """
713
- await self.load_markets()
714
- market = self.market(symbol)
715
- marketId = market['id']
716
- parsedTimeframe = self.safe_integer(self.timeframes, timeframe)
717
- request: dict = {
718
- 'symbol': marketId,
719
- }
720
- if parsedTimeframe is not None:
721
- request['granularity'] = parsedTimeframe
722
- else:
723
- request['granularity'] = timeframe
724
- duration = self.parse_timeframe(timeframe) * 1000
725
- endAt = self.milliseconds()
726
- if since is not None:
727
- request['from'] = since
728
- if limit is None:
729
- limit = self.safe_integer(self.options, 'fetchOHLCVLimit', 200)
730
- endAt = self.sum(since, limit * duration)
731
- request['to'] = endAt
732
- elif limit is not None:
733
- since = endAt - limit * duration
734
- request['from'] = since
735
- response = await self.publicGetKlineQuery(self.extend(request, params))
736
- #
737
- # {
738
- # "code": "200000",
739
- # "data": [
740
- # [1636459200000, 4779.3, 4792.1, 4768.7, 4770.3, 78051],
741
- # [1636460100000, 4770.25, 4778.55, 4757.55, 4777.25, 80164],
742
- # [1636461000000, 4777.25, 4791.45, 4774.5, 4791.3, 51555]
743
- # ]
744
- # }
745
- #
746
- data = self.safe_list(response, 'data', [])
747
- return self.parse_ohlcvs(data, market, timeframe, since, limit)
748
-
749
- def parse_balance(self, response) -> Balances:
750
- result: dict = {
751
- 'info': response,
752
- 'timestamp': None,
753
- 'datetime': None,
754
- }
755
- data = self.safe_value(response, 'data')
756
- currencyId = self.safe_string(data, 'currency')
757
- code = self.safe_currency_code(currencyId)
758
- account = self.account()
759
- account['free'] = self.safe_string(data, 'availableBalance')
760
- account['total'] = self.safe_string(data, 'accountEquity')
761
- result[code] = account
762
- return self.safe_balance(result)
763
-
764
- async def fetch_balance(self, params={}) -> Balances:
765
- """
766
- query for balance and get the amount of funds available for trading or funds locked in orders
767
- :see: https://futures-docs.poloniex.com/#get-account-overview
768
- :param dict [params]: extra parameters specific to the exchange API endpoint
769
- :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
770
- """
771
- await self.load_markets()
772
- currencyId = self.safe_string(params, 'currency')
773
- request: dict = {}
774
- if currencyId is not None:
775
- currency = self.currency(currencyId)
776
- request = {
777
- 'currency': currency['id'],
778
- }
779
- response = await self.privateGetAccountOverview(self.extend(request, params))
780
- #
781
- # {
782
- # "code": "200000",
783
- # "data": {
784
- # "accountEquity": 0.00005,
785
- # "unrealisedPNL": 0,
786
- # "marginBalance": 0.00005,
787
- # "positionMargin": 0,
788
- # "orderMargin": 0,
789
- # "frozenFunds": 0,
790
- # "availableBalance": 0.00005,
791
- # "currency": "XBT"
792
- # }
793
- # }
794
- #
795
- return self.parse_balance(response)
796
-
797
- async def create_order(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={}):
798
- """
799
- Create an order on the exchange
800
- :see: https://futures-docs.poloniex.com/#place-an-order
801
- :param str symbol: Unified CCXT market symbol
802
- :param str type: 'limit' or 'market'
803
- :param str side: 'buy' or 'sell'
804
- :param float amount: the amount of currency to trade
805
- :param float [price]: *ignored in "market" orders* the price at which the order is to be fullfilled at in units of the quote currency
806
- :param dict [params]: extra parameters specific to the exchange API endpoint
807
- :param float [params.leverage]: Leverage size of the order
808
- :param float [params.stopPrice]: The price at which a trigger order is triggered at
809
- :param bool [params.reduceOnly]: A mark to reduce the position size only. Set to False by default. Need to set the position size when reduceOnly is True.
810
- :param str [params.timeInForce]: GTC, GTT, IOC, or FOK, default is GTC, limit orders only
811
- :param str [params.postOnly]: Post only flag, invalid when timeInForce is IOC or FOK
812
- :param str [params.clientOid]: client order id, defaults to uuid if not passed
813
- :param str [params.remark]: remark for the order, length cannot exceed 100 utf8 characters
814
- :param str [params.stop]: 'up' or 'down', defaults to 'up' if side is sell and 'down' if side is buy, requires stopPrice
815
- :param str [params.stopPriceType]: TP, IP or MP, defaults to TP
816
- :param bool [params.closeOrder]: set to True to close position
817
- :param bool [params.forceHold]: A mark to forcely hold the funds for an order, even though it's an order to reduce the position size. This helps the order stay on the order book and not get canceled when the position size changes. Set to False by default.
818
- :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
819
- """
820
- await self.load_markets()
821
- market = self.market(symbol)
822
- # required param, cannot be used twice
823
- clientOrderId = self.safe_string_2(params, 'clientOid', 'clientOrderId', self.uuid())
824
- params = self.omit(params, ['clientOid', 'clientOrderId'])
825
- if amount < 1:
826
- raise InvalidOrder(self.id + ' createOrder() minimum contract order amount is 1')
827
- preciseAmount = int(self.amount_to_precision(symbol, amount))
828
- request: dict = {
829
- 'clientOid': clientOrderId,
830
- 'side': side,
831
- 'symbol': market['id'],
832
- 'type': type, # limit or market
833
- 'size': preciseAmount,
834
- 'leverage': 1,
835
- }
836
- stopPrice = self.safe_value_2(params, 'triggerPrice', 'stopPrice')
837
- if stopPrice:
838
- request['stop'] = 'up' if (side == 'buy') else 'down'
839
- stopPriceType = self.safe_string(params, 'stopPriceType', 'TP')
840
- request['stopPriceType'] = stopPriceType
841
- request['stopPrice'] = self.price_to_precision(symbol, stopPrice)
842
- timeInForce = self.safe_string_upper(params, 'timeInForce')
843
- if type == 'limit':
844
- if price is None:
845
- raise ArgumentsRequired(self.id + ' createOrder() requires a price argument for limit orders')
846
- else:
847
- request['price'] = self.price_to_precision(symbol, price)
848
- if timeInForce is not None:
849
- request['timeInForce'] = timeInForce
850
- postOnly = self.safe_bool(params, 'postOnly', False)
851
- hidden = self.safe_value(params, 'hidden')
852
- if postOnly and (hidden is not None):
853
- raise BadRequest(self.id + ' createOrder() does not support the postOnly parameter together with a hidden parameter')
854
- iceberg = self.safe_value(params, 'iceberg')
855
- if iceberg:
856
- visibleSize = self.safe_value(params, 'visibleSize')
857
- if visibleSize is None:
858
- raise ArgumentsRequired(self.id + ' createOrder() requires a visibleSize parameter for iceberg orders')
859
- params = self.omit(params, ['timeInForce', 'stopPrice', 'triggerPrice']) # Time in force only valid for limit orders, exchange error when gtc for market orders
860
- response = await self.privatePostOrders(self.extend(request, params))
861
- #
862
- # {
863
- # "code": "200000",
864
- # "data": {
865
- # "orderId": "619717484f1d010001510cde",
866
- # },
867
- # }
868
- #
869
- data = self.safe_value(response, 'data', {})
870
- return self.safe_order({
871
- 'id': self.safe_string(data, 'orderId'),
872
- 'clientOrderId': None,
873
- 'timestamp': None,
874
- 'datetime': None,
875
- 'lastTradeTimestamp': None,
876
- 'symbol': None,
877
- 'type': None,
878
- 'side': None,
879
- 'price': None,
880
- 'amount': None,
881
- 'cost': None,
882
- 'average': None,
883
- 'filled': None,
884
- 'remaining': None,
885
- 'status': None,
886
- 'fee': None,
887
- 'trades': None,
888
- 'timeInForce': None,
889
- 'postOnly': None,
890
- 'stopPrice': None,
891
- 'info': response,
892
- }, market)
893
-
894
- async def cancel_order(self, id: str, symbol: Str = None, params={}):
895
- """
896
- cancels an open order
897
- :see: https://futures-docs.poloniex.com/#cancel-an-order
898
- :param str id: order id
899
- :param str symbol: unified symbol of the market the order was made in
900
- :param dict [params]: extra parameters specific to the exchange API endpoint
901
- :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
902
- """
903
- await self.load_markets()
904
- request: dict = {
905
- 'order-id': id,
906
- }
907
- response = await self.privateDeleteOrdersOrderId(self.extend(request, params))
908
- #
909
- # {
910
- # "code": "200000",
911
- # "data": {
912
- # "cancelledOrderIds": [
913
- # "619714b8b6353000014c505a",
914
- # ],
915
- # "cancelFailedOrders": [
916
- # {
917
- # "orderId": "63a9c5c2b9e7d70007eb0cd5",
918
- # "orderState": "2"
919
- # }
920
- # ],
921
- # },
922
- # }
923
- #
924
- data = self.safe_value(response, 'data')
925
- cancelledOrderIds = self.safe_value(data, 'cancelledOrderIds')
926
- cancelledOrderIdsLength = len(cancelledOrderIds)
927
- if cancelledOrderIdsLength == 0:
928
- raise InvalidOrder(self.id + ' cancelOrder() order already cancelled')
929
- return self.parse_order(data)
930
-
931
- async def fetch_positions(self, symbols: Strings = None, params={}):
932
- """
933
- fetch all open positions
934
- :see: https://futures-docs.poloniex.com/#get-position-list
935
- :param str[]|None symbols: list of unified market symbols
936
- :param dict [params]: extra parameters specific to the exchange API endpoint
937
- :returns dict[]: a list of `position structure <https://docs.ccxt.com/#/?id=position-structure>`
938
- """
939
- await self.load_markets()
940
- response = await self.privateGetPositions(params)
941
- #
942
- # {
943
- # "code": "200000",
944
- # "data": [
945
- # {
946
- # "id": "615ba79f83a3410001cde321",
947
- # "symbol": "ETHUSDTM",
948
- # "autoDeposit": False,
949
- # "maintMarginReq": 0.005,
950
- # "riskLimit": 1000000,
951
- # "realLeverage": 18.61,
952
- # "crossMode": False,
953
- # "delevPercentage": 0.86,
954
- # "openingTimestamp": 1638563515618,
955
- # "currentTimestamp": 1638576872774,
956
- # "currentQty": 2,
957
- # "currentCost": 83.64200000,
958
- # "currentComm": 0.05018520,
959
- # "unrealisedCost": 83.64200000,
960
- # "realisedGrossCost": 0.00000000,
961
- # "realisedCost": 0.05018520,
962
- # "isOpen": True,
963
- # "markPrice": 4225.01,
964
- # "markValue": 84.50020000,
965
- # "posCost": 83.64200000,
966
- # "posCross": 0.0000000000,
967
- # "posInit": 3.63660870,
968
- # "posComm": 0.05236717,
969
- # "posLoss": 0.00000000,
970
- # "posMargin": 3.68897586,
971
- # "posMaint": 0.50637594,
972
- # "maintMargin": 4.54717586,
973
- # "realisedGrossPnl": 0.00000000,
974
- # "realisedPnl": -0.05018520,
975
- # "unrealisedPnl": 0.85820000,
976
- # "unrealisedPnlPcnt": 0.0103,
977
- # "unrealisedRoePcnt": 0.2360,
978
- # "avgEntryPrice": 4182.10,
979
- # "liquidationPrice": 4023.00,
980
- # "bankruptPrice": 4000.25,
981
- # "settleCurrency": "USDT",
982
- # "isInverse": False
983
- # }
984
- # ]
985
- # }
986
- #
987
- data = self.safe_list(response, 'data')
988
- return self.parse_positions(data, symbols)
989
-
990
- def parse_position(self, position: dict, market: Market = None):
991
- #
992
- # {
993
- # "code": "200000",
994
- # "data": [
995
- # {
996
- # "id": "615ba79f83a3410001cde321", # Position ID
997
- # "symbol": "ETHUSDTM", # Symbol
998
- # "autoDeposit": False, # Auto deposit margin or not
999
- # "maintMarginReq": 0.005, # Maintenance margin requirement
1000
- # "riskLimit": 1000000, # Risk limit
1001
- # "realLeverage": 25.92, # Leverage of the order
1002
- # "crossMode": False, # Cross mode or not
1003
- # "delevPercentage": 0.76, # ADL ranking percentile
1004
- # "openingTimestamp": 1638578546031, # Open time
1005
- # "currentTimestamp": 1638578563580, # Current timestamp
1006
- # "currentQty": 2, # Current postion quantity
1007
- # "currentCost": 83.787, # Current postion value
1008
- # "currentComm": 0.0167574, # Current commission
1009
- # "unrealisedCost": 83.787, # Unrealised value
1010
- # "realisedGrossCost": 0.0, # Accumulated realised gross profit value
1011
- # "realisedCost": 0.0167574, # Current realised position value
1012
- # "isOpen": True, # Opened position or not
1013
- # "markPrice": 4183.38, # Mark price
1014
- # "markValue": 83.6676, # Mark value
1015
- # "posCost": 83.787, # Position value
1016
- # "posCross": 0.0, # added margin
1017
- # "posInit": 3.35148, # Leverage margin
1018
- # "posComm": 0.05228309, # Bankruptcy cost
1019
- # "posLoss": 0.0, # Funding fees paid out
1020
- # "posMargin": 3.40376309, # Position margin
1021
- # "posMaint": 0.50707892, # Maintenance margin
1022
- # "maintMargin": 3.28436309, # Position margin
1023
- # "realisedGrossPnl": 0.0, # Accumulated realised gross profit value
1024
- # "realisedPnl": -0.0167574, # Realised profit and loss
1025
- # "unrealisedPnl": -0.1194, # Unrealised profit and loss
1026
- # "unrealisedPnlPcnt": -0.0014, # Profit-loss ratio of the position
1027
- # "unrealisedRoePcnt": -0.0356, # Rate of return on investment
1028
- # "avgEntryPrice": 4189.35, # Average entry price
1029
- # "liquidationPrice": 4044.55, # Liquidation price
1030
- # "bankruptPrice": 4021.75, # Bankruptcy price
1031
- # "settleCurrency": "USDT", # Currency used to clear and settle the trades
1032
- # "isInverse": False
1033
- # }
1034
- # ]
1035
- # }
1036
- #
1037
- symbol = self.safe_string(position, 'symbol')
1038
- market = self.safe_market(symbol, market)
1039
- timestamp = self.safe_integer(position, 'currentTimestamp')
1040
- size = self.safe_string(position, 'currentQty')
1041
- side: Str
1042
- if Precise.string_gt(size, '0'):
1043
- side = 'long'
1044
- elif Precise.string_lt(size, '0'):
1045
- side = 'short'
1046
- notional = Precise.string_abs(self.safe_string(position, 'posCost'))
1047
- initialMargin = self.safe_string(position, 'posInit')
1048
- initialMarginPercentage = Precise.string_div(initialMargin, notional)
1049
- # marginRatio = Precise.string_div(maintenanceRate, collateral)
1050
- unrealisedPnl = self.safe_string(position, 'unrealisedPnl')
1051
- crossMode = self.safe_value(position, 'crossMode')
1052
- # currently crossMode is always set to False and only isolated positions are supported
1053
- marginMode = 'cross' if crossMode else 'isolated'
1054
- return {
1055
- 'info': position,
1056
- 'id': None,
1057
- 'symbol': self.safe_string(market, 'symbol'),
1058
- 'timestamp': timestamp,
1059
- 'datetime': self.iso8601(timestamp),
1060
- 'initialMargin': self.parse_number(initialMargin),
1061
- 'initialMarginPercentage': self.parse_number(initialMarginPercentage),
1062
- 'maintenanceMargin': self.safe_number(position, 'posMaint'),
1063
- 'maintenanceMarginPercentage': self.safe_number(position, 'maintMarginReq'),
1064
- 'entryPrice': self.safe_number(position, 'avgEntryPrice'),
1065
- 'notional': self.parse_number(notional),
1066
- 'leverage': self.safe_number(position, 'realLeverage'),
1067
- 'unrealizedPnl': self.parse_number(unrealisedPnl),
1068
- 'contracts': self.parse_number(Precise.string_abs(size)),
1069
- 'contractSize': self.safe_value(market, 'contractSize'),
1070
- 'marginRatio': None,
1071
- 'liquidationPrice': self.safe_number(position, 'liquidationPrice'),
1072
- 'markPrice': self.safe_number(position, 'markPrice'),
1073
- 'collateral': self.safe_number(position, 'maintMargin'),
1074
- 'marginMode': marginMode,
1075
- 'side': side,
1076
- 'percentage': self.parse_number(Precise.string_div(unrealisedPnl, initialMargin)),
1077
- 'stopLossPrice': None,
1078
- 'takeProfitPrice': None,
1079
- }
1080
-
1081
- async def fetch_funding_history(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}):
1082
- """
1083
- fetch the history of funding payments paid and received on self account
1084
- :see: https://futures-docs.poloniex.com/#get-funding-history
1085
- :param str symbol: unified market symbol
1086
- :param int [since]: the earliest time in ms to fetch funding history for
1087
- :param int [limit]: the maximum number of funding history structures to retrieve
1088
- :param dict [params]: extra parameters specific to the exchange API endpoint
1089
- :returns dict: a `funding history structure <https://docs.ccxt.com/#/?id=funding-history-structure>`
1090
- """
1091
- if symbol is None:
1092
- raise ArgumentsRequired(self.id + ' fetchFundingHistory() requires a symbol argument')
1093
- await self.load_markets()
1094
- market = self.market(symbol)
1095
- request: dict = {
1096
- 'symbol': market['id'],
1097
- }
1098
- if since is not None:
1099
- request['startAt'] = since
1100
- if limit is not None:
1101
- # * Since is ignored if limit is defined
1102
- request['maxCount'] = limit
1103
- response = await self.privateGetFundingHistory(self.extend(request, params))
1104
- #
1105
- # {
1106
- # "code": "200000",
1107
- # "data": {
1108
- # "dataList": [
1109
- # {
1110
- # "id": 239471298749817,
1111
- # "symbol": "ETHUSDTM",
1112
- # "timePoint": 1638532800000,
1113
- # "fundingRate": 0.000100,
1114
- # "markPrice": 4612.8300000000,
1115
- # "positionQty": 12,
1116
- # "positionCost": 553.5396000000,
1117
- # "funding": -0.0553539600,
1118
- # "settleCurrency": "USDT"
1119
- # },
1120
- # ...
1121
- # ],
1122
- # "hasMore": True
1123
- # }
1124
- # }
1125
- #
1126
- data = self.safe_value(response, 'data')
1127
- dataList = self.safe_value(data, 'dataList', [])
1128
- dataListLength = len(dataList)
1129
- fees = []
1130
- for i in range(0, dataListLength):
1131
- listItem = dataList[i]
1132
- timestamp = self.safe_integer(listItem, 'timePoint')
1133
- fees.append({
1134
- 'info': listItem,
1135
- 'symbol': symbol,
1136
- 'code': self.safe_currency_code(self.safe_string(listItem, 'settleCurrency')),
1137
- 'timestamp': timestamp,
1138
- 'datetime': self.iso8601(timestamp),
1139
- 'id': self.safe_number(listItem, 'id'),
1140
- 'amount': self.safe_number(listItem, 'funding'),
1141
- 'fundingRate': self.safe_number(listItem, 'fundingRate'),
1142
- 'markPrice': self.safe_number(listItem, 'markPrice'),
1143
- 'positionQty': self.safe_number(listItem, 'positionQty'),
1144
- 'positionCost': self.safe_number(listItem, 'positionCost'),
1145
- })
1146
- return fees
1147
-
1148
- async def cancel_all_orders(self, symbol: Str = None, params={}):
1149
- """
1150
- cancel all open orders
1151
- :param str symbol: unified market symbol, only orders in the market of self symbol are cancelled when symbol is not None
1152
- :param dict [params]: extra parameters specific to the exchange API endpoint
1153
- :param dict [params.stop]: When True, all the trigger orders will be cancelled
1154
- :returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
1155
- """
1156
- await self.load_markets()
1157
- request: dict = {}
1158
- if symbol is not None:
1159
- request['symbol'] = self.market_id(symbol)
1160
- stop = self.safe_value_2(params, 'stop', 'trigger')
1161
- params = self.omit(params, ['stop', 'trigger'])
1162
- response = None
1163
- if stop:
1164
- response = await self.privateDeleteStopOrders(self.extend(request, params))
1165
- else:
1166
- response = await self.privateDeleteOrders(self.extend(request, params))
1167
- #
1168
- # {
1169
- # "code": "200000",
1170
- # "data": {
1171
- # "cancelledOrderIds": [
1172
- # "619714b8b6353000014c505a",
1173
- # ],
1174
- # },
1175
- # }
1176
- #
1177
- data = self.safe_value(response, 'data')
1178
- result = []
1179
- cancelledOrderIds = self.safe_value(data, 'cancelledOrderIds')
1180
- cancelledOrderIdsLength = len(cancelledOrderIds)
1181
- for i in range(0, cancelledOrderIdsLength):
1182
- cancelledOrderId = self.safe_string(cancelledOrderIds, i)
1183
- result.append(self.safe_order({
1184
- 'id': cancelledOrderId,
1185
- 'clientOrderId': None,
1186
- 'timestamp': None,
1187
- 'datetime': None,
1188
- 'lastTradeTimestamp': None,
1189
- 'symbol': None,
1190
- 'type': None,
1191
- 'side': None,
1192
- 'price': None,
1193
- 'amount': None,
1194
- 'cost': None,
1195
- 'average': None,
1196
- 'filled': None,
1197
- 'remaining': None,
1198
- 'status': None,
1199
- 'fee': None,
1200
- 'trades': None,
1201
- 'timeInForce': None,
1202
- 'postOnly': None,
1203
- 'stopPrice': None,
1204
- 'info': response,
1205
- }))
1206
- return result
1207
-
1208
- async def fetch_orders_by_status(self, status, symbol: Str = None, since: Int = None, limit: Int = None, params={}):
1209
- """
1210
- fetches a list of orders placed on the exchange
1211
- :see: https://futures-docs.poloniex.com/#get-order-list
1212
- :see: https://futures-docs.poloniex.com/#get-untriggered-stop-order-list
1213
- :param str status: 'active' or 'closed', only 'active' is valid for stop orders
1214
- :param str symbol: unified symbol for the market to retrieve orders from
1215
- :param int [since]: timestamp in ms of the earliest order to retrieve
1216
- :param int [limit]: The maximum number of orders to retrieve
1217
- :param dict [params]: exchange specific parameters
1218
- :param bool [params.stop]: set to True to retrieve untriggered stop orders
1219
- :param int [params.until]: End time in ms
1220
- :param str [params.side]: buy or sell
1221
- :param str [params.type]: limit or market
1222
- :returns: An `array of order structures <https://docs.ccxt.com/#/?id=order-structure>`
1223
- """
1224
- await self.load_markets()
1225
- stop = self.safe_value_2(params, 'stop', 'trigger')
1226
- until = self.safe_integer(params, 'until')
1227
- params = self.omit(params, ['trigger', 'stop', 'until'])
1228
- if status == 'closed':
1229
- status = 'done'
1230
- request: dict = {}
1231
- if not stop:
1232
- request['status'] = 'active' if (status == 'open') else 'done'
1233
- elif status != 'open':
1234
- raise BadRequest(self.id + ' fetchOrdersByStatus() can only fetch untriggered stop orders')
1235
- market: Market = None
1236
- if symbol is not None:
1237
- market = self.market(symbol)
1238
- request['symbol'] = market['id']
1239
- if since is not None:
1240
- request['startAt'] = since
1241
- if until is not None:
1242
- request['endAt'] = until
1243
- response = None
1244
- if stop:
1245
- response = await self.privateGetStopOrders(self.extend(request, params))
1246
- else:
1247
- response = await self.privateGetOrders(self.extend(request, params))
1248
- #
1249
- # {
1250
- # "code": "200000",
1251
- # "data": {
1252
- # "totalNum": 1,
1253
- # "totalPage": 1,
1254
- # "pageSize": 50,
1255
- # "currentPage": 1,
1256
- # "items": [
1257
- # {
1258
- # "symbol": "ADAUSDTPERP",
1259
- # "leverage": "1",
1260
- # "hidden": False,
1261
- # "forceHold": False,
1262
- # "closeOrder": False,
1263
- # "type": "limit",
1264
- # "isActive": True,
1265
- # "createdAt": 1678936920000,
1266
- # "orderTime": 1678936920480905922,
1267
- # "price": "0.3",
1268
- # "iceberg": False,
1269
- # "stopTriggered": False,
1270
- # "id": "64128b582cc0710007a3c840",
1271
- # "value": "3",
1272
- # "timeInForce": "GTC",
1273
- # "updatedAt": 1678936920000,
1274
- # "side": "buy",
1275
- # "stopPriceType": "",
1276
- # "dealValue": "0",
1277
- # "dealSize": 0,
1278
- # "settleCurrency": "USDT",
1279
- # "stp": "",
1280
- # "filledValue": "0",
1281
- # "postOnly": False,
1282
- # "size": 1,
1283
- # "stop": "",
1284
- # "filledSize": 0,
1285
- # "reduceOnly": False,
1286
- # "marginType": 1,
1287
- # "cancelExist": False,
1288
- # "clientOid": "ba669f39-dfcc-4664-9801-a42d06e59c2e",
1289
- # "status": "open"
1290
- # }
1291
- # ]
1292
- # }
1293
- # }
1294
- #
1295
- responseData = self.safe_value(response, 'data', {})
1296
- orders = self.safe_value(responseData, 'items', [])
1297
- ordersLength = len(orders)
1298
- result = []
1299
- for i in range(0, ordersLength):
1300
- order = orders[i]
1301
- orderStatus = self.safe_string(order, 'status')
1302
- if status == orderStatus:
1303
- result.append(orders[i])
1304
- return self.parse_orders(result, market, since, limit)
1305
-
1306
- async def fetch_open_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Order]:
1307
- """
1308
- fetch all unfilled currently open orders
1309
- :see: https://futures-docs.poloniex.com/#get-order-list
1310
- :see: https://futures-docs.poloniex.com/#get-untriggered-stop-order-list
1311
- :param str symbol: unified market symbol
1312
- :param int [since]: the earliest time in ms to fetch open orders for
1313
- :param int [limit]: the maximum number of open orders structures to retrieve
1314
- :param dict [params]: extra parameters specific to the exchange API endpoint
1315
- :param int [params.until]: end time in ms
1316
- :param str [params.side]: buy or sell
1317
- :param str [params.type]: limit, or market
1318
- :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
1319
- """
1320
- return await self.fetch_orders_by_status('open', symbol, since, limit, params)
1321
-
1322
- async def fetch_closed_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Order]:
1323
- """
1324
- fetches information on multiple closed orders made by the user
1325
- :see: https://futures-docs.poloniex.com/#get-order-list
1326
- :see: https://futures-docs.poloniex.com/#get-untriggered-stop-order-list
1327
- :param str symbol: unified market symbol of the market orders were made in
1328
- :param int [since]: the earliest time in ms to fetch orders for
1329
- :param int [limit]: the maximum number of order structures to retrieve
1330
- :param dict [params]: extra parameters specific to the exchange API endpoint
1331
- :param int [params.until]: end time in ms
1332
- :param str [params.side]: buy or sell
1333
- :param str [params.type]: limit, or market
1334
- :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
1335
- """
1336
- return await self.fetch_orders_by_status('closed', symbol, since, limit, params)
1337
-
1338
- async def fetch_order(self, id: Str = None, symbol: Str = None, params={}):
1339
- """
1340
- fetches information on an order made by the user
1341
- :see: https://futures-docs.poloniex.com/#get-details-of-a-single-order
1342
- :see: https://futures-docs.poloniex.com/#get-single-order-by-clientoid
1343
- :param str symbol: unified symbol of the market the order was made in
1344
- :param dict [params]: extra parameters specific to the exchange API endpoint
1345
- :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
1346
- """
1347
- await self.load_markets()
1348
- request: dict = {}
1349
- response = None
1350
- if id is None:
1351
- clientOrderId = self.safe_string_2(params, 'clientOid', 'clientOrderId')
1352
- if clientOrderId is None:
1353
- raise InvalidOrder(self.id + ' fetchOrder() requires parameter id or params.clientOid')
1354
- request['clientOid'] = clientOrderId
1355
- params = self.omit(params, ['clientOid', 'clientOrderId'])
1356
- response = await self.privateGetClientOrderIdClientOid(self.extend(request, params))
1357
- else:
1358
- request['order-id'] = id
1359
- response = await self.privateGetOrdersOrderId(self.extend(request, params))
1360
- #
1361
- # {
1362
- # "code": "200000",
1363
- # "data": {
1364
- # "symbol": "ADAUSDTPERP",
1365
- # "leverage": "1",
1366
- # "hidden": False,
1367
- # "forceHold": False,
1368
- # "closeOrder": False,
1369
- # "type": "market",
1370
- # "isActive": False,
1371
- # "createdAt": 1678929587000,
1372
- # "orderTime": 1678929587248115582,
1373
- # "iceberg": False,
1374
- # "stopTriggered": False,
1375
- # "id": "64126eb38c6919000737dcdc",
1376
- # "value": "3.1783",
1377
- # "timeInForce": "GTC",
1378
- # "updatedAt": 1678929587000,
1379
- # "side": "buy",
1380
- # "stopPriceType": "",
1381
- # "dealValue": "3.1783",
1382
- # "dealSize": 1,
1383
- # "settleCurrency": "USDT",
1384
- # "trades": [
1385
- # {
1386
- # "feePay": "0.00158915",
1387
- # "tradeId": "64126eb36803eb0001ff99bc"
1388
- # }
1389
- # ],
1390
- # "endAt": 1678929587000,
1391
- # "stp": "",
1392
- # "filledValue": "3.1783",
1393
- # "postOnly": False,
1394
- # "size": 1,
1395
- # "stop": "",
1396
- # "filledSize": 1,
1397
- # "reduceOnly": False,
1398
- # "marginType": 1,
1399
- # "cancelExist": False,
1400
- # "clientOid": "d19e8fcb-2df4-44bc-afd4-67dd42048246",
1401
- # "status": "done"
1402
- # }
1403
- # }
1404
- #
1405
- market = self.market(symbol) if (symbol is not None) else None
1406
- responseData = self.safe_dict(response, 'data')
1407
- return self.parse_order(responseData, market)
1408
-
1409
- def parse_order(self, order: dict, market: Market = None) -> Order:
1410
- #
1411
- # createOrder
1412
- #
1413
- # {
1414
- # "code": "200000",
1415
- # "data": {
1416
- # "orderId": "619717484f1d010001510cde",
1417
- # },
1418
- # }
1419
- #
1420
- # fetchOrder
1421
- #
1422
- # {
1423
- # "symbol": "ADAUSDTPERP",
1424
- # "leverage": "1",
1425
- # "hidden": False,
1426
- # "forceHold": False,
1427
- # "closeOrder": False,
1428
- # "type": "market",
1429
- # "isActive": False,
1430
- # "createdAt": 1678929587000,
1431
- # "orderTime": 1678929587248115582,
1432
- # "iceberg": False,
1433
- # "stopTriggered": False,
1434
- # "id": "64126eb38c6919000737dcdc",
1435
- # "value": "3.1783",
1436
- # "timeInForce": "GTC",
1437
- # "updatedAt": 1678929587000,
1438
- # "side": "buy",
1439
- # "stopPriceType": "",
1440
- # "dealValue": "3.1783",
1441
- # "dealSize": 1,
1442
- # "settleCurrency": "USDT",
1443
- # "trades": [
1444
- # {
1445
- # "feePay": "0.00158915",
1446
- # "tradeId": "64126eb36803eb0001ff99bc"
1447
- # }
1448
- # ],
1449
- # "endAt": 1678929587000,
1450
- # "stp": "",
1451
- # "filledValue": "3.1783",
1452
- # "postOnly": False,
1453
- # "size": 1,
1454
- # "stop": "",
1455
- # "filledSize": 1,
1456
- # "reduceOnly": False,
1457
- # "marginType": 1,
1458
- # "cancelExist": False,
1459
- # "clientOid": "d19e8fcb-2df4-44bc-afd4-67dd42048246",
1460
- # "status": "done"
1461
- # }
1462
- #
1463
- # cancelOrder
1464
- #
1465
- # {
1466
- # "cancelledOrderIds": [
1467
- # "619714b8b6353000014c505a",
1468
- # ],
1469
- # "cancelFailedOrders": [
1470
- # {
1471
- # "orderId": "63a9c5c2b9e7d70007eb0cd5",
1472
- # "orderState": "2"
1473
- # }
1474
- # ],
1475
- # },
1476
- #
1477
- marketId = self.safe_string(order, 'symbol')
1478
- market = self.safe_market(marketId, market)
1479
- timestamp = self.safe_integer(order, 'createdAt')
1480
- # price is zero for market order
1481
- # omitZero is called in safeOrder2
1482
- feeCurrencyId = self.safe_string(order, 'feeCurrency')
1483
- filled = self.safe_string(order, 'dealSize')
1484
- rawCost = self.safe_string_2(order, 'dealFunds', 'filledValue')
1485
- average: Str = None
1486
- if Precise.string_gt(filled, '0'):
1487
- contractSize = self.safe_string(market, 'contractSize')
1488
- if market['linear']:
1489
- average = Precise.string_div(rawCost, Precise.string_mul(contractSize, filled))
1490
- else:
1491
- average = Precise.string_div(Precise.string_mul(contractSize, filled), rawCost)
1492
- # precision reported by their api is 8 d.p.
1493
- # average = Precise.string_div(rawCost, Precise.string_mul(filled, market['contractSize']))
1494
- # bool
1495
- isActive = self.safe_bool(order, 'isActive', False)
1496
- cancelExist = self.safe_bool(order, 'cancelExist', False)
1497
- status = 'open' if isActive else 'closed'
1498
- id = self.safe_string(order, 'id')
1499
- if 'cancelledOrderIds' in order:
1500
- cancelledOrderIds = self.safe_value(order, 'cancelledOrderIds')
1501
- id = self.safe_string(cancelledOrderIds, 0)
1502
- return self.safe_order({
1503
- 'info': order,
1504
- 'id': id,
1505
- 'clientOrderId': self.safe_string(order, 'clientOid'),
1506
- 'symbol': self.safe_string(market, 'symbol'),
1507
- 'type': self.safe_string(order, 'type'),
1508
- 'timeInForce': self.safe_string(order, 'timeInForce'),
1509
- 'postOnly': self.safe_value(order, 'postOnly'),
1510
- 'side': self.safe_string(order, 'side'),
1511
- 'amount': self.safe_string(order, 'size'),
1512
- 'price': self.safe_string(order, 'price'),
1513
- 'stopPrice': self.safe_string(order, 'stopPrice'),
1514
- 'cost': self.safe_string(order, 'dealValue'),
1515
- 'filled': filled,
1516
- 'remaining': None,
1517
- 'timestamp': timestamp,
1518
- 'datetime': self.iso8601(timestamp),
1519
- 'fee': {
1520
- 'currency': self.safe_currency_code(feeCurrencyId),
1521
- 'cost': self.safe_string(order, 'fee'),
1522
- },
1523
- 'status': 'canceled' if cancelExist else status,
1524
- 'lastTradeTimestamp': None,
1525
- 'average': average,
1526
- 'trades': None,
1527
- }, market)
1528
-
1529
- async def fetch_funding_rate(self, symbol: str, params={}):
1530
- """
1531
- fetch the current funding rate
1532
- :see: https://futures-docs.poloniex.com/#get-premium-index
1533
- :param str symbol: unified market symbol
1534
- :param dict [params]: extra parameters specific to the exchange API endpoint
1535
- :returns dict: a `funding rate structure <https://docs.ccxt.com/#/?id=funding-rate-structure>`
1536
- """
1537
- await self.load_markets()
1538
- market = self.market(symbol)
1539
- request: dict = {
1540
- 'symbol': market['id'],
1541
- }
1542
- response = await self.publicGetFundingRateSymbolCurrent(self.extend(request, params))
1543
- #
1544
- # {
1545
- # "symbol": ".BTCUSDTPERPFPI8H",
1546
- # "granularity": 28800000,
1547
- # "timePoint": 1558000800000,
1548
- # "value": 0.00375,
1549
- # "predictedValue": 0.00375
1550
- # }
1551
- #
1552
- data = self.safe_value(response, 'data')
1553
- fundingTimestamp = self.safe_integer(data, 'timePoint')
1554
- # the website displayes the previous funding rate as "funding rate"
1555
- return {
1556
- 'info': data,
1557
- 'symbol': market['symbol'],
1558
- 'markPrice': None,
1559
- 'indexPrice': None,
1560
- 'interestRate': None,
1561
- 'estimatedSettlePrice': None,
1562
- 'timestamp': None,
1563
- 'datetime': None,
1564
- 'fundingRate': self.safe_number(data, 'predictedValue'),
1565
- 'fundingTimestamp': None,
1566
- 'fundingDatetime': None,
1567
- 'nextFundingRate': None,
1568
- 'nextFundingTimestamp': None,
1569
- 'nextFundingDatetime': None,
1570
- 'previousFundingRate': self.safe_number(data, 'value'),
1571
- 'previousFundingTimestamp': fundingTimestamp,
1572
- 'previousFundingDatetime': self.iso8601(fundingTimestamp),
1573
- }
1574
-
1575
- async def fetch_my_trades(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}):
1576
- """
1577
- fetch all trades made by the user
1578
- :see: https://futures-docs.poloniex.com/#get-fills
1579
- :param str symbol: unified market symbol
1580
- :param int [since]: the earliest time in ms to fetch trades for
1581
- :param int [limit]: the maximum number of trades structures to retrieve
1582
- :param dict [params]: extra parameters specific to the exchange API endpoint
1583
- :param str orderIdFills: filles for a specific order(other parameters can be ignored if specified)
1584
- :param str side: buy or sell
1585
- :param str type: limit, market, limit_stop or market_stop
1586
- :param int endAt: end time(milisecond)
1587
- :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
1588
- """
1589
- await self.load_markets()
1590
- request: dict = {
1591
- }
1592
- market = None
1593
- if symbol is not None:
1594
- market = self.market(symbol)
1595
- request['symbol'] = market['id']
1596
- if since is not None:
1597
- request['startAt'] = since
1598
- response = await self.privateGetFills(self.extend(request, params))
1599
- #
1600
- # {
1601
- # "code": "200000",
1602
- # "data": {
1603
- # "currentPage":1,
1604
- # "pageSize":1,
1605
- # "totalNum":251915,
1606
- # "totalPage":251915,
1607
- # "items":[
1608
- # {
1609
- # "symbol": "BTCUSDTPERP", #Ticker symbol of the contract
1610
- # "tradeId": "5ce24c1f0c19fc3c58edc47c", #Trade ID
1611
- # "orderId": "5ce24c16b210233c36ee321d", # Order ID
1612
- # "side": "sell", #Transaction side
1613
- # "liquidity": "taker", #Liquidity- taker or maker
1614
- # "price": "8302", #Filled price
1615
- # "size": 10, #Filled amount
1616
- # "value": "0.001204529", #Order value
1617
- # "feeRate": "0.0005", #Floating fees
1618
- # "fixFee": "0.00000006", #Fixed fees
1619
- # "feeCurrency": "XBT", #Charging currency
1620
- # "stop": "", #A mark to the stop order type
1621
- # "fee": "0.0000012022", #Transaction fee
1622
- # "orderType": "limit", #Order type
1623
- # "tradeType": "trade", #Trade type(trade, liquidation, ADL or settlement)
1624
- # "createdAt": 1558334496000, #Time the order created
1625
- # "settleCurrency": "XBT", #settlement currency
1626
- # "tradeTime": 1558334496000000000 #trade time in nanosecond
1627
- # }
1628
- # ]
1629
- # }
1630
- # }
1631
- #
1632
- data = self.safe_value(response, 'data', {})
1633
- trades = self.safe_list(data, 'items', [])
1634
- return self.parse_trades(trades, market, since, limit)
1635
-
1636
- async def set_margin_mode(self, marginMode: str, symbol: Str = None, params={}):
1637
- """
1638
- set margin mode to 'cross' or 'isolated'
1639
- :see: https://futures-docs.poloniex.com/#change-margin-mode
1640
- :param str marginMode: "0"(isolated) or "1"(cross)
1641
- :param str symbol: unified market symbol
1642
- :param dict [params]: extra parameters specific to the exchange API endpoint
1643
- :returns dict: response from the exchange
1644
- """
1645
- if symbol is None:
1646
- raise ArgumentsRequired(self.id + ' setMarginMode() requires a symbol argument')
1647
- if (marginMode != '0') and (marginMode != '1') and (marginMode != 'isolated') and (marginMode != 'cross'):
1648
- raise ArgumentsRequired(self.id + ' setMarginMode() marginMode must be 0/isolated or 1/cross')
1649
- await self.load_markets()
1650
- if marginMode == 'isolated':
1651
- marginMode = '0'
1652
- if marginMode == 'cross':
1653
- marginMode = '1'
1654
- market = self.market(symbol)
1655
- request: dict = {
1656
- 'symbol': market['id'],
1657
- 'marginType': self.parse_to_int(marginMode),
1658
- }
1659
- return await self.privatePostMarginTypeChange(request)
1660
-
1661
- def sign(self, path, api='public', method='GET', params={}, headers=None, body=None):
1662
- url = self.urls['api'][api]
1663
- versions = self.safe_value(self.options, 'versions', {})
1664
- apiVersions = self.safe_value(versions, api, {})
1665
- methodVersions = self.safe_value(apiVersions, method, {})
1666
- defaultVersion = self.safe_string(methodVersions, path, self.version)
1667
- version = self.safe_string(params, 'version', defaultVersion)
1668
- tail = '/api/' + version + '/' + self.implode_params(path, params)
1669
- url += tail
1670
- query = self.omit(params, self.extract_params(path))
1671
- queryLength = query
1672
- if api == 'public':
1673
- if queryLength:
1674
- url += '?' + self.urlencode(query)
1675
- else:
1676
- self.check_required_credentials()
1677
- endpoint = '/api/v1/' + self.implode_params(path, params)
1678
- bodyEncoded = self.urlencode(query)
1679
- if method != 'GET' and method != 'HEAD':
1680
- body = query
1681
- else:
1682
- if queryLength and bodyEncoded != '':
1683
- url += '?' + bodyEncoded
1684
- endpoint += '?' + bodyEncoded
1685
- now = str(self.milliseconds())
1686
- endpart = ''
1687
- if body is not None:
1688
- body = self.json(query)
1689
- endpart = body
1690
- payload = now + method + endpoint + endpart
1691
- signature = self.hmac(self.encode(payload), self.encode(self.secret), hashlib.sha256, 'base64')
1692
- headers = {
1693
- 'PF-API-SIGN': signature,
1694
- 'PF-API-TIMESTAMP': now,
1695
- 'PF-API-KEY': self.apiKey,
1696
- 'PF-API-PASSPHRASE': self.password,
1697
- }
1698
- headers['Content-Type'] = 'application/json'
1699
- return {'url': url, 'method': method, 'body': body, 'headers': headers}
1700
-
1701
- def handle_errors(self, code: int, reason: str, url: str, method: str, headers: dict, body: str, response, requestHeaders, requestBody):
1702
- if not response:
1703
- self.throw_broadly_matched_exception(self.exceptions['broad'], body, body)
1704
- return None
1705
- #
1706
- # bad
1707
- # {"code": "400100", "msg": "validation.createOrder.clientOidIsRequired"}
1708
- # good
1709
- # {code: "200000", data: {...}}
1710
- #
1711
- errorCode = self.safe_string(response, 'code')
1712
- message = self.safe_string(response, 'msg', '')
1713
- feedback = self.id + ' ' + message
1714
- self.throw_exactly_matched_exception(self.exceptions['exact'], message, feedback)
1715
- self.throw_exactly_matched_exception(self.exceptions['exact'], errorCode, feedback)
1716
- self.throw_broadly_matched_exception(self.exceptions['broad'], body, feedback)
1717
- return None