ccxt 4.2.18 → 4.2.19

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 (426) hide show
  1. package/README.md +8 -8
  2. package/dist/ccxt.browser.js +34202 -33193
  3. package/dist/ccxt.browser.min.js +2 -2
  4. package/dist/cjs/ccxt.js +12 -1
  5. package/dist/cjs/src/alpaca.js +18 -18
  6. package/dist/cjs/src/ascendex.js +13 -6
  7. package/dist/cjs/src/base/Exchange.js +266 -27
  8. package/dist/cjs/src/bigone.js +434 -168
  9. package/dist/cjs/src/binance.js +163 -34
  10. package/dist/cjs/src/binanceus.js +8 -0
  11. package/dist/cjs/src/bingx.js +183 -41
  12. package/dist/cjs/src/bitfinex.js +2 -3
  13. package/dist/cjs/src/bitget.js +59 -16
  14. package/dist/cjs/src/bitmart.js +5 -5
  15. package/dist/cjs/src/bitmex.js +4 -6
  16. package/dist/cjs/src/bitpanda.js +5 -1991
  17. package/dist/cjs/src/bitstamp.js +8 -0
  18. package/dist/cjs/src/bybit.js +27 -47
  19. package/dist/cjs/src/coinbase.js +176 -26
  20. package/dist/cjs/src/coincheck.js +1 -0
  21. package/dist/cjs/src/coinex.js +3 -0
  22. package/dist/cjs/src/coinlist.js +13 -6
  23. package/dist/cjs/src/coinone.js +2 -2
  24. package/dist/cjs/src/coinsph.js +4 -5
  25. package/dist/cjs/src/delta.js +7 -1
  26. package/dist/cjs/src/deribit.js +17 -4
  27. package/dist/cjs/src/gate.js +151 -169
  28. package/dist/cjs/src/gemini.js +1 -1
  29. package/dist/cjs/src/hitbtc.js +2 -3
  30. package/dist/cjs/src/htx.js +157 -7
  31. package/dist/cjs/src/huobijp.js +2 -3
  32. package/dist/cjs/src/independentreserve.js +7 -5
  33. package/dist/cjs/src/kraken.js +86 -54
  34. package/dist/cjs/src/kucoin.js +5 -0
  35. package/dist/cjs/src/kucoinfutures.js +131 -77
  36. package/dist/cjs/src/lbank.js +60 -33
  37. package/dist/cjs/src/luno.js +84 -2
  38. package/dist/cjs/src/mexc.js +3 -3
  39. package/dist/cjs/src/oceanex.js +1 -1
  40. package/dist/cjs/src/okx.js +23 -11
  41. package/dist/cjs/{js/src/bitpanda.js → src/onetrading.js} +39 -39
  42. package/dist/cjs/src/phemex.js +37 -27
  43. package/dist/cjs/src/poloniexfutures.js +1 -0
  44. package/dist/cjs/src/pro/binance.js +66 -25
  45. package/dist/cjs/src/pro/bitget.js +1 -1
  46. package/dist/cjs/src/pro/bitpanda.js +5 -1330
  47. package/dist/cjs/src/pro/coinbase.js +4 -1
  48. package/dist/cjs/src/pro/hitbtc.js +5 -4
  49. package/dist/cjs/src/pro/htx.js +6 -1
  50. package/dist/cjs/src/pro/kraken.js +1 -1
  51. package/dist/cjs/src/pro/krakenfutures.js +7 -1
  52. package/dist/cjs/src/pro/kucoin.js +46 -36
  53. package/dist/cjs/src/pro/kucoinfutures.js +45 -37
  54. package/dist/cjs/src/pro/lbank.js +881 -0
  55. package/dist/cjs/src/pro/okx.js +52 -2
  56. package/dist/cjs/{js/src/pro/bitpanda.js → src/pro/onetrading.js} +4 -7
  57. package/dist/cjs/src/pro/poloniex.js +2 -2
  58. package/dist/cjs/src/pro/poloniexfutures.js +43 -35
  59. package/dist/cjs/src/pro/woo.js +126 -0
  60. package/dist/cjs/src/probit.js +4 -2
  61. package/dist/cjs/src/upbit.js +12 -12
  62. package/dist/cjs/src/wavesexchange.js +1 -1
  63. package/dist/cjs/src/whitebit.js +1 -0
  64. package/dist/cjs/src/woo.js +56 -0
  65. package/js/ccxt.d.ts +11 -2
  66. package/js/ccxt.js +8 -2
  67. package/js/src/abstract/bitpanda.d.ts +4 -4
  68. package/js/src/abstract/bitstamp.d.ts +8 -0
  69. package/js/src/abstract/gate.d.ts +1 -0
  70. package/js/src/abstract/gateio.d.ts +1 -0
  71. package/js/src/abstract/htx.d.ts +3 -0
  72. package/js/src/abstract/huobi.d.ts +3 -0
  73. package/js/src/abstract/luno.d.ts +1 -0
  74. package/js/src/abstract/onetrading.d.ts +38 -0
  75. package/js/src/ascendex.js +2 -0
  76. package/js/src/bingx.js +1 -1
  77. package/js/src/bitget.js +22 -3
  78. package/js/src/bitpanda.d.ts +2 -72
  79. package/js/src/bitpanda.js +5 -1991
  80. package/js/src/bitstamp.js +8 -0
  81. package/js/src/deribit.js +11 -3
  82. package/js/src/gate.d.ts +1 -0
  83. package/js/src/gate.js +50 -110
  84. package/js/src/htx.js +3 -0
  85. package/js/src/kraken.d.ts +1 -0
  86. package/js/src/kraken.js +39 -38
  87. package/js/src/lbank.js +1 -0
  88. package/js/src/luno.d.ts +3 -1
  89. package/js/src/luno.js +84 -2
  90. package/js/src/mexc.js +1 -2
  91. package/js/src/onetrading.d.ts +74 -0
  92. package/js/src/onetrading.js +2003 -0
  93. package/js/src/poloniexfutures.js +1 -0
  94. package/js/src/pro/binance.js +6 -1
  95. package/js/src/pro/bitpanda.d.ts +2 -34
  96. package/js/src/pro/bitpanda.js +5 -1330
  97. package/js/src/pro/lbank.d.ts +29 -0
  98. package/js/src/pro/lbank.js +882 -0
  99. package/js/src/pro/onetrading.d.ts +36 -0
  100. package/js/src/pro/onetrading.js +1339 -0
  101. package/package.json +2 -2
  102. package/rollup.config.js +2 -0
  103. package/skip-tests.json +2 -1
  104. package/test-commonjs.cjs +25 -1
  105. package/dist/cjs/js/ccxt.js +0 -478
  106. package/dist/cjs/js/src/abstract/alpaca.js +0 -9
  107. package/dist/cjs/js/src/abstract/ascendex.js +0 -9
  108. package/dist/cjs/js/src/abstract/bigone.js +0 -9
  109. package/dist/cjs/js/src/abstract/binance.js +0 -9
  110. package/dist/cjs/js/src/abstract/bingx.js +0 -9
  111. package/dist/cjs/js/src/abstract/bit2c.js +0 -9
  112. package/dist/cjs/js/src/abstract/bitbank.js +0 -9
  113. package/dist/cjs/js/src/abstract/bitbns.js +0 -9
  114. package/dist/cjs/js/src/abstract/bitfinex.js +0 -9
  115. package/dist/cjs/js/src/abstract/bitfinex2.js +0 -9
  116. package/dist/cjs/js/src/abstract/bitflyer.js +0 -9
  117. package/dist/cjs/js/src/abstract/bitforex.js +0 -9
  118. package/dist/cjs/js/src/abstract/bitget.js +0 -9
  119. package/dist/cjs/js/src/abstract/bithumb.js +0 -9
  120. package/dist/cjs/js/src/abstract/bitmart.js +0 -9
  121. package/dist/cjs/js/src/abstract/bitmex.js +0 -9
  122. package/dist/cjs/js/src/abstract/bitopro.js +0 -9
  123. package/dist/cjs/js/src/abstract/bitpanda.js +0 -9
  124. package/dist/cjs/js/src/abstract/bitrue.js +0 -9
  125. package/dist/cjs/js/src/abstract/bitso.js +0 -9
  126. package/dist/cjs/js/src/abstract/bitstamp.js +0 -9
  127. package/dist/cjs/js/src/abstract/bitteam.js +0 -9
  128. package/dist/cjs/js/src/abstract/bitvavo.js +0 -9
  129. package/dist/cjs/js/src/abstract/bl3p.js +0 -9
  130. package/dist/cjs/js/src/abstract/blockchaincom.js +0 -9
  131. package/dist/cjs/js/src/abstract/btcalpha.js +0 -9
  132. package/dist/cjs/js/src/abstract/btcbox.js +0 -9
  133. package/dist/cjs/js/src/abstract/btcmarkets.js +0 -9
  134. package/dist/cjs/js/src/abstract/btcturk.js +0 -9
  135. package/dist/cjs/js/src/abstract/bybit.js +0 -9
  136. package/dist/cjs/js/src/abstract/cex.js +0 -9
  137. package/dist/cjs/js/src/abstract/coinbase.js +0 -9
  138. package/dist/cjs/js/src/abstract/coinbasepro.js +0 -9
  139. package/dist/cjs/js/src/abstract/coincheck.js +0 -9
  140. package/dist/cjs/js/src/abstract/coinex.js +0 -9
  141. package/dist/cjs/js/src/abstract/coinlist.js +0 -9
  142. package/dist/cjs/js/src/abstract/coinmate.js +0 -9
  143. package/dist/cjs/js/src/abstract/coinone.js +0 -9
  144. package/dist/cjs/js/src/abstract/coinsph.js +0 -9
  145. package/dist/cjs/js/src/abstract/coinspot.js +0 -9
  146. package/dist/cjs/js/src/abstract/cryptocom.js +0 -9
  147. package/dist/cjs/js/src/abstract/currencycom.js +0 -9
  148. package/dist/cjs/js/src/abstract/delta.js +0 -9
  149. package/dist/cjs/js/src/abstract/deribit.js +0 -9
  150. package/dist/cjs/js/src/abstract/digifinex.js +0 -9
  151. package/dist/cjs/js/src/abstract/exmo.js +0 -9
  152. package/dist/cjs/js/src/abstract/gate.js +0 -9
  153. package/dist/cjs/js/src/abstract/gemini.js +0 -9
  154. package/dist/cjs/js/src/abstract/hitbtc.js +0 -9
  155. package/dist/cjs/js/src/abstract/hollaex.js +0 -9
  156. package/dist/cjs/js/src/abstract/htx.js +0 -9
  157. package/dist/cjs/js/src/abstract/huobijp.js +0 -9
  158. package/dist/cjs/js/src/abstract/idex.js +0 -9
  159. package/dist/cjs/js/src/abstract/independentreserve.js +0 -9
  160. package/dist/cjs/js/src/abstract/indodax.js +0 -9
  161. package/dist/cjs/js/src/abstract/kraken.js +0 -9
  162. package/dist/cjs/js/src/abstract/krakenfutures.js +0 -9
  163. package/dist/cjs/js/src/abstract/kucoin.js +0 -9
  164. package/dist/cjs/js/src/abstract/kucoinfutures.js +0 -9
  165. package/dist/cjs/js/src/abstract/kuna.js +0 -9
  166. package/dist/cjs/js/src/abstract/latoken.js +0 -9
  167. package/dist/cjs/js/src/abstract/lbank.js +0 -9
  168. package/dist/cjs/js/src/abstract/luno.js +0 -9
  169. package/dist/cjs/js/src/abstract/lykke.js +0 -9
  170. package/dist/cjs/js/src/abstract/mercado.js +0 -9
  171. package/dist/cjs/js/src/abstract/mexc.js +0 -9
  172. package/dist/cjs/js/src/abstract/ndax.js +0 -9
  173. package/dist/cjs/js/src/abstract/novadax.js +0 -9
  174. package/dist/cjs/js/src/abstract/oceanex.js +0 -9
  175. package/dist/cjs/js/src/abstract/okcoin.js +0 -9
  176. package/dist/cjs/js/src/abstract/okx.js +0 -9
  177. package/dist/cjs/js/src/abstract/p2b.js +0 -9
  178. package/dist/cjs/js/src/abstract/paymium.js +0 -9
  179. package/dist/cjs/js/src/abstract/phemex.js +0 -9
  180. package/dist/cjs/js/src/abstract/poloniex.js +0 -9
  181. package/dist/cjs/js/src/abstract/poloniexfutures.js +0 -9
  182. package/dist/cjs/js/src/abstract/probit.js +0 -9
  183. package/dist/cjs/js/src/abstract/timex.js +0 -9
  184. package/dist/cjs/js/src/abstract/tokocrypto.js +0 -9
  185. package/dist/cjs/js/src/abstract/upbit.js +0 -9
  186. package/dist/cjs/js/src/abstract/wavesexchange.js +0 -9
  187. package/dist/cjs/js/src/abstract/wazirx.js +0 -9
  188. package/dist/cjs/js/src/abstract/whitebit.js +0 -9
  189. package/dist/cjs/js/src/abstract/woo.js +0 -9
  190. package/dist/cjs/js/src/abstract/yobit.js +0 -9
  191. package/dist/cjs/js/src/abstract/zaif.js +0 -9
  192. package/dist/cjs/js/src/abstract/zonda.js +0 -9
  193. package/dist/cjs/js/src/ace.js +0 -1058
  194. package/dist/cjs/js/src/alpaca.js +0 -1125
  195. package/dist/cjs/js/src/ascendex.js +0 -3365
  196. package/dist/cjs/js/src/base/Exchange.js +0 -5260
  197. package/dist/cjs/js/src/base/Precise.js +0 -263
  198. package/dist/cjs/js/src/base/errors.js +0 -299
  199. package/dist/cjs/js/src/base/functions/crypto.js +0 -78
  200. package/dist/cjs/js/src/base/functions/encode.js +0 -44
  201. package/dist/cjs/js/src/base/functions/generic.js +0 -193
  202. package/dist/cjs/js/src/base/functions/misc.js +0 -96
  203. package/dist/cjs/js/src/base/functions/number.js +0 -297
  204. package/dist/cjs/js/src/base/functions/platform.js +0 -28
  205. package/dist/cjs/js/src/base/functions/rsa.js +0 -34
  206. package/dist/cjs/js/src/base/functions/string.js +0 -48
  207. package/dist/cjs/js/src/base/functions/throttle.js +0 -66
  208. package/dist/cjs/js/src/base/functions/time.js +0 -187
  209. package/dist/cjs/js/src/base/functions/totp.js +0 -24
  210. package/dist/cjs/js/src/base/functions/type.js +0 -162
  211. package/dist/cjs/js/src/base/functions.js +0 -157
  212. package/dist/cjs/js/src/base/ws/Cache.js +0 -254
  213. package/dist/cjs/js/src/base/ws/Client.js +0 -299
  214. package/dist/cjs/js/src/base/ws/Future.js +0 -34
  215. package/dist/cjs/js/src/base/ws/OrderBook.js +0 -107
  216. package/dist/cjs/js/src/base/ws/OrderBookSide.js +0 -281
  217. package/dist/cjs/js/src/base/ws/WsClient.js +0 -69
  218. package/dist/cjs/js/src/bequant.js +0 -33
  219. package/dist/cjs/js/src/bigone.js +0 -2213
  220. package/dist/cjs/js/src/binance.js +0 -9851
  221. package/dist/cjs/js/src/binancecoinm.js +0 -45
  222. package/dist/cjs/js/src/binanceus.js +0 -92
  223. package/dist/cjs/js/src/binanceusdm.js +0 -58
  224. package/dist/cjs/js/src/bingx.js +0 -3872
  225. package/dist/cjs/js/src/bit2c.js +0 -916
  226. package/dist/cjs/js/src/bitbank.js +0 -1000
  227. package/dist/cjs/js/src/bitbay.js +0 -17
  228. package/dist/cjs/js/src/bitbns.js +0 -1220
  229. package/dist/cjs/js/src/bitcoincom.js +0 -17
  230. package/dist/cjs/js/src/bitfinex.js +0 -1670
  231. package/dist/cjs/js/src/bitfinex2.js +0 -2990
  232. package/dist/cjs/js/src/bitflyer.js +0 -1045
  233. package/dist/cjs/js/src/bitforex.js +0 -852
  234. package/dist/cjs/js/src/bitget.js +0 -8295
  235. package/dist/cjs/js/src/bithumb.js +0 -1090
  236. package/dist/cjs/js/src/bitmart.js +0 -4454
  237. package/dist/cjs/js/src/bitmex.js +0 -2881
  238. package/dist/cjs/js/src/bitopro.js +0 -1724
  239. package/dist/cjs/js/src/bitrue.js +0 -3253
  240. package/dist/cjs/js/src/bitso.js +0 -1753
  241. package/dist/cjs/js/src/bitstamp.js +0 -2188
  242. package/dist/cjs/js/src/bitteam.js +0 -2309
  243. package/dist/cjs/js/src/bitvavo.js +0 -1968
  244. package/dist/cjs/js/src/bl3p.js +0 -447
  245. package/dist/cjs/js/src/blockchaincom.js +0 -1160
  246. package/dist/cjs/js/src/btcalpha.js +0 -929
  247. package/dist/cjs/js/src/btcbox.js +0 -565
  248. package/dist/cjs/js/src/btcmarkets.js +0 -1237
  249. package/dist/cjs/js/src/btcturk.js +0 -929
  250. package/dist/cjs/js/src/bybit.js +0 -7624
  251. package/dist/cjs/js/src/cex.js +0 -1693
  252. package/dist/cjs/js/src/coinbase.js +0 -3424
  253. package/dist/cjs/js/src/coinbasepro.js +0 -1866
  254. package/dist/cjs/js/src/coincheck.js +0 -844
  255. package/dist/cjs/js/src/coinex.js +0 -5417
  256. package/dist/cjs/js/src/coinlist.js +0 -2337
  257. package/dist/cjs/js/src/coinmate.js +0 -989
  258. package/dist/cjs/js/src/coinone.js +0 -1185
  259. package/dist/cjs/js/src/coinsph.js +0 -1933
  260. package/dist/cjs/js/src/coinspot.js +0 -548
  261. package/dist/cjs/js/src/cryptocom.js +0 -3007
  262. package/dist/cjs/js/src/currencycom.js +0 -2015
  263. package/dist/cjs/js/src/delta.js +0 -3262
  264. package/dist/cjs/js/src/deribit.js +0 -3310
  265. package/dist/cjs/js/src/digifinex.js +0 -4307
  266. package/dist/cjs/js/src/exmo.js +0 -2645
  267. package/dist/cjs/js/src/fmfwio.js +0 -34
  268. package/dist/cjs/js/src/gate.js +0 -7077
  269. package/dist/cjs/js/src/gateio.js +0 -16
  270. package/dist/cjs/js/src/gemini.js +0 -1801
  271. package/dist/cjs/js/src/hitbtc.js +0 -3660
  272. package/dist/cjs/js/src/hitbtc3.js +0 -19
  273. package/dist/cjs/js/src/hollaex.js +0 -1882
  274. package/dist/cjs/js/src/htx.js +0 -9174
  275. package/dist/cjs/js/src/huobi.js +0 -16
  276. package/dist/cjs/js/src/huobijp.js +0 -1918
  277. package/dist/cjs/js/src/idex.js +0 -1770
  278. package/dist/cjs/js/src/independentreserve.js +0 -761
  279. package/dist/cjs/js/src/indodax.js +0 -1069
  280. package/dist/cjs/js/src/kraken.js +0 -2891
  281. package/dist/cjs/js/src/krakenfutures.js +0 -2407
  282. package/dist/cjs/js/src/kucoin.js +0 -4494
  283. package/dist/cjs/js/src/kucoinfutures.js +0 -2529
  284. package/dist/cjs/js/src/kuna.js +0 -1949
  285. package/dist/cjs/js/src/latoken.js +0 -1729
  286. package/dist/cjs/js/src/lbank.js +0 -2851
  287. package/dist/cjs/js/src/luno.js +0 -1044
  288. package/dist/cjs/js/src/lykke.js +0 -1303
  289. package/dist/cjs/js/src/mercado.js +0 -897
  290. package/dist/cjs/js/src/mexc.js +0 -5407
  291. package/dist/cjs/js/src/ndax.js +0 -2450
  292. package/dist/cjs/js/src/novadax.js +0 -1556
  293. package/dist/cjs/js/src/oceanex.js +0 -964
  294. package/dist/cjs/js/src/okcoin.js +0 -3115
  295. package/dist/cjs/js/src/okx.js +0 -7331
  296. package/dist/cjs/js/src/p2b.js +0 -1243
  297. package/dist/cjs/js/src/paymium.js +0 -597
  298. package/dist/cjs/js/src/phemex.js +0 -4725
  299. package/dist/cjs/js/src/poloniex.js +0 -2356
  300. package/dist/cjs/js/src/poloniexfutures.js +0 -1794
  301. package/dist/cjs/js/src/pro/alpaca.js +0 -714
  302. package/dist/cjs/js/src/pro/ascendex.js +0 -957
  303. package/dist/cjs/js/src/pro/bequant.js +0 -33
  304. package/dist/cjs/js/src/pro/binance.js +0 -2796
  305. package/dist/cjs/js/src/pro/binancecoinm.js +0 -23
  306. package/dist/cjs/js/src/pro/binanceus.js +0 -51
  307. package/dist/cjs/js/src/pro/binanceusdm.js +0 -32
  308. package/dist/cjs/js/src/pro/bingx.js +0 -944
  309. package/dist/cjs/js/src/pro/bitcoincom.js +0 -29
  310. package/dist/cjs/js/src/pro/bitfinex.js +0 -672
  311. package/dist/cjs/js/src/pro/bitfinex2.js +0 -1159
  312. package/dist/cjs/js/src/pro/bitget.js +0 -1733
  313. package/dist/cjs/js/src/pro/bitmart.js +0 -1486
  314. package/dist/cjs/js/src/pro/bitmex.js +0 -1576
  315. package/dist/cjs/js/src/pro/bitopro.js +0 -327
  316. package/dist/cjs/js/src/pro/bitrue.js +0 -462
  317. package/dist/cjs/js/src/pro/bitstamp.js +0 -547
  318. package/dist/cjs/js/src/pro/bitvavo.js +0 -704
  319. package/dist/cjs/js/src/pro/blockchaincom.js +0 -794
  320. package/dist/cjs/js/src/pro/bybit.js +0 -1843
  321. package/dist/cjs/js/src/pro/cex.js +0 -1510
  322. package/dist/cjs/js/src/pro/coinbase.js +0 -561
  323. package/dist/cjs/js/src/pro/coinbasepro.js +0 -968
  324. package/dist/cjs/js/src/pro/coinex.js +0 -1095
  325. package/dist/cjs/js/src/pro/cryptocom.js +0 -1020
  326. package/dist/cjs/js/src/pro/currencycom.js +0 -563
  327. package/dist/cjs/js/src/pro/deribit.js +0 -825
  328. package/dist/cjs/js/src/pro/exmo.js +0 -658
  329. package/dist/cjs/js/src/pro/gate.js +0 -1316
  330. package/dist/cjs/js/src/pro/gateio.js +0 -16
  331. package/dist/cjs/js/src/pro/gemini.js +0 -649
  332. package/dist/cjs/js/src/pro/hitbtc.js +0 -1294
  333. package/dist/cjs/js/src/pro/hollaex.js +0 -597
  334. package/dist/cjs/js/src/pro/htx.js +0 -2388
  335. package/dist/cjs/js/src/pro/huobi.js +0 -16
  336. package/dist/cjs/js/src/pro/huobijp.js +0 -606
  337. package/dist/cjs/js/src/pro/idex.js +0 -714
  338. package/dist/cjs/js/src/pro/independentreserve.js +0 -280
  339. package/dist/cjs/js/src/pro/kraken.js +0 -1364
  340. package/dist/cjs/js/src/pro/krakenfutures.js +0 -1506
  341. package/dist/cjs/js/src/pro/kucoin.js +0 -1062
  342. package/dist/cjs/js/src/pro/kucoinfutures.js +0 -989
  343. package/dist/cjs/js/src/pro/luno.js +0 -322
  344. package/dist/cjs/js/src/pro/mexc.js +0 -1170
  345. package/dist/cjs/js/src/pro/ndax.js +0 -545
  346. package/dist/cjs/js/src/pro/okcoin.js +0 -760
  347. package/dist/cjs/js/src/pro/okx.js +0 -1608
  348. package/dist/cjs/js/src/pro/phemex.js +0 -1511
  349. package/dist/cjs/js/src/pro/poloniex.js +0 -1253
  350. package/dist/cjs/js/src/pro/poloniexfutures.js +0 -1022
  351. package/dist/cjs/js/src/pro/probit.js +0 -586
  352. package/dist/cjs/js/src/pro/upbit.js +0 -234
  353. package/dist/cjs/js/src/pro/wazirx.js +0 -776
  354. package/dist/cjs/js/src/pro/whitebit.js +0 -927
  355. package/dist/cjs/js/src/pro/woo.js +0 -895
  356. package/dist/cjs/js/src/probit.js +0 -1867
  357. package/dist/cjs/js/src/static_dependencies/fflake/browser.js +0 -401
  358. package/dist/cjs/js/src/static_dependencies/jsencrypt/JSEncrypt.js +0 -195
  359. package/dist/cjs/js/src/static_dependencies/jsencrypt/JSEncryptRSAKey.js +0 -308
  360. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/asn1js/asn1.js +0 -554
  361. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/asn1js/base64.js +0 -94
  362. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/asn1js/hex.js +0 -70
  363. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/asn1js/int10.js +0 -91
  364. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/base64.js +0 -16
  365. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/jsbn.js +0 -1760
  366. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/prng4.js +0 -52
  367. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/rng.js +0 -81
  368. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/rsa.js +0 -376
  369. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/util.js +0 -70
  370. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsrsasign/asn1-1.0.js +0 -1580
  371. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsrsasign/yahoo.js +0 -74
  372. package/dist/cjs/js/src/static_dependencies/noble-curves/_shortw_utils.js +0 -24
  373. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/curve.js +0 -158
  374. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/edwards.js +0 -429
  375. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/hash-to-curve.js +0 -176
  376. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/modular.js +0 -324
  377. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/montgomery.js +0 -163
  378. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/utils.js +0 -245
  379. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/weierstrass.js +0 -1018
  380. package/dist/cjs/js/src/static_dependencies/noble-curves/ed25519.js +0 -383
  381. package/dist/cjs/js/src/static_dependencies/noble-curves/secp256k1.js +0 -258
  382. package/dist/cjs/js/src/static_dependencies/noble-hashes/_assert.js +0 -53
  383. package/dist/cjs/js/src/static_dependencies/noble-hashes/_sha2.js +0 -120
  384. package/dist/cjs/js/src/static_dependencies/noble-hashes/_u64.js +0 -69
  385. package/dist/cjs/js/src/static_dependencies/noble-hashes/crypto.js +0 -7
  386. package/dist/cjs/js/src/static_dependencies/noble-hashes/hmac.js +0 -83
  387. package/dist/cjs/js/src/static_dependencies/noble-hashes/md5.js +0 -240
  388. package/dist/cjs/js/src/static_dependencies/noble-hashes/sha1.js +0 -91
  389. package/dist/cjs/js/src/static_dependencies/noble-hashes/sha256.js +0 -130
  390. package/dist/cjs/js/src/static_dependencies/noble-hashes/sha3.js +0 -214
  391. package/dist/cjs/js/src/static_dependencies/noble-hashes/sha512.js +0 -239
  392. package/dist/cjs/js/src/static_dependencies/noble-hashes/utils.js +0 -93
  393. package/dist/cjs/js/src/static_dependencies/node-fetch/body.js +0 -354
  394. package/dist/cjs/js/src/static_dependencies/node-fetch/errors/abort-error.js +0 -16
  395. package/dist/cjs/js/src/static_dependencies/node-fetch/errors/base.js +0 -20
  396. package/dist/cjs/js/src/static_dependencies/node-fetch/errors/fetch-error.js +0 -30
  397. package/dist/cjs/js/src/static_dependencies/node-fetch/headers.js +0 -239
  398. package/dist/cjs/js/src/static_dependencies/node-fetch/index.js +0 -372
  399. package/dist/cjs/js/src/static_dependencies/node-fetch/request.js +0 -273
  400. package/dist/cjs/js/src/static_dependencies/node-fetch/response.js +0 -139
  401. package/dist/cjs/js/src/static_dependencies/node-fetch/utils/get-search.js +0 -14
  402. package/dist/cjs/js/src/static_dependencies/node-fetch/utils/is-redirect.js +0 -16
  403. package/dist/cjs/js/src/static_dependencies/node-fetch/utils/is.js +0 -81
  404. package/dist/cjs/js/src/static_dependencies/node-fetch/utils/referrer.js +0 -292
  405. package/dist/cjs/js/src/static_dependencies/proxies/agent-base/index.js +0 -103
  406. package/dist/cjs/js/src/static_dependencies/proxies/http-proxy-agent/index.js +0 -140
  407. package/dist/cjs/js/src/static_dependencies/proxies/https-proxy-agent/index.js +0 -175
  408. package/dist/cjs/js/src/static_dependencies/proxies/https-proxy-agent/parse-proxy-response.js +0 -95
  409. package/dist/cjs/js/src/static_dependencies/qs/index.cjs.js +0 -7
  410. package/dist/cjs/js/src/static_dependencies/scure-base/index.js +0 -383
  411. package/dist/cjs/js/src/timex.js +0 -1562
  412. package/dist/cjs/js/src/tokocrypto.js +0 -2542
  413. package/dist/cjs/js/src/upbit.js +0 -1844
  414. package/dist/cjs/js/src/wavesexchange.js +0 -2607
  415. package/dist/cjs/js/src/wazirx.js +0 -953
  416. package/dist/cjs/js/src/whitebit.js +0 -2310
  417. package/dist/cjs/js/src/woo.js +0 -2769
  418. package/dist/cjs/js/src/yobit.js +0 -1314
  419. package/dist/cjs/js/src/zaif.js +0 -736
  420. package/dist/cjs/js/src/zonda.js +0 -1883
  421. package/dist/cjs/src/abstract/bitpanda.js +0 -9
  422. package/test.ts +0 -0
  423. /package/dist/cjs/{js/src/abstract/ace.js → src/abstract/onetrading.js} +0 -0
  424. /package/dist/cjs/{js/src → src}/pro/coincheck.js +0 -0
  425. /package/dist/cjs/{js/src → src}/pro/coinone.js +0 -0
  426. /package/js/src/abstract/{bitpanda.js → onetrading.js} +0 -0
@@ -1,3310 +0,0 @@
1
- 'use strict';
2
-
3
- var deribit$1 = require('./abstract/deribit.js');
4
- var number = require('./base/functions/number.js');
5
- var errors = require('./base/errors.js');
6
- var Precise = require('./base/Precise.js');
7
- var sha256 = require('./static_dependencies/noble-hashes/sha256.js');
8
- var totp = require('./base/functions/totp.js');
9
-
10
- // ---------------------------------------------------------------------------
11
- // ---------------------------------------------------------------------------
12
- /**
13
- * @class deribit
14
- * @augments Exchange
15
- */
16
- class deribit extends deribit$1 {
17
- describe() {
18
- return this.deepExtend(super.describe(), {
19
- 'id': 'deribit',
20
- 'name': 'Deribit',
21
- 'countries': ['NL'],
22
- 'version': 'v2',
23
- 'userAgent': undefined,
24
- // 20 requests per second for non-matching-engine endpoints, 1000ms / 20 = 50ms between requests
25
- // 5 requests per second for matching-engine endpoints, cost = (1000ms / rateLimit) / 5 = 4
26
- 'rateLimit': 50,
27
- 'pro': true,
28
- 'has': {
29
- 'CORS': true,
30
- 'spot': false,
31
- 'margin': false,
32
- 'swap': true,
33
- 'future': true,
34
- 'option': true,
35
- 'cancelAllOrders': true,
36
- 'cancelOrder': true,
37
- 'cancelOrders': false,
38
- 'createDepositAddress': true,
39
- 'createOrder': true,
40
- 'createStopLimitOrder': true,
41
- 'createStopMarketOrder': true,
42
- 'createStopOrder': true,
43
- 'createTrailingAmountOrder': true,
44
- 'editOrder': true,
45
- 'fetchAccounts': true,
46
- 'fetchBalance': true,
47
- 'fetchBorrowRateHistories': false,
48
- 'fetchBorrowRateHistory': false,
49
- 'fetchClosedOrders': true,
50
- 'fetchCrossBorrowRate': false,
51
- 'fetchCrossBorrowRates': false,
52
- 'fetchCurrencies': true,
53
- 'fetchDeposit': false,
54
- 'fetchDepositAddress': true,
55
- 'fetchDeposits': true,
56
- 'fetchDepositWithdrawFees': true,
57
- 'fetchFundingRate': true,
58
- 'fetchFundingRateHistory': true,
59
- 'fetchGreeks': true,
60
- 'fetchIndexOHLCV': false,
61
- 'fetchIsolatedBorrowRate': false,
62
- 'fetchIsolatedBorrowRates': false,
63
- 'fetchLeverageTiers': false,
64
- 'fetchLiquidations': true,
65
- 'fetchMarginMode': false,
66
- 'fetchMarkets': true,
67
- 'fetchMarkOHLCV': false,
68
- 'fetchMyLiquidations': true,
69
- 'fetchMySettlementHistory': false,
70
- 'fetchMyTrades': true,
71
- 'fetchOHLCV': true,
72
- 'fetchOpenOrders': true,
73
- 'fetchOrder': true,
74
- 'fetchOrderBook': true,
75
- 'fetchOrders': false,
76
- 'fetchOrderTrades': true,
77
- 'fetchPosition': true,
78
- 'fetchPositionMode': false,
79
- 'fetchPositions': true,
80
- 'fetchPremiumIndexOHLCV': false,
81
- 'fetchStatus': true,
82
- 'fetchTicker': true,
83
- 'fetchTickers': true,
84
- 'fetchTime': true,
85
- 'fetchTrades': true,
86
- 'fetchTradingFee': false,
87
- 'fetchTradingFees': true,
88
- 'fetchTransactions': false,
89
- 'fetchTransfer': false,
90
- 'fetchTransfers': true,
91
- 'fetchUnderlyingAssets': false,
92
- 'fetchVolatilityHistory': true,
93
- 'fetchWithdrawal': false,
94
- 'fetchWithdrawals': true,
95
- 'transfer': true,
96
- 'withdraw': true,
97
- },
98
- 'timeframes': {
99
- '1m': '1',
100
- '3m': '3',
101
- '5m': '5',
102
- '10m': '10',
103
- '15m': '15',
104
- '30m': '30',
105
- '1h': '60',
106
- '2h': '120',
107
- '3h': '180',
108
- '6h': '360',
109
- '12h': '720',
110
- '1d': '1D',
111
- },
112
- 'urls': {
113
- 'test': {
114
- 'rest': 'https://test.deribit.com',
115
- },
116
- 'logo': 'https://user-images.githubusercontent.com/1294454/41933112-9e2dd65a-798b-11e8-8440-5bab2959fcb8.jpg',
117
- 'api': {
118
- 'rest': 'https://www.deribit.com',
119
- },
120
- 'www': 'https://www.deribit.com',
121
- 'doc': [
122
- 'https://docs.deribit.com/v2',
123
- 'https://github.com/deribit',
124
- ],
125
- 'fees': 'https://www.deribit.com/pages/information/fees',
126
- 'referral': {
127
- 'url': 'https://www.deribit.com/reg-1189.4038',
128
- 'discount': 0.1,
129
- },
130
- },
131
- 'api': {
132
- 'public': {
133
- 'get': {
134
- // Authentication
135
- 'auth': 1,
136
- 'exchange_token': 1,
137
- 'fork_token': 1,
138
- // Session management
139
- 'set_heartbeat': 1,
140
- 'disable_heartbeat': 1,
141
- // Supporting
142
- 'get_time': 1,
143
- 'hello': 1,
144
- 'status': 1,
145
- 'test': 1,
146
- // Subscription management
147
- 'subscribe': 1,
148
- 'unsubscribe': 1,
149
- 'unsubscribe_all': 1,
150
- // Account management
151
- 'get_announcements': 1,
152
- // Market data
153
- 'get_book_summary_by_currency': 1,
154
- 'get_book_summary_by_instrument': 1,
155
- 'get_contract_size': 1,
156
- 'get_currencies': 1,
157
- 'get_delivery_prices': 1,
158
- 'get_funding_chart_data': 1,
159
- 'get_funding_rate_history': 1,
160
- 'get_funding_rate_value': 1,
161
- 'get_historical_volatility': 1,
162
- 'get_index': 1,
163
- 'get_index_price': 1,
164
- 'get_index_price_names': 1,
165
- 'get_instrument': 1,
166
- 'get_instruments': 1,
167
- 'get_last_settlements_by_currency': 1,
168
- 'get_last_settlements_by_instrument': 1,
169
- 'get_last_trades_by_currency': 1,
170
- 'get_last_trades_by_currency_and_time': 1,
171
- 'get_last_trades_by_instrument': 1,
172
- 'get_last_trades_by_instrument_and_time': 1,
173
- 'get_mark_price_history': 1,
174
- 'get_order_book': 1,
175
- 'get_trade_volumes': 1,
176
- 'get_tradingview_chart_data': 1,
177
- 'get_volatility_index_data': 1,
178
- 'ticker': 1,
179
- },
180
- },
181
- 'private': {
182
- 'get': {
183
- // Authentication
184
- 'logout': 1,
185
- // Session management
186
- 'enable_cancel_on_disconnect': 1,
187
- 'disable_cancel_on_disconnect': 1,
188
- 'get_cancel_on_disconnect': 1,
189
- // Subscription management
190
- 'subscribe': 1,
191
- 'unsubscribe': 1,
192
- 'unsubscribe_all': 1,
193
- // Account management
194
- 'change_api_key_name': 1,
195
- 'change_scope_in_api_key': 1,
196
- 'change_subaccount_name': 1,
197
- 'create_api_key': 1,
198
- 'create_subaccount': 1,
199
- 'disable_api_key': 1,
200
- 'disable_tfa_for_subaccount': 1,
201
- 'enable_affiliate_program': 1,
202
- 'enable_api_key': 1,
203
- 'get_access_log': 1,
204
- 'get_account_summary': 1,
205
- 'get_affiliate_program_info': 1,
206
- 'get_email_language': 1,
207
- 'get_new_announcements': 1,
208
- 'get_portfolio_margins': 1,
209
- 'get_position': 1,
210
- 'get_positions': 1,
211
- 'get_subaccounts': 1,
212
- 'get_subaccounts_details': 1,
213
- 'get_transaction_log': 1,
214
- 'list_api_keys': 1,
215
- 'remove_api_key': 1,
216
- 'remove_subaccount': 1,
217
- 'reset_api_key': 1,
218
- 'set_announcement_as_read': 1,
219
- 'set_api_key_as_default': 1,
220
- 'set_email_for_subaccount': 1,
221
- 'set_email_language': 1,
222
- 'set_password_for_subaccount': 1,
223
- 'toggle_notifications_from_subaccount': 1,
224
- 'toggle_subaccount_login': 1,
225
- // Block Trade
226
- 'execute_block_trade': 4,
227
- 'get_block_trade': 1,
228
- 'get_last_block_trades_by_currency': 1,
229
- 'invalidate_block_trade_signature': 1,
230
- 'verify_block_trade': 4,
231
- // Trading
232
- 'buy': 4,
233
- 'sell': 4,
234
- 'edit': 4,
235
- 'edit_by_label': 4,
236
- 'cancel': 4,
237
- 'cancel_all': 4,
238
- 'cancel_all_by_currency': 4,
239
- 'cancel_all_by_instrument': 4,
240
- 'cancel_by_label': 4,
241
- 'close_position': 4,
242
- 'get_margins': 1,
243
- 'get_mmp_config': 1,
244
- 'get_open_orders_by_currency': 1,
245
- 'get_open_orders_by_instrument': 1,
246
- 'get_order_history_by_currency': 1,
247
- 'get_order_history_by_instrument': 1,
248
- 'get_order_margin_by_ids': 1,
249
- 'get_order_state': 1,
250
- 'get_stop_order_history': 1,
251
- 'get_trigger_order_history': 1,
252
- 'get_user_trades_by_currency': 1,
253
- 'get_user_trades_by_currency_and_time': 1,
254
- 'get_user_trades_by_instrument': 1,
255
- 'get_user_trades_by_instrument_and_time': 1,
256
- 'get_user_trades_by_order': 1,
257
- 'reset_mmp': 1,
258
- 'set_mmp_config': 1,
259
- 'get_settlement_history_by_instrument': 1,
260
- 'get_settlement_history_by_currency': 1,
261
- // Wallet
262
- 'cancel_transfer_by_id': 1,
263
- 'cancel_withdrawal': 1,
264
- 'create_deposit_address': 1,
265
- 'get_current_deposit_address': 1,
266
- 'get_deposits': 1,
267
- 'get_transfers': 1,
268
- 'get_withdrawals': 1,
269
- 'submit_transfer_to_subaccount': 1,
270
- 'submit_transfer_to_user': 1,
271
- 'withdraw': 1,
272
- },
273
- },
274
- },
275
- 'exceptions': {
276
- // 0 or absent Success, No error.
277
- '9999': errors.PermissionDenied,
278
- '10000': errors.AuthenticationError,
279
- '10001': errors.ExchangeError,
280
- '10002': errors.InvalidOrder,
281
- '10003': errors.InvalidOrder,
282
- '10004': errors.OrderNotFound,
283
- '10005': errors.InvalidOrder,
284
- '10006': errors.InvalidOrder,
285
- '10007': errors.InvalidOrder,
286
- '10008': errors.InvalidOrder,
287
- '10009': errors.InsufficientFunds,
288
- '10010': errors.OrderNotFound,
289
- '10011': errors.InvalidOrder,
290
- '10012': errors.InvalidOrder,
291
- '10013': errors.PermissionDenied,
292
- '10014': errors.PermissionDenied,
293
- '10015': errors.PermissionDenied,
294
- '10016': errors.PermissionDenied,
295
- '10017': errors.PermissionDenied,
296
- '10018': errors.PermissionDenied,
297
- '10019': errors.PermissionDenied,
298
- '10020': errors.ExchangeError,
299
- '10021': errors.InvalidOrder,
300
- '10022': errors.InvalidOrder,
301
- '10023': errors.InvalidOrder,
302
- '10024': errors.InvalidOrder,
303
- '10025': errors.InvalidOrder,
304
- '10026': errors.InvalidOrder,
305
- '10027': errors.InvalidOrder,
306
- '10028': errors.DDoSProtection,
307
- '10029': errors.OrderNotFound,
308
- '10030': errors.ExchangeError,
309
- '10031': errors.ExchangeError,
310
- '10032': errors.InvalidOrder,
311
- '10033': errors.NotSupported,
312
- '10034': errors.InvalidOrder,
313
- '10035': errors.InvalidOrder,
314
- '10036': errors.InvalidOrder,
315
- '10040': errors.ExchangeNotAvailable,
316
- '10041': errors.OnMaintenance,
317
- '10043': errors.InvalidOrder,
318
- '10044': errors.InvalidOrder,
319
- '10045': errors.InvalidOrder,
320
- '10046': errors.InvalidOrder,
321
- '10047': errors.DDoSProtection,
322
- '10048': errors.ExchangeError,
323
- '11008': errors.InvalidOrder,
324
- '11029': errors.BadRequest,
325
- '11030': errors.ExchangeError,
326
- '11031': errors.ExchangeError,
327
- '11035': errors.DDoSProtection,
328
- '11036': errors.InvalidOrder,
329
- '11037': errors.BadRequest,
330
- '11038': errors.InvalidOrder,
331
- '11039': errors.InvalidOrder,
332
- '11041': errors.InvalidOrder,
333
- '11042': errors.PermissionDenied,
334
- '11043': errors.BadRequest,
335
- '11044': errors.InvalidOrder,
336
- '11045': errors.BadRequest,
337
- '11046': errors.BadRequest,
338
- '11047': errors.BadRequest,
339
- '11048': errors.ExchangeError,
340
- '11049': errors.BadRequest,
341
- '11050': errors.BadRequest,
342
- '11051': errors.OnMaintenance,
343
- '11052': errors.ExchangeError,
344
- '11053': errors.ExchangeError,
345
- '11090': errors.InvalidAddress,
346
- '11091': errors.InvalidAddress,
347
- '11092': errors.InvalidAddress,
348
- '11093': errors.DDoSProtection,
349
- '11094': errors.ExchangeError,
350
- '11095': errors.ExchangeError,
351
- '11096': errors.ExchangeError,
352
- '12000': errors.AuthenticationError,
353
- '12001': errors.DDoSProtection,
354
- '12002': errors.ExchangeError,
355
- '12998': errors.AuthenticationError,
356
- '12003': errors.AuthenticationError,
357
- '12004': errors.AuthenticationError,
358
- '12005': errors.AuthenticationError,
359
- '12100': errors.ExchangeError,
360
- '12999': errors.AuthenticationError,
361
- '13000': errors.AuthenticationError,
362
- '13001': errors.AuthenticationError,
363
- '13002': errors.PermissionDenied,
364
- '13003': errors.AuthenticationError,
365
- '13004': errors.AuthenticationError,
366
- '13005': errors.AuthenticationError,
367
- '13006': errors.AuthenticationError,
368
- '13007': errors.AuthenticationError,
369
- '13008': errors.ExchangeError,
370
- '13009': errors.AuthenticationError,
371
- '13010': errors.BadRequest,
372
- '13011': errors.BadRequest,
373
- '13012': errors.PermissionDenied,
374
- '13013': errors.BadRequest,
375
- '13014': errors.BadRequest,
376
- '13015': errors.BadRequest,
377
- '13016': errors.BadRequest,
378
- '13017': errors.ExchangeError,
379
- '13018': errors.ExchangeError,
380
- '13019': errors.ExchangeError,
381
- '13020': errors.ExchangeError,
382
- '13021': errors.PermissionDenied,
383
- '13025': errors.ExchangeError,
384
- '-32602': errors.BadRequest,
385
- '-32601': errors.BadRequest,
386
- '-32700': errors.BadRequest,
387
- '-32000': errors.BadRequest,
388
- '11054': errors.InvalidOrder, // 'post_only_reject' post order would be filled immediately
389
- },
390
- 'precisionMode': number.TICK_SIZE,
391
- 'options': {
392
- 'code': 'BTC',
393
- 'fetchBalance': {
394
- 'code': 'BTC',
395
- },
396
- 'fetchPositions': {
397
- 'code': 'BTC',
398
- },
399
- 'transfer': {
400
- 'method': 'privateGetSubmitTransferToSubaccount', // or 'privateGetSubmitTransferToUser'
401
- },
402
- },
403
- });
404
- }
405
- async fetchTime(params = {}) {
406
- /**
407
- * @method
408
- * @name deribit#fetchTime
409
- * @description fetches the current integer timestamp in milliseconds from the exchange server
410
- * @param {object} [params] extra parameters specific to the exchange API endpoint
411
- * @returns {int} the current integer timestamp in milliseconds from the exchange server
412
- */
413
- const response = await this.publicGetGetTime(params);
414
- //
415
- // {
416
- // "jsonrpc": "2.0",
417
- // "result": 1583922446019,
418
- // "usIn": 1583922446019955,
419
- // "usOut": 1583922446019956,
420
- // "usDiff": 1,
421
- // "testnet": false
422
- // }
423
- //
424
- return this.safeInteger(response, 'result');
425
- }
426
- async fetchCurrencies(params = {}) {
427
- /**
428
- * @method
429
- * @name deribit#fetchCurrencies
430
- * @description fetches all available currencies on an exchange
431
- * @see https://docs.deribit.com/#public-get_currencies
432
- * @param {object} [params] extra parameters specific to the exchange API endpoint
433
- * @returns {object} an associative dictionary of currencies
434
- */
435
- const response = await this.publicGetGetCurrencies(params);
436
- //
437
- // {
438
- // "jsonrpc": "2.0",
439
- // "result": [
440
- // {
441
- // "withdrawal_priorities": [],
442
- // "withdrawal_fee": 0.01457324,
443
- // "min_withdrawal_fee": 0.000001,
444
- // "min_confirmations": 1,
445
- // "fee_precision": 8,
446
- // "currency_long": "Solana",
447
- // "currency": "SOL",
448
- // "coin_type": "SOL"
449
- // },
450
- // ...
451
- // ],
452
- // "usIn": 1688652701456124,
453
- // "usOut": 1688652701456390,
454
- // "usDiff": 266,
455
- // "testnet": true
456
- // }
457
- //
458
- const data = this.safeValue(response, 'result', {});
459
- const result = {};
460
- for (let i = 0; i < data.length; i++) {
461
- const currency = data[i];
462
- const currencyId = this.safeString(currency, 'currency');
463
- const code = this.safeCurrencyCode(currencyId);
464
- const name = this.safeString(currency, 'currency_long');
465
- result[code] = {
466
- 'info': currency,
467
- 'code': code,
468
- 'id': currencyId,
469
- 'name': name,
470
- 'active': undefined,
471
- 'deposit': undefined,
472
- 'withdraw': undefined,
473
- 'fee': this.safeNumber(currency, 'withdrawal_fee'),
474
- 'precision': this.parseNumber(this.parsePrecision(this.safeString(currency, 'fee_precision'))),
475
- 'limits': {
476
- 'amount': {
477
- 'min': undefined,
478
- 'max': undefined,
479
- },
480
- 'withdraw': {
481
- 'min': undefined,
482
- 'max': undefined,
483
- },
484
- 'deposit': {
485
- 'min': undefined,
486
- 'max': undefined,
487
- },
488
- },
489
- 'networks': undefined,
490
- };
491
- }
492
- return result;
493
- }
494
- codeFromOptions(methodName, params = {}) {
495
- const defaultCode = this.safeValue(this.options, 'code', 'BTC');
496
- const options = this.safeValue(this.options, methodName, {});
497
- const code = this.safeValue(options, 'code', defaultCode);
498
- return this.safeValue(params, 'code', code);
499
- }
500
- async fetchStatus(params = {}) {
501
- /**
502
- * @method
503
- * @name deribit#fetchStatus
504
- * @description the latest known information on the availability of the exchange API
505
- * @param {object} [params] extra parameters specific to the exchange API endpoint
506
- * @returns {object} a [status structure]{@link https://docs.ccxt.com/#/?id=exchange-status-structure}
507
- */
508
- const response = await this.publicGetStatus(params);
509
- //
510
- // {
511
- // "jsonrpc": "2.0",
512
- // "result": {
513
- // "locked": "false" // true, partial, false
514
- // },
515
- // "usIn": 1650641690226788,
516
- // "usOut": 1650641690226836,
517
- // "usDiff": 48,
518
- // "testnet": false
519
- // }
520
- //
521
- const result = this.safeValue(response, 'result');
522
- const locked = this.safeString(result, 'locked');
523
- const updateTime = this.safeIntegerProduct(response, 'usIn', 0.001, this.milliseconds());
524
- return {
525
- 'status': (locked === 'false') ? 'ok' : 'maintenance',
526
- 'updated': updateTime,
527
- 'eta': undefined,
528
- 'url': undefined,
529
- 'info': response,
530
- };
531
- }
532
- async fetchAccounts(params = {}) {
533
- /**
534
- * @method
535
- * @name deribit#fetchAccounts
536
- * @description fetch all the accounts associated with a profile
537
- * @param {object} [params] extra parameters specific to the exchange API endpoint
538
- * @returns {object} a dictionary of [account structures]{@link https://docs.ccxt.com/#/?id=account-structure} indexed by the account type
539
- */
540
- await this.loadMarkets();
541
- const response = await this.privateGetGetSubaccounts(params);
542
- //
543
- // {
544
- // "jsonrpc": "2.0",
545
- // "result": [{
546
- // "username": "someusername",
547
- // "type": "main",
548
- // "system_name": "someusername",
549
- // "security_keys_enabled": false,
550
- // "security_keys_assignments": [],
551
- // "receive_notifications": false,
552
- // "login_enabled": true,
553
- // "is_password": true,
554
- // "id": "238216",
555
- // "email": "pablo@abcdef.com"
556
- // },
557
- // {
558
- // "username": "someusername_1",
559
- // "type": "subaccount",
560
- // "system_name": "someusername_1",
561
- // "security_keys_enabled": false,
562
- // "security_keys_assignments": [],
563
- // "receive_notifications": false,
564
- // "login_enabled": false,
565
- // "is_password": false,
566
- // "id": "245499",
567
- // "email": "pablo@abcdef.com"
568
- // }
569
- // ],
570
- // "usIn": "1652736468292006",
571
- // "usOut": "1652736468292377",
572
- // "usDiff": "371",
573
- // "testnet": false
574
- // }
575
- //
576
- const result = this.safeValue(response, 'result', []);
577
- return this.parseAccounts(result);
578
- }
579
- parseAccount(account, currency = undefined) {
580
- //
581
- // {
582
- // "username": "someusername_1",
583
- // "type": "subaccount",
584
- // "system_name": "someusername_1",
585
- // "security_keys_enabled": false,
586
- // "security_keys_assignments": [],
587
- // "receive_notifications": false,
588
- // "login_enabled": false,
589
- // "is_password": false,
590
- // "id": "245499",
591
- // "email": "pablo@abcdef.com"
592
- // }
593
- //
594
- return {
595
- 'info': account,
596
- 'id': this.safeString(account, 'id'),
597
- 'type': this.safeString(account, 'type'),
598
- 'code': this.safeCurrencyCode(undefined, currency),
599
- };
600
- }
601
- async fetchMarkets(params = {}) {
602
- /**
603
- * @method
604
- * @name deribit#fetchMarkets
605
- * @description retrieves data on all markets for deribit
606
- * @param {object} [params] extra parameters specific to the exchange API endpoint
607
- * @returns {object[]} an array of objects representing market data
608
- */
609
- const currenciesResponse = await this.publicGetGetCurrencies(params);
610
- //
611
- // {
612
- // "jsonrpc": "2.0",
613
- // "result": [
614
- // {
615
- // "withdrawal_priorities": [
616
- // { value: 0.15, name: "very_low" },
617
- // { value: 1.5, name: "very_high" },
618
- // ],
619
- // "withdrawal_fee": 0.0005,
620
- // "min_withdrawal_fee": 0.0005,
621
- // "min_confirmations": 1,
622
- // "fee_precision": 4,
623
- // "currency_long": "Bitcoin",
624
- // "currency": "BTC",
625
- // "coin_type": "BITCOIN"
626
- // }
627
- // ],
628
- // "usIn": 1583761588590479,
629
- // "usOut": 1583761588590544,
630
- // "usDiff": 65,
631
- // "testnet": false
632
- // }
633
- //
634
- const parsedMarkets = {};
635
- const currenciesResult = this.safeValue(currenciesResponse, 'result', []);
636
- const result = [];
637
- for (let i = 0; i < currenciesResult.length; i++) {
638
- const currencyId = this.safeString(currenciesResult[i], 'currency');
639
- const request = {
640
- 'currency': currencyId,
641
- };
642
- const instrumentsResponse = await this.publicGetGetInstruments(this.extend(request, params));
643
- //
644
- // {
645
- // "jsonrpc":"2.0",
646
- // "result":[
647
- // {
648
- // "tick_size":0.0005,
649
- // "taker_commission":0.0003,
650
- // "strike":52000.0,
651
- // "settlement_period":"month",
652
- // "settlement_currency":"BTC",
653
- // "quote_currency":"BTC",
654
- // "option_type":"put", // put, call
655
- // "min_trade_amount":0.1,
656
- // "maker_commission":0.0003,
657
- // "kind":"option",
658
- // "is_active":true,
659
- // "instrument_name":"BTC-24JUN22-52000-P",
660
- // "expiration_timestamp":1656057600000,
661
- // "creation_timestamp":1648199543000,
662
- // "counter_currency":"USD",
663
- // "contract_size":1.0,
664
- // "block_trade_commission":0.0003,
665
- // "base_currency":"BTC"
666
- // },
667
- // {
668
- // "tick_size":0.5,
669
- // "taker_commission":0.0005,
670
- // "settlement_period":"month", // month, week
671
- // "settlement_currency":"BTC",
672
- // "quote_currency":"USD",
673
- // "min_trade_amount":10.0,
674
- // "max_liquidation_commission":0.0075,
675
- // "max_leverage":50,
676
- // "maker_commission":0.0,
677
- // "kind":"future",
678
- // "is_active":true,
679
- // "instrument_name":"BTC-27MAY22",
680
- // "future_type":"reversed",
681
- // "expiration_timestamp":1653638400000,
682
- // "creation_timestamp":1648195209000,
683
- // "counter_currency":"USD",
684
- // "contract_size":10.0,
685
- // "block_trade_commission":0.0001,
686
- // "base_currency":"BTC"
687
- // },
688
- // {
689
- // "tick_size":0.5,
690
- // "taker_commission":0.0005,
691
- // "settlement_period":"perpetual",
692
- // "settlement_currency":"BTC",
693
- // "quote_currency":"USD",
694
- // "min_trade_amount":10.0,
695
- // "max_liquidation_commission":0.0075,
696
- // "max_leverage":50,
697
- // "maker_commission":0.0,
698
- // "kind":"future",
699
- // "is_active":true,
700
- // "instrument_name":"BTC-PERPETUAL",
701
- // "future_type":"reversed",
702
- // "expiration_timestamp":32503708800000,
703
- // "creation_timestamp":1534242287000,
704
- // "counter_currency":"USD",
705
- // "contract_size":10.0,
706
- // "block_trade_commission":0.0001,
707
- // "base_currency":"BTC"
708
- // },
709
- // ],
710
- // "usIn":1648691472831791,
711
- // "usOut":1648691472831896,
712
- // "usDiff":105,
713
- // "testnet":false
714
- // }
715
- //
716
- const instrumentsResult = this.safeValue(instrumentsResponse, 'result', []);
717
- for (let k = 0; k < instrumentsResult.length; k++) {
718
- const market = instrumentsResult[k];
719
- const kind = this.safeString(market, 'kind');
720
- const isSpot = (kind === 'spot');
721
- const id = this.safeString(market, 'instrument_name');
722
- const baseId = this.safeString(market, 'base_currency');
723
- const quoteId = this.safeString(market, 'counter_currency');
724
- const settleId = this.safeString(market, 'settlement_currency');
725
- const base = this.safeCurrencyCode(baseId);
726
- const quote = this.safeCurrencyCode(quoteId);
727
- const settle = this.safeCurrencyCode(settleId);
728
- const settlementPeriod = this.safeValue(market, 'settlement_period');
729
- const swap = (settlementPeriod === 'perpetual');
730
- const future = !swap && (kind.indexOf('future') >= 0);
731
- const option = (kind.indexOf('option') >= 0);
732
- const isComboMarket = kind.indexOf('combo') >= 0;
733
- const expiry = this.safeInteger(market, 'expiration_timestamp');
734
- let strike = undefined;
735
- let optionType = undefined;
736
- let symbol = id;
737
- let type = 'swap';
738
- if (future) {
739
- type = 'future';
740
- }
741
- else if (option) {
742
- type = 'option';
743
- }
744
- else if (isSpot) {
745
- type = 'spot';
746
- }
747
- if (isSpot) {
748
- symbol = base + '/' + quote;
749
- }
750
- else if (!isComboMarket) {
751
- symbol = base + '/' + quote + ':' + settle;
752
- if (option || future) {
753
- symbol = symbol + '-' + this.yymmdd(expiry, '');
754
- if (option) {
755
- strike = this.safeNumber(market, 'strike');
756
- optionType = this.safeString(market, 'option_type');
757
- const letter = (optionType === 'call') ? 'C' : 'P';
758
- symbol = symbol + '-' + this.numberToString(strike) + '-' + letter;
759
- }
760
- }
761
- }
762
- const parsedMarketValue = this.safeValue(parsedMarkets, symbol);
763
- if (parsedMarketValue) {
764
- continue;
765
- }
766
- parsedMarkets[symbol] = true;
767
- const minTradeAmount = this.safeNumber(market, 'min_trade_amount');
768
- const tickSize = this.safeNumber(market, 'tick_size');
769
- result.push({
770
- 'id': id,
771
- 'symbol': symbol,
772
- 'base': base,
773
- 'quote': quote,
774
- 'settle': settle,
775
- 'baseId': baseId,
776
- 'quoteId': quoteId,
777
- 'settleId': settleId,
778
- 'type': type,
779
- 'spot': isSpot,
780
- 'margin': false,
781
- 'swap': swap,
782
- 'future': future,
783
- 'option': option,
784
- 'active': this.safeValue(market, 'is_active'),
785
- 'contract': !isSpot,
786
- 'linear': (settle === quote),
787
- 'inverse': (settle !== quote),
788
- 'taker': this.safeNumber(market, 'taker_commission'),
789
- 'maker': this.safeNumber(market, 'maker_commission'),
790
- 'contractSize': this.safeNumber(market, 'contract_size'),
791
- 'expiry': expiry,
792
- 'expiryDatetime': this.iso8601(expiry),
793
- 'strike': strike,
794
- 'optionType': optionType,
795
- 'precision': {
796
- 'amount': minTradeAmount,
797
- 'price': tickSize,
798
- },
799
- 'limits': {
800
- 'leverage': {
801
- 'min': undefined,
802
- 'max': undefined,
803
- },
804
- 'amount': {
805
- 'min': minTradeAmount,
806
- 'max': undefined,
807
- },
808
- 'price': {
809
- 'min': tickSize,
810
- 'max': undefined,
811
- },
812
- 'cost': {
813
- 'min': undefined,
814
- 'max': undefined,
815
- },
816
- },
817
- 'created': this.safeInteger(market, 'creation_timestamp'),
818
- 'info': market,
819
- });
820
- }
821
- }
822
- return result;
823
- }
824
- parseBalance(balance) {
825
- const result = {
826
- 'info': balance,
827
- };
828
- const currencyId = this.safeString(balance, 'currency');
829
- const currencyCode = this.safeCurrencyCode(currencyId);
830
- const account = this.account();
831
- account['free'] = this.safeString(balance, 'available_funds');
832
- account['used'] = this.safeString(balance, 'maintenance_margin');
833
- account['total'] = this.safeString(balance, 'equity');
834
- result[currencyCode] = account;
835
- return this.safeBalance(result);
836
- }
837
- async fetchBalance(params = {}) {
838
- /**
839
- * @method
840
- * @name deribit#fetchBalance
841
- * @description query for balance and get the amount of funds available for trading or funds locked in orders
842
- * @param {object} [params] extra parameters specific to the exchange API endpoint
843
- * @returns {object} a [balance structure]{@link https://docs.ccxt.com/#/?id=balance-structure}
844
- */
845
- await this.loadMarkets();
846
- const code = this.codeFromOptions('fetchBalance', params);
847
- const currency = this.currency(code);
848
- const request = {
849
- 'currency': currency['id'],
850
- };
851
- const response = await this.privateGetGetAccountSummary(this.extend(request, params));
852
- //
853
- // {
854
- // "jsonrpc": "2.0",
855
- // "result": {
856
- // "total_pl": 0,
857
- // "session_upl": 0,
858
- // "session_rpl": 0,
859
- // "session_funding": 0,
860
- // "portfolio_margining_enabled": false,
861
- // "options_vega": 0,
862
- // "options_theta": 0,
863
- // "options_session_upl": 0,
864
- // "options_session_rpl": 0,
865
- // "options_pl": 0,
866
- // "options_gamma": 0,
867
- // "options_delta": 0,
868
- // "margin_balance": 0.00062359,
869
- // "maintenance_margin": 0,
870
- // "limits": {
871
- // "non_matching_engine_burst": 300,
872
- // "non_matching_engine": 200,
873
- // "matching_engine_burst": 20,
874
- // "matching_engine": 2
875
- // },
876
- // "initial_margin": 0,
877
- // "futures_session_upl": 0,
878
- // "futures_session_rpl": 0,
879
- // "futures_pl": 0,
880
- // "equity": 0.00062359,
881
- // "deposit_address": "13tUtNsJSZa1F5GeCmwBywVrymHpZispzw",
882
- // "delta_total": 0,
883
- // "currency": "BTC",
884
- // "balance": 0.00062359,
885
- // "available_withdrawal_funds": 0.00062359,
886
- // "available_funds": 0.00062359
887
- // },
888
- // "usIn": 1583775838115975,
889
- // "usOut": 1583775838116520,
890
- // "usDiff": 545,
891
- // "testnet": false
892
- // }
893
- //
894
- const result = this.safeValue(response, 'result', {});
895
- return this.parseBalance(result);
896
- }
897
- async createDepositAddress(code, params = {}) {
898
- /**
899
- * @method
900
- * @name deribit#createDepositAddress
901
- * @description create a currency deposit address
902
- * @param {string} code unified currency code of the currency for the deposit address
903
- * @param {object} [params] extra parameters specific to the exchange API endpoint
904
- * @returns {object} an [address structure]{@link https://docs.ccxt.com/#/?id=address-structure}
905
- */
906
- await this.loadMarkets();
907
- const currency = this.currency(code);
908
- const request = {
909
- 'currency': currency['id'],
910
- };
911
- const response = await this.privateGetCreateDepositAddress(this.extend(request, params));
912
- //
913
- // {
914
- // "jsonrpc": "2.0",
915
- // "id": 7538,
916
- // "result": {
917
- // "address": "2N8udZGBc1hLRCFsU9kGwMPpmYUwMFTuCwB",
918
- // "creation_timestamp": 1550575165170,
919
- // "currency": "BTC",
920
- // "type": "deposit"
921
- // }
922
- // }
923
- //
924
- const result = this.safeValue(response, 'result', {});
925
- const address = this.safeString(result, 'address');
926
- this.checkAddress(address);
927
- return {
928
- 'currency': code,
929
- 'address': address,
930
- 'tag': undefined,
931
- 'info': response,
932
- };
933
- }
934
- async fetchDepositAddress(code, params = {}) {
935
- /**
936
- * @method
937
- * @name deribit#fetchDepositAddress
938
- * @description fetch the deposit address for a currency associated with this account
939
- * @param {string} code unified currency code
940
- * @param {object} [params] extra parameters specific to the exchange API endpoint
941
- * @returns {object} an [address structure]{@link https://docs.ccxt.com/#/?id=address-structure}
942
- */
943
- await this.loadMarkets();
944
- const currency = this.currency(code);
945
- const request = {
946
- 'currency': currency['id'],
947
- };
948
- const response = await this.privateGetGetCurrentDepositAddress(this.extend(request, params));
949
- //
950
- // {
951
- // "jsonrpc": "2.0",
952
- // "result": {
953
- // "type": "deposit",
954
- // "status": "ready",
955
- // "requires_confirmation": true,
956
- // "currency": "BTC",
957
- // "creation_timestamp": 1514694684651,
958
- // "address": "13tUtNsJSZa1F5GeCmwBywVrymHpZispzw"
959
- // },
960
- // "usIn": 1583785137274288,
961
- // "usOut": 1583785137274454,
962
- // "usDiff": 166,
963
- // "testnet": false
964
- // }
965
- //
966
- const result = this.safeValue(response, 'result', {});
967
- const address = this.safeString(result, 'address');
968
- this.checkAddress(address);
969
- return {
970
- 'currency': code,
971
- 'address': address,
972
- 'tag': undefined,
973
- 'network': undefined,
974
- 'info': response,
975
- };
976
- }
977
- parseTicker(ticker, market = undefined) {
978
- //
979
- // fetchTicker /public/ticker
980
- //
981
- // {
982
- // "timestamp": 1583778859480,
983
- // "stats": { volume: 60627.57263769, low: 7631.5, high: 8311.5 },
984
- // "state": "open",
985
- // "settlement_price": 7903.21,
986
- // "open_interest": 111543850,
987
- // "min_price": 7634,
988
- // "max_price": 7866.51,
989
- // "mark_price": 7750.02,
990
- // "last_price": 7750.5,
991
- // "instrument_name": "BTC-PERPETUAL",
992
- // "index_price": 7748.01,
993
- // "funding_8h": 0.0000026,
994
- // "current_funding": 0,
995
- // "best_bid_price": 7750,
996
- // "best_bid_amount": 19470,
997
- // "best_ask_price": 7750.5,
998
- // "best_ask_amount": 343280
999
- // }
1000
- //
1001
- // fetchTicker /public/get_book_summary_by_instrument
1002
- // fetchTickers /public/get_book_summary_by_currency
1003
- //
1004
- // {
1005
- // "volume": 124.1,
1006
- // "underlying_price": 7856.445926872601,
1007
- // "underlying_index": "SYN.BTC-10MAR20",
1008
- // "quote_currency": "USD",
1009
- // "open_interest": 121.8,
1010
- // "mid_price": 0.01975,
1011
- // "mark_price": 0.01984559,
1012
- // "low": 0.0095,
1013
- // "last": 0.0205,
1014
- // "interest_rate": 0,
1015
- // "instrument_name": "BTC-10MAR20-7750-C",
1016
- // "high": 0.0295,
1017
- // "estimated_delivery_price": 7856.29,
1018
- // "creation_timestamp": 1583783678366,
1019
- // "bid_price": 0.0185,
1020
- // "base_currency": "BTC",
1021
- // "ask_price": 0.021
1022
- // },
1023
- //
1024
- const timestamp = this.safeInteger2(ticker, 'timestamp', 'creation_timestamp');
1025
- const marketId = this.safeString(ticker, 'instrument_name');
1026
- const symbol = this.safeSymbol(marketId, market);
1027
- const last = this.safeString2(ticker, 'last_price', 'last');
1028
- const stats = this.safeValue(ticker, 'stats', ticker);
1029
- return this.safeTicker({
1030
- 'symbol': symbol,
1031
- 'timestamp': timestamp,
1032
- 'datetime': this.iso8601(timestamp),
1033
- 'high': this.safeString2(stats, 'high', 'max_price'),
1034
- 'low': this.safeString2(stats, 'low', 'min_price'),
1035
- 'bid': this.safeString2(ticker, 'best_bid_price', 'bid_price'),
1036
- 'bidVolume': this.safeString(ticker, 'best_bid_amount'),
1037
- 'ask': this.safeString2(ticker, 'best_ask_price', 'ask_price'),
1038
- 'askVolume': this.safeString(ticker, 'best_ask_amount'),
1039
- 'vwap': undefined,
1040
- 'open': undefined,
1041
- 'close': last,
1042
- 'last': last,
1043
- 'previousClose': undefined,
1044
- 'change': undefined,
1045
- 'percentage': undefined,
1046
- 'average': undefined,
1047
- 'baseVolume': undefined,
1048
- 'quoteVolume': this.safeString(stats, 'volume'),
1049
- 'info': ticker,
1050
- }, market);
1051
- }
1052
- async fetchTicker(symbol, params = {}) {
1053
- /**
1054
- * @method
1055
- * @name deribit#fetchTicker
1056
- * @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
1057
- * @param {string} symbol unified symbol of the market to fetch the ticker for
1058
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1059
- * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
1060
- */
1061
- await this.loadMarkets();
1062
- const market = this.market(symbol);
1063
- const request = {
1064
- 'instrument_name': market['id'],
1065
- };
1066
- const response = await this.publicGetTicker(this.extend(request, params));
1067
- //
1068
- // {
1069
- // "jsonrpc": "2.0",
1070
- // "result": {
1071
- // "timestamp": 1583778859480,
1072
- // "stats": { volume: 60627.57263769, low: 7631.5, high: 8311.5 },
1073
- // "state": "open",
1074
- // "settlement_price": 7903.21,
1075
- // "open_interest": 111543850,
1076
- // "min_price": 7634,
1077
- // "max_price": 7866.51,
1078
- // "mark_price": 7750.02,
1079
- // "last_price": 7750.5,
1080
- // "instrument_name": "BTC-PERPETUAL",
1081
- // "index_price": 7748.01,
1082
- // "funding_8h": 0.0000026,
1083
- // "current_funding": 0,
1084
- // "best_bid_price": 7750,
1085
- // "best_bid_amount": 19470,
1086
- // "best_ask_price": 7750.5,
1087
- // "best_ask_amount": 343280
1088
- // },
1089
- // "usIn": 1583778859483941,
1090
- // "usOut": 1583778859484075,
1091
- // "usDiff": 134,
1092
- // "testnet": false
1093
- // }
1094
- //
1095
- const result = this.safeValue(response, 'result');
1096
- return this.parseTicker(result, market);
1097
- }
1098
- async fetchTickers(symbols = undefined, params = {}) {
1099
- /**
1100
- * @method
1101
- * @name deribit#fetchTickers
1102
- * @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
1103
- * @param {string[]|undefined} symbols unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
1104
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1105
- * @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/#/?id=ticker-structure}
1106
- */
1107
- await this.loadMarkets();
1108
- symbols = this.marketSymbols(symbols);
1109
- const code = this.codeFromOptions('fetchTickers', params);
1110
- const currency = this.currency(code);
1111
- const request = {
1112
- 'currency': currency['id'],
1113
- };
1114
- const response = await this.publicGetGetBookSummaryByCurrency(this.extend(request, params));
1115
- //
1116
- // {
1117
- // "jsonrpc": "2.0",
1118
- // "result": [
1119
- // {
1120
- // "volume": 124.1,
1121
- // "underlying_price": 7856.445926872601,
1122
- // "underlying_index": "SYN.BTC-10MAR20",
1123
- // "quote_currency": "USD",
1124
- // "open_interest": 121.8,
1125
- // "mid_price": 0.01975,
1126
- // "mark_price": 0.01984559,
1127
- // "low": 0.0095,
1128
- // "last": 0.0205,
1129
- // "interest_rate": 0,
1130
- // "instrument_name": "BTC-10MAR20-7750-C",
1131
- // "high": 0.0295,
1132
- // "estimated_delivery_price": 7856.29,
1133
- // "creation_timestamp": 1583783678366,
1134
- // "bid_price": 0.0185,
1135
- // "base_currency": "BTC",
1136
- // "ask_price": 0.021
1137
- // },
1138
- // ],
1139
- // "usIn": 1583783678361966,
1140
- // "usOut": 1583783678372069,
1141
- // "usDiff": 10103,
1142
- // "testnet": false
1143
- // }
1144
- //
1145
- const result = this.safeValue(response, 'result', []);
1146
- const tickers = {};
1147
- for (let i = 0; i < result.length; i++) {
1148
- const ticker = this.parseTicker(result[i]);
1149
- const symbol = ticker['symbol'];
1150
- tickers[symbol] = ticker;
1151
- }
1152
- return this.filterByArrayTickers(tickers, 'symbol', symbols);
1153
- }
1154
- async fetchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
1155
- /**
1156
- * @method
1157
- * @name deribit#fetchOHLCV
1158
- * @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
1159
- * @param {string} symbol unified symbol of the market to fetch OHLCV data for
1160
- * @param {string} timeframe the length of time each candle represents
1161
- * @param {int} [since] timestamp in ms of the earliest candle to fetch
1162
- * @param {int} [limit] the maximum amount of candles to fetch
1163
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1164
- * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
1165
- */
1166
- await this.loadMarkets();
1167
- const market = this.market(symbol);
1168
- const request = {
1169
- 'instrument_name': market['id'],
1170
- 'resolution': this.safeString(this.timeframes, timeframe, timeframe),
1171
- };
1172
- const duration = this.parseTimeframe(timeframe);
1173
- const now = this.milliseconds();
1174
- if (since === undefined) {
1175
- if (limit === undefined) {
1176
- limit = 1000; // at max, it provides 5000 bars, but we set generous default here
1177
- }
1178
- request['start_timestamp'] = now - (limit - 1) * duration * 1000;
1179
- request['end_timestamp'] = now;
1180
- }
1181
- else {
1182
- request['start_timestamp'] = since;
1183
- if (limit === undefined) {
1184
- request['end_timestamp'] = now;
1185
- }
1186
- else {
1187
- request['end_timestamp'] = this.sum(since, limit * duration * 1000);
1188
- }
1189
- }
1190
- const response = await this.publicGetGetTradingviewChartData(this.extend(request, params));
1191
- //
1192
- // {
1193
- // "jsonrpc": "2.0",
1194
- // "result": {
1195
- // "volume": [ 3.6680847969999992, 22.682721123, 3.011587939, 0 ],
1196
- // "ticks": [ 1583916960000, 1583917020000, 1583917080000, 1583917140000 ],
1197
- // "status": "ok",
1198
- // "open": [ 7834, 7839, 7833.5, 7833 ],
1199
- // "low": [ 7834, 7833.5, 7832.5, 7833 ],
1200
- // "high": [ 7839.5, 7839, 7833.5, 7833 ],
1201
- // "cost": [ 28740, 177740, 23590, 0 ],
1202
- // "close": [ 7839.5, 7833.5, 7833, 7833 ]
1203
- // },
1204
- // "usIn": 1583917166709801,
1205
- // "usOut": 1583917166710175,
1206
- // "usDiff": 374,
1207
- // "testnet": false
1208
- // }
1209
- //
1210
- const result = this.safeValue(response, 'result', {});
1211
- const ohlcvs = this.convertTradingViewToOHLCV(result, 'ticks', 'open', 'high', 'low', 'close', 'volume', true);
1212
- return this.parseOHLCVs(ohlcvs, market, timeframe, since, limit);
1213
- }
1214
- parseTrade(trade, market = undefined) {
1215
- //
1216
- // fetchTrades (public)
1217
- //
1218
- // {
1219
- // "trade_seq":132564271,
1220
- // "trade_id":"195402220",
1221
- // "timestamp":1639684927932,
1222
- // "tick_direction":0,
1223
- // "price":47946.5,
1224
- // "mark_price":47944.13,
1225
- // "instrument_name":"BTC-PERPETUAL",
1226
- // "index_price":47925.45,
1227
- // "direction":"buy",
1228
- // "amount":580.0
1229
- // }
1230
- //
1231
- //
1232
- // fetchMyTrades, fetchOrderTrades (private)
1233
- //
1234
- // {
1235
- // "trade_seq": 3,
1236
- // "trade_id": "ETH-34066",
1237
- // "timestamp": 1550219814585,
1238
- // "tick_direction": 1,
1239
- // "state": "open",
1240
- // "self_trade": false,
1241
- // "reduce_only": false,
1242
- // "price": 0.04,
1243
- // "post_only": false,
1244
- // "order_type": "limit",
1245
- // "order_id": "ETH-334607",
1246
- // "matching_id": null,
1247
- // "liquidity": "M",
1248
- // "iv": 56.83,
1249
- // "instrument_name": "ETH-22FEB19-120-C",
1250
- // "index_price": 121.37,
1251
- // "fee_currency": "ETH",
1252
- // "fee": 0.0011,
1253
- // "direction": "buy",
1254
- // "amount": 11
1255
- // }
1256
- //
1257
- const id = this.safeString(trade, 'trade_id');
1258
- const marketId = this.safeString(trade, 'instrument_name');
1259
- const symbol = this.safeSymbol(marketId, market);
1260
- const timestamp = this.safeInteger(trade, 'timestamp');
1261
- const side = this.safeString(trade, 'direction');
1262
- const priceString = this.safeString(trade, 'price');
1263
- market = this.safeMarket(marketId, market);
1264
- // Amount for inverse perpetual and futures is in USD which in ccxt is the cost
1265
- // For options amount and linear is in corresponding cryptocurrency contracts, e.g., BTC or ETH
1266
- const amount = this.safeString(trade, 'amount');
1267
- let cost = Precise["default"].stringMul(amount, priceString);
1268
- if (market['inverse']) {
1269
- cost = Precise["default"].stringDiv(amount, priceString);
1270
- }
1271
- const liquidity = this.safeString(trade, 'liquidity');
1272
- let takerOrMaker = undefined;
1273
- if (liquidity !== undefined) {
1274
- // M = maker, T = taker, MT = both
1275
- takerOrMaker = (liquidity === 'M') ? 'maker' : 'taker';
1276
- }
1277
- const feeCostString = this.safeString(trade, 'fee');
1278
- let fee = undefined;
1279
- if (feeCostString !== undefined) {
1280
- const feeCurrencyId = this.safeString(trade, 'fee_currency');
1281
- const feeCurrencyCode = this.safeCurrencyCode(feeCurrencyId);
1282
- fee = {
1283
- 'cost': feeCostString,
1284
- 'currency': feeCurrencyCode,
1285
- };
1286
- }
1287
- return this.safeTrade({
1288
- 'id': id,
1289
- 'info': trade,
1290
- 'timestamp': timestamp,
1291
- 'datetime': this.iso8601(timestamp),
1292
- 'symbol': symbol,
1293
- 'order': this.safeString(trade, 'order_id'),
1294
- 'type': this.safeString(trade, 'order_type'),
1295
- 'side': side,
1296
- 'takerOrMaker': takerOrMaker,
1297
- 'price': priceString,
1298
- 'amount': amount,
1299
- 'cost': cost,
1300
- 'fee': fee,
1301
- }, market);
1302
- }
1303
- async fetchTrades(symbol, since = undefined, limit = undefined, params = {}) {
1304
- /**
1305
- * @method
1306
- * @name deribit#fetchTrades
1307
- * @see https://docs.deribit.com/#private-get_user_trades_by_currency
1308
- * @description get the list of most recent trades for a particular symbol.
1309
- * @param {string} symbol unified symbol of the market to fetch trades for
1310
- * @param {int} [since] timestamp in ms of the earliest trade to fetch
1311
- * @param {int} [limit] the maximum amount of trades to fetch
1312
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1313
- * @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
1314
- */
1315
- await this.loadMarkets();
1316
- const market = this.market(symbol);
1317
- const request = {
1318
- 'instrument_name': market['id'],
1319
- 'include_old': true,
1320
- };
1321
- if (since !== undefined) {
1322
- request['start_timestamp'] = since;
1323
- }
1324
- if (limit !== undefined) {
1325
- request['count'] = Math.min(limit, 1000); // default 10
1326
- }
1327
- let response = undefined;
1328
- if (since === undefined) {
1329
- response = await this.publicGetGetLastTradesByInstrument(this.extend(request, params));
1330
- }
1331
- else {
1332
- response = await this.publicGetGetLastTradesByInstrumentAndTime(this.extend(request, params));
1333
- }
1334
- //
1335
- // {
1336
- // "jsonrpc":"2.0",
1337
- // "result": {
1338
- // "trades": [
1339
- // {
1340
- // "trade_seq":132564271,
1341
- // "trade_id":"195402220",
1342
- // "timestamp":1639684927932,
1343
- // "tick_direction":0,
1344
- // "price":47946.5,
1345
- // "mark_price":47944.13,
1346
- // "instrument_name":"BTC-PERPETUAL",
1347
- // "index_price":47925.45,
1348
- // "direction":"buy","amount":580.0
1349
- // }
1350
- // ],
1351
- // "has_more":true
1352
- // },
1353
- // "usIn":1639684931934671,
1354
- // "usOut":1639684931935337,
1355
- // "usDiff":666,
1356
- // "testnet":false
1357
- // }
1358
- //
1359
- const result = this.safeValue(response, 'result', {});
1360
- const trades = this.safeValue(result, 'trades', []);
1361
- return this.parseTrades(trades, market, since, limit);
1362
- }
1363
- async fetchTradingFees(params = {}) {
1364
- /**
1365
- * @method
1366
- * @name deribit#fetchTradingFees
1367
- * @description fetch the trading fees for multiple markets
1368
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1369
- * @returns {object} a dictionary of [fee structures]{@link https://docs.ccxt.com/#/?id=fee-structure} indexed by market symbols
1370
- */
1371
- await this.loadMarkets();
1372
- const code = this.codeFromOptions('fetchTradingFees', params);
1373
- const currency = this.currency(code);
1374
- const request = {
1375
- 'currency': currency['id'],
1376
- 'extended': true,
1377
- };
1378
- const response = await this.privateGetGetAccountSummary(this.extend(request, params));
1379
- //
1380
- // {
1381
- // "jsonrpc": "2.0",
1382
- // "result": {
1383
- // "total_pl": 0,
1384
- // "session_upl": 0,
1385
- // "session_rpl": 0,
1386
- // "session_funding": 0,
1387
- // "portfolio_margining_enabled": false,
1388
- // "options_vega": 0,
1389
- // "options_theta": 0,
1390
- // "options_session_upl": 0,
1391
- // "options_session_rpl": 0,
1392
- // "options_pl": 0,
1393
- // "options_gamma": 0,
1394
- // "options_delta": 0,
1395
- // "margin_balance": 0.00062359,
1396
- // "maintenance_margin": 0,
1397
- // "limits": {
1398
- // "non_matching_engine_burst": 300,
1399
- // "non_matching_engine": 200,
1400
- // "matching_engine_burst": 20,
1401
- // "matching_engine": 2
1402
- // },
1403
- // "initial_margin": 0,
1404
- // "futures_session_upl": 0,
1405
- // "futures_session_rpl": 0,
1406
- // "futures_pl": 0,
1407
- // "equity": 0.00062359,
1408
- // "deposit_address": "13tUtNsJSZa1F5GeCmwBywVrymHpZispzw",
1409
- // "delta_total": 0,
1410
- // "currency": "BTC",
1411
- // "balance": 0.00062359,
1412
- // "available_withdrawal_funds": 0.00062359,
1413
- // "available_funds": 0.00062359,
1414
- // "fees": [
1415
- // "currency": '',
1416
- // "instrument_type": "perpetual",
1417
- // "fee_type": "relative",
1418
- // "maker_fee": 0,
1419
- // "taker_fee": 0,
1420
- // ],
1421
- // },
1422
- // "usIn": 1583775838115975,
1423
- // "usOut": 1583775838116520,
1424
- // "usDiff": 545,
1425
- // "testnet": false
1426
- // }
1427
- //
1428
- const result = this.safeValue(response, 'result', {});
1429
- const fees = this.safeValue(result, 'fees', []);
1430
- let perpetualFee = {};
1431
- let futureFee = {};
1432
- let optionFee = {};
1433
- for (let i = 0; i < fees.length; i++) {
1434
- const fee = fees[i];
1435
- const instrumentType = this.safeString(fee, 'instrument_type');
1436
- if (instrumentType === 'future') {
1437
- futureFee = {
1438
- 'info': fee,
1439
- 'maker': this.safeNumber(fee, 'maker_fee'),
1440
- 'taker': this.safeNumber(fee, 'taker_fee'),
1441
- };
1442
- }
1443
- else if (instrumentType === 'perpetual') {
1444
- perpetualFee = {
1445
- 'info': fee,
1446
- 'maker': this.safeNumber(fee, 'maker_fee'),
1447
- 'taker': this.safeNumber(fee, 'taker_fee'),
1448
- };
1449
- }
1450
- else if (instrumentType === 'option') {
1451
- optionFee = {
1452
- 'info': fee,
1453
- 'maker': this.safeNumber(fee, 'maker_fee'),
1454
- 'taker': this.safeNumber(fee, 'taker_fee'),
1455
- };
1456
- }
1457
- }
1458
- const parsedFees = {};
1459
- for (let i = 0; i < this.symbols.length; i++) {
1460
- const symbol = this.symbols[i];
1461
- const market = this.market(symbol);
1462
- let fee = {
1463
- 'info': market,
1464
- 'symbol': symbol,
1465
- 'percentage': true,
1466
- 'tierBased': true,
1467
- 'maker': market['maker'],
1468
- 'taker': market['taker'],
1469
- };
1470
- if (market['swap']) {
1471
- fee = this.extend(fee, perpetualFee);
1472
- }
1473
- else if (market['future']) {
1474
- fee = this.extend(fee, futureFee);
1475
- }
1476
- else if (market['option']) {
1477
- fee = this.extend(fee, optionFee);
1478
- }
1479
- parsedFees[symbol] = fee;
1480
- }
1481
- return parsedFees;
1482
- }
1483
- async fetchOrderBook(symbol, limit = undefined, params = {}) {
1484
- /**
1485
- * @method
1486
- * @name deribit#fetchOrderBook
1487
- * @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
1488
- * @param {string} symbol unified symbol of the market to fetch the order book for
1489
- * @param {int} [limit] the maximum amount of order book entries to return
1490
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1491
- * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
1492
- */
1493
- await this.loadMarkets();
1494
- const market = this.market(symbol);
1495
- const request = {
1496
- 'instrument_name': market['id'],
1497
- };
1498
- if (limit !== undefined) {
1499
- request['depth'] = limit;
1500
- }
1501
- const response = await this.publicGetGetOrderBook(this.extend(request, params));
1502
- //
1503
- // {
1504
- // "jsonrpc": "2.0",
1505
- // "result": {
1506
- // "timestamp": 1583781354740,
1507
- // "stats": { volume: 61249.66735634, low: 7631.5, high: 8311.5 },
1508
- // "state": "open",
1509
- // "settlement_price": 7903.21,
1510
- // "open_interest": 111536690,
1511
- // "min_price": 7695.13,
1512
- // "max_price": 7929.49,
1513
- // "mark_price": 7813.06,
1514
- // "last_price": 7814.5,
1515
- // "instrument_name": "BTC-PERPETUAL",
1516
- // "index_price": 7810.12,
1517
- // "funding_8h": 0.0000031,
1518
- // "current_funding": 0,
1519
- // "change_id": 17538025952,
1520
- // "bids": [
1521
- // [7814, 351820],
1522
- // [7813.5, 207490],
1523
- // [7813, 32160],
1524
- // ],
1525
- // "best_bid_price": 7814,
1526
- // "best_bid_amount": 351820,
1527
- // "best_ask_price": 7814.5,
1528
- // "best_ask_amount": 11880,
1529
- // "asks": [
1530
- // [7814.5, 11880],
1531
- // [7815, 18100],
1532
- // [7815.5, 2640],
1533
- // ],
1534
- // },
1535
- // "usIn": 1583781354745804,
1536
- // "usOut": 1583781354745932,
1537
- // "usDiff": 128,
1538
- // "testnet": false
1539
- // }
1540
- //
1541
- const result = this.safeValue(response, 'result', {});
1542
- const timestamp = this.safeInteger(result, 'timestamp');
1543
- const nonce = this.safeInteger(result, 'change_id');
1544
- const orderbook = this.parseOrderBook(result, market['symbol'], timestamp);
1545
- orderbook['nonce'] = nonce;
1546
- return orderbook;
1547
- }
1548
- parseOrderStatus(status) {
1549
- const statuses = {
1550
- 'open': 'open',
1551
- 'cancelled': 'canceled',
1552
- 'filled': 'closed',
1553
- 'rejected': 'rejected',
1554
- 'untriggered': 'open',
1555
- };
1556
- return this.safeString(statuses, status, status);
1557
- }
1558
- parseTimeInForce(timeInForce) {
1559
- const timeInForces = {
1560
- 'good_til_cancelled': 'GTC',
1561
- 'fill_or_kill': 'FOK',
1562
- 'immediate_or_cancel': 'IOC',
1563
- };
1564
- return this.safeString(timeInForces, timeInForce, timeInForce);
1565
- }
1566
- parseOrderType(orderType) {
1567
- const orderTypes = {
1568
- 'stop_limit': 'limit',
1569
- 'take_limit': 'limit',
1570
- 'stop_market': 'market',
1571
- 'take_market': 'market',
1572
- };
1573
- return this.safeString(orderTypes, orderType, orderType);
1574
- }
1575
- parseOrder(order, market = undefined) {
1576
- //
1577
- // createOrder
1578
- //
1579
- // {
1580
- // "time_in_force": "good_til_cancelled",
1581
- // "reduce_only": false,
1582
- // "profit_loss": 0,
1583
- // "price": "market_price",
1584
- // "post_only": false,
1585
- // "order_type": "market",
1586
- // "order_state": "filled",
1587
- // "order_id": "ETH-349249",
1588
- // "max_show": 40,
1589
- // "last_update_timestamp": 1550657341322,
1590
- // "label": "market0000234",
1591
- // "is_liquidation": false,
1592
- // "instrument_name": "ETH-PERPETUAL",
1593
- // "filled_amount": 40,
1594
- // "direction": "buy",
1595
- // "creation_timestamp": 1550657341322,
1596
- // "commission": 0.000139,
1597
- // "average_price": 143.81,
1598
- // "api": true,
1599
- // "amount": 40,
1600
- // "trades": [], // injected by createOrder
1601
- // }
1602
- //
1603
- const marketId = this.safeString(order, 'instrument_name');
1604
- market = this.safeMarket(marketId, market);
1605
- const timestamp = this.safeInteger(order, 'creation_timestamp');
1606
- const lastUpdate = this.safeInteger(order, 'last_update_timestamp');
1607
- const id = this.safeString(order, 'order_id');
1608
- let priceString = this.safeString(order, 'price');
1609
- if (priceString === 'market_price') {
1610
- priceString = undefined;
1611
- }
1612
- const averageString = this.safeString(order, 'average_price');
1613
- // Inverse contracts amount is in USD which in ccxt is the cost
1614
- // For options and Linear contracts amount is in corresponding cryptocurrency, e.g., BTC or ETH
1615
- const filledString = this.safeString(order, 'filled_amount');
1616
- const amount = this.safeString(order, 'amount');
1617
- let cost = Precise["default"].stringMul(filledString, averageString);
1618
- if (market['inverse']) {
1619
- if (this.parseNumber(averageString) !== 0) {
1620
- cost = Precise["default"].stringDiv(amount, averageString);
1621
- }
1622
- }
1623
- let lastTradeTimestamp = undefined;
1624
- if (filledString !== undefined) {
1625
- const isFilledPositive = Precise["default"].stringGt(filledString, '0');
1626
- if (isFilledPositive) {
1627
- lastTradeTimestamp = lastUpdate;
1628
- }
1629
- }
1630
- const status = this.parseOrderStatus(this.safeString(order, 'order_state'));
1631
- const side = this.safeStringLower(order, 'direction');
1632
- let feeCostString = this.safeString(order, 'commission');
1633
- let fee = undefined;
1634
- if (feeCostString !== undefined) {
1635
- feeCostString = Precise["default"].stringAbs(feeCostString);
1636
- fee = {
1637
- 'cost': feeCostString,
1638
- 'currency': market['base'],
1639
- };
1640
- }
1641
- const rawType = this.safeString(order, 'order_type');
1642
- const type = this.parseOrderType(rawType);
1643
- // injected in createOrder
1644
- const trades = this.safeValue(order, 'trades');
1645
- const timeInForce = this.parseTimeInForce(this.safeString(order, 'time_in_force'));
1646
- const stopPrice = this.safeValue(order, 'stop_price');
1647
- const postOnly = this.safeValue(order, 'post_only');
1648
- return this.safeOrder({
1649
- 'info': order,
1650
- 'id': id,
1651
- 'clientOrderId': undefined,
1652
- 'timestamp': timestamp,
1653
- 'datetime': this.iso8601(timestamp),
1654
- 'lastTradeTimestamp': lastTradeTimestamp,
1655
- 'symbol': market['symbol'],
1656
- 'type': type,
1657
- 'timeInForce': timeInForce,
1658
- 'postOnly': postOnly,
1659
- 'side': side,
1660
- 'price': priceString,
1661
- 'stopPrice': stopPrice,
1662
- 'triggerPrice': stopPrice,
1663
- 'amount': amount,
1664
- 'cost': cost,
1665
- 'average': averageString,
1666
- 'filled': filledString,
1667
- 'remaining': undefined,
1668
- 'status': status,
1669
- 'fee': fee,
1670
- 'trades': trades,
1671
- }, market);
1672
- }
1673
- async fetchOrder(id, symbol = undefined, params = {}) {
1674
- /**
1675
- * @method
1676
- * @name deribit#fetchOrder
1677
- * @description fetches information on an order made by the user
1678
- * @param {string} symbol unified symbol of the market the order was made in
1679
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1680
- * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1681
- */
1682
- await this.loadMarkets();
1683
- const request = {
1684
- 'order_id': id,
1685
- };
1686
- let market = undefined;
1687
- if (symbol !== undefined) {
1688
- market = this.market(symbol);
1689
- }
1690
- const response = await this.privateGetGetOrderState(this.extend(request, params));
1691
- //
1692
- // {
1693
- // "jsonrpc": "2.0",
1694
- // "id": 4316,
1695
- // "result": {
1696
- // "time_in_force": "good_til_cancelled",
1697
- // "reduce_only": false,
1698
- // "profit_loss": 0.051134,
1699
- // "price": 118.94,
1700
- // "post_only": false,
1701
- // "order_type": "limit",
1702
- // "order_state": "filled",
1703
- // "order_id": "ETH-331562",
1704
- // "max_show": 37,
1705
- // "last_update_timestamp": 1550219810944,
1706
- // "label": "",
1707
- // "is_liquidation": false,
1708
- // "instrument_name": "ETH-PERPETUAL",
1709
- // "filled_amount": 37,
1710
- // "direction": "sell",
1711
- // "creation_timestamp": 1550219749176,
1712
- // "commission": 0.000031,
1713
- // "average_price": 118.94,
1714
- // "api": false,
1715
- // "amount": 37
1716
- // }
1717
- // }
1718
- //
1719
- const result = this.safeValue(response, 'result');
1720
- return this.parseOrder(result, market);
1721
- }
1722
- async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
1723
- /**
1724
- * @method
1725
- * @name deribit#createOrder
1726
- * @description create a trade order
1727
- * @see https://docs.deribit.com/#private-buy
1728
- * @param {string} symbol unified symbol of the market to create an order in
1729
- * @param {string} type 'market' or 'limit'
1730
- * @param {string} side 'buy' or 'sell'
1731
- * @param {float} amount how much you want to trade in units of the base currency. For inverse perpetual and futures the amount is in the quote currency USD. For options it is in the underlying assets base currency.
1732
- * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
1733
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1734
- * @param {string} [params.trigger] the trigger type 'index_price', 'mark_price', or 'last_price', default is 'last_price'
1735
- * @param {float} [params.trailingAmount] the quote amount to trail away from the current market price
1736
- * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1737
- */
1738
- await this.loadMarkets();
1739
- const market = this.market(symbol);
1740
- const request = {
1741
- 'instrument_name': market['id'],
1742
- 'amount': this.amountToPrecision(symbol, amount),
1743
- 'type': type, // limit, stop_limit, market, stop_market, default is limit
1744
- // 'label': 'string', // user-defined label for the order (maximum 64 characters)
1745
- // 'price': this.priceToPrecision (symbol, 123.45), // only for limit and stop_limit orders
1746
- // 'time_in_force' : 'good_til_cancelled', // fill_or_kill, immediate_or_cancel
1747
- // 'max_show': 123.45, // max amount within an order to be shown to other customers, 0 for invisible order
1748
- // 'post_only': false, // if the new price would cause the order to be filled immediately (as taker), the price will be changed to be just below the spread.
1749
- // 'reject_post_only': false, // if true the order is put to order book unmodified or request is rejected
1750
- // 'reduce_only': false, // if true, the order is intended to only reduce a current position
1751
- // 'stop_price': false, // stop price, required for stop_limit orders
1752
- // 'trigger': 'index_price', // mark_price, last_price, required for stop_limit orders
1753
- // 'advanced': 'usd', // 'implv', advanced option order type, options only
1754
- };
1755
- const trigger = this.safeString(params, 'trigger', 'last_price');
1756
- const timeInForce = this.safeStringUpper(params, 'timeInForce');
1757
- const reduceOnly = this.safeValue2(params, 'reduceOnly', 'reduce_only');
1758
- // only stop loss sell orders are allowed when price crossed from above
1759
- const stopLossPrice = this.safeValue(params, 'stopLossPrice');
1760
- // only take profit buy orders are allowed when price crossed from below
1761
- const takeProfitPrice = this.safeValue(params, 'takeProfitPrice');
1762
- const trailingAmount = this.safeString2(params, 'trailingAmount', 'trigger_offset');
1763
- const isTrailingAmountOrder = trailingAmount !== undefined;
1764
- const isStopLimit = type === 'stop_limit';
1765
- const isStopMarket = type === 'stop_market';
1766
- const isTakeLimit = type === 'take_limit';
1767
- const isTakeMarket = type === 'take_market';
1768
- const isStopLossOrder = isStopLimit || isStopMarket || (stopLossPrice !== undefined);
1769
- const isTakeProfitOrder = isTakeLimit || isTakeMarket || (takeProfitPrice !== undefined);
1770
- if (isStopLossOrder && isTakeProfitOrder) {
1771
- throw new errors.InvalidOrder(this.id + ' createOrder () only allows one of stopLossPrice or takeProfitPrice to be specified');
1772
- }
1773
- const isStopOrder = isStopLossOrder || isTakeProfitOrder;
1774
- const isLimitOrder = (type === 'limit') || isStopLimit || isTakeLimit;
1775
- const isMarketOrder = (type === 'market') || isStopMarket || isTakeMarket;
1776
- const exchangeSpecificPostOnly = this.safeValue(params, 'post_only');
1777
- const postOnly = this.isPostOnly(isMarketOrder, exchangeSpecificPostOnly, params);
1778
- if (isLimitOrder) {
1779
- request['type'] = 'limit';
1780
- request['price'] = this.priceToPrecision(symbol, price);
1781
- }
1782
- else {
1783
- request['type'] = 'market';
1784
- }
1785
- if (isTrailingAmountOrder) {
1786
- request['trigger'] = trigger;
1787
- request['type'] = 'trailing_stop';
1788
- request['trigger_offset'] = this.parseToNumeric(trailingAmount);
1789
- }
1790
- else if (isStopOrder) {
1791
- const triggerPrice = (stopLossPrice !== undefined) ? stopLossPrice : takeProfitPrice;
1792
- request['trigger_price'] = this.priceToPrecision(symbol, triggerPrice);
1793
- request['trigger'] = trigger;
1794
- if (isStopLossOrder) {
1795
- if (isMarketOrder) {
1796
- // stop_market (sell only)
1797
- request['type'] = 'stop_market';
1798
- }
1799
- else {
1800
- // stop_limit (sell only)
1801
- request['type'] = 'stop_limit';
1802
- }
1803
- }
1804
- else {
1805
- if (isMarketOrder) {
1806
- // take_market (buy only)
1807
- request['type'] = 'take_market';
1808
- }
1809
- else {
1810
- // take_limit (buy only)
1811
- request['type'] = 'take_limit';
1812
- }
1813
- }
1814
- }
1815
- if (reduceOnly) {
1816
- request['reduce_only'] = true;
1817
- }
1818
- if (postOnly) {
1819
- request['post_only'] = true;
1820
- request['reject_post_only'] = true;
1821
- }
1822
- if (timeInForce !== undefined) {
1823
- if (timeInForce === 'GTC') {
1824
- request['time_in_force'] = 'good_til_cancelled';
1825
- }
1826
- if (timeInForce === 'IOC') {
1827
- request['time_in_force'] = 'immediate_or_cancel';
1828
- }
1829
- if (timeInForce === 'FOK') {
1830
- request['time_in_force'] = 'fill_or_kill';
1831
- }
1832
- }
1833
- params = this.omit(params, ['timeInForce', 'stopLossPrice', 'takeProfitPrice', 'postOnly', 'reduceOnly', 'trailingAmount']);
1834
- let response = undefined;
1835
- if (this.capitalize(side) === 'Buy') {
1836
- response = await this.privateGetBuy(this.extend(request, params));
1837
- }
1838
- else {
1839
- response = await this.privateGetSell(this.extend(request, params));
1840
- }
1841
- //
1842
- // {
1843
- // "jsonrpc": "2.0",
1844
- // "id": 5275,
1845
- // "result": {
1846
- // "trades": [
1847
- // {
1848
- // "trade_seq": 14151,
1849
- // "trade_id": "ETH-37435",
1850
- // "timestamp": 1550657341322,
1851
- // "tick_direction": 2,
1852
- // "state": "closed",
1853
- // "self_trade": false,
1854
- // "price": 143.81,
1855
- // "order_type": "market",
1856
- // "order_id": "ETH-349249",
1857
- // "matching_id": null,
1858
- // "liquidity": "T",
1859
- // "label": "market0000234",
1860
- // "instrument_name": "ETH-PERPETUAL",
1861
- // "index_price": 143.73,
1862
- // "fee_currency": "ETH",
1863
- // "fee": 0.000139,
1864
- // "direction": "buy",
1865
- // "amount": 40
1866
- // }
1867
- // ],
1868
- // "order": {
1869
- // "time_in_force": "good_til_cancelled",
1870
- // "reduce_only": false,
1871
- // "profit_loss": 0,
1872
- // "price": "market_price",
1873
- // "post_only": false,
1874
- // "order_type": "market",
1875
- // "order_state": "filled",
1876
- // "order_id": "ETH-349249",
1877
- // "max_show": 40,
1878
- // "last_update_timestamp": 1550657341322,
1879
- // "label": "market0000234",
1880
- // "is_liquidation": false,
1881
- // "instrument_name": "ETH-PERPETUAL",
1882
- // "filled_amount": 40,
1883
- // "direction": "buy",
1884
- // "creation_timestamp": 1550657341322,
1885
- // "commission": 0.000139,
1886
- // "average_price": 143.81,
1887
- // "api": true,
1888
- // "amount": 40
1889
- // }
1890
- // }
1891
- // }
1892
- //
1893
- const result = this.safeValue(response, 'result', {});
1894
- const order = this.safeValue(result, 'order');
1895
- const trades = this.safeValue(result, 'trades', []);
1896
- order['trades'] = trades;
1897
- return this.parseOrder(order, market);
1898
- }
1899
- async editOrder(id, symbol, type, side, amount = undefined, price = undefined, params = {}) {
1900
- /**
1901
- * @method
1902
- * @name deribit#editOrder
1903
- * @description edit a trade order
1904
- * @see https://docs.deribit.com/#private-edit
1905
- * @param {string} id edit order id
1906
- * @param {string} [symbol] unified symbol of the market to edit an order in
1907
- * @param {string} [type] 'market' or 'limit'
1908
- * @param {string} [side] 'buy' or 'sell'
1909
- * @param {float} amount how much you want to trade in units of the base currency, inverse swap and future use the quote currency
1910
- * @param {float} [price] the price at which the order is to be fullfilled, in units of the base currency, ignored in market orders
1911
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1912
- * @param {float} [params.trailingAmount] the quote amount to trail away from the current market price
1913
- * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1914
- */
1915
- if (amount === undefined) {
1916
- throw new errors.ArgumentsRequired(this.id + ' editOrder() requires an amount argument');
1917
- }
1918
- await this.loadMarkets();
1919
- const request = {
1920
- 'order_id': id,
1921
- 'amount': this.amountToPrecision(symbol, amount),
1922
- // 'post_only': false, // if the new price would cause the order to be filled immediately (as taker), the price will be changed to be just below the spread.
1923
- // 'reject_post_only': false, // if true the order is put to order book unmodified or request is rejected
1924
- // 'reduce_only': false, // if true, the order is intended to only reduce a current position
1925
- // 'stop_price': false, // stop price, required for stop_limit orders
1926
- // 'advanced': 'usd', // 'implv', advanced option order type, options only
1927
- };
1928
- if (price !== undefined) {
1929
- request['price'] = this.priceToPrecision(symbol, price);
1930
- }
1931
- const trailingAmount = this.safeString2(params, 'trailingAmount', 'trigger_offset');
1932
- const isTrailingAmountOrder = trailingAmount !== undefined;
1933
- if (isTrailingAmountOrder) {
1934
- request['trigger_offset'] = this.parseToNumeric(trailingAmount);
1935
- params = this.omit(params, 'trigger_offset');
1936
- }
1937
- const response = await this.privateGetEdit(this.extend(request, params));
1938
- const result = this.safeValue(response, 'result', {});
1939
- const order = this.safeValue(result, 'order');
1940
- const trades = this.safeValue(result, 'trades', []);
1941
- order['trades'] = trades;
1942
- return this.parseOrder(order);
1943
- }
1944
- async cancelOrder(id, symbol = undefined, params = {}) {
1945
- /**
1946
- * @method
1947
- * @name deribit#cancelOrder
1948
- * @description cancels an open order
1949
- * @param {string} id order id
1950
- * @param {string} symbol not used by deribit cancelOrder ()
1951
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1952
- * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1953
- */
1954
- await this.loadMarkets();
1955
- const request = {
1956
- 'order_id': id,
1957
- };
1958
- const response = await this.privateGetCancel(this.extend(request, params));
1959
- const result = this.safeValue(response, 'result', {});
1960
- return this.parseOrder(result);
1961
- }
1962
- async cancelAllOrders(symbol = undefined, params = {}) {
1963
- /**
1964
- * @method
1965
- * @name deribit#cancelAllOrders
1966
- * @description cancel all open orders
1967
- * @param {string} symbol unified market symbol, only orders in the market of this symbol are cancelled when symbol is not undefined
1968
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1969
- * @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
1970
- */
1971
- await this.loadMarkets();
1972
- const request = {};
1973
- let response = undefined;
1974
- if (symbol === undefined) {
1975
- response = await this.privateGetCancelAll(this.extend(request, params));
1976
- }
1977
- else {
1978
- const market = this.market(symbol);
1979
- request['instrument_name'] = market['id'];
1980
- response = await this.privateGetCancelAllByInstrument(this.extend(request, params));
1981
- }
1982
- return response;
1983
- }
1984
- async fetchOpenOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
1985
- /**
1986
- * @method
1987
- * @name deribit#fetchOpenOrders
1988
- * @description fetch all unfilled currently open orders
1989
- * @param {string} symbol unified market symbol
1990
- * @param {int} [since] the earliest time in ms to fetch open orders for
1991
- * @param {int} [limit] the maximum number of open orders structures to retrieve
1992
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1993
- * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
1994
- */
1995
- await this.loadMarkets();
1996
- const request = {};
1997
- let market = undefined;
1998
- let response = undefined;
1999
- if (symbol === undefined) {
2000
- const code = this.codeFromOptions('fetchOpenOrders', params);
2001
- const currency = this.currency(code);
2002
- request['currency'] = currency['id'];
2003
- response = await this.privateGetGetOpenOrdersByCurrency(this.extend(request, params));
2004
- }
2005
- else {
2006
- market = this.market(symbol);
2007
- request['instrument_name'] = market['id'];
2008
- response = await this.privateGetGetOpenOrdersByInstrument(this.extend(request, params));
2009
- }
2010
- const result = this.safeValue(response, 'result', []);
2011
- return this.parseOrders(result, market, since, limit);
2012
- }
2013
- async fetchClosedOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
2014
- /**
2015
- * @method
2016
- * @name deribit#fetchClosedOrders
2017
- * @description fetches information on multiple closed orders made by the user
2018
- * @param {string} symbol unified market symbol of the market orders were made in
2019
- * @param {int} [since] the earliest time in ms to fetch orders for
2020
- * @param {int} [limit] the maximum number of order structures to retrieve
2021
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2022
- * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
2023
- */
2024
- await this.loadMarkets();
2025
- const request = {};
2026
- let market = undefined;
2027
- let response = undefined;
2028
- if (symbol === undefined) {
2029
- const code = this.codeFromOptions('fetchClosedOrders', params);
2030
- const currency = this.currency(code);
2031
- request['currency'] = currency['id'];
2032
- response = await this.privateGetGetOrderHistoryByCurrency(this.extend(request, params));
2033
- }
2034
- else {
2035
- market = this.market(symbol);
2036
- request['instrument_name'] = market['id'];
2037
- response = await this.privateGetGetOrderHistoryByInstrument(this.extend(request, params));
2038
- }
2039
- const result = this.safeValue(response, 'result', []);
2040
- return this.parseOrders(result, market, since, limit);
2041
- }
2042
- async fetchOrderTrades(id, symbol = undefined, since = undefined, limit = undefined, params = {}) {
2043
- /**
2044
- * @method
2045
- * @name deribit#fetchOrderTrades
2046
- * @description fetch all the trades made from a single order
2047
- * @param {string} id order id
2048
- * @param {string} symbol unified market symbol
2049
- * @param {int} [since] the earliest time in ms to fetch trades for
2050
- * @param {int} [limit] the maximum number of trades to retrieve
2051
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2052
- * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure}
2053
- */
2054
- await this.loadMarkets();
2055
- const request = {
2056
- 'order_id': id,
2057
- };
2058
- const response = await this.privateGetGetUserTradesByOrder(this.extend(request, params));
2059
- //
2060
- // {
2061
- // "jsonrpc": "2.0",
2062
- // "id": 9367,
2063
- // "result": {
2064
- // "trades": [
2065
- // {
2066
- // "trade_seq": 3,
2067
- // "trade_id": "ETH-34066",
2068
- // "timestamp": 1550219814585,
2069
- // "tick_direction": 1,
2070
- // "state": "open",
2071
- // "self_trade": false,
2072
- // "reduce_only": false,
2073
- // "price": 0.04,
2074
- // "post_only": false,
2075
- // "order_type": "limit",
2076
- // "order_id": "ETH-334607",
2077
- // "matching_id": null,
2078
- // "liquidity": "M",
2079
- // "iv": 56.83,
2080
- // "instrument_name": "ETH-22FEB19-120-C",
2081
- // "index_price": 121.37,
2082
- // "fee_currency": "ETH",
2083
- // "fee": 0.0011,
2084
- // "direction": "buy",
2085
- // "amount": 11
2086
- // },
2087
- // ],
2088
- // "has_more": true
2089
- // }
2090
- // }
2091
- //
2092
- const result = this.safeValue(response, 'result', {});
2093
- return this.parseTrades(result, undefined, since, limit);
2094
- }
2095
- async fetchMyTrades(symbol = undefined, since = undefined, limit = undefined, params = {}) {
2096
- /**
2097
- * @method
2098
- * @name deribit#fetchMyTrades
2099
- * @description fetch all trades made by the user
2100
- * @param {string} symbol unified market symbol
2101
- * @param {int} [since] the earliest time in ms to fetch trades for
2102
- * @param {int} [limit] the maximum number of trades structures to retrieve
2103
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2104
- * @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure}
2105
- */
2106
- await this.loadMarkets();
2107
- const request = {
2108
- 'include_old': true,
2109
- };
2110
- let market = undefined;
2111
- if (limit !== undefined) {
2112
- request['count'] = limit; // default 10
2113
- }
2114
- let response = undefined;
2115
- if (symbol === undefined) {
2116
- const code = this.codeFromOptions('fetchMyTrades', params);
2117
- const currency = this.currency(code);
2118
- request['currency'] = currency['id'];
2119
- if (since === undefined) {
2120
- response = await this.privateGetGetUserTradesByCurrency(this.extend(request, params));
2121
- }
2122
- else {
2123
- request['start_timestamp'] = since;
2124
- response = await this.privateGetGetUserTradesByCurrencyAndTime(this.extend(request, params));
2125
- }
2126
- }
2127
- else {
2128
- market = this.market(symbol);
2129
- request['instrument_name'] = market['id'];
2130
- if (since === undefined) {
2131
- response = await this.privateGetGetUserTradesByInstrument(this.extend(request, params));
2132
- }
2133
- else {
2134
- request['start_timestamp'] = since;
2135
- response = await this.privateGetGetUserTradesByInstrumentAndTime(this.extend(request, params));
2136
- }
2137
- }
2138
- //
2139
- // {
2140
- // "jsonrpc": "2.0",
2141
- // "id": 9367,
2142
- // "result": {
2143
- // "trades": [
2144
- // {
2145
- // "trade_seq": 3,
2146
- // "trade_id": "ETH-34066",
2147
- // "timestamp": 1550219814585,
2148
- // "tick_direction": 1,
2149
- // "state": "open",
2150
- // "self_trade": false,
2151
- // "reduce_only": false,
2152
- // "price": 0.04,
2153
- // "post_only": false,
2154
- // "order_type": "limit",
2155
- // "order_id": "ETH-334607",
2156
- // "matching_id": null,
2157
- // "liquidity": "M",
2158
- // "iv": 56.83,
2159
- // "instrument_name": "ETH-22FEB19-120-C",
2160
- // "index_price": 121.37,
2161
- // "fee_currency": "ETH",
2162
- // "fee": 0.0011,
2163
- // "direction": "buy",
2164
- // "amount": 11
2165
- // },
2166
- // ],
2167
- // "has_more": true
2168
- // }
2169
- // }
2170
- //
2171
- const result = this.safeValue(response, 'result', {});
2172
- const trades = this.safeValue(result, 'trades', []);
2173
- return this.parseTrades(trades, market, since, limit);
2174
- }
2175
- async fetchDeposits(code = undefined, since = undefined, limit = undefined, params = {}) {
2176
- /**
2177
- * @method
2178
- * @name deribit#fetchDeposits
2179
- * @description fetch all deposits made to an account
2180
- * @param {string} code unified currency code
2181
- * @param {int} [since] the earliest time in ms to fetch deposits for
2182
- * @param {int} [limit] the maximum number of deposits structures to retrieve
2183
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2184
- * @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/#/?id=transaction-structure}
2185
- */
2186
- if (code === undefined) {
2187
- throw new errors.ArgumentsRequired(this.id + ' fetchDeposits() requires a currency code argument');
2188
- }
2189
- await this.loadMarkets();
2190
- const currency = this.currency(code);
2191
- const request = {
2192
- 'currency': currency['id'],
2193
- };
2194
- if (limit !== undefined) {
2195
- request['count'] = limit;
2196
- }
2197
- const response = await this.privateGetGetDeposits(this.extend(request, params));
2198
- //
2199
- // {
2200
- // "jsonrpc": "2.0",
2201
- // "id": 5611,
2202
- // "result": {
2203
- // "count": 1,
2204
- // "data": [
2205
- // {
2206
- // "address": "2N35qDKDY22zmJq9eSyiAerMD4enJ1xx6ax",
2207
- // "amount": 5,
2208
- // "currency": "BTC",
2209
- // "received_timestamp": 1549295017670,
2210
- // "state": "completed",
2211
- // "transaction_id": "230669110fdaf0a0dbcdc079b6b8b43d5af29cc73683835b9bc6b3406c065fda",
2212
- // "updated_timestamp": 1549295130159
2213
- // }
2214
- // ]
2215
- // }
2216
- // }
2217
- //
2218
- const result = this.safeValue(response, 'result', {});
2219
- const data = this.safeValue(result, 'data', []);
2220
- return this.parseTransactions(data, currency, since, limit, params);
2221
- }
2222
- async fetchWithdrawals(code = undefined, since = undefined, limit = undefined, params = {}) {
2223
- /**
2224
- * @method
2225
- * @name deribit#fetchWithdrawals
2226
- * @description fetch all withdrawals made from an account
2227
- * @param {string} code unified currency code
2228
- * @param {int} [since] the earliest time in ms to fetch withdrawals for
2229
- * @param {int} [limit] the maximum number of withdrawals structures to retrieve
2230
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2231
- * @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/#/?id=transaction-structure}
2232
- */
2233
- if (code === undefined) {
2234
- throw new errors.ArgumentsRequired(this.id + ' fetchWithdrawals() requires a currency code argument');
2235
- }
2236
- await this.loadMarkets();
2237
- const currency = this.currency(code);
2238
- const request = {
2239
- 'currency': currency['id'],
2240
- };
2241
- if (limit !== undefined) {
2242
- request['count'] = limit;
2243
- }
2244
- const response = await this.privateGetGetWithdrawals(this.extend(request, params));
2245
- //
2246
- // {
2247
- // "jsonrpc": "2.0",
2248
- // "id": 2745,
2249
- // "result": {
2250
- // "count": 1,
2251
- // "data": [
2252
- // {
2253
- // "address": "2NBqqD5GRJ8wHy1PYyCXTe9ke5226FhavBz",
2254
- // "amount": 0.5,
2255
- // "confirmed_timestamp": null,
2256
- // "created_timestamp": 1550571443070,
2257
- // "currency": "BTC",
2258
- // "fee": 0.0001,
2259
- // "id": 1,
2260
- // "priority": 0.15,
2261
- // "state": "unconfirmed",
2262
- // "transaction_id": null,
2263
- // "updated_timestamp": 1550571443070
2264
- // }
2265
- // ]
2266
- // }
2267
- // }
2268
- //
2269
- const result = this.safeValue(response, 'result', {});
2270
- const data = this.safeValue(result, 'data', []);
2271
- return this.parseTransactions(data, currency, since, limit, params);
2272
- }
2273
- parseTransactionStatus(status) {
2274
- const statuses = {
2275
- 'completed': 'ok',
2276
- 'unconfirmed': 'pending',
2277
- };
2278
- return this.safeString(statuses, status, status);
2279
- }
2280
- parseTransaction(transaction, currency = undefined) {
2281
- //
2282
- // fetchWithdrawals
2283
- //
2284
- // {
2285
- // "address": "2NBqqD5GRJ8wHy1PYyCXTe9ke5226FhavBz",
2286
- // "amount": 0.5,
2287
- // "confirmed_timestamp": null,
2288
- // "created_timestamp": 1550571443070,
2289
- // "currency": "BTC",
2290
- // "fee": 0.0001,
2291
- // "id": 1,
2292
- // "priority": 0.15,
2293
- // "state": "unconfirmed",
2294
- // "transaction_id": null,
2295
- // "updated_timestamp": 1550571443070
2296
- // }
2297
- //
2298
- // fetchDeposits
2299
- //
2300
- // {
2301
- // "address": "2N35qDKDY22zmJq9eSyiAerMD4enJ1xx6ax",
2302
- // "amount": 5,
2303
- // "currency": "BTC",
2304
- // "received_timestamp": 1549295017670,
2305
- // "state": "completed",
2306
- // "transaction_id": "230669110fdaf0a0dbcdc079b6b8b43d5af29cc73683835b9bc6b3406c065fda",
2307
- // "updated_timestamp": 1549295130159
2308
- // }
2309
- //
2310
- const currencyId = this.safeString(transaction, 'currency');
2311
- const code = this.safeCurrencyCode(currencyId, currency);
2312
- const timestamp = this.safeInteger2(transaction, 'created_timestamp', 'received_timestamp');
2313
- const updated = this.safeInteger(transaction, 'updated_timestamp');
2314
- const status = this.parseTransactionStatus(this.safeString(transaction, 'state'));
2315
- const address = this.safeString(transaction, 'address');
2316
- const feeCost = this.safeNumber(transaction, 'fee');
2317
- let type = 'deposit';
2318
- let fee = undefined;
2319
- if (feeCost !== undefined) {
2320
- type = 'withdrawal';
2321
- fee = {
2322
- 'cost': feeCost,
2323
- 'currency': code,
2324
- };
2325
- }
2326
- return {
2327
- 'info': transaction,
2328
- 'id': this.safeString(transaction, 'id'),
2329
- 'txid': this.safeString(transaction, 'transaction_id'),
2330
- 'timestamp': timestamp,
2331
- 'datetime': this.iso8601(timestamp),
2332
- 'address': address,
2333
- 'addressTo': address,
2334
- 'addressFrom': undefined,
2335
- 'tag': undefined,
2336
- 'tagTo': undefined,
2337
- 'tagFrom': undefined,
2338
- 'type': type,
2339
- 'amount': this.safeNumber(transaction, 'amount'),
2340
- 'currency': code,
2341
- 'status': status,
2342
- 'updated': updated,
2343
- 'network': undefined,
2344
- 'internal': undefined,
2345
- 'comment': undefined,
2346
- 'fee': fee,
2347
- };
2348
- }
2349
- parsePosition(position, market = undefined) {
2350
- //
2351
- // {
2352
- // "jsonrpc": "2.0",
2353
- // "id": 404,
2354
- // "result": {
2355
- // "average_price": 0,
2356
- // "delta": 0,
2357
- // "direction": "buy",
2358
- // "estimated_liquidation_price": 0,
2359
- // "floating_profit_loss": 0,
2360
- // "index_price": 3555.86,
2361
- // "initial_margin": 0,
2362
- // "instrument_name": "BTC-PERPETUAL",
2363
- // "leverage": 100,
2364
- // "kind": "future",
2365
- // "maintenance_margin": 0,
2366
- // "mark_price": 3556.62,
2367
- // "open_orders_margin": 0.000165889,
2368
- // "realized_profit_loss": 0,
2369
- // "settlement_price": 3555.44,
2370
- // "size": 0,
2371
- // "size_currency": 0,
2372
- // "total_profit_loss": 0
2373
- // }
2374
- // }
2375
- //
2376
- const contract = this.safeString(position, 'instrument_name');
2377
- market = this.safeMarket(contract, market);
2378
- let side = this.safeString(position, 'direction');
2379
- side = (side === 'buy') ? 'long' : 'short';
2380
- const unrealizedPnl = this.safeString(position, 'floating_profit_loss');
2381
- const initialMarginString = this.safeString(position, 'initial_margin');
2382
- const notionalString = this.safeString(position, 'size_currency');
2383
- const maintenanceMarginString = this.safeString(position, 'maintenance_margin');
2384
- const currentTime = this.milliseconds();
2385
- return this.safePosition({
2386
- 'info': position,
2387
- 'id': undefined,
2388
- 'symbol': this.safeString(market, 'symbol'),
2389
- 'timestamp': currentTime,
2390
- 'datetime': this.iso8601(currentTime),
2391
- 'lastUpdateTimestamp': undefined,
2392
- 'initialMargin': this.parseNumber(initialMarginString),
2393
- 'initialMarginPercentage': this.parseNumber(Precise["default"].stringMul(Precise["default"].stringDiv(initialMarginString, notionalString), '100')),
2394
- 'maintenanceMargin': this.parseNumber(maintenanceMarginString),
2395
- 'maintenanceMarginPercentage': this.parseNumber(Precise["default"].stringMul(Precise["default"].stringDiv(maintenanceMarginString, notionalString), '100')),
2396
- 'entryPrice': this.safeNumber(position, 'average_price'),
2397
- 'notional': this.parseNumber(notionalString),
2398
- 'leverage': this.safeInteger(position, 'leverage'),
2399
- 'unrealizedPnl': this.parseNumber(unrealizedPnl),
2400
- 'contracts': undefined,
2401
- 'contractSize': this.safeNumber(market, 'contractSize'),
2402
- 'marginRatio': undefined,
2403
- 'liquidationPrice': this.safeNumber(position, 'estimated_liquidation_price'),
2404
- 'markPrice': this.safeNumber(position, 'mark_price'),
2405
- 'lastPrice': undefined,
2406
- 'collateral': undefined,
2407
- 'marginMode': undefined,
2408
- 'side': side,
2409
- 'percentage': undefined,
2410
- 'hedged': undefined,
2411
- 'stopLossPrice': undefined,
2412
- 'takeProfitPrice': undefined,
2413
- });
2414
- }
2415
- async fetchPosition(symbol, params = {}) {
2416
- /**
2417
- * @method
2418
- * @name deribit#fetchPosition
2419
- * @description fetch data on a single open contract trade position
2420
- * @param {string} symbol unified market symbol of the market the position is held in, default is undefined
2421
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2422
- * @returns {object} a [position structure]{@link https://docs.ccxt.com/#/?id=position-structure}
2423
- */
2424
- await this.loadMarkets();
2425
- const market = this.market(symbol);
2426
- const request = {
2427
- 'instrument_name': market['id'],
2428
- };
2429
- const response = await this.privateGetGetPosition(this.extend(request, params));
2430
- //
2431
- // {
2432
- // "jsonrpc": "2.0",
2433
- // "id": 404,
2434
- // "result": {
2435
- // "average_price": 0,
2436
- // "delta": 0,
2437
- // "direction": "buy",
2438
- // "estimated_liquidation_price": 0,
2439
- // "floating_profit_loss": 0,
2440
- // "index_price": 3555.86,
2441
- // "initial_margin": 0,
2442
- // "instrument_name": "BTC-PERPETUAL",
2443
- // "leverage": 100,
2444
- // "kind": "future",
2445
- // "maintenance_margin": 0,
2446
- // "mark_price": 3556.62,
2447
- // "open_orders_margin": 0.000165889,
2448
- // "realized_profit_loss": 0,
2449
- // "settlement_price": 3555.44,
2450
- // "size": 0,
2451
- // "size_currency": 0,
2452
- // "total_profit_loss": 0
2453
- // }
2454
- // }
2455
- //
2456
- const result = this.safeValue(response, 'result');
2457
- return this.parsePosition(result);
2458
- }
2459
- async fetchPositions(symbols = undefined, params = {}) {
2460
- /**
2461
- * @method
2462
- * @name deribit#fetchPositions
2463
- * @description fetch all open positions
2464
- * @param {string[]|undefined} symbols list of unified market symbols
2465
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2466
- * @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/#/?id=position-structure}
2467
- */
2468
- await this.loadMarkets();
2469
- let code = undefined;
2470
- if (symbols === undefined) {
2471
- code = this.codeFromOptions('fetchPositions', params);
2472
- }
2473
- else if (typeof symbols === 'string') {
2474
- code = symbols;
2475
- symbols = undefined; // fix https://github.com/ccxt/ccxt/issues/13961
2476
- }
2477
- else {
2478
- if (Array.isArray(symbols)) {
2479
- const length = symbols.length;
2480
- if (length !== 1) {
2481
- throw new errors.BadRequest(this.id + ' fetchPositions() symbols argument cannot contain more than 1 symbol');
2482
- }
2483
- const market = this.market(symbols[0]);
2484
- code = market['base'];
2485
- }
2486
- }
2487
- const currency = this.currency(code);
2488
- const request = {
2489
- 'currency': currency['id'],
2490
- // "kind" : "future", "option"
2491
- };
2492
- const response = await this.privateGetGetPositions(this.extend(request, params));
2493
- //
2494
- // {
2495
- // "jsonrpc": "2.0",
2496
- // "id": 2236,
2497
- // "result": [
2498
- // {
2499
- // "average_price": 7440.18,
2500
- // "delta": 0.006687487,
2501
- // "direction": "buy",
2502
- // "estimated_liquidation_price": 1.74,
2503
- // "floating_profit_loss": 0,
2504
- // "index_price": 7466.79,
2505
- // "initial_margin": 0.000197283,
2506
- // "instrument_name": "BTC-PERPETUAL",
2507
- // "kind": "future",
2508
- // "leverage": 34,
2509
- // "maintenance_margin": 0.000143783,
2510
- // "mark_price": 7476.65,
2511
- // "open_orders_margin": 0.000197288,
2512
- // "realized_funding": -1e-8,
2513
- // "realized_profit_loss": -9e-9,
2514
- // "settlement_price": 7476.65,
2515
- // "size": 50,
2516
- // "size_currency": 0.006687487,
2517
- // "total_profit_loss": 0.000032781
2518
- // },
2519
- // ]
2520
- // }
2521
- //
2522
- const result = this.safeValue(response, 'result');
2523
- return this.parsePositions(result, symbols);
2524
- }
2525
- async fetchVolatilityHistory(code, params = {}) {
2526
- /**
2527
- * @method
2528
- * @name deribit#fetchVolatilityHistory
2529
- * @description fetch the historical volatility of an option market based on an underlying asset
2530
- * @see https://docs.deribit.com/#public-get_historical_volatility
2531
- * @param {string} code unified currency code
2532
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2533
- * @returns {object[]} a list of [volatility history objects]{@link https://docs.ccxt.com/#/?id=volatility-structure}
2534
- */
2535
- await this.loadMarkets();
2536
- const currency = this.currency(code);
2537
- const request = {
2538
- 'currency': currency['id'],
2539
- };
2540
- const response = await this.publicGetGetHistoricalVolatility(this.extend(request, params));
2541
- //
2542
- // {
2543
- // "jsonrpc": "2.0",
2544
- // "result": [
2545
- // [1640142000000,63.828320460740585],
2546
- // [1640142000000,63.828320460740585],
2547
- // [1640145600000,64.03821964123213]
2548
- // ],
2549
- // "usIn": 1641515379467734,
2550
- // "usOut": 1641515379468095,
2551
- // "usDiff": 361,
2552
- // "testnet": false
2553
- // }
2554
- //
2555
- return this.parseVolatilityHistory(response);
2556
- }
2557
- parseVolatilityHistory(volatility) {
2558
- //
2559
- // {
2560
- // "jsonrpc": "2.0",
2561
- // "result": [
2562
- // [1640142000000,63.828320460740585],
2563
- // [1640142000000,63.828320460740585],
2564
- // [1640145600000,64.03821964123213]
2565
- // ],
2566
- // "usIn": 1641515379467734,
2567
- // "usOut": 1641515379468095,
2568
- // "usDiff": 361,
2569
- // "testnet": false
2570
- // }
2571
- //
2572
- const volatilityResult = this.safeValue(volatility, 'result', []);
2573
- const result = [];
2574
- for (let i = 0; i < volatilityResult.length; i++) {
2575
- const timestamp = this.safeInteger(volatilityResult[i], 0);
2576
- const volatilityObj = this.safeNumber(volatilityResult[i], 1);
2577
- result.push({
2578
- 'info': volatilityObj,
2579
- 'timestamp': timestamp,
2580
- 'datetime': this.iso8601(timestamp),
2581
- 'volatility': volatilityObj,
2582
- });
2583
- }
2584
- return result;
2585
- }
2586
- async fetchTransfers(code = undefined, since = undefined, limit = undefined, params = {}) {
2587
- /**
2588
- * @method
2589
- * @name deribit#fetchTransfers
2590
- * @description fetch a history of internal transfers made on an account
2591
- * @param {string} code unified currency code of the currency transferred
2592
- * @param {int} [since] the earliest time in ms to fetch transfers for
2593
- * @param {int} [limit] the maximum number of transfers structures to retrieve
2594
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2595
- * @returns {object[]} a list of [transfer structures]{@link https://docs.ccxt.com/#/?id=transfer-structure}
2596
- */
2597
- if (code === undefined) {
2598
- throw new errors.ArgumentsRequired(this.id + ' fetchTransfers() requires a currency code argument');
2599
- }
2600
- await this.loadMarkets();
2601
- const currency = this.currency(code);
2602
- const request = {
2603
- 'currency': currency['id'],
2604
- };
2605
- if (limit !== undefined) {
2606
- request['count'] = limit;
2607
- }
2608
- const response = await this.privateGetGetTransfers(this.extend(request, params));
2609
- //
2610
- // {
2611
- // "jsonrpc": "2.0",
2612
- // "id": 7606,
2613
- // "result": {
2614
- // "count": 2,
2615
- // "data": [
2616
- // {
2617
- // "amount": 0.2,
2618
- // "created_timestamp": 1550579457727,
2619
- // "currency": "BTC",
2620
- // "direction": "payment",
2621
- // "id": 2,
2622
- // "other_side": "2MzyQc5Tkik61kJbEpJV5D5H9VfWHZK9Sgy",
2623
- // "state": "prepared",
2624
- // "type": "user",
2625
- // "updated_timestamp": 1550579457727
2626
- // },
2627
- // {
2628
- // "amount": 0.3,
2629
- // "created_timestamp": 1550579255800,
2630
- // "currency": "BTC",
2631
- // "direction": "payment",
2632
- // "id": 1,
2633
- // "other_side": "new_user_1_1",
2634
- // "state": "confirmed",
2635
- // "type": "subaccount",
2636
- // "updated_timestamp": 1550579255800
2637
- // }
2638
- // ]
2639
- // }
2640
- // }
2641
- //
2642
- const result = this.safeValue(response, 'result', {});
2643
- const transfers = this.safeValue(result, 'data', []);
2644
- return this.parseTransfers(transfers, currency, since, limit, params);
2645
- }
2646
- async transfer(code, amount, fromAccount, toAccount, params = {}) {
2647
- /**
2648
- * @method
2649
- * @name deribit#transfer
2650
- * @description transfer currency internally between wallets on the same account
2651
- * @param {string} code unified currency code
2652
- * @param {float} amount amount to transfer
2653
- * @param {string} fromAccount account to transfer from
2654
- * @param {string} toAccount account to transfer to
2655
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2656
- * @returns {object} a [transfer structure]{@link https://docs.ccxt.com/#/?id=transfer-structure}
2657
- */
2658
- await this.loadMarkets();
2659
- const currency = this.currency(code);
2660
- const request = {
2661
- 'amount': amount,
2662
- 'currency': currency['id'],
2663
- 'destination': toAccount,
2664
- };
2665
- let method = this.safeString(params, 'method');
2666
- params = this.omit(params, 'method');
2667
- if (method === undefined) {
2668
- const transferOptions = this.safeValue(this.options, 'transfer', {});
2669
- method = this.safeString(transferOptions, 'method', 'privateGetSubmitTransferToSubaccount');
2670
- }
2671
- let response = undefined;
2672
- if (method === 'privateGetSubmitTransferToUser') {
2673
- response = await this.privateGetSubmitTransferToUser(this.extend(request, params));
2674
- }
2675
- else {
2676
- response = await this.privateGetSubmitTransferToSubaccount(this.extend(request, params));
2677
- }
2678
- //
2679
- // {
2680
- // "jsonrpc": "2.0",
2681
- // "id": 9421,
2682
- // "result": {
2683
- // "updated_timestamp": 1550232862350,
2684
- // "type": "user",
2685
- // "state": "prepared",
2686
- // "other_side": "0x4aa0753d798d668056920094d65321a8e8913e26",
2687
- // "id": 3,
2688
- // "direction": "payment",
2689
- // "currency": "ETH",
2690
- // "created_timestamp": 1550232862350,
2691
- // "amount": 13.456
2692
- // }
2693
- // }
2694
- //
2695
- const result = this.safeValue(response, 'result', {});
2696
- return this.parseTransfer(result, currency);
2697
- }
2698
- parseTransfer(transfer, currency = undefined) {
2699
- //
2700
- // {
2701
- // "updated_timestamp": 1550232862350,
2702
- // "type": "user",
2703
- // "state": "prepared",
2704
- // "other_side": "0x4aa0753d798d668056920094d65321a8e8913e26",
2705
- // "id": 3,
2706
- // "direction": "payment",
2707
- // "currency": "ETH",
2708
- // "created_timestamp": 1550232862350,
2709
- // "amount": 13.456
2710
- // }
2711
- //
2712
- const timestamp = this.safeTimestamp(transfer, 'created_timestamp');
2713
- const status = this.safeString(transfer, 'state');
2714
- const account = this.safeString(transfer, 'other_side');
2715
- const direction = this.safeString(transfer, 'direction');
2716
- const currencyId = this.safeString(transfer, 'currency');
2717
- return {
2718
- 'info': transfer,
2719
- 'id': this.safeString(transfer, 'id'),
2720
- 'status': this.parseTransferStatus(status),
2721
- 'amount': this.safeNumber(transfer, 'amount'),
2722
- 'code': this.safeCurrencyCode(currencyId, currency),
2723
- 'fromAccount': direction !== 'payment' ? account : undefined,
2724
- 'toAccount': direction === 'payment' ? account : undefined,
2725
- 'timestamp': timestamp,
2726
- 'datetime': this.iso8601(timestamp),
2727
- };
2728
- }
2729
- parseTransferStatus(status) {
2730
- const statuses = {
2731
- 'prepared': 'pending',
2732
- 'confirmed': 'ok',
2733
- 'cancelled': 'cancelled',
2734
- 'waiting_for_admin': 'pending',
2735
- };
2736
- return this.safeString(statuses, status, status);
2737
- }
2738
- async withdraw(code, amount, address, tag = undefined, params = {}) {
2739
- /**
2740
- * @method
2741
- * @name deribit#withdraw
2742
- * @description make a withdrawal
2743
- * @param {string} code unified currency code
2744
- * @param {float} amount the amount to withdraw
2745
- * @param {string} address the address to withdraw to
2746
- * @param {string} tag
2747
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2748
- * @returns {object} a [transaction structure]{@link https://docs.ccxt.com/#/?id=transaction-structure}
2749
- */
2750
- [tag, params] = this.handleWithdrawTagAndParams(tag, params);
2751
- this.checkAddress(address);
2752
- await this.loadMarkets();
2753
- const currency = this.currency(code);
2754
- const request = {
2755
- 'currency': currency['id'],
2756
- 'address': address,
2757
- 'amount': amount,
2758
- // 'priority': 'high', // low, mid, high, very_high, extreme_high, insane
2759
- // 'tfa': '123456', // if enabled
2760
- };
2761
- if (this.twofa !== undefined) {
2762
- request['tfa'] = totp.totp(this.twofa);
2763
- }
2764
- const response = await this.privateGetWithdraw(this.extend(request, params));
2765
- return this.parseTransaction(response, currency);
2766
- }
2767
- parseDepositWithdrawFee(fee, currency = undefined) {
2768
- //
2769
- // {
2770
- // "withdrawal_priorities": [],
2771
- // "withdrawal_fee": 0.01457324,
2772
- // "min_withdrawal_fee": 0.000001,
2773
- // "min_confirmations": 1,
2774
- // "fee_precision": 8,
2775
- // "currency_long": "Solana",
2776
- // "currency": "SOL",
2777
- // "coin_type": "SOL"
2778
- // }
2779
- //
2780
- return {
2781
- 'info': fee,
2782
- 'withdraw': {
2783
- 'fee': this.safeNumber(fee, 'withdrawal_fee'),
2784
- 'percentage': false,
2785
- },
2786
- 'deposit': {
2787
- 'fee': undefined,
2788
- 'percentage': undefined,
2789
- },
2790
- 'networks': {},
2791
- };
2792
- }
2793
- async fetchDepositWithdrawFees(codes = undefined, params = {}) {
2794
- /**
2795
- * @method
2796
- * @name deribit#fetchDepositWithdrawFees
2797
- * @description fetch deposit and withdraw fees
2798
- * @see https://docs.deribit.com/#public-get_currencies
2799
- * @param {string[]|undefined} codes list of unified currency codes
2800
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2801
- * @returns {object} a list of [fee structures]{@link https://docs.ccxt.com/#/?id=fee-structure}
2802
- */
2803
- await this.loadMarkets();
2804
- const response = await this.publicGetGetCurrencies(params);
2805
- //
2806
- // {
2807
- // "jsonrpc": "2.0",
2808
- // "result": [
2809
- // {
2810
- // "withdrawal_priorities": [],
2811
- // "withdrawal_fee": 0.01457324,
2812
- // "min_withdrawal_fee": 0.000001,
2813
- // "min_confirmations": 1,
2814
- // "fee_precision": 8,
2815
- // "currency_long": "Solana",
2816
- // "currency": "SOL",
2817
- // "coin_type": "SOL"
2818
- // },
2819
- // ...
2820
- // ],
2821
- // "usIn": 1688652701456124,
2822
- // "usOut": 1688652701456390,
2823
- // "usDiff": 266,
2824
- // "testnet": true
2825
- // }
2826
- //
2827
- const data = this.safeValue(response, 'result', {});
2828
- return this.parseDepositWithdrawFees(data, codes, 'currency');
2829
- }
2830
- async fetchFundingRate(symbol, params = {}) {
2831
- /**
2832
- * @method
2833
- * @name deribit#fetchFundingRate
2834
- * @description fetch the current funding rate
2835
- * @see https://docs.deribit.com/#public-get_funding_rate_value
2836
- * @param {string} symbol unified market symbol
2837
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2838
- * @param {int} [params.start_timestamp] fetch funding rate starting from this timestamp
2839
- * @param {int} [params.end_timestamp] fetch funding rate ending at this timestamp
2840
- * @returns {object} a [funding rate structure]{@link https://docs.ccxt.com/#/?id=funding-rate-structure}
2841
- */
2842
- await this.loadMarkets();
2843
- const market = this.market(symbol);
2844
- const time = this.milliseconds();
2845
- const request = {
2846
- 'instrument_name': market['id'],
2847
- 'start_timestamp': time - (8 * 60 * 60 * 1000),
2848
- 'end_timestamp': time,
2849
- };
2850
- const response = await this.publicGetGetFundingRateValue(this.extend(request, params));
2851
- //
2852
- // {
2853
- // "jsonrpc":"2.0",
2854
- // "result":"0",
2855
- // "usIn":"1691161645596519",
2856
- // "usOut":"1691161645597149",
2857
- // "usDiff":"630",
2858
- // "testnet":false
2859
- // }
2860
- //
2861
- return this.parseFundingRate(response, market);
2862
- }
2863
- async fetchFundingRateHistory(symbol = undefined, since = undefined, limit = undefined, params = {}) {
2864
- /**
2865
- * @method
2866
- * @name deribit#fetchFundingRateHistory
2867
- * @description fetch the current funding rate
2868
- * @see https://docs.deribit.com/#public-get_funding_rate_history
2869
- * @param {string} symbol unified market symbol
2870
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2871
- * @param {int} [params.end_timestamp] fetch funding rate ending at this timestamp
2872
- * @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
2873
- * @returns {object} a [funding rate structure]{@link https://docs.ccxt.com/#/?id=funding-rate-structure}
2874
- */
2875
- await this.loadMarkets();
2876
- const market = this.market(symbol);
2877
- let paginate = false;
2878
- [paginate, params] = this.handleOptionAndParams(params, 'fetchFundingRateHistory', 'paginate');
2879
- if (paginate) {
2880
- return await this.fetchPaginatedCallDeterministic('fetchFundingRateHistory', symbol, since, limit, '8h', params, 720);
2881
- }
2882
- const time = this.milliseconds();
2883
- const month = 30 * 24 * 60 * 60 * 1000;
2884
- if (since === undefined) {
2885
- since = time - month;
2886
- }
2887
- const request = {
2888
- 'instrument_name': market['id'],
2889
- 'start_timestamp': since,
2890
- 'end_timestamp': time,
2891
- };
2892
- const response = await this.publicGetGetFundingRateHistory(this.extend(request, params));
2893
- //
2894
- // {
2895
- // "jsonrpc": "2.0",
2896
- // "id": 7617,
2897
- // "result": [
2898
- // {
2899
- // "timestamp": 1569891600000,
2900
- // "index_price": 8222.87,
2901
- // "prev_index_price": 8305.72,
2902
- // "interest_8h": -0.00009234260068476106,
2903
- // "interest_1h": -4.739622041017375e-7
2904
- // }
2905
- // ]
2906
- // }
2907
- //
2908
- const rates = [];
2909
- const result = this.safeValue(response, 'result', []);
2910
- for (let i = 0; i < result.length; i++) {
2911
- const fr = result[i];
2912
- const rate = this.parseFundingRate(fr, market);
2913
- rates.push(rate);
2914
- }
2915
- return this.filterBySymbolSinceLimit(rates, symbol, since, limit);
2916
- }
2917
- parseFundingRate(contract, market = undefined) {
2918
- //
2919
- // {
2920
- // "jsonrpc":"2.0",
2921
- // "result":"0",
2922
- // "usIn":"1691161645596519",
2923
- // "usOut":"1691161645597149",
2924
- // "usDiff":"630",
2925
- // "testnet":false
2926
- // }
2927
- // history
2928
- // {
2929
- // "timestamp": 1569891600000,
2930
- // "index_price": 8222.87,
2931
- // "prev_index_price": 8305.72,
2932
- // "interest_8h": -0.00009234260068476106,
2933
- // "interest_1h": -4.739622041017375e-7
2934
- // }
2935
- //
2936
- const timestamp = this.safeInteger(contract, 'timestamp');
2937
- const datetime = this.iso8601(timestamp);
2938
- const result = this.safeNumber2(contract, 'result', 'interest_8h');
2939
- return {
2940
- 'info': contract,
2941
- 'symbol': this.safeSymbol(undefined, market),
2942
- 'markPrice': undefined,
2943
- 'indexPrice': this.safeNumber(contract, 'index_price'),
2944
- 'interestRate': undefined,
2945
- 'estimatedSettlePrice': undefined,
2946
- 'timestamp': timestamp,
2947
- 'datetime': datetime,
2948
- 'fundingRate': result,
2949
- 'fundingTimestamp': undefined,
2950
- 'fundingDatetime': undefined,
2951
- 'nextFundingRate': undefined,
2952
- 'nextFundingTimestamp': undefined,
2953
- 'nextFundingDatetime': undefined,
2954
- 'previousFundingRate': undefined,
2955
- 'previousFundingTimestamp': undefined,
2956
- 'previousFundingDatetime': undefined,
2957
- };
2958
- }
2959
- async fetchLiquidations(symbol, since = undefined, limit = undefined, params = {}) {
2960
- /**
2961
- * @method
2962
- * @name deribit#fetchLiquidations
2963
- * @description retrieves the public liquidations of a trading pair
2964
- * @see https://docs.deribit.com/#public-get_last_settlements_by_currency
2965
- * @param {string} symbol unified CCXT market symbol
2966
- * @param {int} [since] the earliest time in ms to fetch liquidations for
2967
- * @param {int} [limit] the maximum number of liquidation structures to retrieve
2968
- * @param {object} [params] exchange specific parameters for the deribit api endpoint
2969
- * @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
2970
- * @returns {object} an array of [liquidation structures]{@link https://docs.ccxt.com/#/?id=liquidation-structure}
2971
- */
2972
- await this.loadMarkets();
2973
- let paginate = false;
2974
- [paginate, params] = this.handleOptionAndParams(params, 'fetchLiquidations', 'paginate');
2975
- if (paginate) {
2976
- return await this.fetchPaginatedCallCursor('fetchLiquidations', symbol, since, limit, params, 'continuation', 'continuation', undefined);
2977
- }
2978
- const market = this.market(symbol);
2979
- if (market['spot']) {
2980
- throw new errors.NotSupported(this.id + ' fetchLiquidations() does not support ' + market['type'] + ' markets');
2981
- }
2982
- const request = {
2983
- 'instrument_name': market['id'],
2984
- 'type': 'bankruptcy',
2985
- };
2986
- if (since !== undefined) {
2987
- request['search_start_timestamp'] = since;
2988
- }
2989
- if (limit !== undefined) {
2990
- request['count'] = limit;
2991
- }
2992
- const response = await this.publicGetGetLastSettlementsByInstrument(this.extend(request, params));
2993
- //
2994
- // {
2995
- // "jsonrpc": "2.0",
2996
- // "result": {
2997
- // "settlements": [
2998
- // {
2999
- // "type": "bankruptcy",
3000
- // "timestamp": 1696579200041,
3001
- // "funded": 10000.0,
3002
- // "session_bankrupcy": 10000.0
3003
- // "session_profit_loss": 112951.68715857354,
3004
- // "session_tax": 0.15,
3005
- // "session_tax_rate": 0.0015,
3006
- // "socialized": 0.001,
3007
- // },
3008
- // ],
3009
- // "continuation": "5dHzoGyD8Hs8KURoUhfgXgHpJTA5oyapoudSmNeAfEftqRbjNE6jNNUpo2oCu1khnZL9ao"
3010
- // },
3011
- // "usIn": 1696652052254890,
3012
- // "usOut": 1696652052255733,
3013
- // "usDiff": 843,
3014
- // "testnet": false
3015
- // }
3016
- //
3017
- const result = this.safeValue(response, 'result', {});
3018
- const cursor = this.safeString(result, 'continuation');
3019
- const settlements = this.safeValue(result, 'settlements', []);
3020
- const settlementsWithCursor = this.addPaginationCursorToResult(cursor, settlements);
3021
- return this.parseLiquidations(settlementsWithCursor, market, since, limit);
3022
- }
3023
- addPaginationCursorToResult(cursor, data) {
3024
- if (cursor !== undefined) {
3025
- const dataLength = data.length;
3026
- if (dataLength > 0) {
3027
- const first = data[0];
3028
- const last = data[dataLength - 1];
3029
- first['continuation'] = cursor;
3030
- last['continuation'] = cursor;
3031
- data[0] = first;
3032
- data[dataLength - 1] = last;
3033
- }
3034
- }
3035
- return data;
3036
- }
3037
- async fetchMyLiquidations(symbol = undefined, since = undefined, limit = undefined, params = {}) {
3038
- /**
3039
- * @method
3040
- * @name deribit#fetchMyLiquidations
3041
- * @description retrieves the users liquidated positions
3042
- * @see https://docs.deribit.com/#private-get_settlement_history_by_instrument
3043
- * @param {string} symbol unified CCXT market symbol
3044
- * @param {int} [since] the earliest time in ms to fetch liquidations for
3045
- * @param {int} [limit] the maximum number of liquidation structures to retrieve
3046
- * @param {object} [params] exchange specific parameters for the deribit api endpoint
3047
- * @returns {object} an array of [liquidation structures]{@link https://docs.ccxt.com/#/?id=liquidation-structure}
3048
- */
3049
- if (symbol === undefined) {
3050
- throw new errors.ArgumentsRequired(this.id + ' fetchMyLiquidations() requires a symbol argument');
3051
- }
3052
- await this.loadMarkets();
3053
- const market = this.market(symbol);
3054
- if (market['spot']) {
3055
- throw new errors.NotSupported(this.id + ' fetchMyLiquidations() does not support ' + market['type'] + ' markets');
3056
- }
3057
- const request = {
3058
- 'instrument_name': market['id'],
3059
- 'type': 'bankruptcy',
3060
- };
3061
- if (since !== undefined) {
3062
- request['search_start_timestamp'] = since;
3063
- }
3064
- if (limit !== undefined) {
3065
- request['count'] = limit;
3066
- }
3067
- const response = await this.privateGetGetSettlementHistoryByInstrument(this.extend(request, params));
3068
- //
3069
- // {
3070
- // "jsonrpc": "2.0",
3071
- // "result": {
3072
- // "settlements": [
3073
- // {
3074
- // "type": "bankruptcy",
3075
- // "timestamp": 1696579200041,
3076
- // "funded": 10000.0,
3077
- // "session_bankrupcy": 10000.0
3078
- // "session_profit_loss": 112951.68715857354,
3079
- // "session_tax": 0.15,
3080
- // "session_tax_rate": 0.0015,
3081
- // "socialized": 0.001,
3082
- // },
3083
- // ],
3084
- // "continuation": "5dHzoGyD8Hs8KURoUhfgXgHpJTA5oyapoudSmNeAfEftqRbjNE6jNNUpo2oCu1khnZL9ao"
3085
- // },
3086
- // "usIn": 1696652052254890,
3087
- // "usOut": 1696652052255733,
3088
- // "usDiff": 843,
3089
- // "testnet": false
3090
- // }
3091
- //
3092
- const result = this.safeValue(response, 'result', {});
3093
- const settlements = this.safeValue(result, 'settlements', []);
3094
- return this.parseLiquidations(settlements, market, since, limit);
3095
- }
3096
- parseLiquidation(liquidation, market = undefined) {
3097
- //
3098
- // {
3099
- // "type": "bankruptcy",
3100
- // "timestamp": 1696579200041,
3101
- // "funded": 1,
3102
- // "session_bankrupcy": 0.001,
3103
- // "session_profit_loss": 0.001,
3104
- // "session_tax": 0.0015,
3105
- // "session_tax_rate": 0.0015,
3106
- // "socialized": 0.001,
3107
- // }
3108
- //
3109
- const timestamp = this.safeInteger(liquidation, 'timestamp');
3110
- return this.safeLiquidation({
3111
- 'info': liquidation,
3112
- 'symbol': this.safeSymbol(undefined, market),
3113
- 'contracts': undefined,
3114
- 'contractSize': this.safeNumber(market, 'contractSize'),
3115
- 'price': undefined,
3116
- 'baseValue': this.safeNumber(liquidation, 'session_bankrupcy'),
3117
- 'quoteValue': undefined,
3118
- 'timestamp': timestamp,
3119
- 'datetime': this.iso8601(timestamp),
3120
- });
3121
- }
3122
- async fetchGreeks(symbol, params = {}) {
3123
- /**
3124
- * @method
3125
- * @name deribit#fetchGreeks
3126
- * @description fetches an option contracts greeks, financial metrics used to measure the factors that affect the price of an options contract
3127
- * @see https://docs.deribit.com/#public-ticker
3128
- * @param {string} symbol unified symbol of the market to fetch greeks for
3129
- * @param {object} [params] extra parameters specific to the exchange API endpoint
3130
- * @returns {object} a [greeks structure]{@link https://docs.ccxt.com/#/?id=greeks-structure}
3131
- */
3132
- await this.loadMarkets();
3133
- const market = this.market(symbol);
3134
- const request = {
3135
- 'instrument_name': market['id'],
3136
- };
3137
- const response = await this.publicGetTicker(this.extend(request, params));
3138
- //
3139
- // {
3140
- // "jsonrpc": "2.0",
3141
- // "result": {
3142
- // "estimated_delivery_price": 36552.72,
3143
- // "best_bid_amount": 0.2,
3144
- // "best_ask_amount": 9.1,
3145
- // "interest_rate": 0.0,
3146
- // "best_bid_price": 0.214,
3147
- // "best_ask_price": 0.219,
3148
- // "open_interest": 368.8,
3149
- // "settlement_price": 0.22103022,
3150
- // "last_price": 0.215,
3151
- // "bid_iv": 60.51,
3152
- // "ask_iv": 61.88,
3153
- // "mark_iv": 61.27,
3154
- // "underlying_index": "BTC-27SEP24",
3155
- // "underlying_price": 38992.71,
3156
- // "min_price": 0.1515,
3157
- // "max_price": 0.326,
3158
- // "mark_price": 0.2168,
3159
- // "instrument_name": "BTC-27SEP24-40000-C",
3160
- // "index_price": 36552.72,
3161
- // "greeks": {
3162
- // "rho": 130.63998,
3163
- // "theta": -13.48784,
3164
- // "vega": 141.90146,
3165
- // "gamma": 0.00002,
3166
- // "delta": 0.59621
3167
- // },
3168
- // "stats": {
3169
- // "volume_usd": 100453.9,
3170
- // "volume": 12.0,
3171
- // "price_change": -2.2727,
3172
- // "low": 0.2065,
3173
- // "high": 0.238
3174
- // },
3175
- // "state": "open",
3176
- // "timestamp": 1699578548021
3177
- // },
3178
- // "usIn": 1699578548308414,
3179
- // "usOut": 1699578548308606,
3180
- // "usDiff": 192,
3181
- // "testnet": false
3182
- // }
3183
- //
3184
- const result = this.safeValue(response, 'result', {});
3185
- return this.parseGreeks(result, market);
3186
- }
3187
- parseGreeks(greeks, market = undefined) {
3188
- //
3189
- // {
3190
- // "estimated_delivery_price": 36552.72,
3191
- // "best_bid_amount": 0.2,
3192
- // "best_ask_amount": 9.1,
3193
- // "interest_rate": 0.0,
3194
- // "best_bid_price": 0.214,
3195
- // "best_ask_price": 0.219,
3196
- // "open_interest": 368.8,
3197
- // "settlement_price": 0.22103022,
3198
- // "last_price": 0.215,
3199
- // "bid_iv": 60.51,
3200
- // "ask_iv": 61.88,
3201
- // "mark_iv": 61.27,
3202
- // "underlying_index": "BTC-27SEP24",
3203
- // "underlying_price": 38992.71,
3204
- // "min_price": 0.1515,
3205
- // "max_price": 0.326,
3206
- // "mark_price": 0.2168,
3207
- // "instrument_name": "BTC-27SEP24-40000-C",
3208
- // "index_price": 36552.72,
3209
- // "greeks": {
3210
- // "rho": 130.63998,
3211
- // "theta": -13.48784,
3212
- // "vega": 141.90146,
3213
- // "gamma": 0.00002,
3214
- // "delta": 0.59621
3215
- // },
3216
- // "stats": {
3217
- // "volume_usd": 100453.9,
3218
- // "volume": 12.0,
3219
- // "price_change": -2.2727,
3220
- // "low": 0.2065,
3221
- // "high": 0.238
3222
- // },
3223
- // "state": "open",
3224
- // "timestamp": 1699578548021
3225
- // }
3226
- //
3227
- const timestamp = this.safeInteger(greeks, 'timestamp');
3228
- const marketId = this.safeString(greeks, 'instrument_name');
3229
- const symbol = this.safeSymbol(marketId, market);
3230
- const stats = this.safeValue(greeks, 'greeks', {});
3231
- return {
3232
- 'symbol': symbol,
3233
- 'timestamp': timestamp,
3234
- 'datetime': this.iso8601(timestamp),
3235
- 'delta': this.safeNumber(stats, 'delta'),
3236
- 'gamma': this.safeNumber(stats, 'gamma'),
3237
- 'theta': this.safeNumber(stats, 'theta'),
3238
- 'vega': this.safeNumber(stats, 'vega'),
3239
- 'rho': this.safeNumber(stats, 'rho'),
3240
- 'bidSize': this.safeNumber(greeks, 'best_bid_amount'),
3241
- 'askSize': this.safeNumber(greeks, 'best_ask_amount'),
3242
- 'bidImpliedVolatility': this.safeNumber(greeks, 'bid_iv'),
3243
- 'askImpliedVolatility': this.safeNumber(greeks, 'ask_iv'),
3244
- 'markImpliedVolatility': this.safeNumber(greeks, 'mark_iv'),
3245
- 'bidPrice': this.safeNumber(greeks, 'best_bid_price'),
3246
- 'askPrice': this.safeNumber(greeks, 'best_ask_price'),
3247
- 'markPrice': this.safeNumber(greeks, 'mark_price'),
3248
- 'lastPrice': this.safeNumber(greeks, 'last_price'),
3249
- 'underlyingPrice': this.safeNumber(greeks, 'underlying_price'),
3250
- 'info': greeks,
3251
- };
3252
- }
3253
- nonce() {
3254
- return this.milliseconds();
3255
- }
3256
- sign(path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
3257
- let request = '/' + 'api/' + this.version + '/' + api + '/' + path;
3258
- if (api === 'public') {
3259
- if (Object.keys(params).length) {
3260
- request += '?' + this.urlencode(params);
3261
- }
3262
- }
3263
- if (api === 'private') {
3264
- this.checkRequiredCredentials();
3265
- const nonce = this.nonce().toString();
3266
- const timestamp = this.milliseconds().toString();
3267
- const requestBody = '';
3268
- if (Object.keys(params).length) {
3269
- request += '?' + this.urlencode(params);
3270
- }
3271
- const requestData = method + "\n" + request + "\n" + requestBody + "\n"; // eslint-disable-line quotes
3272
- const auth = timestamp + "\n" + nonce + "\n" + requestData; // eslint-disable-line quotes
3273
- const signature = this.hmac(this.encode(auth), this.encode(this.secret), sha256.sha256);
3274
- headers = {
3275
- 'Authorization': 'deri-hmac-sha256 id=' + this.apiKey + ',ts=' + timestamp + ',sig=' + signature + ',' + 'nonce=' + nonce,
3276
- };
3277
- }
3278
- const url = this.urls['api']['rest'] + request;
3279
- return { 'url': url, 'method': method, 'body': body, 'headers': headers };
3280
- }
3281
- handleErrors(httpCode, reason, url, method, headers, body, response, requestHeaders, requestBody) {
3282
- if (!response) {
3283
- return undefined; // fallback to default error handler
3284
- }
3285
- //
3286
- // {
3287
- // "jsonrpc": "2.0",
3288
- // "error": {
3289
- // "message": "Invalid params",
3290
- // "data": { reason: "invalid currency", param: "currency" },
3291
- // "code": -32602
3292
- // },
3293
- // "testnet": false,
3294
- // "usIn": 1583763842150374,
3295
- // "usOut": 1583763842150410,
3296
- // "usDiff": 36
3297
- // }
3298
- //
3299
- const error = this.safeValue(response, 'error');
3300
- if (error !== undefined) {
3301
- const errorCode = this.safeString(error, 'code');
3302
- const feedback = this.id + ' ' + body;
3303
- this.throwExactlyMatchedException(this.exceptions, errorCode, feedback);
3304
- throw new errors.ExchangeError(feedback); // unknown message
3305
- }
3306
- return undefined;
3307
- }
3308
- }
3309
-
3310
- module.exports = deribit;