ccxt 4.2.17 → 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 (439) hide show
  1. package/README.md +9 -9
  2. package/dist/ccxt.browser.js +48992 -47725
  3. package/dist/ccxt.browser.min.js +3 -3
  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/coincheck.js +208 -0
  49. package/dist/cjs/src/pro/hitbtc.js +5 -4
  50. package/dist/cjs/src/pro/htx.js +6 -1
  51. package/dist/cjs/src/pro/kraken.js +1 -1
  52. package/dist/cjs/src/pro/krakenfutures.js +7 -1
  53. package/dist/cjs/src/pro/kucoin.js +46 -36
  54. package/dist/cjs/src/pro/kucoinfutures.js +45 -37
  55. package/dist/cjs/src/pro/lbank.js +881 -0
  56. package/dist/cjs/src/pro/okx.js +52 -2
  57. package/dist/cjs/{js/src/pro/bitpanda.js → src/pro/onetrading.js} +4 -7
  58. package/dist/cjs/src/pro/poloniex.js +2 -2
  59. package/dist/cjs/src/pro/poloniexfutures.js +43 -35
  60. package/dist/cjs/src/pro/woo.js +126 -0
  61. package/dist/cjs/src/probit.js +4 -2
  62. package/dist/cjs/src/upbit.js +12 -12
  63. package/dist/cjs/src/wavesexchange.js +1 -1
  64. package/dist/cjs/src/whitebit.js +1 -0
  65. package/dist/cjs/src/woo.js +56 -0
  66. package/js/ccxt.d.ts +14 -2
  67. package/js/ccxt.js +10 -2
  68. package/js/src/abstract/bitpanda.d.ts +4 -4
  69. package/js/src/abstract/bitstamp.d.ts +8 -0
  70. package/js/src/abstract/gate.d.ts +1 -0
  71. package/js/src/abstract/gateio.d.ts +1 -0
  72. package/js/src/abstract/htx.d.ts +3 -0
  73. package/js/src/abstract/huobi.d.ts +3 -0
  74. package/js/src/abstract/luno.d.ts +1 -0
  75. package/js/src/abstract/onetrading.d.ts +38 -0
  76. package/js/src/ascendex.js +2 -0
  77. package/js/src/base/Exchange.d.ts +2 -3
  78. package/js/src/base/Exchange.js +5 -2
  79. package/js/src/binance.js +7 -1
  80. package/js/src/bingx.d.ts +1 -0
  81. package/js/src/bingx.js +26 -0
  82. package/js/src/bitget.js +22 -3
  83. package/js/src/bitpanda.d.ts +2 -72
  84. package/js/src/bitpanda.js +5 -1991
  85. package/js/src/bitstamp.js +8 -0
  86. package/js/src/bybit.js +21 -47
  87. package/js/src/coincheck.js +1 -0
  88. package/js/src/deribit.js +16 -4
  89. package/js/src/gate.d.ts +1 -0
  90. package/js/src/gate.js +50 -110
  91. package/js/src/htx.js +3 -0
  92. package/js/src/kraken.d.ts +1 -0
  93. package/js/src/kraken.js +40 -39
  94. package/js/src/lbank.js +1 -0
  95. package/js/src/luno.d.ts +3 -1
  96. package/js/src/luno.js +84 -2
  97. package/js/src/mexc.js +1 -2
  98. package/js/src/onetrading.d.ts +74 -0
  99. package/js/src/onetrading.js +2003 -0
  100. package/js/src/poloniexfutures.js +1 -0
  101. package/js/src/pro/binance.js +7 -2
  102. package/js/src/pro/bitget.js +1 -1
  103. package/js/src/pro/bitpanda.d.ts +2 -34
  104. package/js/src/pro/bitpanda.js +5 -1330
  105. package/js/src/pro/coincheck.d.ts +12 -0
  106. package/js/src/pro/coincheck.js +209 -0
  107. package/js/src/pro/kucoin.js +43 -35
  108. package/js/src/pro/kucoinfutures.js +45 -37
  109. package/js/src/pro/lbank.d.ts +29 -0
  110. package/js/src/pro/lbank.js +882 -0
  111. package/js/src/pro/onetrading.d.ts +36 -0
  112. package/js/src/pro/onetrading.js +1339 -0
  113. package/js/src/pro/poloniexfutures.js +43 -35
  114. package/js/src/whitebit.js +1 -0
  115. package/package.json +2 -2
  116. package/rollup.config.js +2 -0
  117. package/skip-tests.json +14 -2
  118. package/test-commonjs.cjs +25 -1
  119. package/dist/cjs/js/ccxt.js +0 -476
  120. package/dist/cjs/js/src/abstract/alpaca.js +0 -9
  121. package/dist/cjs/js/src/abstract/ascendex.js +0 -9
  122. package/dist/cjs/js/src/abstract/bigone.js +0 -9
  123. package/dist/cjs/js/src/abstract/binance.js +0 -9
  124. package/dist/cjs/js/src/abstract/bingx.js +0 -9
  125. package/dist/cjs/js/src/abstract/bit2c.js +0 -9
  126. package/dist/cjs/js/src/abstract/bitbank.js +0 -9
  127. package/dist/cjs/js/src/abstract/bitbns.js +0 -9
  128. package/dist/cjs/js/src/abstract/bitfinex.js +0 -9
  129. package/dist/cjs/js/src/abstract/bitfinex2.js +0 -9
  130. package/dist/cjs/js/src/abstract/bitflyer.js +0 -9
  131. package/dist/cjs/js/src/abstract/bitforex.js +0 -9
  132. package/dist/cjs/js/src/abstract/bitget.js +0 -9
  133. package/dist/cjs/js/src/abstract/bithumb.js +0 -9
  134. package/dist/cjs/js/src/abstract/bitmart.js +0 -9
  135. package/dist/cjs/js/src/abstract/bitmex.js +0 -9
  136. package/dist/cjs/js/src/abstract/bitopro.js +0 -9
  137. package/dist/cjs/js/src/abstract/bitpanda.js +0 -9
  138. package/dist/cjs/js/src/abstract/bitrue.js +0 -9
  139. package/dist/cjs/js/src/abstract/bitso.js +0 -9
  140. package/dist/cjs/js/src/abstract/bitstamp.js +0 -9
  141. package/dist/cjs/js/src/abstract/bitteam.js +0 -9
  142. package/dist/cjs/js/src/abstract/bitvavo.js +0 -9
  143. package/dist/cjs/js/src/abstract/bl3p.js +0 -9
  144. package/dist/cjs/js/src/abstract/blockchaincom.js +0 -9
  145. package/dist/cjs/js/src/abstract/btcalpha.js +0 -9
  146. package/dist/cjs/js/src/abstract/btcbox.js +0 -9
  147. package/dist/cjs/js/src/abstract/btcmarkets.js +0 -9
  148. package/dist/cjs/js/src/abstract/btcturk.js +0 -9
  149. package/dist/cjs/js/src/abstract/bybit.js +0 -9
  150. package/dist/cjs/js/src/abstract/cex.js +0 -9
  151. package/dist/cjs/js/src/abstract/coinbase.js +0 -9
  152. package/dist/cjs/js/src/abstract/coinbasepro.js +0 -9
  153. package/dist/cjs/js/src/abstract/coincheck.js +0 -9
  154. package/dist/cjs/js/src/abstract/coinex.js +0 -9
  155. package/dist/cjs/js/src/abstract/coinlist.js +0 -9
  156. package/dist/cjs/js/src/abstract/coinmate.js +0 -9
  157. package/dist/cjs/js/src/abstract/coinone.js +0 -9
  158. package/dist/cjs/js/src/abstract/coinsph.js +0 -9
  159. package/dist/cjs/js/src/abstract/coinspot.js +0 -9
  160. package/dist/cjs/js/src/abstract/cryptocom.js +0 -9
  161. package/dist/cjs/js/src/abstract/currencycom.js +0 -9
  162. package/dist/cjs/js/src/abstract/delta.js +0 -9
  163. package/dist/cjs/js/src/abstract/deribit.js +0 -9
  164. package/dist/cjs/js/src/abstract/digifinex.js +0 -9
  165. package/dist/cjs/js/src/abstract/exmo.js +0 -9
  166. package/dist/cjs/js/src/abstract/gate.js +0 -9
  167. package/dist/cjs/js/src/abstract/gemini.js +0 -9
  168. package/dist/cjs/js/src/abstract/hitbtc.js +0 -9
  169. package/dist/cjs/js/src/abstract/hollaex.js +0 -9
  170. package/dist/cjs/js/src/abstract/htx.js +0 -9
  171. package/dist/cjs/js/src/abstract/huobijp.js +0 -9
  172. package/dist/cjs/js/src/abstract/idex.js +0 -9
  173. package/dist/cjs/js/src/abstract/independentreserve.js +0 -9
  174. package/dist/cjs/js/src/abstract/indodax.js +0 -9
  175. package/dist/cjs/js/src/abstract/kraken.js +0 -9
  176. package/dist/cjs/js/src/abstract/krakenfutures.js +0 -9
  177. package/dist/cjs/js/src/abstract/kucoin.js +0 -9
  178. package/dist/cjs/js/src/abstract/kucoinfutures.js +0 -9
  179. package/dist/cjs/js/src/abstract/kuna.js +0 -9
  180. package/dist/cjs/js/src/abstract/latoken.js +0 -9
  181. package/dist/cjs/js/src/abstract/lbank.js +0 -9
  182. package/dist/cjs/js/src/abstract/luno.js +0 -9
  183. package/dist/cjs/js/src/abstract/lykke.js +0 -9
  184. package/dist/cjs/js/src/abstract/mercado.js +0 -9
  185. package/dist/cjs/js/src/abstract/mexc.js +0 -9
  186. package/dist/cjs/js/src/abstract/ndax.js +0 -9
  187. package/dist/cjs/js/src/abstract/novadax.js +0 -9
  188. package/dist/cjs/js/src/abstract/oceanex.js +0 -9
  189. package/dist/cjs/js/src/abstract/okcoin.js +0 -9
  190. package/dist/cjs/js/src/abstract/okx.js +0 -9
  191. package/dist/cjs/js/src/abstract/p2b.js +0 -9
  192. package/dist/cjs/js/src/abstract/paymium.js +0 -9
  193. package/dist/cjs/js/src/abstract/phemex.js +0 -9
  194. package/dist/cjs/js/src/abstract/poloniex.js +0 -9
  195. package/dist/cjs/js/src/abstract/poloniexfutures.js +0 -9
  196. package/dist/cjs/js/src/abstract/probit.js +0 -9
  197. package/dist/cjs/js/src/abstract/timex.js +0 -9
  198. package/dist/cjs/js/src/abstract/tokocrypto.js +0 -9
  199. package/dist/cjs/js/src/abstract/upbit.js +0 -9
  200. package/dist/cjs/js/src/abstract/wavesexchange.js +0 -9
  201. package/dist/cjs/js/src/abstract/wazirx.js +0 -9
  202. package/dist/cjs/js/src/abstract/whitebit.js +0 -9
  203. package/dist/cjs/js/src/abstract/woo.js +0 -9
  204. package/dist/cjs/js/src/abstract/yobit.js +0 -9
  205. package/dist/cjs/js/src/abstract/zaif.js +0 -9
  206. package/dist/cjs/js/src/abstract/zonda.js +0 -9
  207. package/dist/cjs/js/src/ace.js +0 -1058
  208. package/dist/cjs/js/src/alpaca.js +0 -1125
  209. package/dist/cjs/js/src/ascendex.js +0 -3365
  210. package/dist/cjs/js/src/base/Exchange.js +0 -5257
  211. package/dist/cjs/js/src/base/Precise.js +0 -263
  212. package/dist/cjs/js/src/base/errors.js +0 -299
  213. package/dist/cjs/js/src/base/functions/crypto.js +0 -78
  214. package/dist/cjs/js/src/base/functions/encode.js +0 -44
  215. package/dist/cjs/js/src/base/functions/generic.js +0 -193
  216. package/dist/cjs/js/src/base/functions/misc.js +0 -96
  217. package/dist/cjs/js/src/base/functions/number.js +0 -297
  218. package/dist/cjs/js/src/base/functions/platform.js +0 -28
  219. package/dist/cjs/js/src/base/functions/rsa.js +0 -34
  220. package/dist/cjs/js/src/base/functions/string.js +0 -48
  221. package/dist/cjs/js/src/base/functions/throttle.js +0 -66
  222. package/dist/cjs/js/src/base/functions/time.js +0 -187
  223. package/dist/cjs/js/src/base/functions/totp.js +0 -24
  224. package/dist/cjs/js/src/base/functions/type.js +0 -162
  225. package/dist/cjs/js/src/base/functions.js +0 -157
  226. package/dist/cjs/js/src/base/ws/Cache.js +0 -254
  227. package/dist/cjs/js/src/base/ws/Client.js +0 -299
  228. package/dist/cjs/js/src/base/ws/Future.js +0 -34
  229. package/dist/cjs/js/src/base/ws/OrderBook.js +0 -107
  230. package/dist/cjs/js/src/base/ws/OrderBookSide.js +0 -281
  231. package/dist/cjs/js/src/base/ws/WsClient.js +0 -69
  232. package/dist/cjs/js/src/bequant.js +0 -33
  233. package/dist/cjs/js/src/bigone.js +0 -2213
  234. package/dist/cjs/js/src/binance.js +0 -9845
  235. package/dist/cjs/js/src/binancecoinm.js +0 -45
  236. package/dist/cjs/js/src/binanceus.js +0 -92
  237. package/dist/cjs/js/src/binanceusdm.js +0 -58
  238. package/dist/cjs/js/src/bingx.js +0 -3846
  239. package/dist/cjs/js/src/bit2c.js +0 -916
  240. package/dist/cjs/js/src/bitbank.js +0 -1000
  241. package/dist/cjs/js/src/bitbay.js +0 -17
  242. package/dist/cjs/js/src/bitbns.js +0 -1220
  243. package/dist/cjs/js/src/bitcoincom.js +0 -17
  244. package/dist/cjs/js/src/bitfinex.js +0 -1670
  245. package/dist/cjs/js/src/bitfinex2.js +0 -2990
  246. package/dist/cjs/js/src/bitflyer.js +0 -1045
  247. package/dist/cjs/js/src/bitforex.js +0 -852
  248. package/dist/cjs/js/src/bitget.js +0 -8295
  249. package/dist/cjs/js/src/bithumb.js +0 -1090
  250. package/dist/cjs/js/src/bitmart.js +0 -4454
  251. package/dist/cjs/js/src/bitmex.js +0 -2881
  252. package/dist/cjs/js/src/bitopro.js +0 -1724
  253. package/dist/cjs/js/src/bitrue.js +0 -3253
  254. package/dist/cjs/js/src/bitso.js +0 -1753
  255. package/dist/cjs/js/src/bitstamp.js +0 -2188
  256. package/dist/cjs/js/src/bitteam.js +0 -2309
  257. package/dist/cjs/js/src/bitvavo.js +0 -1968
  258. package/dist/cjs/js/src/bl3p.js +0 -447
  259. package/dist/cjs/js/src/blockchaincom.js +0 -1160
  260. package/dist/cjs/js/src/btcalpha.js +0 -929
  261. package/dist/cjs/js/src/btcbox.js +0 -565
  262. package/dist/cjs/js/src/btcmarkets.js +0 -1237
  263. package/dist/cjs/js/src/btcturk.js +0 -929
  264. package/dist/cjs/js/src/bybit.js +0 -7650
  265. package/dist/cjs/js/src/cex.js +0 -1693
  266. package/dist/cjs/js/src/coinbase.js +0 -3424
  267. package/dist/cjs/js/src/coinbasepro.js +0 -1866
  268. package/dist/cjs/js/src/coincheck.js +0 -843
  269. package/dist/cjs/js/src/coinex.js +0 -5417
  270. package/dist/cjs/js/src/coinlist.js +0 -2337
  271. package/dist/cjs/js/src/coinmate.js +0 -989
  272. package/dist/cjs/js/src/coinone.js +0 -1185
  273. package/dist/cjs/js/src/coinsph.js +0 -1933
  274. package/dist/cjs/js/src/coinspot.js +0 -548
  275. package/dist/cjs/js/src/cryptocom.js +0 -3007
  276. package/dist/cjs/js/src/currencycom.js +0 -2015
  277. package/dist/cjs/js/src/delta.js +0 -3262
  278. package/dist/cjs/js/src/deribit.js +0 -3306
  279. package/dist/cjs/js/src/digifinex.js +0 -4307
  280. package/dist/cjs/js/src/exmo.js +0 -2645
  281. package/dist/cjs/js/src/fmfwio.js +0 -34
  282. package/dist/cjs/js/src/gate.js +0 -7077
  283. package/dist/cjs/js/src/gateio.js +0 -16
  284. package/dist/cjs/js/src/gemini.js +0 -1801
  285. package/dist/cjs/js/src/hitbtc.js +0 -3660
  286. package/dist/cjs/js/src/hitbtc3.js +0 -19
  287. package/dist/cjs/js/src/hollaex.js +0 -1882
  288. package/dist/cjs/js/src/htx.js +0 -9174
  289. package/dist/cjs/js/src/huobi.js +0 -16
  290. package/dist/cjs/js/src/huobijp.js +0 -1918
  291. package/dist/cjs/js/src/idex.js +0 -1770
  292. package/dist/cjs/js/src/independentreserve.js +0 -761
  293. package/dist/cjs/js/src/indodax.js +0 -1069
  294. package/dist/cjs/js/src/kraken.js +0 -2891
  295. package/dist/cjs/js/src/krakenfutures.js +0 -2407
  296. package/dist/cjs/js/src/kucoin.js +0 -4494
  297. package/dist/cjs/js/src/kucoinfutures.js +0 -2529
  298. package/dist/cjs/js/src/kuna.js +0 -1949
  299. package/dist/cjs/js/src/latoken.js +0 -1729
  300. package/dist/cjs/js/src/lbank.js +0 -2851
  301. package/dist/cjs/js/src/luno.js +0 -1044
  302. package/dist/cjs/js/src/lykke.js +0 -1303
  303. package/dist/cjs/js/src/mercado.js +0 -897
  304. package/dist/cjs/js/src/mexc.js +0 -5407
  305. package/dist/cjs/js/src/ndax.js +0 -2450
  306. package/dist/cjs/js/src/novadax.js +0 -1556
  307. package/dist/cjs/js/src/oceanex.js +0 -964
  308. package/dist/cjs/js/src/okcoin.js +0 -3115
  309. package/dist/cjs/js/src/okx.js +0 -7331
  310. package/dist/cjs/js/src/p2b.js +0 -1243
  311. package/dist/cjs/js/src/paymium.js +0 -597
  312. package/dist/cjs/js/src/phemex.js +0 -4725
  313. package/dist/cjs/js/src/poloniex.js +0 -2356
  314. package/dist/cjs/js/src/poloniexfutures.js +0 -1794
  315. package/dist/cjs/js/src/pro/alpaca.js +0 -714
  316. package/dist/cjs/js/src/pro/ascendex.js +0 -957
  317. package/dist/cjs/js/src/pro/bequant.js +0 -33
  318. package/dist/cjs/js/src/pro/binance.js +0 -2796
  319. package/dist/cjs/js/src/pro/binancecoinm.js +0 -23
  320. package/dist/cjs/js/src/pro/binanceus.js +0 -51
  321. package/dist/cjs/js/src/pro/binanceusdm.js +0 -32
  322. package/dist/cjs/js/src/pro/bingx.js +0 -944
  323. package/dist/cjs/js/src/pro/bitcoincom.js +0 -29
  324. package/dist/cjs/js/src/pro/bitfinex.js +0 -672
  325. package/dist/cjs/js/src/pro/bitfinex2.js +0 -1159
  326. package/dist/cjs/js/src/pro/bitget.js +0 -1733
  327. package/dist/cjs/js/src/pro/bitmart.js +0 -1486
  328. package/dist/cjs/js/src/pro/bitmex.js +0 -1576
  329. package/dist/cjs/js/src/pro/bitopro.js +0 -327
  330. package/dist/cjs/js/src/pro/bitrue.js +0 -462
  331. package/dist/cjs/js/src/pro/bitstamp.js +0 -547
  332. package/dist/cjs/js/src/pro/bitvavo.js +0 -704
  333. package/dist/cjs/js/src/pro/blockchaincom.js +0 -794
  334. package/dist/cjs/js/src/pro/bybit.js +0 -1843
  335. package/dist/cjs/js/src/pro/cex.js +0 -1510
  336. package/dist/cjs/js/src/pro/coinbase.js +0 -561
  337. package/dist/cjs/js/src/pro/coinbasepro.js +0 -968
  338. package/dist/cjs/js/src/pro/coinex.js +0 -1095
  339. package/dist/cjs/js/src/pro/cryptocom.js +0 -1020
  340. package/dist/cjs/js/src/pro/currencycom.js +0 -563
  341. package/dist/cjs/js/src/pro/deribit.js +0 -825
  342. package/dist/cjs/js/src/pro/exmo.js +0 -658
  343. package/dist/cjs/js/src/pro/gate.js +0 -1316
  344. package/dist/cjs/js/src/pro/gateio.js +0 -16
  345. package/dist/cjs/js/src/pro/gemini.js +0 -649
  346. package/dist/cjs/js/src/pro/hitbtc.js +0 -1294
  347. package/dist/cjs/js/src/pro/hollaex.js +0 -597
  348. package/dist/cjs/js/src/pro/htx.js +0 -2388
  349. package/dist/cjs/js/src/pro/huobi.js +0 -16
  350. package/dist/cjs/js/src/pro/huobijp.js +0 -606
  351. package/dist/cjs/js/src/pro/idex.js +0 -714
  352. package/dist/cjs/js/src/pro/independentreserve.js +0 -280
  353. package/dist/cjs/js/src/pro/kraken.js +0 -1364
  354. package/dist/cjs/js/src/pro/krakenfutures.js +0 -1506
  355. package/dist/cjs/js/src/pro/kucoin.js +0 -1054
  356. package/dist/cjs/js/src/pro/kucoinfutures.js +0 -981
  357. package/dist/cjs/js/src/pro/luno.js +0 -322
  358. package/dist/cjs/js/src/pro/mexc.js +0 -1170
  359. package/dist/cjs/js/src/pro/ndax.js +0 -545
  360. package/dist/cjs/js/src/pro/okcoin.js +0 -760
  361. package/dist/cjs/js/src/pro/okx.js +0 -1608
  362. package/dist/cjs/js/src/pro/phemex.js +0 -1511
  363. package/dist/cjs/js/src/pro/poloniex.js +0 -1253
  364. package/dist/cjs/js/src/pro/poloniexfutures.js +0 -1014
  365. package/dist/cjs/js/src/pro/probit.js +0 -586
  366. package/dist/cjs/js/src/pro/upbit.js +0 -234
  367. package/dist/cjs/js/src/pro/wazirx.js +0 -776
  368. package/dist/cjs/js/src/pro/whitebit.js +0 -927
  369. package/dist/cjs/js/src/pro/woo.js +0 -895
  370. package/dist/cjs/js/src/probit.js +0 -1867
  371. package/dist/cjs/js/src/static_dependencies/fflake/browser.js +0 -401
  372. package/dist/cjs/js/src/static_dependencies/jsencrypt/JSEncrypt.js +0 -195
  373. package/dist/cjs/js/src/static_dependencies/jsencrypt/JSEncryptRSAKey.js +0 -308
  374. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/asn1js/asn1.js +0 -554
  375. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/asn1js/base64.js +0 -94
  376. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/asn1js/hex.js +0 -70
  377. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/asn1js/int10.js +0 -91
  378. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/base64.js +0 -16
  379. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/jsbn.js +0 -1760
  380. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/prng4.js +0 -52
  381. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/rng.js +0 -81
  382. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/rsa.js +0 -376
  383. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/util.js +0 -70
  384. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsrsasign/asn1-1.0.js +0 -1580
  385. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsrsasign/yahoo.js +0 -74
  386. package/dist/cjs/js/src/static_dependencies/noble-curves/_shortw_utils.js +0 -24
  387. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/curve.js +0 -158
  388. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/edwards.js +0 -429
  389. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/hash-to-curve.js +0 -176
  390. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/modular.js +0 -324
  391. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/montgomery.js +0 -163
  392. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/utils.js +0 -245
  393. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/weierstrass.js +0 -1018
  394. package/dist/cjs/js/src/static_dependencies/noble-curves/ed25519.js +0 -383
  395. package/dist/cjs/js/src/static_dependencies/noble-curves/secp256k1.js +0 -258
  396. package/dist/cjs/js/src/static_dependencies/noble-hashes/_assert.js +0 -53
  397. package/dist/cjs/js/src/static_dependencies/noble-hashes/_sha2.js +0 -120
  398. package/dist/cjs/js/src/static_dependencies/noble-hashes/_u64.js +0 -69
  399. package/dist/cjs/js/src/static_dependencies/noble-hashes/crypto.js +0 -7
  400. package/dist/cjs/js/src/static_dependencies/noble-hashes/hmac.js +0 -83
  401. package/dist/cjs/js/src/static_dependencies/noble-hashes/md5.js +0 -240
  402. package/dist/cjs/js/src/static_dependencies/noble-hashes/sha1.js +0 -91
  403. package/dist/cjs/js/src/static_dependencies/noble-hashes/sha256.js +0 -130
  404. package/dist/cjs/js/src/static_dependencies/noble-hashes/sha3.js +0 -214
  405. package/dist/cjs/js/src/static_dependencies/noble-hashes/sha512.js +0 -239
  406. package/dist/cjs/js/src/static_dependencies/noble-hashes/utils.js +0 -93
  407. package/dist/cjs/js/src/static_dependencies/node-fetch/body.js +0 -354
  408. package/dist/cjs/js/src/static_dependencies/node-fetch/errors/abort-error.js +0 -16
  409. package/dist/cjs/js/src/static_dependencies/node-fetch/errors/base.js +0 -20
  410. package/dist/cjs/js/src/static_dependencies/node-fetch/errors/fetch-error.js +0 -30
  411. package/dist/cjs/js/src/static_dependencies/node-fetch/headers.js +0 -239
  412. package/dist/cjs/js/src/static_dependencies/node-fetch/index.js +0 -372
  413. package/dist/cjs/js/src/static_dependencies/node-fetch/request.js +0 -273
  414. package/dist/cjs/js/src/static_dependencies/node-fetch/response.js +0 -139
  415. package/dist/cjs/js/src/static_dependencies/node-fetch/utils/get-search.js +0 -14
  416. package/dist/cjs/js/src/static_dependencies/node-fetch/utils/is-redirect.js +0 -16
  417. package/dist/cjs/js/src/static_dependencies/node-fetch/utils/is.js +0 -81
  418. package/dist/cjs/js/src/static_dependencies/node-fetch/utils/referrer.js +0 -292
  419. package/dist/cjs/js/src/static_dependencies/proxies/agent-base/index.js +0 -103
  420. package/dist/cjs/js/src/static_dependencies/proxies/http-proxy-agent/index.js +0 -140
  421. package/dist/cjs/js/src/static_dependencies/proxies/https-proxy-agent/index.js +0 -175
  422. package/dist/cjs/js/src/static_dependencies/proxies/https-proxy-agent/parse-proxy-response.js +0 -95
  423. package/dist/cjs/js/src/static_dependencies/qs/index.cjs.js +0 -7
  424. package/dist/cjs/js/src/static_dependencies/scure-base/index.js +0 -383
  425. package/dist/cjs/js/src/timex.js +0 -1562
  426. package/dist/cjs/js/src/tokocrypto.js +0 -2542
  427. package/dist/cjs/js/src/upbit.js +0 -1844
  428. package/dist/cjs/js/src/wavesexchange.js +0 -2607
  429. package/dist/cjs/js/src/wazirx.js +0 -953
  430. package/dist/cjs/js/src/whitebit.js +0 -2309
  431. package/dist/cjs/js/src/woo.js +0 -2769
  432. package/dist/cjs/js/src/yobit.js +0 -1314
  433. package/dist/cjs/js/src/zaif.js +0 -736
  434. package/dist/cjs/js/src/zonda.js +0 -1883
  435. package/dist/cjs/src/abstract/bitpanda.js +0 -9
  436. package/test.ts +0 -0
  437. /package/dist/cjs/{js/src/abstract/ace.js → src/abstract/onetrading.js} +0 -0
  438. /package/dist/cjs/{js/src → src}/pro/coinone.js +0 -0
  439. /package/js/src/abstract/{bitpanda.js → onetrading.js} +0 -0
@@ -1,3306 +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
- const response = await this.privateGetGetOrderState(this.extend(request, params));
1687
- //
1688
- // {
1689
- // "jsonrpc": "2.0",
1690
- // "id": 4316,
1691
- // "result": {
1692
- // "time_in_force": "good_til_cancelled",
1693
- // "reduce_only": false,
1694
- // "profit_loss": 0.051134,
1695
- // "price": 118.94,
1696
- // "post_only": false,
1697
- // "order_type": "limit",
1698
- // "order_state": "filled",
1699
- // "order_id": "ETH-331562",
1700
- // "max_show": 37,
1701
- // "last_update_timestamp": 1550219810944,
1702
- // "label": "",
1703
- // "is_liquidation": false,
1704
- // "instrument_name": "ETH-PERPETUAL",
1705
- // "filled_amount": 37,
1706
- // "direction": "sell",
1707
- // "creation_timestamp": 1550219749176,
1708
- // "commission": 0.000031,
1709
- // "average_price": 118.94,
1710
- // "api": false,
1711
- // "amount": 37
1712
- // }
1713
- // }
1714
- //
1715
- const result = this.safeValue(response, 'result');
1716
- return this.parseOrder(result);
1717
- }
1718
- async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
1719
- /**
1720
- * @method
1721
- * @name deribit#createOrder
1722
- * @description create a trade order
1723
- * @see https://docs.deribit.com/#private-buy
1724
- * @param {string} symbol unified symbol of the market to create an order in
1725
- * @param {string} type 'market' or 'limit'
1726
- * @param {string} side 'buy' or 'sell'
1727
- * @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.
1728
- * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
1729
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1730
- * @param {string} [params.trigger] the trigger type 'index_price', 'mark_price', or 'last_price', default is 'last_price'
1731
- * @param {float} [params.trailingAmount] the quote amount to trail away from the current market price
1732
- * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1733
- */
1734
- await this.loadMarkets();
1735
- const market = this.market(symbol);
1736
- const request = {
1737
- 'instrument_name': market['id'],
1738
- 'amount': this.amountToPrecision(symbol, amount),
1739
- 'type': type, // limit, stop_limit, market, stop_market, default is limit
1740
- // 'label': 'string', // user-defined label for the order (maximum 64 characters)
1741
- // 'price': this.priceToPrecision (symbol, 123.45), // only for limit and stop_limit orders
1742
- // 'time_in_force' : 'good_til_cancelled', // fill_or_kill, immediate_or_cancel
1743
- // 'max_show': 123.45, // max amount within an order to be shown to other customers, 0 for invisible order
1744
- // '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.
1745
- // 'reject_post_only': false, // if true the order is put to order book unmodified or request is rejected
1746
- // 'reduce_only': false, // if true, the order is intended to only reduce a current position
1747
- // 'stop_price': false, // stop price, required for stop_limit orders
1748
- // 'trigger': 'index_price', // mark_price, last_price, required for stop_limit orders
1749
- // 'advanced': 'usd', // 'implv', advanced option order type, options only
1750
- };
1751
- const trigger = this.safeString(params, 'trigger', 'last_price');
1752
- const timeInForce = this.safeStringUpper(params, 'timeInForce');
1753
- const reduceOnly = this.safeValue2(params, 'reduceOnly', 'reduce_only');
1754
- // only stop loss sell orders are allowed when price crossed from above
1755
- const stopLossPrice = this.safeValue(params, 'stopLossPrice');
1756
- // only take profit buy orders are allowed when price crossed from below
1757
- const takeProfitPrice = this.safeValue(params, 'takeProfitPrice');
1758
- const trailingAmount = this.safeString2(params, 'trailingAmount', 'trigger_offset');
1759
- const isTrailingAmountOrder = trailingAmount !== undefined;
1760
- const isStopLimit = type === 'stop_limit';
1761
- const isStopMarket = type === 'stop_market';
1762
- const isTakeLimit = type === 'take_limit';
1763
- const isTakeMarket = type === 'take_market';
1764
- const isStopLossOrder = isStopLimit || isStopMarket || (stopLossPrice !== undefined);
1765
- const isTakeProfitOrder = isTakeLimit || isTakeMarket || (takeProfitPrice !== undefined);
1766
- if (isStopLossOrder && isTakeProfitOrder) {
1767
- throw new errors.InvalidOrder(this.id + ' createOrder () only allows one of stopLossPrice or takeProfitPrice to be specified');
1768
- }
1769
- const isStopOrder = isStopLossOrder || isTakeProfitOrder;
1770
- const isLimitOrder = (type === 'limit') || isStopLimit || isTakeLimit;
1771
- const isMarketOrder = (type === 'market') || isStopMarket || isTakeMarket;
1772
- const exchangeSpecificPostOnly = this.safeValue(params, 'post_only');
1773
- const postOnly = this.isPostOnly(isMarketOrder, exchangeSpecificPostOnly, params);
1774
- if (isLimitOrder) {
1775
- request['type'] = 'limit';
1776
- request['price'] = this.priceToPrecision(symbol, price);
1777
- }
1778
- else {
1779
- request['type'] = 'market';
1780
- }
1781
- if (isTrailingAmountOrder) {
1782
- request['trigger'] = trigger;
1783
- request['type'] = 'trailing_stop';
1784
- request['trigger_offset'] = this.parseToNumeric(trailingAmount);
1785
- }
1786
- else if (isStopOrder) {
1787
- const triggerPrice = (stopLossPrice !== undefined) ? stopLossPrice : takeProfitPrice;
1788
- request['trigger_price'] = this.priceToPrecision(symbol, triggerPrice);
1789
- request['trigger'] = trigger;
1790
- if (isStopLossOrder) {
1791
- if (isMarketOrder) {
1792
- // stop_market (sell only)
1793
- request['type'] = 'stop_market';
1794
- }
1795
- else {
1796
- // stop_limit (sell only)
1797
- request['type'] = 'stop_limit';
1798
- }
1799
- }
1800
- else {
1801
- if (isMarketOrder) {
1802
- // take_market (buy only)
1803
- request['type'] = 'take_market';
1804
- }
1805
- else {
1806
- // take_limit (buy only)
1807
- request['type'] = 'take_limit';
1808
- }
1809
- }
1810
- }
1811
- if (reduceOnly) {
1812
- request['reduce_only'] = true;
1813
- }
1814
- if (postOnly) {
1815
- request['post_only'] = true;
1816
- request['reject_post_only'] = true;
1817
- }
1818
- if (timeInForce !== undefined) {
1819
- if (timeInForce === 'GTC') {
1820
- request['time_in_force'] = 'good_til_cancelled';
1821
- }
1822
- if (timeInForce === 'IOC') {
1823
- request['time_in_force'] = 'immediate_or_cancel';
1824
- }
1825
- if (timeInForce === 'FOK') {
1826
- request['time_in_force'] = 'fill_or_kill';
1827
- }
1828
- }
1829
- params = this.omit(params, ['timeInForce', 'stopLossPrice', 'takeProfitPrice', 'postOnly', 'reduceOnly', 'trailingAmount']);
1830
- let response = undefined;
1831
- if (this.capitalize(side) === 'Buy') {
1832
- response = await this.privateGetBuy(this.extend(request, params));
1833
- }
1834
- else {
1835
- response = await this.privateGetSell(this.extend(request, params));
1836
- }
1837
- //
1838
- // {
1839
- // "jsonrpc": "2.0",
1840
- // "id": 5275,
1841
- // "result": {
1842
- // "trades": [
1843
- // {
1844
- // "trade_seq": 14151,
1845
- // "trade_id": "ETH-37435",
1846
- // "timestamp": 1550657341322,
1847
- // "tick_direction": 2,
1848
- // "state": "closed",
1849
- // "self_trade": false,
1850
- // "price": 143.81,
1851
- // "order_type": "market",
1852
- // "order_id": "ETH-349249",
1853
- // "matching_id": null,
1854
- // "liquidity": "T",
1855
- // "label": "market0000234",
1856
- // "instrument_name": "ETH-PERPETUAL",
1857
- // "index_price": 143.73,
1858
- // "fee_currency": "ETH",
1859
- // "fee": 0.000139,
1860
- // "direction": "buy",
1861
- // "amount": 40
1862
- // }
1863
- // ],
1864
- // "order": {
1865
- // "time_in_force": "good_til_cancelled",
1866
- // "reduce_only": false,
1867
- // "profit_loss": 0,
1868
- // "price": "market_price",
1869
- // "post_only": false,
1870
- // "order_type": "market",
1871
- // "order_state": "filled",
1872
- // "order_id": "ETH-349249",
1873
- // "max_show": 40,
1874
- // "last_update_timestamp": 1550657341322,
1875
- // "label": "market0000234",
1876
- // "is_liquidation": false,
1877
- // "instrument_name": "ETH-PERPETUAL",
1878
- // "filled_amount": 40,
1879
- // "direction": "buy",
1880
- // "creation_timestamp": 1550657341322,
1881
- // "commission": 0.000139,
1882
- // "average_price": 143.81,
1883
- // "api": true,
1884
- // "amount": 40
1885
- // }
1886
- // }
1887
- // }
1888
- //
1889
- const result = this.safeValue(response, 'result', {});
1890
- const order = this.safeValue(result, 'order');
1891
- const trades = this.safeValue(result, 'trades', []);
1892
- order['trades'] = trades;
1893
- return this.parseOrder(order, market);
1894
- }
1895
- async editOrder(id, symbol, type, side, amount = undefined, price = undefined, params = {}) {
1896
- /**
1897
- * @method
1898
- * @name deribit#editOrder
1899
- * @description edit a trade order
1900
- * @see https://docs.deribit.com/#private-edit
1901
- * @param {string} id edit order id
1902
- * @param {string} [symbol] unified symbol of the market to edit an order in
1903
- * @param {string} [type] 'market' or 'limit'
1904
- * @param {string} [side] 'buy' or 'sell'
1905
- * @param {float} amount how much you want to trade in units of the base currency, inverse swap and future use the quote currency
1906
- * @param {float} [price] the price at which the order is to be fullfilled, in units of the base currency, ignored in market orders
1907
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1908
- * @param {float} [params.trailingAmount] the quote amount to trail away from the current market price
1909
- * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1910
- */
1911
- if (amount === undefined) {
1912
- throw new errors.ArgumentsRequired(this.id + ' editOrder() requires an amount argument');
1913
- }
1914
- await this.loadMarkets();
1915
- const request = {
1916
- 'order_id': id,
1917
- 'amount': this.amountToPrecision(symbol, amount),
1918
- // '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.
1919
- // 'reject_post_only': false, // if true the order is put to order book unmodified or request is rejected
1920
- // 'reduce_only': false, // if true, the order is intended to only reduce a current position
1921
- // 'stop_price': false, // stop price, required for stop_limit orders
1922
- // 'advanced': 'usd', // 'implv', advanced option order type, options only
1923
- };
1924
- if (price !== undefined) {
1925
- request['price'] = this.priceToPrecision(symbol, price);
1926
- }
1927
- const trailingAmount = this.safeString2(params, 'trailingAmount', 'trigger_offset');
1928
- const isTrailingAmountOrder = trailingAmount !== undefined;
1929
- if (isTrailingAmountOrder) {
1930
- request['trigger_offset'] = this.parseToNumeric(trailingAmount);
1931
- params = this.omit(params, 'trigger_offset');
1932
- }
1933
- const response = await this.privateGetEdit(this.extend(request, params));
1934
- const result = this.safeValue(response, 'result', {});
1935
- const order = this.safeValue(result, 'order');
1936
- const trades = this.safeValue(result, 'trades', []);
1937
- order['trades'] = trades;
1938
- return this.parseOrder(order);
1939
- }
1940
- async cancelOrder(id, symbol = undefined, params = {}) {
1941
- /**
1942
- * @method
1943
- * @name deribit#cancelOrder
1944
- * @description cancels an open order
1945
- * @param {string} id order id
1946
- * @param {string} symbol not used by deribit cancelOrder ()
1947
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1948
- * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1949
- */
1950
- await this.loadMarkets();
1951
- const request = {
1952
- 'order_id': id,
1953
- };
1954
- const response = await this.privateGetCancel(this.extend(request, params));
1955
- const result = this.safeValue(response, 'result', {});
1956
- return this.parseOrder(result);
1957
- }
1958
- async cancelAllOrders(symbol = undefined, params = {}) {
1959
- /**
1960
- * @method
1961
- * @name deribit#cancelAllOrders
1962
- * @description cancel all open orders
1963
- * @param {string} symbol unified market symbol, only orders in the market of this symbol are cancelled when symbol is not undefined
1964
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1965
- * @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
1966
- */
1967
- await this.loadMarkets();
1968
- const request = {};
1969
- let response = undefined;
1970
- if (symbol === undefined) {
1971
- response = await this.privateGetCancelAll(this.extend(request, params));
1972
- }
1973
- else {
1974
- const market = this.market(symbol);
1975
- request['instrument_name'] = market['id'];
1976
- response = await this.privateGetCancelAllByInstrument(this.extend(request, params));
1977
- }
1978
- return response;
1979
- }
1980
- async fetchOpenOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
1981
- /**
1982
- * @method
1983
- * @name deribit#fetchOpenOrders
1984
- * @description fetch all unfilled currently open orders
1985
- * @param {string} symbol unified market symbol
1986
- * @param {int} [since] the earliest time in ms to fetch open orders for
1987
- * @param {int} [limit] the maximum number of open orders structures to retrieve
1988
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1989
- * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
1990
- */
1991
- await this.loadMarkets();
1992
- const request = {};
1993
- let market = undefined;
1994
- let response = undefined;
1995
- if (symbol === undefined) {
1996
- const code = this.codeFromOptions('fetchOpenOrders', params);
1997
- const currency = this.currency(code);
1998
- request['currency'] = currency['id'];
1999
- response = await this.privateGetGetOpenOrdersByCurrency(this.extend(request, params));
2000
- }
2001
- else {
2002
- market = this.market(symbol);
2003
- request['instrument_name'] = market['id'];
2004
- response = await this.privateGetGetOpenOrdersByInstrument(this.extend(request, params));
2005
- }
2006
- const result = this.safeValue(response, 'result', []);
2007
- return this.parseOrders(result, market, since, limit);
2008
- }
2009
- async fetchClosedOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
2010
- /**
2011
- * @method
2012
- * @name deribit#fetchClosedOrders
2013
- * @description fetches information on multiple closed orders made by the user
2014
- * @param {string} symbol unified market symbol of the market orders were made in
2015
- * @param {int} [since] the earliest time in ms to fetch orders for
2016
- * @param {int} [limit] the maximum number of order structures to retrieve
2017
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2018
- * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
2019
- */
2020
- await this.loadMarkets();
2021
- const request = {};
2022
- let market = undefined;
2023
- let response = undefined;
2024
- if (symbol === undefined) {
2025
- const code = this.codeFromOptions('fetchClosedOrders', params);
2026
- const currency = this.currency(code);
2027
- request['currency'] = currency['id'];
2028
- response = await this.privateGetGetOrderHistoryByCurrency(this.extend(request, params));
2029
- }
2030
- else {
2031
- market = this.market(symbol);
2032
- request['instrument_name'] = market['id'];
2033
- response = await this.privateGetGetOrderHistoryByInstrument(this.extend(request, params));
2034
- }
2035
- const result = this.safeValue(response, 'result', []);
2036
- return this.parseOrders(result, market, since, limit);
2037
- }
2038
- async fetchOrderTrades(id, symbol = undefined, since = undefined, limit = undefined, params = {}) {
2039
- /**
2040
- * @method
2041
- * @name deribit#fetchOrderTrades
2042
- * @description fetch all the trades made from a single order
2043
- * @param {string} id order id
2044
- * @param {string} symbol unified market symbol
2045
- * @param {int} [since] the earliest time in ms to fetch trades for
2046
- * @param {int} [limit] the maximum number of trades to retrieve
2047
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2048
- * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure}
2049
- */
2050
- await this.loadMarkets();
2051
- const request = {
2052
- 'order_id': id,
2053
- };
2054
- const response = await this.privateGetGetUserTradesByOrder(this.extend(request, params));
2055
- //
2056
- // {
2057
- // "jsonrpc": "2.0",
2058
- // "id": 9367,
2059
- // "result": {
2060
- // "trades": [
2061
- // {
2062
- // "trade_seq": 3,
2063
- // "trade_id": "ETH-34066",
2064
- // "timestamp": 1550219814585,
2065
- // "tick_direction": 1,
2066
- // "state": "open",
2067
- // "self_trade": false,
2068
- // "reduce_only": false,
2069
- // "price": 0.04,
2070
- // "post_only": false,
2071
- // "order_type": "limit",
2072
- // "order_id": "ETH-334607",
2073
- // "matching_id": null,
2074
- // "liquidity": "M",
2075
- // "iv": 56.83,
2076
- // "instrument_name": "ETH-22FEB19-120-C",
2077
- // "index_price": 121.37,
2078
- // "fee_currency": "ETH",
2079
- // "fee": 0.0011,
2080
- // "direction": "buy",
2081
- // "amount": 11
2082
- // },
2083
- // ],
2084
- // "has_more": true
2085
- // }
2086
- // }
2087
- //
2088
- const result = this.safeValue(response, 'result', {});
2089
- return this.parseTrades(result, undefined, since, limit);
2090
- }
2091
- async fetchMyTrades(symbol = undefined, since = undefined, limit = undefined, params = {}) {
2092
- /**
2093
- * @method
2094
- * @name deribit#fetchMyTrades
2095
- * @description fetch all trades made by the user
2096
- * @param {string} symbol unified market symbol
2097
- * @param {int} [since] the earliest time in ms to fetch trades for
2098
- * @param {int} [limit] the maximum number of trades structures to retrieve
2099
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2100
- * @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure}
2101
- */
2102
- await this.loadMarkets();
2103
- const request = {
2104
- 'include_old': true,
2105
- };
2106
- let market = undefined;
2107
- if (limit !== undefined) {
2108
- request['count'] = limit; // default 10
2109
- }
2110
- let response = undefined;
2111
- if (symbol === undefined) {
2112
- const code = this.codeFromOptions('fetchMyTrades', params);
2113
- const currency = this.currency(code);
2114
- request['currency'] = currency['id'];
2115
- if (since === undefined) {
2116
- response = await this.privateGetGetUserTradesByCurrency(this.extend(request, params));
2117
- }
2118
- else {
2119
- request['start_timestamp'] = since;
2120
- response = await this.privateGetGetUserTradesByCurrencyAndTime(this.extend(request, params));
2121
- }
2122
- }
2123
- else {
2124
- market = this.market(symbol);
2125
- request['instrument_name'] = market['id'];
2126
- if (since === undefined) {
2127
- response = await this.privateGetGetUserTradesByInstrument(this.extend(request, params));
2128
- }
2129
- else {
2130
- request['start_timestamp'] = since;
2131
- response = await this.privateGetGetUserTradesByInstrumentAndTime(this.extend(request, params));
2132
- }
2133
- }
2134
- //
2135
- // {
2136
- // "jsonrpc": "2.0",
2137
- // "id": 9367,
2138
- // "result": {
2139
- // "trades": [
2140
- // {
2141
- // "trade_seq": 3,
2142
- // "trade_id": "ETH-34066",
2143
- // "timestamp": 1550219814585,
2144
- // "tick_direction": 1,
2145
- // "state": "open",
2146
- // "self_trade": false,
2147
- // "reduce_only": false,
2148
- // "price": 0.04,
2149
- // "post_only": false,
2150
- // "order_type": "limit",
2151
- // "order_id": "ETH-334607",
2152
- // "matching_id": null,
2153
- // "liquidity": "M",
2154
- // "iv": 56.83,
2155
- // "instrument_name": "ETH-22FEB19-120-C",
2156
- // "index_price": 121.37,
2157
- // "fee_currency": "ETH",
2158
- // "fee": 0.0011,
2159
- // "direction": "buy",
2160
- // "amount": 11
2161
- // },
2162
- // ],
2163
- // "has_more": true
2164
- // }
2165
- // }
2166
- //
2167
- const result = this.safeValue(response, 'result', {});
2168
- const trades = this.safeValue(result, 'trades', []);
2169
- return this.parseTrades(trades, market, since, limit);
2170
- }
2171
- async fetchDeposits(code = undefined, since = undefined, limit = undefined, params = {}) {
2172
- /**
2173
- * @method
2174
- * @name deribit#fetchDeposits
2175
- * @description fetch all deposits made to an account
2176
- * @param {string} code unified currency code
2177
- * @param {int} [since] the earliest time in ms to fetch deposits for
2178
- * @param {int} [limit] the maximum number of deposits structures to retrieve
2179
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2180
- * @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/#/?id=transaction-structure}
2181
- */
2182
- if (code === undefined) {
2183
- throw new errors.ArgumentsRequired(this.id + ' fetchDeposits() requires a currency code argument');
2184
- }
2185
- await this.loadMarkets();
2186
- const currency = this.currency(code);
2187
- const request = {
2188
- 'currency': currency['id'],
2189
- };
2190
- if (limit !== undefined) {
2191
- request['count'] = limit;
2192
- }
2193
- const response = await this.privateGetGetDeposits(this.extend(request, params));
2194
- //
2195
- // {
2196
- // "jsonrpc": "2.0",
2197
- // "id": 5611,
2198
- // "result": {
2199
- // "count": 1,
2200
- // "data": [
2201
- // {
2202
- // "address": "2N35qDKDY22zmJq9eSyiAerMD4enJ1xx6ax",
2203
- // "amount": 5,
2204
- // "currency": "BTC",
2205
- // "received_timestamp": 1549295017670,
2206
- // "state": "completed",
2207
- // "transaction_id": "230669110fdaf0a0dbcdc079b6b8b43d5af29cc73683835b9bc6b3406c065fda",
2208
- // "updated_timestamp": 1549295130159
2209
- // }
2210
- // ]
2211
- // }
2212
- // }
2213
- //
2214
- const result = this.safeValue(response, 'result', {});
2215
- const data = this.safeValue(result, 'data', []);
2216
- return this.parseTransactions(data, currency, since, limit, params);
2217
- }
2218
- async fetchWithdrawals(code = undefined, since = undefined, limit = undefined, params = {}) {
2219
- /**
2220
- * @method
2221
- * @name deribit#fetchWithdrawals
2222
- * @description fetch all withdrawals made from an account
2223
- * @param {string} code unified currency code
2224
- * @param {int} [since] the earliest time in ms to fetch withdrawals for
2225
- * @param {int} [limit] the maximum number of withdrawals structures to retrieve
2226
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2227
- * @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/#/?id=transaction-structure}
2228
- */
2229
- if (code === undefined) {
2230
- throw new errors.ArgumentsRequired(this.id + ' fetchWithdrawals() requires a currency code argument');
2231
- }
2232
- await this.loadMarkets();
2233
- const currency = this.currency(code);
2234
- const request = {
2235
- 'currency': currency['id'],
2236
- };
2237
- if (limit !== undefined) {
2238
- request['count'] = limit;
2239
- }
2240
- const response = await this.privateGetGetWithdrawals(this.extend(request, params));
2241
- //
2242
- // {
2243
- // "jsonrpc": "2.0",
2244
- // "id": 2745,
2245
- // "result": {
2246
- // "count": 1,
2247
- // "data": [
2248
- // {
2249
- // "address": "2NBqqD5GRJ8wHy1PYyCXTe9ke5226FhavBz",
2250
- // "amount": 0.5,
2251
- // "confirmed_timestamp": null,
2252
- // "created_timestamp": 1550571443070,
2253
- // "currency": "BTC",
2254
- // "fee": 0.0001,
2255
- // "id": 1,
2256
- // "priority": 0.15,
2257
- // "state": "unconfirmed",
2258
- // "transaction_id": null,
2259
- // "updated_timestamp": 1550571443070
2260
- // }
2261
- // ]
2262
- // }
2263
- // }
2264
- //
2265
- const result = this.safeValue(response, 'result', {});
2266
- const data = this.safeValue(result, 'data', []);
2267
- return this.parseTransactions(data, currency, since, limit, params);
2268
- }
2269
- parseTransactionStatus(status) {
2270
- const statuses = {
2271
- 'completed': 'ok',
2272
- 'unconfirmed': 'pending',
2273
- };
2274
- return this.safeString(statuses, status, status);
2275
- }
2276
- parseTransaction(transaction, currency = undefined) {
2277
- //
2278
- // fetchWithdrawals
2279
- //
2280
- // {
2281
- // "address": "2NBqqD5GRJ8wHy1PYyCXTe9ke5226FhavBz",
2282
- // "amount": 0.5,
2283
- // "confirmed_timestamp": null,
2284
- // "created_timestamp": 1550571443070,
2285
- // "currency": "BTC",
2286
- // "fee": 0.0001,
2287
- // "id": 1,
2288
- // "priority": 0.15,
2289
- // "state": "unconfirmed",
2290
- // "transaction_id": null,
2291
- // "updated_timestamp": 1550571443070
2292
- // }
2293
- //
2294
- // fetchDeposits
2295
- //
2296
- // {
2297
- // "address": "2N35qDKDY22zmJq9eSyiAerMD4enJ1xx6ax",
2298
- // "amount": 5,
2299
- // "currency": "BTC",
2300
- // "received_timestamp": 1549295017670,
2301
- // "state": "completed",
2302
- // "transaction_id": "230669110fdaf0a0dbcdc079b6b8b43d5af29cc73683835b9bc6b3406c065fda",
2303
- // "updated_timestamp": 1549295130159
2304
- // }
2305
- //
2306
- const currencyId = this.safeString(transaction, 'currency');
2307
- const code = this.safeCurrencyCode(currencyId, currency);
2308
- const timestamp = this.safeInteger2(transaction, 'created_timestamp', 'received_timestamp');
2309
- const updated = this.safeInteger(transaction, 'updated_timestamp');
2310
- const status = this.parseTransactionStatus(this.safeString(transaction, 'state'));
2311
- const address = this.safeString(transaction, 'address');
2312
- const feeCost = this.safeNumber(transaction, 'fee');
2313
- let type = 'deposit';
2314
- let fee = undefined;
2315
- if (feeCost !== undefined) {
2316
- type = 'withdrawal';
2317
- fee = {
2318
- 'cost': feeCost,
2319
- 'currency': code,
2320
- };
2321
- }
2322
- return {
2323
- 'info': transaction,
2324
- 'id': this.safeString(transaction, 'id'),
2325
- 'txid': this.safeString(transaction, 'transaction_id'),
2326
- 'timestamp': timestamp,
2327
- 'datetime': this.iso8601(timestamp),
2328
- 'address': address,
2329
- 'addressTo': address,
2330
- 'addressFrom': undefined,
2331
- 'tag': undefined,
2332
- 'tagTo': undefined,
2333
- 'tagFrom': undefined,
2334
- 'type': type,
2335
- 'amount': this.safeNumber(transaction, 'amount'),
2336
- 'currency': code,
2337
- 'status': status,
2338
- 'updated': updated,
2339
- 'network': undefined,
2340
- 'internal': undefined,
2341
- 'comment': undefined,
2342
- 'fee': fee,
2343
- };
2344
- }
2345
- parsePosition(position, market = undefined) {
2346
- //
2347
- // {
2348
- // "jsonrpc": "2.0",
2349
- // "id": 404,
2350
- // "result": {
2351
- // "average_price": 0,
2352
- // "delta": 0,
2353
- // "direction": "buy",
2354
- // "estimated_liquidation_price": 0,
2355
- // "floating_profit_loss": 0,
2356
- // "index_price": 3555.86,
2357
- // "initial_margin": 0,
2358
- // "instrument_name": "BTC-PERPETUAL",
2359
- // "leverage": 100,
2360
- // "kind": "future",
2361
- // "maintenance_margin": 0,
2362
- // "mark_price": 3556.62,
2363
- // "open_orders_margin": 0.000165889,
2364
- // "realized_profit_loss": 0,
2365
- // "settlement_price": 3555.44,
2366
- // "size": 0,
2367
- // "size_currency": 0,
2368
- // "total_profit_loss": 0
2369
- // }
2370
- // }
2371
- //
2372
- const contract = this.safeString(position, 'instrument_name');
2373
- market = this.safeMarket(contract, market);
2374
- let side = this.safeString(position, 'direction');
2375
- side = (side === 'buy') ? 'long' : 'short';
2376
- const unrealizedPnl = this.safeString(position, 'floating_profit_loss');
2377
- const initialMarginString = this.safeString(position, 'initial_margin');
2378
- const notionalString = this.safeString(position, 'size_currency');
2379
- const maintenanceMarginString = this.safeString(position, 'maintenance_margin');
2380
- const currentTime = this.milliseconds();
2381
- return this.safePosition({
2382
- 'info': position,
2383
- 'id': undefined,
2384
- 'symbol': this.safeString(market, 'symbol'),
2385
- 'timestamp': currentTime,
2386
- 'datetime': this.iso8601(currentTime),
2387
- 'lastUpdateTimestamp': undefined,
2388
- 'initialMargin': this.parseNumber(initialMarginString),
2389
- 'initialMarginPercentage': this.parseNumber(Precise["default"].stringMul(Precise["default"].stringDiv(initialMarginString, notionalString), '100')),
2390
- 'maintenanceMargin': this.parseNumber(maintenanceMarginString),
2391
- 'maintenanceMarginPercentage': this.parseNumber(Precise["default"].stringMul(Precise["default"].stringDiv(maintenanceMarginString, notionalString), '100')),
2392
- 'entryPrice': this.safeNumber(position, 'average_price'),
2393
- 'notional': this.parseNumber(notionalString),
2394
- 'leverage': this.safeInteger(position, 'leverage'),
2395
- 'unrealizedPnl': this.parseNumber(unrealizedPnl),
2396
- 'contracts': undefined,
2397
- 'contractSize': this.safeNumber(market, 'contractSize'),
2398
- 'marginRatio': undefined,
2399
- 'liquidationPrice': this.safeNumber(position, 'estimated_liquidation_price'),
2400
- 'markPrice': this.safeNumber(position, 'mark_price'),
2401
- 'lastPrice': undefined,
2402
- 'collateral': undefined,
2403
- 'marginMode': undefined,
2404
- 'side': side,
2405
- 'percentage': undefined,
2406
- 'hedged': undefined,
2407
- 'stopLossPrice': undefined,
2408
- 'takeProfitPrice': undefined,
2409
- });
2410
- }
2411
- async fetchPosition(symbol, params = {}) {
2412
- /**
2413
- * @method
2414
- * @name deribit#fetchPosition
2415
- * @description fetch data on a single open contract trade position
2416
- * @param {string} symbol unified market symbol of the market the position is held in, default is undefined
2417
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2418
- * @returns {object} a [position structure]{@link https://docs.ccxt.com/#/?id=position-structure}
2419
- */
2420
- await this.loadMarkets();
2421
- const market = this.market(symbol);
2422
- const request = {
2423
- 'instrument_name': market['id'],
2424
- };
2425
- const response = await this.privateGetGetPosition(this.extend(request, params));
2426
- //
2427
- // {
2428
- // "jsonrpc": "2.0",
2429
- // "id": 404,
2430
- // "result": {
2431
- // "average_price": 0,
2432
- // "delta": 0,
2433
- // "direction": "buy",
2434
- // "estimated_liquidation_price": 0,
2435
- // "floating_profit_loss": 0,
2436
- // "index_price": 3555.86,
2437
- // "initial_margin": 0,
2438
- // "instrument_name": "BTC-PERPETUAL",
2439
- // "leverage": 100,
2440
- // "kind": "future",
2441
- // "maintenance_margin": 0,
2442
- // "mark_price": 3556.62,
2443
- // "open_orders_margin": 0.000165889,
2444
- // "realized_profit_loss": 0,
2445
- // "settlement_price": 3555.44,
2446
- // "size": 0,
2447
- // "size_currency": 0,
2448
- // "total_profit_loss": 0
2449
- // }
2450
- // }
2451
- //
2452
- const result = this.safeValue(response, 'result');
2453
- return this.parsePosition(result);
2454
- }
2455
- async fetchPositions(symbols = undefined, params = {}) {
2456
- /**
2457
- * @method
2458
- * @name deribit#fetchPositions
2459
- * @description fetch all open positions
2460
- * @param {string[]|undefined} symbols list of unified market symbols
2461
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2462
- * @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/#/?id=position-structure}
2463
- */
2464
- await this.loadMarkets();
2465
- let code = undefined;
2466
- if (symbols === undefined) {
2467
- code = this.codeFromOptions('fetchPositions', params);
2468
- }
2469
- else if (typeof symbols === 'string') {
2470
- code = symbols;
2471
- symbols = undefined; // fix https://github.com/ccxt/ccxt/issues/13961
2472
- }
2473
- else {
2474
- if (Array.isArray(symbols)) {
2475
- const length = symbols.length;
2476
- if (length !== 1) {
2477
- throw new errors.BadRequest(this.id + ' fetchPositions() symbols argument cannot contain more than 1 symbol');
2478
- }
2479
- const market = this.market(symbols[0]);
2480
- code = market['base'];
2481
- }
2482
- }
2483
- const currency = this.currency(code);
2484
- const request = {
2485
- 'currency': currency['id'],
2486
- // "kind" : "future", "option"
2487
- };
2488
- const response = await this.privateGetGetPositions(this.extend(request, params));
2489
- //
2490
- // {
2491
- // "jsonrpc": "2.0",
2492
- // "id": 2236,
2493
- // "result": [
2494
- // {
2495
- // "average_price": 7440.18,
2496
- // "delta": 0.006687487,
2497
- // "direction": "buy",
2498
- // "estimated_liquidation_price": 1.74,
2499
- // "floating_profit_loss": 0,
2500
- // "index_price": 7466.79,
2501
- // "initial_margin": 0.000197283,
2502
- // "instrument_name": "BTC-PERPETUAL",
2503
- // "kind": "future",
2504
- // "leverage": 34,
2505
- // "maintenance_margin": 0.000143783,
2506
- // "mark_price": 7476.65,
2507
- // "open_orders_margin": 0.000197288,
2508
- // "realized_funding": -1e-8,
2509
- // "realized_profit_loss": -9e-9,
2510
- // "settlement_price": 7476.65,
2511
- // "size": 50,
2512
- // "size_currency": 0.006687487,
2513
- // "total_profit_loss": 0.000032781
2514
- // },
2515
- // ]
2516
- // }
2517
- //
2518
- const result = this.safeValue(response, 'result');
2519
- return this.parsePositions(result, symbols);
2520
- }
2521
- async fetchVolatilityHistory(code, params = {}) {
2522
- /**
2523
- * @method
2524
- * @name deribit#fetchVolatilityHistory
2525
- * @description fetch the historical volatility of an option market based on an underlying asset
2526
- * @see https://docs.deribit.com/#public-get_historical_volatility
2527
- * @param {string} code unified currency code
2528
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2529
- * @returns {object[]} a list of [volatility history objects]{@link https://docs.ccxt.com/#/?id=volatility-structure}
2530
- */
2531
- await this.loadMarkets();
2532
- const currency = this.currency(code);
2533
- const request = {
2534
- 'currency': currency['id'],
2535
- };
2536
- const response = await this.publicGetGetHistoricalVolatility(this.extend(request, params));
2537
- //
2538
- // {
2539
- // "jsonrpc": "2.0",
2540
- // "result": [
2541
- // [1640142000000,63.828320460740585],
2542
- // [1640142000000,63.828320460740585],
2543
- // [1640145600000,64.03821964123213]
2544
- // ],
2545
- // "usIn": 1641515379467734,
2546
- // "usOut": 1641515379468095,
2547
- // "usDiff": 361,
2548
- // "testnet": false
2549
- // }
2550
- //
2551
- return this.parseVolatilityHistory(response);
2552
- }
2553
- parseVolatilityHistory(volatility) {
2554
- //
2555
- // {
2556
- // "jsonrpc": "2.0",
2557
- // "result": [
2558
- // [1640142000000,63.828320460740585],
2559
- // [1640142000000,63.828320460740585],
2560
- // [1640145600000,64.03821964123213]
2561
- // ],
2562
- // "usIn": 1641515379467734,
2563
- // "usOut": 1641515379468095,
2564
- // "usDiff": 361,
2565
- // "testnet": false
2566
- // }
2567
- //
2568
- const volatilityResult = this.safeValue(volatility, 'result', []);
2569
- const result = [];
2570
- for (let i = 0; i < volatilityResult.length; i++) {
2571
- const timestamp = this.safeInteger(volatilityResult[i], 0);
2572
- const volatilityObj = this.safeNumber(volatilityResult[i], 1);
2573
- result.push({
2574
- 'info': volatilityObj,
2575
- 'timestamp': timestamp,
2576
- 'datetime': this.iso8601(timestamp),
2577
- 'volatility': volatilityObj,
2578
- });
2579
- }
2580
- return result;
2581
- }
2582
- async fetchTransfers(code = undefined, since = undefined, limit = undefined, params = {}) {
2583
- /**
2584
- * @method
2585
- * @name deribit#fetchTransfers
2586
- * @description fetch a history of internal transfers made on an account
2587
- * @param {string} code unified currency code of the currency transferred
2588
- * @param {int} [since] the earliest time in ms to fetch transfers for
2589
- * @param {int} [limit] the maximum number of transfers structures to retrieve
2590
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2591
- * @returns {object[]} a list of [transfer structures]{@link https://docs.ccxt.com/#/?id=transfer-structure}
2592
- */
2593
- if (code === undefined) {
2594
- throw new errors.ArgumentsRequired(this.id + ' fetchTransfers() requires a currency code argument');
2595
- }
2596
- await this.loadMarkets();
2597
- const currency = this.currency(code);
2598
- const request = {
2599
- 'currency': currency['id'],
2600
- };
2601
- if (limit !== undefined) {
2602
- request['count'] = limit;
2603
- }
2604
- const response = await this.privateGetGetTransfers(this.extend(request, params));
2605
- //
2606
- // {
2607
- // "jsonrpc": "2.0",
2608
- // "id": 7606,
2609
- // "result": {
2610
- // "count": 2,
2611
- // "data": [
2612
- // {
2613
- // "amount": 0.2,
2614
- // "created_timestamp": 1550579457727,
2615
- // "currency": "BTC",
2616
- // "direction": "payment",
2617
- // "id": 2,
2618
- // "other_side": "2MzyQc5Tkik61kJbEpJV5D5H9VfWHZK9Sgy",
2619
- // "state": "prepared",
2620
- // "type": "user",
2621
- // "updated_timestamp": 1550579457727
2622
- // },
2623
- // {
2624
- // "amount": 0.3,
2625
- // "created_timestamp": 1550579255800,
2626
- // "currency": "BTC",
2627
- // "direction": "payment",
2628
- // "id": 1,
2629
- // "other_side": "new_user_1_1",
2630
- // "state": "confirmed",
2631
- // "type": "subaccount",
2632
- // "updated_timestamp": 1550579255800
2633
- // }
2634
- // ]
2635
- // }
2636
- // }
2637
- //
2638
- const result = this.safeValue(response, 'result', {});
2639
- const transfers = this.safeValue(result, 'data', []);
2640
- return this.parseTransfers(transfers, currency, since, limit, params);
2641
- }
2642
- async transfer(code, amount, fromAccount, toAccount, params = {}) {
2643
- /**
2644
- * @method
2645
- * @name deribit#transfer
2646
- * @description transfer currency internally between wallets on the same account
2647
- * @param {string} code unified currency code
2648
- * @param {float} amount amount to transfer
2649
- * @param {string} fromAccount account to transfer from
2650
- * @param {string} toAccount account to transfer to
2651
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2652
- * @returns {object} a [transfer structure]{@link https://docs.ccxt.com/#/?id=transfer-structure}
2653
- */
2654
- await this.loadMarkets();
2655
- const currency = this.currency(code);
2656
- const request = {
2657
- 'amount': amount,
2658
- 'currency': currency['id'],
2659
- 'destination': toAccount,
2660
- };
2661
- let method = this.safeString(params, 'method');
2662
- params = this.omit(params, 'method');
2663
- if (method === undefined) {
2664
- const transferOptions = this.safeValue(this.options, 'transfer', {});
2665
- method = this.safeString(transferOptions, 'method', 'privateGetSubmitTransferToSubaccount');
2666
- }
2667
- let response = undefined;
2668
- if (method === 'privateGetSubmitTransferToUser') {
2669
- response = await this.privateGetSubmitTransferToUser(this.extend(request, params));
2670
- }
2671
- else {
2672
- response = await this.privateGetSubmitTransferToSubaccount(this.extend(request, params));
2673
- }
2674
- //
2675
- // {
2676
- // "jsonrpc": "2.0",
2677
- // "id": 9421,
2678
- // "result": {
2679
- // "updated_timestamp": 1550232862350,
2680
- // "type": "user",
2681
- // "state": "prepared",
2682
- // "other_side": "0x4aa0753d798d668056920094d65321a8e8913e26",
2683
- // "id": 3,
2684
- // "direction": "payment",
2685
- // "currency": "ETH",
2686
- // "created_timestamp": 1550232862350,
2687
- // "amount": 13.456
2688
- // }
2689
- // }
2690
- //
2691
- const result = this.safeValue(response, 'result', {});
2692
- return this.parseTransfer(result, currency);
2693
- }
2694
- parseTransfer(transfer, currency = undefined) {
2695
- //
2696
- // {
2697
- // "updated_timestamp": 1550232862350,
2698
- // "type": "user",
2699
- // "state": "prepared",
2700
- // "other_side": "0x4aa0753d798d668056920094d65321a8e8913e26",
2701
- // "id": 3,
2702
- // "direction": "payment",
2703
- // "currency": "ETH",
2704
- // "created_timestamp": 1550232862350,
2705
- // "amount": 13.456
2706
- // }
2707
- //
2708
- const timestamp = this.safeTimestamp(transfer, 'created_timestamp');
2709
- const status = this.safeString(transfer, 'state');
2710
- const account = this.safeString(transfer, 'other_side');
2711
- const direction = this.safeString(transfer, 'direction');
2712
- const currencyId = this.safeString(transfer, 'currency');
2713
- return {
2714
- 'info': transfer,
2715
- 'id': this.safeString(transfer, 'id'),
2716
- 'status': this.parseTransferStatus(status),
2717
- 'amount': this.safeNumber(transfer, 'amount'),
2718
- 'code': this.safeCurrencyCode(currencyId, currency),
2719
- 'fromAccount': direction !== 'payment' ? account : undefined,
2720
- 'toAccount': direction === 'payment' ? account : undefined,
2721
- 'timestamp': timestamp,
2722
- 'datetime': this.iso8601(timestamp),
2723
- };
2724
- }
2725
- parseTransferStatus(status) {
2726
- const statuses = {
2727
- 'prepared': 'pending',
2728
- 'confirmed': 'ok',
2729
- 'cancelled': 'cancelled',
2730
- 'waiting_for_admin': 'pending',
2731
- };
2732
- return this.safeString(statuses, status, status);
2733
- }
2734
- async withdraw(code, amount, address, tag = undefined, params = {}) {
2735
- /**
2736
- * @method
2737
- * @name deribit#withdraw
2738
- * @description make a withdrawal
2739
- * @param {string} code unified currency code
2740
- * @param {float} amount the amount to withdraw
2741
- * @param {string} address the address to withdraw to
2742
- * @param {string} tag
2743
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2744
- * @returns {object} a [transaction structure]{@link https://docs.ccxt.com/#/?id=transaction-structure}
2745
- */
2746
- [tag, params] = this.handleWithdrawTagAndParams(tag, params);
2747
- this.checkAddress(address);
2748
- await this.loadMarkets();
2749
- const currency = this.currency(code);
2750
- const request = {
2751
- 'currency': currency['id'],
2752
- 'address': address,
2753
- 'amount': amount,
2754
- // 'priority': 'high', // low, mid, high, very_high, extreme_high, insane
2755
- // 'tfa': '123456', // if enabled
2756
- };
2757
- if (this.twofa !== undefined) {
2758
- request['tfa'] = totp.totp(this.twofa);
2759
- }
2760
- const response = await this.privateGetWithdraw(this.extend(request, params));
2761
- return this.parseTransaction(response, currency);
2762
- }
2763
- parseDepositWithdrawFee(fee, currency = undefined) {
2764
- //
2765
- // {
2766
- // "withdrawal_priorities": [],
2767
- // "withdrawal_fee": 0.01457324,
2768
- // "min_withdrawal_fee": 0.000001,
2769
- // "min_confirmations": 1,
2770
- // "fee_precision": 8,
2771
- // "currency_long": "Solana",
2772
- // "currency": "SOL",
2773
- // "coin_type": "SOL"
2774
- // }
2775
- //
2776
- return {
2777
- 'info': fee,
2778
- 'withdraw': {
2779
- 'fee': this.safeNumber(fee, 'withdrawal_fee'),
2780
- 'percentage': false,
2781
- },
2782
- 'deposit': {
2783
- 'fee': undefined,
2784
- 'percentage': undefined,
2785
- },
2786
- 'networks': {},
2787
- };
2788
- }
2789
- async fetchDepositWithdrawFees(codes = undefined, params = {}) {
2790
- /**
2791
- * @method
2792
- * @name deribit#fetchDepositWithdrawFees
2793
- * @description fetch deposit and withdraw fees
2794
- * @see https://docs.deribit.com/#public-get_currencies
2795
- * @param {string[]|undefined} codes list of unified currency codes
2796
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2797
- * @returns {object} a list of [fee structures]{@link https://docs.ccxt.com/#/?id=fee-structure}
2798
- */
2799
- await this.loadMarkets();
2800
- const response = await this.publicGetGetCurrencies(params);
2801
- //
2802
- // {
2803
- // "jsonrpc": "2.0",
2804
- // "result": [
2805
- // {
2806
- // "withdrawal_priorities": [],
2807
- // "withdrawal_fee": 0.01457324,
2808
- // "min_withdrawal_fee": 0.000001,
2809
- // "min_confirmations": 1,
2810
- // "fee_precision": 8,
2811
- // "currency_long": "Solana",
2812
- // "currency": "SOL",
2813
- // "coin_type": "SOL"
2814
- // },
2815
- // ...
2816
- // ],
2817
- // "usIn": 1688652701456124,
2818
- // "usOut": 1688652701456390,
2819
- // "usDiff": 266,
2820
- // "testnet": true
2821
- // }
2822
- //
2823
- const data = this.safeValue(response, 'result', {});
2824
- return this.parseDepositWithdrawFees(data, codes, 'currency');
2825
- }
2826
- async fetchFundingRate(symbol, params = {}) {
2827
- /**
2828
- * @method
2829
- * @name deribit#fetchFundingRate
2830
- * @description fetch the current funding rate
2831
- * @see https://docs.deribit.com/#public-get_funding_rate_value
2832
- * @param {string} symbol unified market symbol
2833
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2834
- * @param {int} [params.start_timestamp] fetch funding rate starting from this timestamp
2835
- * @param {int} [params.end_timestamp] fetch funding rate ending at this timestamp
2836
- * @returns {object} a [funding rate structure]{@link https://docs.ccxt.com/#/?id=funding-rate-structure}
2837
- */
2838
- await this.loadMarkets();
2839
- const market = this.market(symbol);
2840
- const time = this.milliseconds();
2841
- const request = {
2842
- 'instrument_name': market['id'],
2843
- 'start_timestamp': time - (8 * 60 * 60 * 1000),
2844
- 'end_timestamp': time,
2845
- };
2846
- const response = await this.publicGetGetFundingRateValue(this.extend(request, params));
2847
- //
2848
- // {
2849
- // "jsonrpc":"2.0",
2850
- // "result":"0",
2851
- // "usIn":"1691161645596519",
2852
- // "usOut":"1691161645597149",
2853
- // "usDiff":"630",
2854
- // "testnet":false
2855
- // }
2856
- //
2857
- return this.parseFundingRate(response, market);
2858
- }
2859
- async fetchFundingRateHistory(symbol = undefined, since = undefined, limit = undefined, params = {}) {
2860
- /**
2861
- * @method
2862
- * @name deribit#fetchFundingRateHistory
2863
- * @description fetch the current funding rate
2864
- * @see https://docs.deribit.com/#public-get_funding_rate_history
2865
- * @param {string} symbol unified market symbol
2866
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2867
- * @param {int} [params.end_timestamp] fetch funding rate ending at this timestamp
2868
- * @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)
2869
- * @returns {object} a [funding rate structure]{@link https://docs.ccxt.com/#/?id=funding-rate-structure}
2870
- */
2871
- await this.loadMarkets();
2872
- const market = this.market(symbol);
2873
- let paginate = false;
2874
- [paginate, params] = this.handleOptionAndParams(params, 'fetchFundingRateHistory', 'paginate');
2875
- if (paginate) {
2876
- return await this.fetchPaginatedCallDeterministic('fetchFundingRateHistory', symbol, since, limit, '8h', params, 720);
2877
- }
2878
- const time = this.milliseconds();
2879
- const month = 30 * 24 * 60 * 60 * 1000;
2880
- if (since === undefined) {
2881
- since = time - month;
2882
- }
2883
- const request = {
2884
- 'instrument_name': market['id'],
2885
- 'start_timestamp': since,
2886
- 'end_timestamp': time,
2887
- };
2888
- const response = await this.publicGetGetFundingRateHistory(this.extend(request, params));
2889
- //
2890
- // {
2891
- // "jsonrpc": "2.0",
2892
- // "id": 7617,
2893
- // "result": [
2894
- // {
2895
- // "timestamp": 1569891600000,
2896
- // "index_price": 8222.87,
2897
- // "prev_index_price": 8305.72,
2898
- // "interest_8h": -0.00009234260068476106,
2899
- // "interest_1h": -4.739622041017375e-7
2900
- // }
2901
- // ]
2902
- // }
2903
- //
2904
- const rates = [];
2905
- const result = this.safeValue(response, 'result', []);
2906
- for (let i = 0; i < result.length; i++) {
2907
- const fr = result[i];
2908
- const rate = this.parseFundingRate(fr, market);
2909
- rates.push(rate);
2910
- }
2911
- return this.filterBySymbolSinceLimit(rates, symbol, since, limit);
2912
- }
2913
- parseFundingRate(contract, market = undefined) {
2914
- //
2915
- // {
2916
- // "jsonrpc":"2.0",
2917
- // "result":"0",
2918
- // "usIn":"1691161645596519",
2919
- // "usOut":"1691161645597149",
2920
- // "usDiff":"630",
2921
- // "testnet":false
2922
- // }
2923
- // history
2924
- // {
2925
- // "timestamp": 1569891600000,
2926
- // "index_price": 8222.87,
2927
- // "prev_index_price": 8305.72,
2928
- // "interest_8h": -0.00009234260068476106,
2929
- // "interest_1h": -4.739622041017375e-7
2930
- // }
2931
- //
2932
- const timestamp = this.safeInteger(contract, 'timestamp');
2933
- const datetime = this.iso8601(timestamp);
2934
- const result = this.safeNumber2(contract, 'result', 'interest_8h');
2935
- return {
2936
- 'info': contract,
2937
- 'symbol': this.safeSymbol(undefined, market),
2938
- 'markPrice': undefined,
2939
- 'indexPrice': this.safeNumber(contract, 'index_price'),
2940
- 'interestRate': undefined,
2941
- 'estimatedSettlePrice': undefined,
2942
- 'timestamp': timestamp,
2943
- 'datetime': datetime,
2944
- 'fundingRate': result,
2945
- 'fundingTimestamp': undefined,
2946
- 'fundingDatetime': undefined,
2947
- 'nextFundingRate': undefined,
2948
- 'nextFundingTimestamp': undefined,
2949
- 'nextFundingDatetime': undefined,
2950
- 'previousFundingRate': undefined,
2951
- 'previousFundingTimestamp': undefined,
2952
- 'previousFundingDatetime': undefined,
2953
- };
2954
- }
2955
- async fetchLiquidations(symbol, since = undefined, limit = undefined, params = {}) {
2956
- /**
2957
- * @method
2958
- * @name deribit#fetchLiquidations
2959
- * @description retrieves the public liquidations of a trading pair
2960
- * @see https://docs.deribit.com/#public-get_last_settlements_by_currency
2961
- * @param {string} symbol unified CCXT market symbol
2962
- * @param {int} [since] the earliest time in ms to fetch liquidations for
2963
- * @param {int} [limit] the maximum number of liquidation structures to retrieve
2964
- * @param {object} [params] exchange specific parameters for the deribit api endpoint
2965
- * @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)
2966
- * @returns {object} an array of [liquidation structures]{@link https://docs.ccxt.com/#/?id=liquidation-structure}
2967
- */
2968
- await this.loadMarkets();
2969
- let paginate = false;
2970
- [paginate, params] = this.handleOptionAndParams(params, 'fetchLiquidations', 'paginate');
2971
- if (paginate) {
2972
- return await this.fetchPaginatedCallCursor('fetchLiquidations', symbol, since, limit, params, 'continuation', 'continuation', undefined);
2973
- }
2974
- const market = this.market(symbol);
2975
- if (market['spot']) {
2976
- throw new errors.NotSupported(this.id + ' fetchLiquidations() does not support ' + market['type'] + ' markets');
2977
- }
2978
- const request = {
2979
- 'instrument_name': market['id'],
2980
- 'type': 'bankruptcy',
2981
- };
2982
- if (since !== undefined) {
2983
- request['search_start_timestamp'] = since;
2984
- }
2985
- if (limit !== undefined) {
2986
- request['count'] = limit;
2987
- }
2988
- const response = await this.publicGetGetLastSettlementsByInstrument(this.extend(request, params));
2989
- //
2990
- // {
2991
- // "jsonrpc": "2.0",
2992
- // "result": {
2993
- // "settlements": [
2994
- // {
2995
- // "type": "bankruptcy",
2996
- // "timestamp": 1696579200041,
2997
- // "funded": 10000.0,
2998
- // "session_bankrupcy": 10000.0
2999
- // "session_profit_loss": 112951.68715857354,
3000
- // "session_tax": 0.15,
3001
- // "session_tax_rate": 0.0015,
3002
- // "socialized": 0.001,
3003
- // },
3004
- // ],
3005
- // "continuation": "5dHzoGyD8Hs8KURoUhfgXgHpJTA5oyapoudSmNeAfEftqRbjNE6jNNUpo2oCu1khnZL9ao"
3006
- // },
3007
- // "usIn": 1696652052254890,
3008
- // "usOut": 1696652052255733,
3009
- // "usDiff": 843,
3010
- // "testnet": false
3011
- // }
3012
- //
3013
- const result = this.safeValue(response, 'result', {});
3014
- const cursor = this.safeString(result, 'continuation');
3015
- const settlements = this.safeValue(result, 'settlements', []);
3016
- const settlementsWithCursor = this.addPaginationCursorToResult(cursor, settlements);
3017
- return this.parseLiquidations(settlementsWithCursor, market, since, limit);
3018
- }
3019
- addPaginationCursorToResult(cursor, data) {
3020
- if (cursor !== undefined) {
3021
- const dataLength = data.length;
3022
- if (dataLength > 0) {
3023
- const first = data[0];
3024
- const last = data[dataLength - 1];
3025
- first['continuation'] = cursor;
3026
- last['continuation'] = cursor;
3027
- data[0] = first;
3028
- data[dataLength - 1] = last;
3029
- }
3030
- }
3031
- return data;
3032
- }
3033
- async fetchMyLiquidations(symbol = undefined, since = undefined, limit = undefined, params = {}) {
3034
- /**
3035
- * @method
3036
- * @name deribit#fetchMyLiquidations
3037
- * @description retrieves the users liquidated positions
3038
- * @see https://docs.deribit.com/#private-get_settlement_history_by_instrument
3039
- * @param {string} symbol unified CCXT market symbol
3040
- * @param {int} [since] the earliest time in ms to fetch liquidations for
3041
- * @param {int} [limit] the maximum number of liquidation structures to retrieve
3042
- * @param {object} [params] exchange specific parameters for the deribit api endpoint
3043
- * @returns {object} an array of [liquidation structures]{@link https://docs.ccxt.com/#/?id=liquidation-structure}
3044
- */
3045
- if (symbol === undefined) {
3046
- throw new errors.ArgumentsRequired(this.id + ' fetchMyLiquidations() requires a symbol argument');
3047
- }
3048
- await this.loadMarkets();
3049
- const market = this.market(symbol);
3050
- if (market['spot']) {
3051
- throw new errors.NotSupported(this.id + ' fetchMyLiquidations() does not support ' + market['type'] + ' markets');
3052
- }
3053
- const request = {
3054
- 'instrument_name': market['id'],
3055
- 'type': 'bankruptcy',
3056
- };
3057
- if (since !== undefined) {
3058
- request['search_start_timestamp'] = since;
3059
- }
3060
- if (limit !== undefined) {
3061
- request['count'] = limit;
3062
- }
3063
- const response = await this.privateGetGetSettlementHistoryByInstrument(this.extend(request, params));
3064
- //
3065
- // {
3066
- // "jsonrpc": "2.0",
3067
- // "result": {
3068
- // "settlements": [
3069
- // {
3070
- // "type": "bankruptcy",
3071
- // "timestamp": 1696579200041,
3072
- // "funded": 10000.0,
3073
- // "session_bankrupcy": 10000.0
3074
- // "session_profit_loss": 112951.68715857354,
3075
- // "session_tax": 0.15,
3076
- // "session_tax_rate": 0.0015,
3077
- // "socialized": 0.001,
3078
- // },
3079
- // ],
3080
- // "continuation": "5dHzoGyD8Hs8KURoUhfgXgHpJTA5oyapoudSmNeAfEftqRbjNE6jNNUpo2oCu1khnZL9ao"
3081
- // },
3082
- // "usIn": 1696652052254890,
3083
- // "usOut": 1696652052255733,
3084
- // "usDiff": 843,
3085
- // "testnet": false
3086
- // }
3087
- //
3088
- const result = this.safeValue(response, 'result', {});
3089
- const settlements = this.safeValue(result, 'settlements', []);
3090
- return this.parseLiquidations(settlements, market, since, limit);
3091
- }
3092
- parseLiquidation(liquidation, market = undefined) {
3093
- //
3094
- // {
3095
- // "type": "bankruptcy",
3096
- // "timestamp": 1696579200041,
3097
- // "funded": 1,
3098
- // "session_bankrupcy": 0.001,
3099
- // "session_profit_loss": 0.001,
3100
- // "session_tax": 0.0015,
3101
- // "session_tax_rate": 0.0015,
3102
- // "socialized": 0.001,
3103
- // }
3104
- //
3105
- const timestamp = this.safeInteger(liquidation, 'timestamp');
3106
- return this.safeLiquidation({
3107
- 'info': liquidation,
3108
- 'symbol': this.safeSymbol(undefined, market),
3109
- 'contracts': undefined,
3110
- 'contractSize': this.safeNumber(market, 'contractSize'),
3111
- 'price': undefined,
3112
- 'baseValue': this.safeNumber(liquidation, 'session_bankrupcy'),
3113
- 'quoteValue': undefined,
3114
- 'timestamp': timestamp,
3115
- 'datetime': this.iso8601(timestamp),
3116
- });
3117
- }
3118
- async fetchGreeks(symbol, params = {}) {
3119
- /**
3120
- * @method
3121
- * @name deribit#fetchGreeks
3122
- * @description fetches an option contracts greeks, financial metrics used to measure the factors that affect the price of an options contract
3123
- * @see https://docs.deribit.com/#public-ticker
3124
- * @param {string} symbol unified symbol of the market to fetch greeks for
3125
- * @param {object} [params] extra parameters specific to the exchange API endpoint
3126
- * @returns {object} a [greeks structure]{@link https://docs.ccxt.com/#/?id=greeks-structure}
3127
- */
3128
- await this.loadMarkets();
3129
- const market = this.market(symbol);
3130
- const request = {
3131
- 'instrument_name': market['id'],
3132
- };
3133
- const response = await this.publicGetTicker(this.extend(request, params));
3134
- //
3135
- // {
3136
- // "jsonrpc": "2.0",
3137
- // "result": {
3138
- // "estimated_delivery_price": 36552.72,
3139
- // "best_bid_amount": 0.2,
3140
- // "best_ask_amount": 9.1,
3141
- // "interest_rate": 0.0,
3142
- // "best_bid_price": 0.214,
3143
- // "best_ask_price": 0.219,
3144
- // "open_interest": 368.8,
3145
- // "settlement_price": 0.22103022,
3146
- // "last_price": 0.215,
3147
- // "bid_iv": 60.51,
3148
- // "ask_iv": 61.88,
3149
- // "mark_iv": 61.27,
3150
- // "underlying_index": "BTC-27SEP24",
3151
- // "underlying_price": 38992.71,
3152
- // "min_price": 0.1515,
3153
- // "max_price": 0.326,
3154
- // "mark_price": 0.2168,
3155
- // "instrument_name": "BTC-27SEP24-40000-C",
3156
- // "index_price": 36552.72,
3157
- // "greeks": {
3158
- // "rho": 130.63998,
3159
- // "theta": -13.48784,
3160
- // "vega": 141.90146,
3161
- // "gamma": 0.00002,
3162
- // "delta": 0.59621
3163
- // },
3164
- // "stats": {
3165
- // "volume_usd": 100453.9,
3166
- // "volume": 12.0,
3167
- // "price_change": -2.2727,
3168
- // "low": 0.2065,
3169
- // "high": 0.238
3170
- // },
3171
- // "state": "open",
3172
- // "timestamp": 1699578548021
3173
- // },
3174
- // "usIn": 1699578548308414,
3175
- // "usOut": 1699578548308606,
3176
- // "usDiff": 192,
3177
- // "testnet": false
3178
- // }
3179
- //
3180
- const result = this.safeValue(response, 'result', {});
3181
- return this.parseGreeks(result, market);
3182
- }
3183
- parseGreeks(greeks, market = undefined) {
3184
- //
3185
- // {
3186
- // "estimated_delivery_price": 36552.72,
3187
- // "best_bid_amount": 0.2,
3188
- // "best_ask_amount": 9.1,
3189
- // "interest_rate": 0.0,
3190
- // "best_bid_price": 0.214,
3191
- // "best_ask_price": 0.219,
3192
- // "open_interest": 368.8,
3193
- // "settlement_price": 0.22103022,
3194
- // "last_price": 0.215,
3195
- // "bid_iv": 60.51,
3196
- // "ask_iv": 61.88,
3197
- // "mark_iv": 61.27,
3198
- // "underlying_index": "BTC-27SEP24",
3199
- // "underlying_price": 38992.71,
3200
- // "min_price": 0.1515,
3201
- // "max_price": 0.326,
3202
- // "mark_price": 0.2168,
3203
- // "instrument_name": "BTC-27SEP24-40000-C",
3204
- // "index_price": 36552.72,
3205
- // "greeks": {
3206
- // "rho": 130.63998,
3207
- // "theta": -13.48784,
3208
- // "vega": 141.90146,
3209
- // "gamma": 0.00002,
3210
- // "delta": 0.59621
3211
- // },
3212
- // "stats": {
3213
- // "volume_usd": 100453.9,
3214
- // "volume": 12.0,
3215
- // "price_change": -2.2727,
3216
- // "low": 0.2065,
3217
- // "high": 0.238
3218
- // },
3219
- // "state": "open",
3220
- // "timestamp": 1699578548021
3221
- // }
3222
- //
3223
- const timestamp = this.safeInteger(greeks, 'timestamp');
3224
- const marketId = this.safeString(greeks, 'instrument_name');
3225
- const symbol = this.safeSymbol(marketId, market);
3226
- const stats = this.safeValue(greeks, 'greeks', {});
3227
- return {
3228
- 'symbol': symbol,
3229
- 'timestamp': timestamp,
3230
- 'datetime': this.iso8601(timestamp),
3231
- 'delta': this.safeNumber(stats, 'delta'),
3232
- 'gamma': this.safeNumber(stats, 'gamma'),
3233
- 'theta': this.safeNumber(stats, 'theta'),
3234
- 'vega': this.safeNumber(stats, 'vega'),
3235
- 'rho': this.safeNumber(stats, 'rho'),
3236
- 'bidSize': this.safeNumber(greeks, 'best_bid_amount'),
3237
- 'askSize': this.safeNumber(greeks, 'best_ask_amount'),
3238
- 'bidImpliedVolatility': this.safeNumber(greeks, 'bid_iv'),
3239
- 'askImpliedVolatility': this.safeNumber(greeks, 'ask_iv'),
3240
- 'markImpliedVolatility': this.safeNumber(greeks, 'mark_iv'),
3241
- 'bidPrice': this.safeNumber(greeks, 'best_bid_price'),
3242
- 'askPrice': this.safeNumber(greeks, 'best_ask_price'),
3243
- 'markPrice': this.safeNumber(greeks, 'mark_price'),
3244
- 'lastPrice': this.safeNumber(greeks, 'last_price'),
3245
- 'underlyingPrice': this.safeNumber(greeks, 'underlying_price'),
3246
- 'info': greeks,
3247
- };
3248
- }
3249
- nonce() {
3250
- return this.milliseconds();
3251
- }
3252
- sign(path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
3253
- let request = '/' + 'api/' + this.version + '/' + api + '/' + path;
3254
- if (api === 'public') {
3255
- if (Object.keys(params).length) {
3256
- request += '?' + this.urlencode(params);
3257
- }
3258
- }
3259
- if (api === 'private') {
3260
- this.checkRequiredCredentials();
3261
- const nonce = this.nonce().toString();
3262
- const timestamp = this.milliseconds().toString();
3263
- const requestBody = '';
3264
- if (Object.keys(params).length) {
3265
- request += '?' + this.urlencode(params);
3266
- }
3267
- const requestData = method + "\n" + request + "\n" + requestBody + "\n"; // eslint-disable-line quotes
3268
- const auth = timestamp + "\n" + nonce + "\n" + requestData; // eslint-disable-line quotes
3269
- const signature = this.hmac(this.encode(auth), this.encode(this.secret), sha256.sha256);
3270
- headers = {
3271
- 'Authorization': 'deri-hmac-sha256 id=' + this.apiKey + ',ts=' + timestamp + ',sig=' + signature + ',' + 'nonce=' + nonce,
3272
- };
3273
- }
3274
- const url = this.urls['api']['rest'] + request;
3275
- return { 'url': url, 'method': method, 'body': body, 'headers': headers };
3276
- }
3277
- handleErrors(httpCode, reason, url, method, headers, body, response, requestHeaders, requestBody) {
3278
- if (!response) {
3279
- return undefined; // fallback to default error handler
3280
- }
3281
- //
3282
- // {
3283
- // "jsonrpc": "2.0",
3284
- // "error": {
3285
- // "message": "Invalid params",
3286
- // "data": { reason: "invalid currency", param: "currency" },
3287
- // "code": -32602
3288
- // },
3289
- // "testnet": false,
3290
- // "usIn": 1583763842150374,
3291
- // "usOut": 1583763842150410,
3292
- // "usDiff": 36
3293
- // }
3294
- //
3295
- const error = this.safeValue(response, 'error');
3296
- if (error !== undefined) {
3297
- const errorCode = this.safeString(error, 'code');
3298
- const feedback = this.id + ' ' + body;
3299
- this.throwExactlyMatchedException(this.exceptions, errorCode, feedback);
3300
- throw new errors.ExchangeError(feedback); // unknown message
3301
- }
3302
- return undefined;
3303
- }
3304
- }
3305
-
3306
- module.exports = deribit;