ccxt 4.2.11 → 4.2.13

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 (392) hide show
  1. package/README.md +5 -5
  2. package/build.sh +2 -2
  3. package/dist/ccxt.browser.js +1347 -490
  4. package/dist/ccxt.browser.min.js +3 -3
  5. package/dist/cjs/_virtual/agent.js +7 -0
  6. package/dist/cjs/_virtual/parse-proxy-response.js +7 -0
  7. package/dist/cjs/_virtual/promisify.js +7 -0
  8. package/dist/cjs/ccxt.js +1 -1
  9. package/dist/cjs/js/ccxt.js +474 -0
  10. package/dist/cjs/js/src/abstract/ace.js +9 -0
  11. package/dist/cjs/js/src/abstract/alpaca.js +9 -0
  12. package/dist/cjs/js/src/abstract/ascendex.js +9 -0
  13. package/dist/cjs/js/src/abstract/bigone.js +9 -0
  14. package/dist/cjs/js/src/abstract/binance.js +9 -0
  15. package/dist/cjs/js/src/abstract/bingx.js +9 -0
  16. package/dist/cjs/js/src/abstract/bit2c.js +9 -0
  17. package/dist/cjs/js/src/abstract/bitbank.js +9 -0
  18. package/dist/cjs/js/src/abstract/bitbns.js +9 -0
  19. package/dist/cjs/js/src/abstract/bitfinex.js +9 -0
  20. package/dist/cjs/js/src/abstract/bitfinex2.js +9 -0
  21. package/dist/cjs/js/src/abstract/bitflyer.js +9 -0
  22. package/dist/cjs/js/src/abstract/bitforex.js +9 -0
  23. package/dist/cjs/js/src/abstract/bitget.js +9 -0
  24. package/dist/cjs/js/src/abstract/bithumb.js +9 -0
  25. package/dist/cjs/js/src/abstract/bitmart.js +9 -0
  26. package/dist/cjs/js/src/abstract/bitmex.js +9 -0
  27. package/dist/cjs/js/src/abstract/bitopro.js +9 -0
  28. package/dist/cjs/js/src/abstract/bitpanda.js +9 -0
  29. package/dist/cjs/js/src/abstract/bitrue.js +9 -0
  30. package/dist/cjs/js/src/abstract/bitso.js +9 -0
  31. package/dist/cjs/js/src/abstract/bitstamp.js +9 -0
  32. package/dist/cjs/js/src/abstract/bitteam.js +9 -0
  33. package/dist/cjs/js/src/abstract/bitvavo.js +9 -0
  34. package/dist/cjs/js/src/abstract/bl3p.js +9 -0
  35. package/dist/cjs/js/src/abstract/blockchaincom.js +9 -0
  36. package/dist/cjs/js/src/abstract/btcalpha.js +9 -0
  37. package/dist/cjs/js/src/abstract/btcbox.js +9 -0
  38. package/dist/cjs/js/src/abstract/btcmarkets.js +9 -0
  39. package/dist/cjs/js/src/abstract/btcturk.js +9 -0
  40. package/dist/cjs/js/src/abstract/bybit.js +9 -0
  41. package/dist/cjs/js/src/abstract/cex.js +9 -0
  42. package/dist/cjs/js/src/abstract/coinbase.js +9 -0
  43. package/dist/cjs/js/src/abstract/coinbasepro.js +9 -0
  44. package/dist/cjs/js/src/abstract/coincheck.js +9 -0
  45. package/dist/cjs/js/src/abstract/coinex.js +9 -0
  46. package/dist/cjs/js/src/abstract/coinlist.js +9 -0
  47. package/dist/cjs/js/src/abstract/coinmate.js +9 -0
  48. package/dist/cjs/js/src/abstract/coinone.js +9 -0
  49. package/dist/cjs/js/src/abstract/coinsph.js +9 -0
  50. package/dist/cjs/js/src/abstract/coinspot.js +9 -0
  51. package/dist/cjs/js/src/abstract/cryptocom.js +9 -0
  52. package/dist/cjs/js/src/abstract/currencycom.js +9 -0
  53. package/dist/cjs/js/src/abstract/delta.js +9 -0
  54. package/dist/cjs/js/src/abstract/deribit.js +9 -0
  55. package/dist/cjs/js/src/abstract/digifinex.js +9 -0
  56. package/dist/cjs/js/src/abstract/exmo.js +9 -0
  57. package/dist/cjs/js/src/abstract/gate.js +9 -0
  58. package/dist/cjs/js/src/abstract/gemini.js +9 -0
  59. package/dist/cjs/js/src/abstract/hitbtc.js +9 -0
  60. package/dist/cjs/js/src/abstract/hollaex.js +9 -0
  61. package/dist/cjs/js/src/abstract/htx.js +9 -0
  62. package/dist/cjs/js/src/abstract/huobijp.js +9 -0
  63. package/dist/cjs/js/src/abstract/idex.js +9 -0
  64. package/dist/cjs/js/src/abstract/independentreserve.js +9 -0
  65. package/dist/cjs/js/src/abstract/indodax.js +9 -0
  66. package/dist/cjs/js/src/abstract/kraken.js +9 -0
  67. package/dist/cjs/js/src/abstract/krakenfutures.js +9 -0
  68. package/dist/cjs/js/src/abstract/kucoin.js +9 -0
  69. package/dist/cjs/js/src/abstract/kucoinfutures.js +9 -0
  70. package/dist/cjs/js/src/abstract/kuna.js +9 -0
  71. package/dist/cjs/js/src/abstract/latoken.js +9 -0
  72. package/dist/cjs/js/src/abstract/lbank.js +9 -0
  73. package/dist/cjs/js/src/abstract/luno.js +9 -0
  74. package/dist/cjs/js/src/abstract/lykke.js +9 -0
  75. package/dist/cjs/js/src/abstract/mercado.js +9 -0
  76. package/dist/cjs/js/src/abstract/mexc.js +9 -0
  77. package/dist/cjs/js/src/abstract/ndax.js +9 -0
  78. package/dist/cjs/js/src/abstract/novadax.js +9 -0
  79. package/dist/cjs/js/src/abstract/oceanex.js +9 -0
  80. package/dist/cjs/js/src/abstract/okcoin.js +9 -0
  81. package/dist/cjs/js/src/abstract/okx.js +9 -0
  82. package/dist/cjs/js/src/abstract/p2b.js +9 -0
  83. package/dist/cjs/js/src/abstract/paymium.js +9 -0
  84. package/dist/cjs/js/src/abstract/phemex.js +9 -0
  85. package/dist/cjs/js/src/abstract/poloniex.js +9 -0
  86. package/dist/cjs/js/src/abstract/poloniexfutures.js +9 -0
  87. package/dist/cjs/js/src/abstract/probit.js +9 -0
  88. package/dist/cjs/js/src/abstract/timex.js +9 -0
  89. package/dist/cjs/js/src/abstract/tokocrypto.js +9 -0
  90. package/dist/cjs/js/src/abstract/upbit.js +9 -0
  91. package/dist/cjs/js/src/abstract/wavesexchange.js +9 -0
  92. package/dist/cjs/js/src/abstract/wazirx.js +9 -0
  93. package/dist/cjs/js/src/abstract/whitebit.js +9 -0
  94. package/dist/cjs/js/src/abstract/woo.js +9 -0
  95. package/dist/cjs/js/src/abstract/yobit.js +9 -0
  96. package/dist/cjs/js/src/abstract/zaif.js +9 -0
  97. package/dist/cjs/js/src/abstract/zonda.js +9 -0
  98. package/dist/cjs/js/src/ace.js +1058 -0
  99. package/dist/cjs/js/src/alpaca.js +1125 -0
  100. package/dist/cjs/js/src/ascendex.js +3360 -0
  101. package/dist/cjs/js/src/base/Exchange.js +5110 -0
  102. package/dist/cjs/js/src/base/Precise.js +263 -0
  103. package/dist/cjs/js/src/base/errors.js +299 -0
  104. package/dist/cjs/js/src/base/functions/crypto.js +78 -0
  105. package/dist/cjs/js/src/base/functions/encode.js +44 -0
  106. package/dist/cjs/js/src/base/functions/generic.js +193 -0
  107. package/dist/cjs/js/src/base/functions/misc.js +96 -0
  108. package/dist/cjs/js/src/base/functions/number.js +297 -0
  109. package/dist/cjs/js/src/base/functions/platform.js +28 -0
  110. package/dist/cjs/js/src/base/functions/rsa.js +34 -0
  111. package/dist/cjs/js/src/base/functions/string.js +48 -0
  112. package/dist/cjs/js/src/base/functions/throttle.js +66 -0
  113. package/dist/cjs/js/src/base/functions/time.js +187 -0
  114. package/dist/cjs/js/src/base/functions/totp.js +24 -0
  115. package/dist/cjs/js/src/base/functions/type.js +162 -0
  116. package/dist/cjs/js/src/base/functions.js +157 -0
  117. package/dist/cjs/js/src/base/ws/Cache.js +254 -0
  118. package/dist/cjs/js/src/base/ws/Client.js +299 -0
  119. package/dist/cjs/js/src/base/ws/Future.js +34 -0
  120. package/dist/cjs/js/src/base/ws/OrderBook.js +107 -0
  121. package/dist/cjs/js/src/base/ws/OrderBookSide.js +281 -0
  122. package/dist/cjs/js/src/base/ws/WsClient.js +69 -0
  123. package/dist/cjs/js/src/bequant.js +33 -0
  124. package/dist/cjs/js/src/bigone.js +2209 -0
  125. package/dist/cjs/js/src/binance.js +9736 -0
  126. package/dist/cjs/js/src/binancecoinm.js +45 -0
  127. package/dist/cjs/js/src/binanceus.js +84 -0
  128. package/dist/cjs/js/src/binanceusdm.js +58 -0
  129. package/dist/cjs/js/src/bingx.js +3807 -0
  130. package/dist/cjs/js/src/bit2c.js +916 -0
  131. package/dist/cjs/js/src/bitbank.js +1000 -0
  132. package/dist/cjs/js/src/bitbay.js +17 -0
  133. package/dist/cjs/js/src/bitbns.js +1220 -0
  134. package/dist/cjs/js/src/bitcoincom.js +17 -0
  135. package/dist/cjs/js/src/bitfinex.js +1670 -0
  136. package/dist/cjs/js/src/bitfinex2.js +2990 -0
  137. package/dist/cjs/js/src/bitflyer.js +1045 -0
  138. package/dist/cjs/js/src/bitforex.js +852 -0
  139. package/dist/cjs/js/src/bitget.js +8291 -0
  140. package/dist/cjs/js/src/bithumb.js +1090 -0
  141. package/dist/cjs/js/src/bitmart.js +4454 -0
  142. package/dist/cjs/js/src/bitmex.js +2884 -0
  143. package/dist/cjs/js/src/bitopro.js +1724 -0
  144. package/dist/cjs/js/src/bitpanda.js +2002 -0
  145. package/dist/cjs/js/src/bitrue.js +3253 -0
  146. package/dist/cjs/js/src/bitso.js +1753 -0
  147. package/dist/cjs/js/src/bitstamp.js +2188 -0
  148. package/dist/cjs/js/src/bitteam.js +2309 -0
  149. package/dist/cjs/js/src/bitvavo.js +1968 -0
  150. package/dist/cjs/js/src/bl3p.js +447 -0
  151. package/dist/cjs/js/src/blockchaincom.js +1160 -0
  152. package/dist/cjs/js/src/btcalpha.js +929 -0
  153. package/dist/cjs/js/src/btcbox.js +565 -0
  154. package/dist/cjs/js/src/btcmarkets.js +1237 -0
  155. package/dist/cjs/js/src/btcturk.js +929 -0
  156. package/dist/cjs/js/src/bybit.js +7646 -0
  157. package/dist/cjs/js/src/cex.js +1693 -0
  158. package/dist/cjs/js/src/coinbase.js +3424 -0
  159. package/dist/cjs/js/src/coinbasepro.js +1866 -0
  160. package/dist/cjs/js/src/coincheck.js +843 -0
  161. package/dist/cjs/js/src/coinex.js +5414 -0
  162. package/dist/cjs/js/src/coinlist.js +2329 -0
  163. package/dist/cjs/js/src/coinmate.js +989 -0
  164. package/dist/cjs/js/src/coinone.js +1185 -0
  165. package/dist/cjs/js/src/coinsph.js +1933 -0
  166. package/dist/cjs/js/src/coinspot.js +548 -0
  167. package/dist/cjs/js/src/cryptocom.js +3007 -0
  168. package/dist/cjs/js/src/currencycom.js +2015 -0
  169. package/dist/cjs/js/src/delta.js +3256 -0
  170. package/dist/cjs/js/src/deribit.js +3306 -0
  171. package/dist/cjs/js/src/digifinex.js +4307 -0
  172. package/dist/cjs/js/src/exmo.js +2645 -0
  173. package/dist/cjs/js/src/fmfwio.js +34 -0
  174. package/dist/cjs/js/src/gate.js +7072 -0
  175. package/dist/cjs/js/src/gateio.js +16 -0
  176. package/dist/cjs/js/src/gemini.js +1801 -0
  177. package/dist/cjs/js/src/hitbtc.js +3660 -0
  178. package/dist/cjs/js/src/hitbtc3.js +19 -0
  179. package/dist/cjs/js/src/hollaex.js +1882 -0
  180. package/dist/cjs/js/src/htx.js +9049 -0
  181. package/dist/cjs/js/src/huobi.js +16 -0
  182. package/dist/cjs/js/src/huobijp.js +1918 -0
  183. package/dist/cjs/js/src/idex.js +1770 -0
  184. package/dist/cjs/js/src/independentreserve.js +761 -0
  185. package/dist/cjs/js/src/indodax.js +1069 -0
  186. package/dist/cjs/js/src/kraken.js +2857 -0
  187. package/dist/cjs/js/src/krakenfutures.js +2407 -0
  188. package/dist/cjs/js/src/kucoin.js +4489 -0
  189. package/dist/cjs/js/src/kucoinfutures.js +2475 -0
  190. package/dist/cjs/js/src/kuna.js +1949 -0
  191. package/dist/cjs/js/src/latoken.js +1729 -0
  192. package/dist/cjs/js/src/lbank.js +2851 -0
  193. package/dist/cjs/js/src/luno.js +1044 -0
  194. package/dist/cjs/js/src/lykke.js +1303 -0
  195. package/dist/cjs/js/src/mercado.js +897 -0
  196. package/dist/cjs/js/src/mexc.js +5407 -0
  197. package/dist/cjs/js/src/ndax.js +2450 -0
  198. package/dist/cjs/js/src/novadax.js +1556 -0
  199. package/dist/cjs/js/src/oceanex.js +964 -0
  200. package/dist/cjs/js/src/okcoin.js +3115 -0
  201. package/dist/cjs/js/src/okx.js +7330 -0
  202. package/dist/cjs/js/src/p2b.js +1243 -0
  203. package/dist/cjs/js/src/paymium.js +597 -0
  204. package/dist/cjs/js/src/phemex.js +4722 -0
  205. package/dist/cjs/js/src/poloniex.js +2356 -0
  206. package/dist/cjs/js/src/poloniexfutures.js +1794 -0
  207. package/dist/cjs/js/src/pro/alpaca.js +714 -0
  208. package/dist/cjs/js/src/pro/ascendex.js +957 -0
  209. package/dist/cjs/js/src/pro/bequant.js +33 -0
  210. package/dist/cjs/js/src/pro/binance.js +2796 -0
  211. package/dist/cjs/js/src/pro/binancecoinm.js +23 -0
  212. package/dist/cjs/js/src/pro/binanceus.js +51 -0
  213. package/dist/cjs/js/src/pro/binanceusdm.js +32 -0
  214. package/dist/cjs/js/src/pro/bingx.js +944 -0
  215. package/dist/cjs/js/src/pro/bitcoincom.js +29 -0
  216. package/dist/cjs/js/src/pro/bitfinex.js +672 -0
  217. package/dist/cjs/js/src/pro/bitfinex2.js +1159 -0
  218. package/dist/cjs/js/src/pro/bitget.js +1733 -0
  219. package/dist/cjs/js/src/pro/bitmart.js +1486 -0
  220. package/dist/cjs/js/src/pro/bitmex.js +1576 -0
  221. package/dist/cjs/js/src/pro/bitopro.js +327 -0
  222. package/dist/cjs/js/src/pro/bitpanda.js +1341 -0
  223. package/dist/cjs/js/src/pro/bitrue.js +462 -0
  224. package/dist/cjs/js/src/pro/bitstamp.js +547 -0
  225. package/dist/cjs/js/src/pro/bitvavo.js +704 -0
  226. package/dist/cjs/js/src/pro/blockchaincom.js +794 -0
  227. package/dist/cjs/js/src/pro/bybit.js +1843 -0
  228. package/dist/cjs/js/src/pro/cex.js +1510 -0
  229. package/dist/cjs/js/src/pro/coinbase.js +561 -0
  230. package/dist/cjs/js/src/pro/coinbasepro.js +968 -0
  231. package/dist/cjs/js/src/pro/coinex.js +1095 -0
  232. package/dist/cjs/js/src/pro/cryptocom.js +1020 -0
  233. package/dist/cjs/js/src/pro/currencycom.js +563 -0
  234. package/dist/cjs/js/src/pro/deribit.js +825 -0
  235. package/dist/cjs/js/src/pro/exmo.js +658 -0
  236. package/dist/cjs/js/src/pro/gate.js +1316 -0
  237. package/dist/cjs/js/src/pro/gateio.js +16 -0
  238. package/dist/cjs/js/src/pro/gemini.js +649 -0
  239. package/dist/cjs/js/src/pro/hitbtc.js +1293 -0
  240. package/dist/cjs/js/src/pro/hollaex.js +597 -0
  241. package/dist/cjs/js/src/pro/htx.js +2383 -0
  242. package/dist/cjs/js/src/pro/huobi.js +16 -0
  243. package/dist/cjs/js/src/pro/huobijp.js +606 -0
  244. package/dist/cjs/js/src/pro/idex.js +714 -0
  245. package/dist/cjs/js/src/pro/independentreserve.js +280 -0
  246. package/dist/cjs/js/src/pro/kraken.js +1364 -0
  247. package/dist/cjs/js/src/pro/krakenfutures.js +1500 -0
  248. package/dist/cjs/js/src/pro/kucoin.js +1052 -0
  249. package/dist/cjs/js/src/pro/kucoinfutures.js +981 -0
  250. package/dist/cjs/js/src/pro/luno.js +322 -0
  251. package/dist/cjs/js/src/pro/mexc.js +1170 -0
  252. package/dist/cjs/js/src/pro/ndax.js +545 -0
  253. package/dist/cjs/js/src/pro/okcoin.js +760 -0
  254. package/dist/cjs/js/src/pro/okx.js +1608 -0
  255. package/dist/cjs/js/src/pro/phemex.js +1511 -0
  256. package/dist/cjs/js/src/pro/poloniex.js +1253 -0
  257. package/dist/cjs/js/src/pro/poloniexfutures.js +1014 -0
  258. package/dist/cjs/js/src/pro/probit.js +586 -0
  259. package/dist/cjs/js/src/pro/upbit.js +234 -0
  260. package/dist/cjs/js/src/pro/wazirx.js +776 -0
  261. package/dist/cjs/js/src/pro/whitebit.js +927 -0
  262. package/dist/cjs/js/src/pro/woo.js +769 -0
  263. package/dist/cjs/js/src/probit.js +1867 -0
  264. package/dist/cjs/js/src/static_dependencies/fflake/browser.js +401 -0
  265. package/dist/cjs/js/src/static_dependencies/jsencrypt/JSEncrypt.js +195 -0
  266. package/dist/cjs/js/src/static_dependencies/jsencrypt/JSEncryptRSAKey.js +308 -0
  267. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/asn1js/asn1.js +554 -0
  268. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/asn1js/base64.js +94 -0
  269. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/asn1js/hex.js +70 -0
  270. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/asn1js/int10.js +91 -0
  271. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/base64.js +16 -0
  272. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/jsbn.js +1760 -0
  273. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/prng4.js +52 -0
  274. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/rng.js +81 -0
  275. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/rsa.js +376 -0
  276. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/util.js +70 -0
  277. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsrsasign/asn1-1.0.js +1580 -0
  278. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsrsasign/yahoo.js +74 -0
  279. package/dist/cjs/js/src/static_dependencies/noble-curves/_shortw_utils.js +24 -0
  280. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/curve.js +158 -0
  281. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/edwards.js +429 -0
  282. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/hash-to-curve.js +176 -0
  283. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/modular.js +324 -0
  284. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/montgomery.js +163 -0
  285. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/utils.js +245 -0
  286. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/weierstrass.js +1018 -0
  287. package/dist/cjs/js/src/static_dependencies/noble-curves/ed25519.js +383 -0
  288. package/dist/cjs/js/src/static_dependencies/noble-curves/secp256k1.js +258 -0
  289. package/dist/cjs/js/src/static_dependencies/noble-hashes/_assert.js +53 -0
  290. package/dist/cjs/js/src/static_dependencies/noble-hashes/_sha2.js +120 -0
  291. package/dist/cjs/js/src/static_dependencies/noble-hashes/_u64.js +69 -0
  292. package/dist/cjs/js/src/static_dependencies/noble-hashes/crypto.js +7 -0
  293. package/dist/cjs/js/src/static_dependencies/noble-hashes/hmac.js +83 -0
  294. package/dist/cjs/js/src/static_dependencies/noble-hashes/md5.js +240 -0
  295. package/dist/cjs/js/src/static_dependencies/noble-hashes/sha1.js +91 -0
  296. package/dist/cjs/js/src/static_dependencies/noble-hashes/sha256.js +130 -0
  297. package/dist/cjs/js/src/static_dependencies/noble-hashes/sha3.js +214 -0
  298. package/dist/cjs/js/src/static_dependencies/noble-hashes/sha512.js +239 -0
  299. package/dist/cjs/js/src/static_dependencies/noble-hashes/utils.js +93 -0
  300. package/dist/cjs/js/src/static_dependencies/node-fetch/body.js +354 -0
  301. package/dist/cjs/js/src/static_dependencies/node-fetch/errors/abort-error.js +16 -0
  302. package/dist/cjs/js/src/static_dependencies/node-fetch/errors/base.js +20 -0
  303. package/dist/cjs/js/src/static_dependencies/node-fetch/errors/fetch-error.js +30 -0
  304. package/dist/cjs/js/src/static_dependencies/node-fetch/headers.js +239 -0
  305. package/dist/cjs/js/src/static_dependencies/node-fetch/index.js +372 -0
  306. package/dist/cjs/js/src/static_dependencies/node-fetch/request.js +273 -0
  307. package/dist/cjs/js/src/static_dependencies/node-fetch/response.js +139 -0
  308. package/dist/cjs/js/src/static_dependencies/node-fetch/utils/get-search.js +14 -0
  309. package/dist/cjs/js/src/static_dependencies/node-fetch/utils/is-redirect.js +16 -0
  310. package/dist/cjs/js/src/static_dependencies/node-fetch/utils/is.js +81 -0
  311. package/dist/cjs/js/src/static_dependencies/node-fetch/utils/referrer.js +292 -0
  312. package/dist/cjs/js/src/static_dependencies/proxies/agent-base/index.js +103 -0
  313. package/dist/cjs/js/src/static_dependencies/proxies/http-proxy-agent/index.js +140 -0
  314. package/dist/cjs/js/src/static_dependencies/proxies/https-proxy-agent/index.js +175 -0
  315. package/dist/cjs/js/src/static_dependencies/proxies/https-proxy-agent/parse-proxy-response.js +95 -0
  316. package/dist/cjs/js/src/static_dependencies/qs/index.cjs.js +7 -0
  317. package/dist/cjs/js/src/static_dependencies/scure-base/index.js +383 -0
  318. package/dist/cjs/js/src/timex.js +1562 -0
  319. package/dist/cjs/js/src/tokocrypto.js +2542 -0
  320. package/dist/cjs/js/src/upbit.js +1844 -0
  321. package/dist/cjs/js/src/wavesexchange.js +2607 -0
  322. package/dist/cjs/js/src/wazirx.js +953 -0
  323. package/dist/cjs/js/src/whitebit.js +2309 -0
  324. package/dist/cjs/js/src/woo.js +2765 -0
  325. package/dist/cjs/js/src/yobit.js +1314 -0
  326. package/dist/cjs/js/src/zaif.js +736 -0
  327. package/dist/cjs/js/src/zonda.js +1883 -0
  328. package/js/ccxt.d.ts +1 -1
  329. package/js/ccxt.js +1 -1
  330. package/js/src/abstract/bigone.d.ts +18 -0
  331. package/js/src/abstract/binance.d.ts +2 -0
  332. package/js/src/abstract/binancecoinm.d.ts +2 -0
  333. package/js/src/abstract/binanceus.d.ts +2 -0
  334. package/js/src/abstract/binanceusdm.d.ts +2 -0
  335. package/js/src/abstract/bingx.d.ts +2 -0
  336. package/js/src/abstract/bybit.d.ts +1 -0
  337. package/js/src/abstract/gate.d.ts +11 -0
  338. package/js/src/abstract/gateio.d.ts +11 -0
  339. package/js/src/abstract/okx.d.ts +1 -0
  340. package/js/src/alpaca.js +18 -18
  341. package/js/src/base/Exchange.d.ts +5 -1
  342. package/js/src/base/Exchange.js +101 -12
  343. package/js/src/bigone.d.ts +3 -2
  344. package/js/src/bigone.js +429 -167
  345. package/js/src/binance.js +48 -34
  346. package/js/src/bingx.js +115 -38
  347. package/js/src/bitfinex.d.ts +2 -2
  348. package/js/src/bitfinex.js +2 -3
  349. package/js/src/bitget.js +33 -13
  350. package/js/src/bitmart.d.ts +2 -2
  351. package/js/src/bitmart.js +5 -5
  352. package/js/src/bitmex.js +1 -0
  353. package/js/src/bybit.js +2 -0
  354. package/js/src/coinbase.d.ts +26 -3
  355. package/js/src/coinbase.js +176 -26
  356. package/js/src/coinlist.js +3 -4
  357. package/js/src/coinone.js +1 -1
  358. package/js/src/coinsph.js +2 -3
  359. package/js/src/deribit.js +1 -0
  360. package/js/src/gate.d.ts +4 -4
  361. package/js/src/gate.js +96 -59
  362. package/js/src/gemini.js +1 -1
  363. package/js/src/hitbtc.d.ts +4 -4
  364. package/js/src/hitbtc.js +2 -3
  365. package/js/src/htx.d.ts +1 -0
  366. package/js/src/htx.js +29 -7
  367. package/js/src/huobijp.js +2 -3
  368. package/js/src/independentreserve.js +7 -5
  369. package/js/src/kraken.js +3 -6
  370. package/js/src/lbank.js +59 -33
  371. package/js/src/mexc.js +2 -1
  372. package/js/src/oceanex.js +1 -1
  373. package/js/src/okx.js +14 -3
  374. package/js/src/phemex.js +9 -2
  375. package/js/src/pro/binance.d.ts +2 -23
  376. package/js/src/pro/binance.js +58 -22
  377. package/js/src/pro/coinbase.d.ts +2 -2
  378. package/js/src/pro/coinbase.js +4 -1
  379. package/js/src/pro/coinbasepro.d.ts +2 -2
  380. package/js/src/pro/hitbtc.d.ts +2 -2
  381. package/js/src/pro/kraken.js +1 -1
  382. package/js/src/pro/okx.d.ts +1 -0
  383. package/js/src/pro/okx.js +52 -2
  384. package/js/src/pro/poloniex.d.ts +2 -2
  385. package/js/src/probit.js +4 -2
  386. package/js/src/upbit.d.ts +3 -101
  387. package/js/src/upbit.js +12 -12
  388. package/js/src/wavesexchange.js +1 -1
  389. package/js/src/woo.d.ts +2 -0
  390. package/js/src/woo.js +52 -0
  391. package/package.json +1 -1
  392. package/skip-tests.json +5 -0
@@ -0,0 +1,3256 @@
1
+ 'use strict';
2
+
3
+ var delta$1 = require('./abstract/delta.js');
4
+ var errors = require('./base/errors.js');
5
+ var number = require('./base/functions/number.js');
6
+ var Precise = require('./base/Precise.js');
7
+ var sha256 = require('./static_dependencies/noble-hashes/sha256.js');
8
+
9
+ // ---------------------------------------------------------------------------
10
+ // ---------------------------------------------------------------------------
11
+ /**
12
+ * @class delta
13
+ * @augments Exchange
14
+ */
15
+ class delta extends delta$1 {
16
+ describe() {
17
+ return this.deepExtend(super.describe(), {
18
+ 'id': 'delta',
19
+ 'name': 'Delta Exchange',
20
+ 'countries': ['VC'],
21
+ 'rateLimit': 300,
22
+ 'version': 'v2',
23
+ // new metainfo interface
24
+ 'has': {
25
+ 'CORS': undefined,
26
+ 'spot': true,
27
+ 'margin': false,
28
+ 'swap': true,
29
+ 'future': false,
30
+ 'option': true,
31
+ 'addMargin': true,
32
+ 'cancelAllOrders': true,
33
+ 'cancelOrder': true,
34
+ 'closeAllPositions': true,
35
+ 'closePosition': false,
36
+ 'createOrder': true,
37
+ 'createReduceOnlyOrder': true,
38
+ 'editOrder': true,
39
+ 'fetchBalance': true,
40
+ 'fetchClosedOrders': true,
41
+ 'fetchCurrencies': true,
42
+ 'fetchDeposit': undefined,
43
+ 'fetchDepositAddress': true,
44
+ 'fetchDeposits': undefined,
45
+ 'fetchFundingHistory': false,
46
+ 'fetchFundingRate': true,
47
+ 'fetchFundingRateHistory': false,
48
+ 'fetchFundingRates': true,
49
+ 'fetchGreeks': true,
50
+ 'fetchIndexOHLCV': true,
51
+ 'fetchLedger': true,
52
+ 'fetchLeverage': true,
53
+ 'fetchLeverageTiers': false,
54
+ 'fetchMarginMode': false,
55
+ 'fetchMarketLeverageTiers': false,
56
+ 'fetchMarkets': true,
57
+ 'fetchMarkOHLCV': true,
58
+ 'fetchMySettlementHistory': false,
59
+ 'fetchMyTrades': true,
60
+ 'fetchOHLCV': true,
61
+ 'fetchOpenInterest': true,
62
+ 'fetchOpenOrders': true,
63
+ 'fetchOrderBook': true,
64
+ 'fetchPosition': true,
65
+ 'fetchPositionMode': false,
66
+ 'fetchPositions': true,
67
+ 'fetchPremiumIndexOHLCV': false,
68
+ 'fetchSettlementHistory': true,
69
+ 'fetchStatus': true,
70
+ 'fetchTicker': true,
71
+ 'fetchTickers': true,
72
+ 'fetchTime': true,
73
+ 'fetchTrades': true,
74
+ 'fetchTransfer': undefined,
75
+ 'fetchTransfers': undefined,
76
+ 'fetchUnderlyingAssets': false,
77
+ 'fetchVolatilityHistory': false,
78
+ 'fetchWithdrawal': undefined,
79
+ 'fetchWithdrawals': undefined,
80
+ 'reduceMargin': true,
81
+ 'setLeverage': true,
82
+ 'setMargin': false,
83
+ 'setMarginMode': false,
84
+ 'setPositionMode': false,
85
+ 'transfer': false,
86
+ 'withdraw': false,
87
+ },
88
+ 'timeframes': {
89
+ '1m': '1m',
90
+ '3m': '3m',
91
+ '5m': '5m',
92
+ '15m': '15m',
93
+ '30m': '30m',
94
+ '1h': '1h',
95
+ '2h': '2h',
96
+ '4h': '4h',
97
+ '6h': '6h',
98
+ '1d': '1d',
99
+ '7d': '7d',
100
+ '1w': '1w',
101
+ '2w': '2w',
102
+ '1M': '30d',
103
+ },
104
+ 'urls': {
105
+ 'logo': 'https://user-images.githubusercontent.com/1294454/99450025-3be60a00-2931-11eb-9302-f4fd8d8589aa.jpg',
106
+ 'test': {
107
+ 'public': 'https://testnet-api.delta.exchange',
108
+ 'private': 'https://testnet-api.delta.exchange',
109
+ },
110
+ 'api': {
111
+ 'public': 'https://api.delta.exchange',
112
+ 'private': 'https://api.delta.exchange',
113
+ },
114
+ 'www': 'https://www.delta.exchange',
115
+ 'doc': [
116
+ 'https://docs.delta.exchange',
117
+ ],
118
+ 'fees': 'https://www.delta.exchange/fees',
119
+ 'referral': 'https://www.delta.exchange/app/signup/?code=IULYNB',
120
+ },
121
+ 'api': {
122
+ 'public': {
123
+ 'get': [
124
+ 'assets',
125
+ 'indices',
126
+ 'products',
127
+ 'products/{symbol}',
128
+ 'tickers',
129
+ 'tickers/{symbol}',
130
+ 'l2orderbook/{symbol}',
131
+ 'trades/{symbol}',
132
+ 'stats',
133
+ 'history/candles',
134
+ 'history/sparklines',
135
+ 'settings',
136
+ ],
137
+ },
138
+ 'private': {
139
+ 'get': [
140
+ 'orders',
141
+ 'products/{product_id}/orders/leverage',
142
+ 'positions/margined',
143
+ 'positions',
144
+ 'orders/history',
145
+ 'fills',
146
+ 'fills/history/download/csv',
147
+ 'wallet/balances',
148
+ 'wallet/transactions',
149
+ 'wallet/transactions/download',
150
+ 'wallets/sub_accounts_transfer_history',
151
+ 'users/trading_preferences',
152
+ 'sub_accounts',
153
+ 'profile',
154
+ 'deposits/address',
155
+ 'orders/leverage',
156
+ ],
157
+ 'post': [
158
+ 'orders',
159
+ 'orders/bracket',
160
+ 'orders/batch',
161
+ 'products/{product_id}/orders/leverage',
162
+ 'positions/change_margin',
163
+ 'positions/close_all',
164
+ 'wallets/sub_account_balance_transfer',
165
+ 'orders/cancel_after',
166
+ 'orders/leverage',
167
+ ],
168
+ 'put': [
169
+ 'orders',
170
+ 'orders/bracket',
171
+ 'orders/batch',
172
+ 'positions/auto_topup',
173
+ 'users/update_mmp',
174
+ 'users/reset_mmp',
175
+ ],
176
+ 'delete': [
177
+ 'orders',
178
+ 'orders/all',
179
+ 'orders/batch',
180
+ ],
181
+ },
182
+ },
183
+ 'fees': {
184
+ 'trading': {
185
+ 'tierBased': true,
186
+ 'percentage': true,
187
+ 'taker': this.parseNumber('0.0015'),
188
+ 'maker': this.parseNumber('0.0010'),
189
+ 'tiers': {
190
+ 'taker': [
191
+ [this.parseNumber('0'), this.parseNumber('0.0015')],
192
+ [this.parseNumber('100'), this.parseNumber('0.0013')],
193
+ [this.parseNumber('250'), this.parseNumber('0.0013')],
194
+ [this.parseNumber('1000'), this.parseNumber('0.001')],
195
+ [this.parseNumber('5000'), this.parseNumber('0.0009')],
196
+ [this.parseNumber('10000'), this.parseNumber('0.00075')],
197
+ [this.parseNumber('20000'), this.parseNumber('0.00065')],
198
+ ],
199
+ 'maker': [
200
+ [this.parseNumber('0'), this.parseNumber('0.001')],
201
+ [this.parseNumber('100'), this.parseNumber('0.001')],
202
+ [this.parseNumber('250'), this.parseNumber('0.0009')],
203
+ [this.parseNumber('1000'), this.parseNumber('0.00075')],
204
+ [this.parseNumber('5000'), this.parseNumber('0.0006')],
205
+ [this.parseNumber('10000'), this.parseNumber('0.0005')],
206
+ [this.parseNumber('20000'), this.parseNumber('0.0005')],
207
+ ],
208
+ },
209
+ },
210
+ },
211
+ 'options': {
212
+ 'networks': {
213
+ 'TRC20': 'TRC20(TRON)',
214
+ 'BEP20': 'BEP20(BSC)',
215
+ },
216
+ },
217
+ 'precisionMode': number.TICK_SIZE,
218
+ 'requiredCredentials': {
219
+ 'apiKey': true,
220
+ 'secret': true,
221
+ },
222
+ 'exceptions': {
223
+ 'exact': {
224
+ // Margin required to place order with selected leverage and quantity is insufficient.
225
+ 'insufficient_margin': errors.InsufficientFunds,
226
+ 'order_size_exceed_available': errors.InvalidOrder,
227
+ 'risk_limits_breached': errors.BadRequest,
228
+ 'invalid_contract': errors.BadSymbol,
229
+ 'immediate_liquidation': errors.InvalidOrder,
230
+ 'out_of_bankruptcy': errors.InvalidOrder,
231
+ 'self_matching_disrupted_post_only': errors.InvalidOrder,
232
+ 'immediate_execution_post_only': errors.InvalidOrder,
233
+ 'bad_schema': errors.BadRequest,
234
+ 'invalid_api_key': errors.AuthenticationError,
235
+ 'invalid_signature': errors.AuthenticationError,
236
+ 'open_order_not_found': errors.OrderNotFound,
237
+ 'unavailable': errors.ExchangeNotAvailable, // {"error":{"code":"unavailable"},"success":false}
238
+ },
239
+ 'broad': {},
240
+ },
241
+ });
242
+ }
243
+ convertExpireDate(date) {
244
+ // parse YYMMDD to timestamp
245
+ const year = date.slice(0, 2);
246
+ const month = date.slice(2, 4);
247
+ const day = date.slice(4, 6);
248
+ const reconstructedDate = '20' + year + '-' + month + '-' + day + 'T00:00:00Z';
249
+ return reconstructedDate;
250
+ }
251
+ createExpiredOptionMarket(symbol) {
252
+ // support expired option contracts
253
+ const quote = 'USDT';
254
+ const optionParts = symbol.split('-');
255
+ const symbolBase = symbol.split('/');
256
+ let base = undefined;
257
+ let expiry = undefined;
258
+ let optionType = undefined;
259
+ if (symbol.indexOf('/') > -1) {
260
+ base = this.safeString(symbolBase, 0);
261
+ expiry = this.safeString(optionParts, 1);
262
+ optionType = this.safeString(optionParts, 3);
263
+ }
264
+ else {
265
+ base = this.safeString(optionParts, 1);
266
+ expiry = this.safeString(optionParts, 3);
267
+ optionType = this.safeString(optionParts, 0);
268
+ }
269
+ const settle = quote;
270
+ const strike = this.safeString(optionParts, 2);
271
+ const datetime = this.convertExpireDate(expiry);
272
+ const timestamp = this.parse8601(datetime);
273
+ return {
274
+ 'id': optionType + '-' + base + '-' + strike + '-' + expiry,
275
+ 'symbol': base + '/' + quote + ':' + settle + '-' + expiry + '-' + strike + '-' + optionType,
276
+ 'base': base,
277
+ 'quote': quote,
278
+ 'settle': settle,
279
+ 'baseId': base,
280
+ 'quoteId': quote,
281
+ 'settleId': settle,
282
+ 'active': false,
283
+ 'type': 'option',
284
+ 'linear': undefined,
285
+ 'inverse': undefined,
286
+ 'spot': false,
287
+ 'swap': false,
288
+ 'future': false,
289
+ 'option': true,
290
+ 'margin': false,
291
+ 'contract': true,
292
+ 'contractSize': this.parseNumber('1'),
293
+ 'expiry': timestamp,
294
+ 'expiryDatetime': datetime,
295
+ 'optionType': (optionType === 'C') ? 'call' : 'put',
296
+ 'strike': this.parseNumber(strike),
297
+ 'precision': {
298
+ 'amount': undefined,
299
+ 'price': undefined,
300
+ },
301
+ 'limits': {
302
+ 'amount': {
303
+ 'min': undefined,
304
+ 'max': undefined,
305
+ },
306
+ 'price': {
307
+ 'min': undefined,
308
+ 'max': undefined,
309
+ },
310
+ 'cost': {
311
+ 'min': undefined,
312
+ 'max': undefined,
313
+ },
314
+ },
315
+ 'info': undefined,
316
+ };
317
+ }
318
+ market(symbol) {
319
+ if (this.markets === undefined) {
320
+ throw new errors.ExchangeError(this.id + ' markets not loaded');
321
+ }
322
+ if (typeof symbol === 'string') {
323
+ if (symbol in this.markets) {
324
+ return this.markets[symbol];
325
+ }
326
+ else if (symbol in this.markets_by_id) {
327
+ const markets = this.markets_by_id[symbol];
328
+ return markets[0];
329
+ }
330
+ else if ((symbol.endsWith('-C')) || (symbol.endsWith('-P')) || (symbol.startsWith('C-')) || (symbol.startsWith('P-'))) {
331
+ return this.createExpiredOptionMarket(symbol);
332
+ }
333
+ }
334
+ throw new errors.BadSymbol(this.id + ' does not have market symbol ' + symbol);
335
+ }
336
+ safeMarket(marketId = undefined, market = undefined, delimiter = undefined, marketType = undefined) {
337
+ const isOption = (marketId !== undefined) && ((marketId.endsWith('-C')) || (marketId.endsWith('-P')) || (marketId.startsWith('C-')) || (marketId.startsWith('P-')));
338
+ if (isOption && !(marketId in this.markets_by_id)) {
339
+ // handle expired option contracts
340
+ return this.createExpiredOptionMarket(marketId);
341
+ }
342
+ return super.safeMarket(marketId, market, delimiter, marketType);
343
+ }
344
+ async fetchTime(params = {}) {
345
+ /**
346
+ * @method
347
+ * @name delta#fetchTime
348
+ * @description fetches the current integer timestamp in milliseconds from the exchange server
349
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
350
+ * @returns {int} the current integer timestamp in milliseconds from the exchange server
351
+ */
352
+ const response = await this.publicGetSettings(params);
353
+ // full response sample under `fetchStatus`
354
+ const result = this.safeValue(response, 'result', {});
355
+ return this.safeIntegerProduct(result, 'server_time', 0.001);
356
+ }
357
+ async fetchStatus(params = {}) {
358
+ /**
359
+ * @method
360
+ * @name delta#fetchStatus
361
+ * @description the latest known information on the availability of the exchange API
362
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
363
+ * @returns {object} a [status structure]{@link https://docs.ccxt.com/#/?id=exchange-status-structure}
364
+ */
365
+ const response = await this.publicGetSettings(params);
366
+ //
367
+ // {
368
+ // "result": {
369
+ // "deto_liquidity_mining_daily_reward": "40775",
370
+ // "deto_msp": "1.0",
371
+ // "deto_staking_daily_reward": "23764.08",
372
+ // "enabled_wallets": [
373
+ // "BTC",
374
+ // ...
375
+ // ],
376
+ // "portfolio_margin_params": {
377
+ // "enabled_portfolios": {
378
+ // ".DEAVAXUSDT": {
379
+ // "asset_id": 5,
380
+ // "futures_contingency_margin_percent": "1",
381
+ // "interest_rate": "0",
382
+ // "maintenance_margin_multiplier": "0.8",
383
+ // "max_price_shock": "20",
384
+ // "max_short_notional_limit": "2000",
385
+ // "options_contingency_margin_percent": "1",
386
+ // "options_discount_range": "10",
387
+ // "options_liq_band_range_percentage": "25",
388
+ // "settling_asset": "USDT",
389
+ // "sort_priority": 5,
390
+ // "underlying_asset": "AVAX",
391
+ // "volatility_down_shock": "30",
392
+ // "volatility_up_shock": "45"
393
+ // },
394
+ // ...
395
+ // },
396
+ // "portfolio_enabled_contracts": [
397
+ // "futures",
398
+ // "perpetual_futures",
399
+ // "call_options",
400
+ // "put_options"
401
+ // ]
402
+ // },
403
+ // "server_time": 1650640673500273,
404
+ // "trade_farming_daily_reward": "100000",
405
+ // "circulating_supply": "140000000",
406
+ // "circulating_supply_update_time": "1636752800",
407
+ // "deto_referral_mining_daily_reward": "0",
408
+ // "deto_total_reward_pool": "100000000",
409
+ // "deto_trade_mining_daily_reward": "0",
410
+ // "kyc_deposit_limit": "20",
411
+ // "kyc_withdrawal_limit": "10000",
412
+ // "maintenance_start_time": "1650387600000000",
413
+ // "msp_deto_commission_percent": "25",
414
+ // "under_maintenance": "false"
415
+ // },
416
+ // "success": true
417
+ // }
418
+ //
419
+ const result = this.safeValue(response, 'result', {});
420
+ const underMaintenance = this.safeString(result, 'under_maintenance');
421
+ const status = (underMaintenance === 'true') ? 'maintenance' : 'ok';
422
+ const updated = this.safeIntegerProduct(result, 'server_time', 0.001, this.milliseconds());
423
+ return {
424
+ 'status': status,
425
+ 'updated': updated,
426
+ 'eta': undefined,
427
+ 'url': undefined,
428
+ 'info': response,
429
+ };
430
+ }
431
+ async fetchCurrencies(params = {}) {
432
+ /**
433
+ * @method
434
+ * @name delta#fetchCurrencies
435
+ * @description fetches all available currencies on an exchange
436
+ * @see https://docs.delta.exchange/#get-list-of-all-assets
437
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
438
+ * @returns {object} an associative dictionary of currencies
439
+ */
440
+ const response = await this.publicGetAssets(params);
441
+ //
442
+ // {
443
+ // "result":[
444
+ // {
445
+ // "base_withdrawal_fee":"0.0005",
446
+ // "deposit_status":"enabled",
447
+ // "id":2,
448
+ // "interest_credit":true,
449
+ // "interest_slabs":[
450
+ // {"limit":"0.1","rate":"0"},
451
+ // {"limit":"1","rate":"0.05"},
452
+ // {"limit":"5","rate":"0.075"},
453
+ // {"limit":"10","rate":"0.1"},
454
+ // {"limit":"9999999999999999","rate":"0"}
455
+ // ],
456
+ // "kyc_deposit_limit":"10",
457
+ // "kyc_withdrawal_limit":"2",
458
+ // "min_withdrawal_amount":"0.001",
459
+ // "minimum_precision":4,
460
+ // "name":"Bitcoin",
461
+ // "precision":8,
462
+ // "sort_priority":1,
463
+ // "symbol":"BTC",
464
+ // "variable_withdrawal_fee":"0",
465
+ // "withdrawal_status":"enabled"
466
+ // },
467
+ // ],
468
+ // "success":true
469
+ // }
470
+ //
471
+ const currencies = this.safeValue(response, 'result', []);
472
+ const result = {};
473
+ for (let i = 0; i < currencies.length; i++) {
474
+ const currency = currencies[i];
475
+ const id = this.safeString(currency, 'symbol');
476
+ const numericId = this.safeInteger(currency, 'id');
477
+ const code = this.safeCurrencyCode(id);
478
+ const depositStatus = this.safeString(currency, 'deposit_status');
479
+ const withdrawalStatus = this.safeString(currency, 'withdrawal_status');
480
+ const depositsEnabled = (depositStatus === 'enabled');
481
+ const withdrawalsEnabled = (withdrawalStatus === 'enabled');
482
+ const active = depositsEnabled && withdrawalsEnabled;
483
+ result[code] = {
484
+ 'id': id,
485
+ 'numericId': numericId,
486
+ 'code': code,
487
+ 'name': this.safeString(currency, 'name'),
488
+ 'info': currency,
489
+ 'active': active,
490
+ 'deposit': depositsEnabled,
491
+ 'withdraw': withdrawalsEnabled,
492
+ 'fee': this.safeNumber(currency, 'base_withdrawal_fee'),
493
+ 'precision': this.parseNumber(this.parsePrecision(this.safeString(currency, 'precision'))),
494
+ 'limits': {
495
+ 'amount': { 'min': undefined, 'max': undefined },
496
+ 'withdraw': {
497
+ 'min': this.safeNumber(currency, 'min_withdrawal_amount'),
498
+ 'max': undefined,
499
+ },
500
+ },
501
+ 'networks': {},
502
+ };
503
+ }
504
+ return result;
505
+ }
506
+ async loadMarkets(reload = false, params = {}) {
507
+ const markets = await super.loadMarkets(reload, params);
508
+ const currenciesByNumericId = this.safeValue(this.options, 'currenciesByNumericId');
509
+ if ((currenciesByNumericId === undefined) || reload) {
510
+ this.options['currenciesByNumericId'] = this.indexBy(this.currencies, 'numericId');
511
+ }
512
+ const marketsByNumericId = this.safeValue(this.options, 'marketsByNumericId');
513
+ if ((marketsByNumericId === undefined) || reload) {
514
+ this.options['marketsByNumericId'] = this.indexBy(this.markets, 'numericId');
515
+ }
516
+ return markets;
517
+ }
518
+ async fetchMarkets(params = {}) {
519
+ /**
520
+ * @method
521
+ * @name delta#fetchMarkets
522
+ * @description retrieves data on all markets for delta
523
+ * @see https://docs.delta.exchange/#get-list-of-products
524
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
525
+ * @returns {object[]} an array of objects representing market data
526
+ */
527
+ const response = await this.publicGetProducts(params);
528
+ //
529
+ // {
530
+ // "meta":{ "after":null, "before":null, "limit":100, "total_count":81 },
531
+ // "result":[
532
+ // // the below response represents item from perpetual market
533
+ // {
534
+ // "annualized_funding":"5.475000000000000000",
535
+ // "is_quanto":false,
536
+ // "ui_config":{
537
+ // "default_trading_view_candle":"15",
538
+ // "leverage_slider_values":[1,3,5,10,25,50],
539
+ // "price_clubbing_values":[0.001,0.005,0.05,0.1,0.5,1,5],
540
+ // "show_bracket_orders":false,
541
+ // "sort_priority":29,
542
+ // "tags":[]
543
+ // },
544
+ // "basis_factor_max_limit":"0.15",
545
+ // "symbol":"P-LINK-D-151120",
546
+ // "id":1584,
547
+ // "default_leverage":"5.000000000000000000",
548
+ // "maker_commission_rate":"0.0005",
549
+ // "contract_unit_currency":"LINK",
550
+ // "strike_price":"12.507948",
551
+ // "settling_asset":{
552
+ // // asset structure
553
+ // },
554
+ // "auction_start_time":null,
555
+ // "auction_finish_time":null,
556
+ // "settlement_time":"2020-11-15T12:00:00Z",
557
+ // "launch_time":"2020-11-14T11:55:05Z",
558
+ // "spot_index":{
559
+ // // index structure
560
+ // },
561
+ // "trading_status":"operational",
562
+ // "tick_size":"0.001",
563
+ // "position_size_limit":100000,
564
+ // "notional_type":"vanilla", // vanilla, inverse
565
+ // "price_band":"0.4",
566
+ // "barrier_price":null,
567
+ // "description":"Daily LINK PUT options quoted in USDT and settled in USDT",
568
+ // "insurance_fund_margin_contribution":"1",
569
+ // "quoting_asset":{
570
+ // // asset structure
571
+ // },
572
+ // "liquidation_penalty_factor":"0.2",
573
+ // "product_specs":{"max_volatility":3,"min_volatility":0.3,"spot_price_band":"0.40"},
574
+ // "initial_margin_scaling_factor":"0.0001",
575
+ // "underlying_asset":{
576
+ // // asset structure
577
+ // },
578
+ // "state":"live",
579
+ // "contract_value":"1",
580
+ // "initial_margin":"2",
581
+ // "impact_size":5000,
582
+ // "settlement_price":null,
583
+ // "contract_type":"put_options", // put_options, call_options, move_options, perpetual_futures, interest_rate_swaps, futures, spreads
584
+ // "taker_commission_rate":"0.0005",
585
+ // "maintenance_margin":"1",
586
+ // "short_description":"LINK Daily PUT Options",
587
+ // "maintenance_margin_scaling_factor":"0.00005",
588
+ // "funding_method":"mark_price",
589
+ // "max_leverage_notional":"20000"
590
+ // },
591
+ // // the below response represents item from spot market
592
+ // {
593
+ // "position_size_limit": 10000000,
594
+ // "settlement_price": null,
595
+ // "funding_method": "mark_price",
596
+ // "settling_asset": null,
597
+ // "impact_size": 10,
598
+ // "id": 32258,
599
+ // "auction_finish_time": null,
600
+ // "description": "Solana tether spot market",
601
+ // "trading_status": "operational",
602
+ // "tick_size": "0.01",
603
+ // "liquidation_penalty_factor": "1",
604
+ // "spot_index": {
605
+ // "config": { "quoting_asset": "USDT", "service_id": 8, "underlying_asset": "SOL" },
606
+ // "constituent_exchanges": [
607
+ // { "exchange": "binance", "health_interval": 60, "health_priority": 1, "weight": 1 },
608
+ // { "exchange": "huobi", "health_interval": 60, "health_priority": 2, "weight": 1 }
609
+ // ],
610
+ // "constituent_indices": null,
611
+ // "description": "Solana index from binance and huobi",
612
+ // "health_interval": 300,
613
+ // "id": 105,
614
+ // "impact_size": "40.000000000000000000",
615
+ // "index_type": "spot_pair",
616
+ // "is_composite": false,
617
+ // "price_method": "ltp",
618
+ // "quoting_asset_id": 5,
619
+ // "symbol": ".DESOLUSDT",
620
+ // "tick_size": "0.000100000000000000",
621
+ // "underlying_asset_id": 66
622
+ // },
623
+ // "contract_type": "spot",
624
+ // "launch_time": "2022-02-03T10:18:11Z",
625
+ // "symbol": "SOL_USDT",
626
+ // "disruption_reason": null,
627
+ // "settlement_time": null,
628
+ // "insurance_fund_margin_contribution": "1",
629
+ // "is_quanto": false,
630
+ // "maintenance_margin": "5",
631
+ // "taker_commission_rate": "0.0005",
632
+ // "auction_start_time": null,
633
+ // "max_leverage_notional": "10000000",
634
+ // "state": "live",
635
+ // "annualized_funding": "0",
636
+ // "notional_type": "vanilla",
637
+ // "price_band": "100",
638
+ // "product_specs": { "kyc_required": false, "max_order_size": 2000, "min_order_size": 0.01, "quoting_precision": 4, "underlying_precision": 2 },
639
+ // "default_leverage": "1.000000000000000000",
640
+ // "initial_margin": "10",
641
+ // "maintenance_margin_scaling_factor": "1",
642
+ // "ui_config": {
643
+ // "default_trading_view_candle": "1d",
644
+ // "leverage_slider_values": [],
645
+ // "price_clubbing_values": [ 0.01, 0.05, 0.1, 0.5, 1, 2.5, 5 ],
646
+ // "show_bracket_orders": false,
647
+ // "sort_priority": 2,
648
+ // "tags": []
649
+ // },
650
+ // "basis_factor_max_limit": "10000",
651
+ // "contract_unit_currency": "SOL",
652
+ // "strike_price": null,
653
+ // "quoting_asset": {
654
+ // "base_withdrawal_fee": "10.000000000000000000",
655
+ // "deposit_status": "enabled",
656
+ // "id": 5,
657
+ // "interest_credit": false,
658
+ // "interest_slabs": null,
659
+ // "kyc_deposit_limit": "100000.000000000000000000",
660
+ // "kyc_withdrawal_limit": "10000.000000000000000000",
661
+ // "min_withdrawal_amount": "30.000000000000000000",
662
+ // "minimum_precision": 2,
663
+ // "name": "Tether",
664
+ // "networks": [
665
+ // { "base_withdrawal_fee": "25", "deposit_status": "enabled", "memo_required": false, "network": "ERC20", "variable_withdrawal_fee": "0", "withdrawal_status": "enabled" },
666
+ // { "base_withdrawal_fee": "1", "deposit_status": "enabled", "memo_required": false, "network": "BEP20(BSC)", "variable_withdrawal_fee": "0", "withdrawal_status": "enabled" },
667
+ // { "base_withdrawal_fee": "1", "deposit_status": "disabled", "memo_required": false, "network": "TRC20(TRON)", "variable_withdrawal_fee": "0", "withdrawal_status": "disabled" }
668
+ // ],
669
+ // "precision": 8,
670
+ // "sort_priority": 1,
671
+ // "symbol": "USDT",
672
+ // "variable_withdrawal_fee": "0.000000000000000000",
673
+ // "withdrawal_status": "enabled"
674
+ // },
675
+ // "maker_commission_rate": "0.0005",
676
+ // "initial_margin_scaling_factor": "2",
677
+ // "underlying_asset": {
678
+ // "base_withdrawal_fee": "0.000000000000000000",
679
+ // "deposit_status": "enabled",
680
+ // "id": 66,
681
+ // "interest_credit": false,
682
+ // "interest_slabs": null,
683
+ // "kyc_deposit_limit": "0.000000000000000000",
684
+ // "kyc_withdrawal_limit": "0.000000000000000000",
685
+ // "min_withdrawal_amount": "0.020000000000000000",
686
+ // "minimum_precision": 4,
687
+ // "name": "Solana",
688
+ // "networks": [
689
+ // { "base_withdrawal_fee": "0.01", "deposit_status": "enabled", "memo_required": false, "network": "SOLANA", "variable_withdrawal_fee": "0", "withdrawal_status": "enabled" },
690
+ // { "base_withdrawal_fee": "0.01", "deposit_status": "enabled", "memo_required": false, "network": "BEP20(BSC)", "variable_withdrawal_fee": "0", "withdrawal_status": "enabled" }
691
+ // ],
692
+ // "precision": 8,
693
+ // "sort_priority": 7,
694
+ // "symbol": "SOL",
695
+ // "variable_withdrawal_fee": "0.000000000000000000",
696
+ // "withdrawal_status": "enabled"
697
+ // },
698
+ // "barrier_price": null,
699
+ // "contract_value": "1",
700
+ // "short_description": "SOL-USDT spot market"
701
+ // },
702
+ // ],
703
+ // "success":true
704
+ // }
705
+ //
706
+ const markets = this.safeValue(response, 'result', []);
707
+ const result = [];
708
+ for (let i = 0; i < markets.length; i++) {
709
+ const market = markets[i];
710
+ let type = this.safeString(market, 'contract_type');
711
+ if (type === 'options_combos') {
712
+ continue;
713
+ }
714
+ // const settlingAsset = this.safeValue (market, 'settling_asset', {});
715
+ const quotingAsset = this.safeValue(market, 'quoting_asset', {});
716
+ const underlyingAsset = this.safeValue(market, 'underlying_asset', {});
717
+ const settlingAsset = this.safeValue(market, 'settling_asset');
718
+ const productSpecs = this.safeValue(market, 'product_specs', {});
719
+ const baseId = this.safeString(underlyingAsset, 'symbol');
720
+ const quoteId = this.safeString(quotingAsset, 'symbol');
721
+ const settleId = this.safeString(settlingAsset, 'symbol');
722
+ const id = this.safeString(market, 'symbol');
723
+ const numericId = this.safeInteger(market, 'id');
724
+ const base = this.safeCurrencyCode(baseId);
725
+ const quote = this.safeCurrencyCode(quoteId);
726
+ const settle = this.safeCurrencyCode(settleId);
727
+ const callOptions = (type === 'call_options');
728
+ const putOptions = (type === 'put_options');
729
+ const moveOptions = (type === 'move_options');
730
+ const spot = (type === 'spot');
731
+ const swap = (type === 'perpetual_futures');
732
+ const future = (type === 'futures');
733
+ const option = (callOptions || putOptions || moveOptions);
734
+ const strike = this.safeString(market, 'strike_price');
735
+ const expiryDatetime = this.safeString(market, 'settlement_time');
736
+ const expiry = this.parse8601(expiryDatetime);
737
+ const contractSize = this.safeNumber(market, 'contract_value');
738
+ let amountPrecision = undefined;
739
+ if (spot) {
740
+ amountPrecision = this.parseNumber(this.parsePrecision(this.safeString(productSpecs, 'underlying_precision'))); // seems inverse of 'impact_size'
741
+ }
742
+ else {
743
+ // other markets (swap, futures, move, spread, irs) seem to use the step of '1' contract
744
+ amountPrecision = this.parseNumber('1');
745
+ }
746
+ const linear = (settle === base);
747
+ let optionType = undefined;
748
+ let symbol = base + '/' + quote;
749
+ if (swap || future || option) {
750
+ symbol = symbol + ':' + settle;
751
+ if (future || option) {
752
+ symbol = symbol + '-' + this.yymmdd(expiry);
753
+ if (option) {
754
+ type = 'option';
755
+ let letter = 'C';
756
+ optionType = 'call';
757
+ if (putOptions) {
758
+ letter = 'P';
759
+ optionType = 'put';
760
+ }
761
+ else if (moveOptions) {
762
+ letter = 'M';
763
+ optionType = 'move';
764
+ }
765
+ symbol = symbol + '-' + strike + '-' + letter;
766
+ }
767
+ else {
768
+ type = 'future';
769
+ }
770
+ }
771
+ else {
772
+ type = 'swap';
773
+ }
774
+ }
775
+ const state = this.safeString(market, 'state');
776
+ result.push({
777
+ 'id': id,
778
+ 'numericId': numericId,
779
+ 'symbol': symbol,
780
+ 'base': base,
781
+ 'quote': quote,
782
+ 'settle': settle,
783
+ 'baseId': baseId,
784
+ 'quoteId': quoteId,
785
+ 'settleId': settleId,
786
+ 'type': type,
787
+ 'spot': spot,
788
+ 'margin': spot ? undefined : false,
789
+ 'swap': swap,
790
+ 'future': future,
791
+ 'option': option,
792
+ 'active': (state === 'live'),
793
+ 'contract': !spot,
794
+ 'linear': spot ? undefined : linear,
795
+ 'inverse': spot ? undefined : !linear,
796
+ 'taker': this.safeNumber(market, 'taker_commission_rate'),
797
+ 'maker': this.safeNumber(market, 'maker_commission_rate'),
798
+ 'contractSize': contractSize,
799
+ 'expiry': expiry,
800
+ 'expiryDatetime': expiryDatetime,
801
+ 'strike': this.parseNumber(strike),
802
+ 'optionType': optionType,
803
+ 'precision': {
804
+ 'amount': amountPrecision,
805
+ 'price': this.safeNumber(market, 'tick_size'),
806
+ },
807
+ 'limits': {
808
+ 'leverage': {
809
+ 'min': undefined,
810
+ 'max': undefined,
811
+ },
812
+ 'amount': {
813
+ 'min': this.parseNumber('1'),
814
+ 'max': this.safeNumber(market, 'position_size_limit'),
815
+ },
816
+ 'price': {
817
+ 'min': undefined,
818
+ 'max': undefined,
819
+ },
820
+ 'cost': {
821
+ 'min': this.safeNumber(market, 'min_size'),
822
+ 'max': undefined,
823
+ },
824
+ },
825
+ 'created': this.parse8601(this.safeString(market, 'launch_time')),
826
+ 'info': market,
827
+ });
828
+ }
829
+ return result;
830
+ }
831
+ parseTicker(ticker, market = undefined) {
832
+ //
833
+ // spot: fetchTicker, fetchTickers
834
+ //
835
+ // {
836
+ // "close": 30634.0,
837
+ // "contract_type": "spot",
838
+ // "greeks": null,
839
+ // "high": 30780.0,
840
+ // "low": 30340.5,
841
+ // "mark_price": "48000",
842
+ // "oi": "0.0000",
843
+ // "oi_change_usd_6h": "0.0000",
844
+ // "oi_contracts": "0",
845
+ // "oi_value": "0.0000",
846
+ // "oi_value_symbol": "BTC",
847
+ // "oi_value_usd": "0.0000",
848
+ // "open": 30464.0,
849
+ // "price_band": null,
850
+ // "product_id": 8320,
851
+ // "quotes": {},
852
+ // "size": 2.6816639999999996,
853
+ // "spot_price": "30637.91465121",
854
+ // "symbol": "BTC_USDT",
855
+ // "timestamp": 1689139767621299,
856
+ // "turnover": 2.6816639999999996,
857
+ // "turnover_symbol": "BTC",
858
+ // "turnover_usd": 81896.45613400004,
859
+ // "volume": 2.6816639999999996
860
+ // }
861
+ //
862
+ // swap: fetchTicker, fetchTickers
863
+ //
864
+ // {
865
+ // "close": 30600.5,
866
+ // "contract_type": "perpetual_futures",
867
+ // "funding_rate": "0.00602961",
868
+ // "greeks": null,
869
+ // "high": 30803.0,
870
+ // "low": 30265.5,
871
+ // "mark_basis": "-0.45601594",
872
+ // "mark_price": "30600.10481568",
873
+ // "oi": "469.9190",
874
+ // "oi_change_usd_6h": "2226314.9900",
875
+ // "oi_contracts": "469919",
876
+ // "oi_value": "469.9190",
877
+ // "oi_value_symbol": "BTC",
878
+ // "oi_value_usd": "14385640.6802",
879
+ // "open": 30458.5,
880
+ // "price_band": {
881
+ // "lower_limit": "29067.08312627",
882
+ // "upper_limit": "32126.77608693"
883
+ // },
884
+ // "product_id": 139,
885
+ // "quotes": {
886
+ // "ask_iv": null,
887
+ // "ask_size": "965",
888
+ // "best_ask": "30600.5",
889
+ // "best_bid": "30599.5",
890
+ // "bid_iv": null,
891
+ // "bid_size": "196",
892
+ // "impact_mid_price": null,
893
+ // "mark_iv": "-0.44931641"
894
+ // },
895
+ // "size": 1226303,
896
+ // "spot_price": "30612.85362773",
897
+ // "symbol": "BTCUSDT",
898
+ // "timestamp": 1689136597460456,
899
+ // "turnover": 37392218.45999999,
900
+ // "turnover_symbol": "USDT",
901
+ // "turnover_usd": 37392218.45999999,
902
+ // "volume": 1226.3029999999485
903
+ // }
904
+ //
905
+ // option: fetchTicker, fetchTickers
906
+ //
907
+ // {
908
+ // "contract_type": "call_options",
909
+ // "greeks": {
910
+ // "delta": "0.60873994",
911
+ // "gamma": "0.00014854",
912
+ // "rho": "7.71808010",
913
+ // "spot": "30598.49040622",
914
+ // "theta": "-30.44743017",
915
+ // "vega": "24.83508248"
916
+ // },
917
+ // "mark_price": "1347.74819696",
918
+ // "mark_vol": "0.39966303",
919
+ // "oi": "2.7810",
920
+ // "oi_change_usd_6h": "0.0000",
921
+ // "oi_contracts": "2781",
922
+ // "oi_value": "2.7810",
923
+ // "oi_value_symbol": "BTC",
924
+ // "oi_value_usd": "85127.4337",
925
+ // "price_band": {
926
+ // "lower_limit": "91.27423497",
927
+ // "upper_limit": "7846.19454697"
928
+ // },
929
+ // "product_id": 107150,
930
+ // "quotes": {
931
+ // "ask_iv": "0.41023239",
932
+ // "ask_size": "2397",
933
+ // "best_ask": "1374",
934
+ // "best_bid": "1322",
935
+ // "bid_iv": "0.38929375",
936
+ // "bid_size": "3995",
937
+ // "impact_mid_price": null,
938
+ // "mark_iv": "0.39965618"
939
+ // },
940
+ // "spot_price": "30598.43379314",
941
+ // "strike_price": "30000",
942
+ // "symbol": "C-BTC-30000-280723",
943
+ // "timestamp": 1689136932893181,
944
+ // "turnover_symbol": "USDT"
945
+ // }
946
+ //
947
+ const timestamp = this.safeIntegerProduct(ticker, 'timestamp', 0.001);
948
+ const marketId = this.safeString(ticker, 'symbol');
949
+ const symbol = this.safeSymbol(marketId, market);
950
+ const last = this.safeString(ticker, 'close');
951
+ const quotes = this.safeValue(ticker, 'quotes', {});
952
+ return this.safeTicker({
953
+ 'symbol': symbol,
954
+ 'timestamp': timestamp,
955
+ 'datetime': this.iso8601(timestamp),
956
+ 'high': this.safeNumber(ticker, 'high'),
957
+ 'low': this.safeNumber(ticker, 'low'),
958
+ 'bid': this.safeNumber(quotes, 'best_bid'),
959
+ 'bidVolume': this.safeNumber(quotes, 'bid_size'),
960
+ 'ask': this.safeNumber(quotes, 'best_ask'),
961
+ 'askVolume': this.safeNumber(quotes, 'ask_size'),
962
+ 'vwap': undefined,
963
+ 'open': this.safeString(ticker, 'open'),
964
+ 'close': last,
965
+ 'last': last,
966
+ 'previousClose': undefined,
967
+ 'change': undefined,
968
+ 'percentage': undefined,
969
+ 'average': undefined,
970
+ 'baseVolume': this.safeNumber(ticker, 'volume'),
971
+ 'quoteVolume': this.safeNumber(ticker, 'turnover'),
972
+ 'info': ticker,
973
+ }, market);
974
+ }
975
+ async fetchTicker(symbol, params = {}) {
976
+ /**
977
+ * @method
978
+ * @name delta#fetchTicker
979
+ * @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
980
+ * @see https://docs.delta.exchange/#get-ticker-for-a-product-by-symbol
981
+ * @param {string} symbol unified symbol of the market to fetch the ticker for
982
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
983
+ * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
984
+ */
985
+ await this.loadMarkets();
986
+ const market = this.market(symbol);
987
+ const request = {
988
+ 'symbol': market['id'],
989
+ };
990
+ const response = await this.publicGetTickersSymbol(this.extend(request, params));
991
+ //
992
+ // spot
993
+ //
994
+ // {
995
+ // "result": {
996
+ // "close": 30634.0,
997
+ // "contract_type": "spot",
998
+ // "greeks": null,
999
+ // "high": 30780.0,
1000
+ // "low": 30340.5,
1001
+ // "mark_price": "48000",
1002
+ // "oi": "0.0000",
1003
+ // "oi_change_usd_6h": "0.0000",
1004
+ // "oi_contracts": "0",
1005
+ // "oi_value": "0.0000",
1006
+ // "oi_value_symbol": "BTC",
1007
+ // "oi_value_usd": "0.0000",
1008
+ // "open": 30464.0,
1009
+ // "price_band": null,
1010
+ // "product_id": 8320,
1011
+ // "quotes": {},
1012
+ // "size": 2.6816639999999996,
1013
+ // "spot_price": "30637.91465121",
1014
+ // "symbol": "BTC_USDT",
1015
+ // "timestamp": 1689139767621299,
1016
+ // "turnover": 2.6816639999999996,
1017
+ // "turnover_symbol": "BTC",
1018
+ // "turnover_usd": 81896.45613400004,
1019
+ // "volume": 2.6816639999999996
1020
+ // },
1021
+ // "success": true
1022
+ // }
1023
+ //
1024
+ // swap
1025
+ //
1026
+ // {
1027
+ // "result": {
1028
+ // "close": 30600.5,
1029
+ // "contract_type": "perpetual_futures",
1030
+ // "funding_rate": "0.00602961",
1031
+ // "greeks": null,
1032
+ // "high": 30803.0,
1033
+ // "low": 30265.5,
1034
+ // "mark_basis": "-0.45601594",
1035
+ // "mark_price": "30600.10481568",
1036
+ // "oi": "469.9190",
1037
+ // "oi_change_usd_6h": "2226314.9900",
1038
+ // "oi_contracts": "469919",
1039
+ // "oi_value": "469.9190",
1040
+ // "oi_value_symbol": "BTC",
1041
+ // "oi_value_usd": "14385640.6802",
1042
+ // "open": 30458.5,
1043
+ // "price_band": {
1044
+ // "lower_limit": "29067.08312627",
1045
+ // "upper_limit": "32126.77608693"
1046
+ // },
1047
+ // "product_id": 139,
1048
+ // "quotes": {
1049
+ // "ask_iv": null,
1050
+ // "ask_size": "965",
1051
+ // "best_ask": "30600.5",
1052
+ // "best_bid": "30599.5",
1053
+ // "bid_iv": null,
1054
+ // "bid_size": "196",
1055
+ // "impact_mid_price": null,
1056
+ // "mark_iv": "-0.44931641"
1057
+ // },
1058
+ // "size": 1226303,
1059
+ // "spot_price": "30612.85362773",
1060
+ // "symbol": "BTCUSDT",
1061
+ // "timestamp": 1689136597460456,
1062
+ // "turnover": 37392218.45999999,
1063
+ // "turnover_symbol": "USDT",
1064
+ // "turnover_usd": 37392218.45999999,
1065
+ // "volume": 1226.3029999999485
1066
+ // },
1067
+ // "success": true
1068
+ // }
1069
+ //
1070
+ // option
1071
+ //
1072
+ // {
1073
+ // "result": {
1074
+ // "contract_type": "call_options",
1075
+ // "greeks": {
1076
+ // "delta": "0.60873994",
1077
+ // "gamma": "0.00014854",
1078
+ // "rho": "7.71808010",
1079
+ // "spot": "30598.49040622",
1080
+ // "theta": "-30.44743017",
1081
+ // "vega": "24.83508248"
1082
+ // },
1083
+ // "mark_price": "1347.74819696",
1084
+ // "mark_vol": "0.39966303",
1085
+ // "oi": "2.7810",
1086
+ // "oi_change_usd_6h": "0.0000",
1087
+ // "oi_contracts": "2781",
1088
+ // "oi_value": "2.7810",
1089
+ // "oi_value_symbol": "BTC",
1090
+ // "oi_value_usd": "85127.4337",
1091
+ // "price_band": {
1092
+ // "lower_limit": "91.27423497",
1093
+ // "upper_limit": "7846.19454697"
1094
+ // },
1095
+ // "product_id": 107150,
1096
+ // "quotes": {
1097
+ // "ask_iv": "0.41023239",
1098
+ // "ask_size": "2397",
1099
+ // "best_ask": "1374",
1100
+ // "best_bid": "1322",
1101
+ // "bid_iv": "0.38929375",
1102
+ // "bid_size": "3995",
1103
+ // "impact_mid_price": null,
1104
+ // "mark_iv": "0.39965618"
1105
+ // },
1106
+ // "spot_price": "30598.43379314",
1107
+ // "strike_price": "30000",
1108
+ // "symbol": "C-BTC-30000-280723",
1109
+ // "timestamp": 1689136932893181,
1110
+ // "turnover_symbol": "USDT"
1111
+ // },
1112
+ // "success": true
1113
+ // }
1114
+ //
1115
+ const result = this.safeValue(response, 'result', {});
1116
+ return this.parseTicker(result, market);
1117
+ }
1118
+ async fetchTickers(symbols = undefined, params = {}) {
1119
+ /**
1120
+ * @method
1121
+ * @name delta#fetchTickers
1122
+ * @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
1123
+ * @see https://docs.delta.exchange/#get-tickers-for-products
1124
+ * @param {string[]|undefined} symbols unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
1125
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1126
+ * @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/#/?id=ticker-structure}
1127
+ */
1128
+ await this.loadMarkets();
1129
+ symbols = this.marketSymbols(symbols);
1130
+ const response = await this.publicGetTickers(params);
1131
+ //
1132
+ // spot
1133
+ //
1134
+ // {
1135
+ // "result": [
1136
+ // {
1137
+ // "close": 30634.0,
1138
+ // "contract_type": "spot",
1139
+ // "greeks": null,
1140
+ // "high": 30780.0,
1141
+ // "low": 30340.5,
1142
+ // "mark_price": "48000",
1143
+ // "oi": "0.0000",
1144
+ // "oi_change_usd_6h": "0.0000",
1145
+ // "oi_contracts": "0",
1146
+ // "oi_value": "0.0000",
1147
+ // "oi_value_symbol": "BTC",
1148
+ // "oi_value_usd": "0.0000",
1149
+ // "open": 30464.0,
1150
+ // "price_band": null,
1151
+ // "product_id": 8320,
1152
+ // "quotes": {},
1153
+ // "size": 2.6816639999999996,
1154
+ // "spot_price": "30637.91465121",
1155
+ // "symbol": "BTC_USDT",
1156
+ // "timestamp": 1689139767621299,
1157
+ // "turnover": 2.6816639999999996,
1158
+ // "turnover_symbol": "BTC",
1159
+ // "turnover_usd": 81896.45613400004,
1160
+ // "volume": 2.6816639999999996
1161
+ // },
1162
+ // ],
1163
+ // "success":true
1164
+ // }
1165
+ //
1166
+ // swap
1167
+ //
1168
+ // {
1169
+ // "result": [
1170
+ // {
1171
+ // "close": 30600.5,
1172
+ // "contract_type": "perpetual_futures",
1173
+ // "funding_rate": "0.00602961",
1174
+ // "greeks": null,
1175
+ // "high": 30803.0,
1176
+ // "low": 30265.5,
1177
+ // "mark_basis": "-0.45601594",
1178
+ // "mark_price": "30600.10481568",
1179
+ // "oi": "469.9190",
1180
+ // "oi_change_usd_6h": "2226314.9900",
1181
+ // "oi_contracts": "469919",
1182
+ // "oi_value": "469.9190",
1183
+ // "oi_value_symbol": "BTC",
1184
+ // "oi_value_usd": "14385640.6802",
1185
+ // "open": 30458.5,
1186
+ // "price_band": {
1187
+ // "lower_limit": "29067.08312627",
1188
+ // "upper_limit": "32126.77608693"
1189
+ // },
1190
+ // "product_id": 139,
1191
+ // "quotes": {
1192
+ // "ask_iv": null,
1193
+ // "ask_size": "965",
1194
+ // "best_ask": "30600.5",
1195
+ // "best_bid": "30599.5",
1196
+ // "bid_iv": null,
1197
+ // "bid_size": "196",
1198
+ // "impact_mid_price": null,
1199
+ // "mark_iv": "-0.44931641"
1200
+ // },
1201
+ // "size": 1226303,
1202
+ // "spot_price": "30612.85362773",
1203
+ // "symbol": "BTCUSDT",
1204
+ // "timestamp": 1689136597460456,
1205
+ // "turnover": 37392218.45999999,
1206
+ // "turnover_symbol": "USDT",
1207
+ // "turnover_usd": 37392218.45999999,
1208
+ // "volume": 1226.3029999999485
1209
+ // },
1210
+ // ],
1211
+ // "success":true
1212
+ // }
1213
+ //
1214
+ // option
1215
+ //
1216
+ // {
1217
+ // "result": [
1218
+ // {
1219
+ // "contract_type": "call_options",
1220
+ // "greeks": {
1221
+ // "delta": "0.60873994",
1222
+ // "gamma": "0.00014854",
1223
+ // "rho": "7.71808010",
1224
+ // "spot": "30598.49040622",
1225
+ // "theta": "-30.44743017",
1226
+ // "vega": "24.83508248"
1227
+ // },
1228
+ // "mark_price": "1347.74819696",
1229
+ // "mark_vol": "0.39966303",
1230
+ // "oi": "2.7810",
1231
+ // "oi_change_usd_6h": "0.0000",
1232
+ // "oi_contracts": "2781",
1233
+ // "oi_value": "2.7810",
1234
+ // "oi_value_symbol": "BTC",
1235
+ // "oi_value_usd": "85127.4337",
1236
+ // "price_band": {
1237
+ // "lower_limit": "91.27423497",
1238
+ // "upper_limit": "7846.19454697"
1239
+ // },
1240
+ // "product_id": 107150,
1241
+ // "quotes": {
1242
+ // "ask_iv": "0.41023239",
1243
+ // "ask_size": "2397",
1244
+ // "best_ask": "1374",
1245
+ // "best_bid": "1322",
1246
+ // "bid_iv": "0.38929375",
1247
+ // "bid_size": "3995",
1248
+ // "impact_mid_price": null,
1249
+ // "mark_iv": "0.39965618"
1250
+ // },
1251
+ // "spot_price": "30598.43379314",
1252
+ // "strike_price": "30000",
1253
+ // "symbol": "C-BTC-30000-280723",
1254
+ // "timestamp": 1689136932893181,
1255
+ // "turnover_symbol": "USDT"
1256
+ // },
1257
+ // ],
1258
+ // "success":true
1259
+ // }
1260
+ //
1261
+ const tickers = this.safeValue(response, 'result', []);
1262
+ const result = {};
1263
+ for (let i = 0; i < tickers.length; i++) {
1264
+ const ticker = this.parseTicker(tickers[i]);
1265
+ const symbol = ticker['symbol'];
1266
+ result[symbol] = ticker;
1267
+ }
1268
+ return this.filterByArrayTickers(result, 'symbol', symbols);
1269
+ }
1270
+ async fetchOrderBook(symbol, limit = undefined, params = {}) {
1271
+ /**
1272
+ * @method
1273
+ * @name delta#fetchOrderBook
1274
+ * @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
1275
+ * @see https://docs.delta.exchange/#get-l2-orderbook
1276
+ * @param {string} symbol unified symbol of the market to fetch the order book for
1277
+ * @param {int} [limit] the maximum amount of order book entries to return
1278
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1279
+ * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
1280
+ */
1281
+ await this.loadMarkets();
1282
+ const market = this.market(symbol);
1283
+ const request = {
1284
+ 'symbol': market['id'],
1285
+ };
1286
+ if (limit !== undefined) {
1287
+ request['depth'] = limit;
1288
+ }
1289
+ const response = await this.publicGetL2orderbookSymbol(this.extend(request, params));
1290
+ //
1291
+ // {
1292
+ // "result":{
1293
+ // "buy":[
1294
+ // {"price":"15814.0","size":912},
1295
+ // {"price":"15813.5","size":1279},
1296
+ // {"price":"15813.0","size":1634},
1297
+ // ],
1298
+ // "sell":[
1299
+ // {"price":"15814.5","size":625},
1300
+ // {"price":"15815.0","size":982},
1301
+ // {"price":"15815.5","size":1328},
1302
+ // ],
1303
+ // "symbol":"BTCUSDT"
1304
+ // },
1305
+ // "success":true
1306
+ // }
1307
+ //
1308
+ const result = this.safeValue(response, 'result', {});
1309
+ return this.parseOrderBook(result, market['symbol'], undefined, 'buy', 'sell', 'price', 'size');
1310
+ }
1311
+ parseTrade(trade, market = undefined) {
1312
+ //
1313
+ // public fetchTrades
1314
+ //
1315
+ // {
1316
+ // "buyer_role":"maker",
1317
+ // "price":"15896.5",
1318
+ // "seller_role":"taker",
1319
+ // "size":241,
1320
+ // "symbol":"BTCUSDT",
1321
+ // "timestamp":1605376684714595
1322
+ // }
1323
+ //
1324
+ // private fetchMyTrades
1325
+ //
1326
+ // {
1327
+ // "commission":"0.008335000000000000",
1328
+ // "created_at":"2020-11-16T19:07:19Z",
1329
+ // "fill_type":"normal",
1330
+ // "id":"e7ff05c233a74245b72381f8dd91d1ce",
1331
+ // "meta_data":{
1332
+ // "effective_commission_rate":"0.0005",
1333
+ // "order_price":"16249",
1334
+ // "order_size":1,
1335
+ // "order_type":"market_order",
1336
+ // "order_unfilled_size":0,
1337
+ // "trading_fee_credits_used":"0"
1338
+ // },
1339
+ // "order_id":"152999629",
1340
+ // "price":"16669",
1341
+ // "product":{
1342
+ // "contract_type":"perpetual_futures",
1343
+ // "contract_unit_currency":"BTC",
1344
+ // "contract_value":"0.001",
1345
+ // "id":139,
1346
+ // "notional_type":"vanilla",
1347
+ // "quoting_asset":{"minimum_precision":2,"precision":6,"symbol":"USDT"},
1348
+ // "settling_asset":{"minimum_precision":2,"precision":6,"symbol":"USDT"},
1349
+ // "symbol":"BTCUSDT",
1350
+ // "tick_size":"0.5",
1351
+ // "underlying_asset":{"minimum_precision":4,"precision":8,"symbol":"BTC"}
1352
+ // },
1353
+ // "product_id":139,
1354
+ // "role":"taker",
1355
+ // "side":"sell",
1356
+ // "size":1
1357
+ // }
1358
+ //
1359
+ const id = this.safeString(trade, 'id');
1360
+ const orderId = this.safeString(trade, 'order_id');
1361
+ let timestamp = this.parse8601(this.safeString(trade, 'created_at'));
1362
+ timestamp = this.safeIntegerProduct(trade, 'timestamp', 0.001, timestamp);
1363
+ const priceString = this.safeString(trade, 'price');
1364
+ const amountString = this.safeString(trade, 'size');
1365
+ const product = this.safeValue(trade, 'product', {});
1366
+ const marketId = this.safeString(product, 'symbol');
1367
+ const symbol = this.safeSymbol(marketId, market);
1368
+ const sellerRole = this.safeString(trade, 'seller_role');
1369
+ let side = this.safeString(trade, 'side');
1370
+ if (side === undefined) {
1371
+ if (sellerRole === 'taker') {
1372
+ side = 'sell';
1373
+ }
1374
+ else if (sellerRole === 'maker') {
1375
+ side = 'buy';
1376
+ }
1377
+ }
1378
+ const takerOrMaker = this.safeString(trade, 'role');
1379
+ const metaData = this.safeValue(trade, 'meta_data', {});
1380
+ let type = this.safeString(metaData, 'order_type');
1381
+ if (type !== undefined) {
1382
+ type = type.replace('_order', '');
1383
+ }
1384
+ const feeCostString = this.safeString(trade, 'commission');
1385
+ let fee = undefined;
1386
+ if (feeCostString !== undefined) {
1387
+ const settlingAsset = this.safeValue(product, 'settling_asset', {});
1388
+ const feeCurrencyId = this.safeString(settlingAsset, 'symbol');
1389
+ const feeCurrencyCode = this.safeCurrencyCode(feeCurrencyId);
1390
+ fee = {
1391
+ 'cost': feeCostString,
1392
+ 'currency': feeCurrencyCode,
1393
+ };
1394
+ }
1395
+ return this.safeTrade({
1396
+ 'id': id,
1397
+ 'order': orderId,
1398
+ 'timestamp': timestamp,
1399
+ 'datetime': this.iso8601(timestamp),
1400
+ 'symbol': symbol,
1401
+ 'type': type,
1402
+ 'side': side,
1403
+ 'price': priceString,
1404
+ 'amount': amountString,
1405
+ 'cost': undefined,
1406
+ 'takerOrMaker': takerOrMaker,
1407
+ 'fee': fee,
1408
+ 'info': trade,
1409
+ }, market);
1410
+ }
1411
+ async fetchTrades(symbol, since = undefined, limit = undefined, params = {}) {
1412
+ /**
1413
+ * @method
1414
+ * @name delta#fetchTrades
1415
+ * @description get the list of most recent trades for a particular symbol
1416
+ * @see https://docs.delta.exchange/#get-public-trades
1417
+ * @param {string} symbol unified symbol of the market to fetch trades for
1418
+ * @param {int} [since] timestamp in ms of the earliest trade to fetch
1419
+ * @param {int} [limit] the maximum amount of trades to fetch
1420
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1421
+ * @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
1422
+ */
1423
+ await this.loadMarkets();
1424
+ const market = this.market(symbol);
1425
+ const request = {
1426
+ 'symbol': market['id'],
1427
+ };
1428
+ const response = await this.publicGetTradesSymbol(this.extend(request, params));
1429
+ //
1430
+ // {
1431
+ // "result":[
1432
+ // {
1433
+ // "buyer_role":"maker",
1434
+ // "price":"15896.5",
1435
+ // "seller_role":"taker",
1436
+ // "size":241,
1437
+ // "symbol":"BTCUSDT",
1438
+ // "timestamp":1605376684714595
1439
+ // }
1440
+ // ],
1441
+ // "success":true
1442
+ // }
1443
+ //
1444
+ const result = this.safeValue(response, 'result', []);
1445
+ return this.parseTrades(result, market, since, limit);
1446
+ }
1447
+ parseOHLCV(ohlcv, market = undefined) {
1448
+ //
1449
+ // {
1450
+ // "time":1605393120,
1451
+ // "open":15989,
1452
+ // "high":15989,
1453
+ // "low":15987.5,
1454
+ // "close":15987.5,
1455
+ // "volume":565
1456
+ // }
1457
+ //
1458
+ return [
1459
+ this.safeTimestamp(ohlcv, 'time'),
1460
+ this.safeNumber(ohlcv, 'open'),
1461
+ this.safeNumber(ohlcv, 'high'),
1462
+ this.safeNumber(ohlcv, 'low'),
1463
+ this.safeNumber(ohlcv, 'close'),
1464
+ this.safeNumber(ohlcv, 'volume'),
1465
+ ];
1466
+ }
1467
+ async fetchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
1468
+ /**
1469
+ * @method
1470
+ * @name delta#fetchOHLCV
1471
+ * @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
1472
+ * @see https://docs.delta.exchange/#get-ohlc-candles
1473
+ * @param {string} symbol unified symbol of the market to fetch OHLCV data for
1474
+ * @param {string} timeframe the length of time each candle represents
1475
+ * @param {int} [since] timestamp in ms of the earliest candle to fetch
1476
+ * @param {int} [limit] the maximum amount of candles to fetch
1477
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1478
+ * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
1479
+ */
1480
+ await this.loadMarkets();
1481
+ const market = this.market(symbol);
1482
+ const request = {
1483
+ 'resolution': this.safeString(this.timeframes, timeframe, timeframe),
1484
+ };
1485
+ const duration = this.parseTimeframe(timeframe);
1486
+ limit = limit ? limit : 2000; // max 2000
1487
+ if (since === undefined) {
1488
+ const end = this.seconds();
1489
+ request['end'] = end;
1490
+ request['start'] = end - limit * duration;
1491
+ }
1492
+ else {
1493
+ const start = this.parseToInt(since / 1000);
1494
+ request['start'] = start;
1495
+ request['end'] = this.sum(start, limit * duration);
1496
+ }
1497
+ const price = this.safeString(params, 'price');
1498
+ if (price === 'mark') {
1499
+ request['symbol'] = 'MARK:' + market['id'];
1500
+ }
1501
+ else if (price === 'index') {
1502
+ request['symbol'] = market['info']['spot_index']['symbol'];
1503
+ }
1504
+ else {
1505
+ request['symbol'] = market['id'];
1506
+ }
1507
+ params = this.omit(params, 'price');
1508
+ const response = await this.publicGetHistoryCandles(this.extend(request, params));
1509
+ //
1510
+ // {
1511
+ // "success":true,
1512
+ // "result":[
1513
+ // {"time":1605393120,"open":15989,"high":15989,"low":15987.5,"close":15987.5,"volume":565},
1514
+ // {"time":1605393180,"open":15966,"high":15966,"low":15959,"close":15959,"volume":24},
1515
+ // {"time":1605393300,"open":15973,"high":15973,"low":15973,"close":15973,"volume":1288},
1516
+ // ]
1517
+ // }
1518
+ //
1519
+ const result = this.safeValue(response, 'result', []);
1520
+ return this.parseOHLCVs(result, market, timeframe, since, limit);
1521
+ }
1522
+ parseBalance(response) {
1523
+ const balances = this.safeValue(response, 'result', []);
1524
+ const result = { 'info': response };
1525
+ const currenciesByNumericId = this.safeValue(this.options, 'currenciesByNumericId', {});
1526
+ for (let i = 0; i < balances.length; i++) {
1527
+ const balance = balances[i];
1528
+ const currencyId = this.safeString(balance, 'asset_id');
1529
+ const currency = this.safeValue(currenciesByNumericId, currencyId);
1530
+ const code = (currency === undefined) ? currencyId : currency['code'];
1531
+ const account = this.account();
1532
+ account['total'] = this.safeString(balance, 'balance');
1533
+ account['free'] = this.safeString(balance, 'available_balance');
1534
+ result[code] = account;
1535
+ }
1536
+ return this.safeBalance(result);
1537
+ }
1538
+ async fetchBalance(params = {}) {
1539
+ /**
1540
+ * @method
1541
+ * @name delta#fetchBalance
1542
+ * @description query for balance and get the amount of funds available for trading or funds locked in orders
1543
+ * @see https://docs.delta.exchange/#get-wallet-balances
1544
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1545
+ * @returns {object} a [balance structure]{@link https://docs.ccxt.com/#/?id=balance-structure}
1546
+ */
1547
+ await this.loadMarkets();
1548
+ const response = await this.privateGetWalletBalances(params);
1549
+ //
1550
+ // {
1551
+ // "result":[
1552
+ // {
1553
+ // "asset_id":1,
1554
+ // "available_balance":"0",
1555
+ // "balance":"0",
1556
+ // "commission":"0",
1557
+ // "id":154883,
1558
+ // "interest_credit":"0",
1559
+ // "order_margin":"0",
1560
+ // "pending_referral_bonus":"0",
1561
+ // "pending_trading_fee_credit":"0",
1562
+ // "position_margin":"0",
1563
+ // "trading_fee_credit":"0",
1564
+ // "user_id":22142
1565
+ // },
1566
+ // ],
1567
+ // "success":true
1568
+ // }
1569
+ //
1570
+ return this.parseBalance(response);
1571
+ }
1572
+ async fetchPosition(symbol, params = {}) {
1573
+ /**
1574
+ * @method
1575
+ * @name delta#fetchPosition
1576
+ * @description fetch data on a single open contract trade position
1577
+ * @see https://docs.delta.exchange/#get-position
1578
+ * @param {string} symbol unified market symbol of the market the position is held in, default is undefined
1579
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1580
+ * @returns {object} a [position structure]{@link https://docs.ccxt.com/#/?id=position-structure}
1581
+ */
1582
+ await this.loadMarkets();
1583
+ const market = this.market(symbol);
1584
+ const request = {
1585
+ 'product_id': market['numericId'],
1586
+ };
1587
+ const response = await this.privateGetPositions(this.extend(request, params));
1588
+ //
1589
+ // {
1590
+ // "result":{
1591
+ // "entry_price":null,
1592
+ // "size":0,
1593
+ // "timestamp":1605454074268079
1594
+ // },
1595
+ // "success":true
1596
+ // }
1597
+ //
1598
+ const result = this.safeValue(response, 'result', {});
1599
+ return this.parsePosition(result, market);
1600
+ }
1601
+ async fetchPositions(symbols = undefined, params = {}) {
1602
+ /**
1603
+ * @method
1604
+ * @name delta#fetchPositions
1605
+ * @description fetch all open positions
1606
+ * @see https://docs.delta.exchange/#get-margined-positions
1607
+ * @param {string[]|undefined} symbols list of unified market symbols
1608
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1609
+ * @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/#/?id=position-structure}
1610
+ */
1611
+ await this.loadMarkets();
1612
+ const response = await this.privateGetPositionsMargined(params);
1613
+ //
1614
+ // {
1615
+ // "success": true,
1616
+ // "result": [
1617
+ // {
1618
+ // "user_id": 0,
1619
+ // "size": 0,
1620
+ // "entry_price": "string",
1621
+ // "margin": "string",
1622
+ // "liquidation_price": "string",
1623
+ // "bankruptcy_price": "string",
1624
+ // "adl_level": 0,
1625
+ // "product_id": 0,
1626
+ // "product_symbol": "string",
1627
+ // "commission": "string",
1628
+ // "realized_pnl": "string",
1629
+ // "realized_funding": "string"
1630
+ // }
1631
+ // ]
1632
+ // }
1633
+ //
1634
+ const result = this.safeValue(response, 'result', []);
1635
+ return this.parsePositions(result, symbols);
1636
+ }
1637
+ parsePosition(position, market = undefined) {
1638
+ //
1639
+ // fetchPosition
1640
+ //
1641
+ // {
1642
+ // "entry_price":null,
1643
+ // "size":0,
1644
+ // "timestamp":1605454074268079
1645
+ // }
1646
+ //
1647
+ //
1648
+ // fetchPositions
1649
+ //
1650
+ // {
1651
+ // "user_id": 0,
1652
+ // "size": 0,
1653
+ // "entry_price": "string",
1654
+ // "margin": "string",
1655
+ // "liquidation_price": "string",
1656
+ // "bankruptcy_price": "string",
1657
+ // "adl_level": 0,
1658
+ // "product_id": 0,
1659
+ // "product_symbol": "string",
1660
+ // "commission": "string",
1661
+ // "realized_pnl": "string",
1662
+ // "realized_funding": "string"
1663
+ // }
1664
+ //
1665
+ const marketId = this.safeString(position, 'product_symbol');
1666
+ market = this.safeMarket(marketId, market);
1667
+ const symbol = market['symbol'];
1668
+ const timestamp = this.safeIntegerProduct(position, 'timestamp', 0.001);
1669
+ const sizeString = this.safeString(position, 'size');
1670
+ let side = undefined;
1671
+ if (sizeString !== undefined) {
1672
+ if (Precise["default"].stringGt(sizeString, '0')) {
1673
+ side = 'buy';
1674
+ }
1675
+ else if (Precise["default"].stringLt(sizeString, '0')) {
1676
+ side = 'sell';
1677
+ }
1678
+ }
1679
+ return this.safePosition({
1680
+ 'info': position,
1681
+ 'id': undefined,
1682
+ 'symbol': symbol,
1683
+ 'notional': undefined,
1684
+ 'marginMode': undefined,
1685
+ 'liquidationPrice': this.safeNumber(position, 'liquidation_price'),
1686
+ 'entryPrice': this.safeNumber(position, 'entry_price'),
1687
+ 'unrealizedPnl': undefined,
1688
+ 'percentage': undefined,
1689
+ 'contracts': this.parseNumber(sizeString),
1690
+ 'contractSize': this.safeNumber(market, 'contractSize'),
1691
+ 'markPrice': undefined,
1692
+ 'side': side,
1693
+ 'hedged': undefined,
1694
+ 'timestamp': timestamp,
1695
+ 'datetime': this.iso8601(timestamp),
1696
+ 'maintenanceMargin': undefined,
1697
+ 'maintenanceMarginPercentage': undefined,
1698
+ 'collateral': undefined,
1699
+ 'initialMargin': undefined,
1700
+ 'initialMarginPercentage': undefined,
1701
+ 'leverage': undefined,
1702
+ 'marginRatio': undefined,
1703
+ 'stopLossPrice': undefined,
1704
+ 'takeProfitPrice': undefined,
1705
+ });
1706
+ }
1707
+ parseOrderStatus(status) {
1708
+ const statuses = {
1709
+ 'open': 'open',
1710
+ 'pending': 'open',
1711
+ 'closed': 'closed',
1712
+ 'cancelled': 'canceled',
1713
+ };
1714
+ return this.safeString(statuses, status, status);
1715
+ }
1716
+ parseOrder(order, market = undefined) {
1717
+ //
1718
+ // createOrder, cancelOrder, editOrder, fetchOpenOrders, fetchClosedOrders
1719
+ //
1720
+ // {
1721
+ // "average_fill_price":null,
1722
+ // "bracket_order":null,
1723
+ // "bracket_stop_loss_limit_price":null,
1724
+ // "bracket_stop_loss_price":null,
1725
+ // "bracket_take_profit_limit_price":null,
1726
+ // "bracket_take_profit_price":null,
1727
+ // "bracket_trail_amount":null,
1728
+ // "cancellation_reason":null,
1729
+ // "client_order_id":null,
1730
+ // "close_on_trigger":"false",
1731
+ // "commission":"0",
1732
+ // "created_at":"2020-11-16T02:38:26Z",
1733
+ // "id":152870626,
1734
+ // "limit_price":"10000",
1735
+ // "meta_data":{"source":"api"},
1736
+ // "order_type":"limit_order",
1737
+ // "paid_commission":"0",
1738
+ // "product_id":139,
1739
+ // "reduce_only":false,
1740
+ // "side":"buy",
1741
+ // "size":0,
1742
+ // "state":"open",
1743
+ // "stop_order_type":null,
1744
+ // "stop_price":null,
1745
+ // "stop_trigger_method":"mark_price",
1746
+ // "time_in_force":"gtc",
1747
+ // "trail_amount":null,
1748
+ // "unfilled_size":0,
1749
+ // "user_id":22142
1750
+ // }
1751
+ //
1752
+ const id = this.safeString(order, 'id');
1753
+ const clientOrderId = this.safeString(order, 'client_order_id');
1754
+ const timestamp = this.parse8601(this.safeString(order, 'created_at'));
1755
+ const marketId = this.safeString(order, 'product_id');
1756
+ const marketsByNumericId = this.safeValue(this.options, 'marketsByNumericId', {});
1757
+ market = this.safeValue(marketsByNumericId, marketId, market);
1758
+ const symbol = (market === undefined) ? marketId : market['symbol'];
1759
+ const status = this.parseOrderStatus(this.safeString(order, 'state'));
1760
+ const side = this.safeString(order, 'side');
1761
+ let type = this.safeString(order, 'order_type');
1762
+ type = type.replace('_order', '');
1763
+ const price = this.safeString(order, 'limit_price');
1764
+ const amount = this.safeString(order, 'size');
1765
+ const remaining = this.safeString(order, 'unfilled_size');
1766
+ const average = this.safeString(order, 'average_fill_price');
1767
+ let fee = undefined;
1768
+ const feeCostString = this.safeString(order, 'paid_commission');
1769
+ if (feeCostString !== undefined) {
1770
+ let feeCurrencyCode = undefined;
1771
+ if (market !== undefined) {
1772
+ const settlingAsset = this.safeValue(market['info'], 'settling_asset', {});
1773
+ const feeCurrencyId = this.safeString(settlingAsset, 'symbol');
1774
+ feeCurrencyCode = this.safeCurrencyCode(feeCurrencyId);
1775
+ }
1776
+ fee = {
1777
+ 'cost': feeCostString,
1778
+ 'currency': feeCurrencyCode,
1779
+ };
1780
+ }
1781
+ return this.safeOrder({
1782
+ 'info': order,
1783
+ 'id': id,
1784
+ 'clientOrderId': clientOrderId,
1785
+ 'timestamp': timestamp,
1786
+ 'datetime': this.iso8601(timestamp),
1787
+ 'lastTradeTimestamp': undefined,
1788
+ 'symbol': symbol,
1789
+ 'type': type,
1790
+ 'side': side,
1791
+ 'price': price,
1792
+ 'amount': amount,
1793
+ 'cost': undefined,
1794
+ 'average': average,
1795
+ 'filled': undefined,
1796
+ 'remaining': remaining,
1797
+ 'status': status,
1798
+ 'fee': fee,
1799
+ 'trades': undefined,
1800
+ }, market);
1801
+ }
1802
+ async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
1803
+ /**
1804
+ * @method
1805
+ * @name delta#createOrder
1806
+ * @description create a trade order
1807
+ * @see https://docs.delta.exchange/#place-order
1808
+ * @param {string} symbol unified symbol of the market to create an order in
1809
+ * @param {string} type 'market' or 'limit'
1810
+ * @param {string} side 'buy' or 'sell'
1811
+ * @param {float} amount how much of currency you want to trade in units of base currency
1812
+ * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
1813
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1814
+ * @param {bool} [params.reduceOnly] *contract only* indicates if this order is to reduce the size of a position
1815
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1816
+ */
1817
+ await this.loadMarkets();
1818
+ const orderType = type + '_order';
1819
+ const market = this.market(symbol);
1820
+ const request = {
1821
+ 'product_id': market['numericId'],
1822
+ // 'limit_price': this.priceToPrecision (market['symbol'], price),
1823
+ 'size': this.amountToPrecision(market['symbol'], amount),
1824
+ 'side': side,
1825
+ 'order_type': orderType,
1826
+ // 'client_order_id': 'string',
1827
+ // 'time_in_force': 'gtc', // gtc, ioc, fok
1828
+ // 'post_only': 'false', // 'true',
1829
+ // 'reduce_only': 'false', // 'true',
1830
+ };
1831
+ if (type === 'limit') {
1832
+ request['limit_price'] = this.priceToPrecision(market['symbol'], price);
1833
+ }
1834
+ const clientOrderId = this.safeString2(params, 'clientOrderId', 'client_order_id');
1835
+ params = this.omit(params, ['clientOrderId', 'client_order_id']);
1836
+ if (clientOrderId !== undefined) {
1837
+ request['client_order_id'] = clientOrderId;
1838
+ }
1839
+ const reduceOnly = this.safeValue(params, 'reduceOnly');
1840
+ if (reduceOnly) {
1841
+ request['reduce_only'] = reduceOnly;
1842
+ params = this.omit(params, 'reduceOnly');
1843
+ }
1844
+ const response = await this.privatePostOrders(this.extend(request, params));
1845
+ //
1846
+ // {
1847
+ // "result":{
1848
+ // "average_fill_price":null,
1849
+ // "bracket_order":null,
1850
+ // "bracket_stop_loss_limit_price":null,
1851
+ // "bracket_stop_loss_price":null,
1852
+ // "bracket_take_profit_limit_price":null,
1853
+ // "bracket_take_profit_price":null,
1854
+ // "bracket_trail_amount":null,
1855
+ // "cancellation_reason":null,
1856
+ // "client_order_id":null,
1857
+ // "close_on_trigger":"false",
1858
+ // "commission":"0",
1859
+ // "created_at":"2020-11-16T02:38:26Z",
1860
+ // "id":152870626,
1861
+ // "limit_price":"10000",
1862
+ // "meta_data":{"source":"api"},
1863
+ // "order_type":"limit_order",
1864
+ // "paid_commission":"0",
1865
+ // "product_id":139,
1866
+ // "reduce_only":false,
1867
+ // "side":"buy",
1868
+ // "size":0,
1869
+ // "state":"open",
1870
+ // "stop_order_type":null,
1871
+ // "stop_price":null,
1872
+ // "stop_trigger_method":"mark_price",
1873
+ // "time_in_force":"gtc",
1874
+ // "trail_amount":null,
1875
+ // "unfilled_size":0,
1876
+ // "user_id":22142
1877
+ // },
1878
+ // "success":true
1879
+ // }
1880
+ //
1881
+ const result = this.safeValue(response, 'result', {});
1882
+ return this.parseOrder(result, market);
1883
+ }
1884
+ async editOrder(id, symbol, type, side, amount = undefined, price = undefined, params = {}) {
1885
+ /**
1886
+ * @method
1887
+ * @name delta#editOrder
1888
+ * @description edit a trade order
1889
+ * @see https://docs.delta.exchange/#edit-order
1890
+ * @param {string} id order id
1891
+ * @param {string} symbol unified symbol of the market to create an order in
1892
+ * @param {string} type 'market' or 'limit'
1893
+ * @param {string} side 'buy' or 'sell'
1894
+ * @param {float} amount how much of the currency you want to trade in units of the base currency
1895
+ * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency
1896
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1897
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1898
+ */
1899
+ await this.loadMarkets();
1900
+ const market = this.market(symbol);
1901
+ const request = {
1902
+ 'id': parseInt(id),
1903
+ 'product_id': market['numericId'],
1904
+ // "limit_price": this.priceToPrecision (symbol, price),
1905
+ // "size": this.amountToPrecision (symbol, amount),
1906
+ };
1907
+ if (amount !== undefined) {
1908
+ request['size'] = parseInt(this.amountToPrecision(symbol, amount));
1909
+ }
1910
+ if (price !== undefined) {
1911
+ request['limit_price'] = this.priceToPrecision(symbol, price);
1912
+ }
1913
+ const response = await this.privatePutOrders(this.extend(request, params));
1914
+ //
1915
+ // {
1916
+ // "success": true,
1917
+ // "result": {
1918
+ // "id": "ashb1212",
1919
+ // "product_id": 27,
1920
+ // "limit_price": "9200",
1921
+ // "side": "buy",
1922
+ // "size": 100,
1923
+ // "unfilled_size": 50,
1924
+ // "user_id": 1,
1925
+ // "order_type": "limit_order",
1926
+ // "state": "open",
1927
+ // "created_at": "..."
1928
+ // }
1929
+ // }
1930
+ //
1931
+ const result = this.safeValue(response, 'result');
1932
+ return this.parseOrder(result, market);
1933
+ }
1934
+ async cancelOrder(id, symbol = undefined, params = {}) {
1935
+ /**
1936
+ * @method
1937
+ * @name delta#cancelOrder
1938
+ * @description cancels an open order
1939
+ * @see https://docs.delta.exchange/#cancel-order
1940
+ * @param {string} id order id
1941
+ * @param {string} symbol unified symbol of the market the order was made in
1942
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1943
+ * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1944
+ */
1945
+ if (symbol === undefined) {
1946
+ throw new errors.ArgumentsRequired(this.id + ' cancelOrder() requires a symbol argument');
1947
+ }
1948
+ await this.loadMarkets();
1949
+ const market = this.market(symbol);
1950
+ const request = {
1951
+ 'id': parseInt(id),
1952
+ 'product_id': market['numericId'],
1953
+ };
1954
+ const response = await this.privateDeleteOrders(this.extend(request, params));
1955
+ //
1956
+ // {
1957
+ // "result":{
1958
+ // "average_fill_price":null,
1959
+ // "bracket_order":null,
1960
+ // "bracket_stop_loss_limit_price":null,
1961
+ // "bracket_stop_loss_price":null,
1962
+ // "bracket_take_profit_limit_price":null,
1963
+ // "bracket_take_profit_price":null,
1964
+ // "bracket_trail_amount":null,
1965
+ // "cancellation_reason":"cancelled_by_user",
1966
+ // "client_order_id":null,
1967
+ // "close_on_trigger":"false",
1968
+ // "commission":"0",
1969
+ // "created_at":"2020-11-16T02:38:26Z",
1970
+ // "id":152870626,
1971
+ // "limit_price":"10000",
1972
+ // "meta_data":{"source":"api"},
1973
+ // "order_type":"limit_order",
1974
+ // "paid_commission":"0",
1975
+ // "product_id":139,
1976
+ // "reduce_only":false,
1977
+ // "side":"buy",
1978
+ // "size":0,
1979
+ // "state":"cancelled",
1980
+ // "stop_order_type":null,
1981
+ // "stop_price":null,
1982
+ // "stop_trigger_method":"mark_price",
1983
+ // "time_in_force":"gtc",
1984
+ // "trail_amount":null,
1985
+ // "unfilled_size":0,
1986
+ // "user_id":22142
1987
+ // },
1988
+ // "success":true
1989
+ // }
1990
+ //
1991
+ const result = this.safeValue(response, 'result');
1992
+ return this.parseOrder(result, market);
1993
+ }
1994
+ async cancelAllOrders(symbol = undefined, params = {}) {
1995
+ /**
1996
+ * @method
1997
+ * @name delta#cancelAllOrders
1998
+ * @description cancel all open orders in a market
1999
+ * @see https://docs.delta.exchange/#cancel-all-open-orders
2000
+ * @param {string} symbol unified market symbol of the market to cancel orders in
2001
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2002
+ * @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
2003
+ */
2004
+ if (symbol === undefined) {
2005
+ throw new errors.ArgumentsRequired(this.id + ' cancelAllOrders() requires a symbol argument');
2006
+ }
2007
+ await this.loadMarkets();
2008
+ const market = this.market(symbol);
2009
+ const request = {
2010
+ 'product_id': market['numericId'],
2011
+ // 'cancel_limit_orders': 'true',
2012
+ // 'cancel_stop_orders': 'true',
2013
+ };
2014
+ const response = this.privateDeleteOrdersAll(this.extend(request, params));
2015
+ //
2016
+ // {
2017
+ // "result":{},
2018
+ // "success":true
2019
+ // }
2020
+ //
2021
+ return response;
2022
+ }
2023
+ async fetchOpenOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
2024
+ /**
2025
+ * @method
2026
+ * @name delta#fetchOpenOrders
2027
+ * @description fetch all unfilled currently open orders
2028
+ * @see https://docs.delta.exchange/#get-active-orders
2029
+ * @param {string} symbol unified market symbol
2030
+ * @param {int} [since] the earliest time in ms to fetch open orders for
2031
+ * @param {int} [limit] the maximum number of open order structures to retrieve
2032
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2033
+ * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
2034
+ */
2035
+ return await this.fetchOrdersWithMethod('privateGetOrders', symbol, since, limit, params);
2036
+ }
2037
+ async fetchClosedOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
2038
+ /**
2039
+ * @method
2040
+ * @name delta#fetchClosedOrders
2041
+ * @description fetches information on multiple closed orders made by the user
2042
+ * @see https://docs.delta.exchange/#get-order-history-cancelled-and-closed
2043
+ * @param {string} symbol unified market symbol of the market orders were made in
2044
+ * @param {int} [since] the earliest time in ms to fetch orders for
2045
+ * @param {int} [limit] the maximum number of order structures to retrieve
2046
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2047
+ * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
2048
+ */
2049
+ return await this.fetchOrdersWithMethod('privateGetOrdersHistory', symbol, since, limit, params);
2050
+ }
2051
+ async fetchOrdersWithMethod(method, symbol = undefined, since = undefined, limit = undefined, params = {}) {
2052
+ await this.loadMarkets();
2053
+ const request = {
2054
+ // 'product_ids': market['id'], // comma-separated
2055
+ // 'contract_types': types, // comma-separated, futures, perpetual_futures, call_options, put_options, interest_rate_swaps, move_options, spreads
2056
+ // 'order_types': types, // comma-separated, market, limit, stop_market, stop_limit, all_stop
2057
+ // 'start_time': since * 1000,
2058
+ // 'end_time': this.microseconds (),
2059
+ // 'after', // after cursor for pagination
2060
+ // 'before', // before cursor for pagination
2061
+ // 'page_size': limit, // number of records per page
2062
+ };
2063
+ let market = undefined;
2064
+ if (symbol !== undefined) {
2065
+ market = this.market(symbol);
2066
+ request['product_ids'] = market['numericId']; // accepts a comma-separated list of ids
2067
+ }
2068
+ if (since !== undefined) {
2069
+ request['start_time'] = since.toString() + '000';
2070
+ }
2071
+ if (limit !== undefined) {
2072
+ request['page_size'] = limit;
2073
+ }
2074
+ const response = await this[method](this.extend(request, params));
2075
+ //
2076
+ // {
2077
+ // "success": true,
2078
+ // "result": [
2079
+ // {
2080
+ // "id": "ashb1212",
2081
+ // "product_id": 27,
2082
+ // "limit_price": "9200",
2083
+ // "side": "buy",
2084
+ // "size": 100,
2085
+ // "unfilled_size": 50,
2086
+ // "user_id": 1,
2087
+ // "order_type": "limit_order",
2088
+ // "state": "open",
2089
+ // "created_at": "..."
2090
+ // }
2091
+ // ],
2092
+ // "meta": {
2093
+ // "after": "string",
2094
+ // "before": "string"
2095
+ // }
2096
+ // }
2097
+ //
2098
+ const result = this.safeValue(response, 'result', []);
2099
+ return this.parseOrders(result, market, since, limit);
2100
+ }
2101
+ async fetchMyTrades(symbol = undefined, since = undefined, limit = undefined, params = {}) {
2102
+ /**
2103
+ * @method
2104
+ * @name delta#fetchMyTrades
2105
+ * @description fetch all trades made by the user
2106
+ * @see https://docs.delta.exchange/#get-user-fills-by-filters
2107
+ * @param {string} symbol unified market symbol
2108
+ * @param {int} [since] the earliest time in ms to fetch trades for
2109
+ * @param {int} [limit] the maximum number of trades structures to retrieve
2110
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2111
+ * @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure}
2112
+ */
2113
+ await this.loadMarkets();
2114
+ const request = {
2115
+ // 'product_ids': market['id'], // comma-separated
2116
+ // 'contract_types': types, // comma-separated, futures, perpetual_futures, call_options, put_options, interest_rate_swaps, move_options, spreads
2117
+ // 'start_time': since * 1000,
2118
+ // 'end_time': this.microseconds (),
2119
+ // 'after', // after cursor for pagination
2120
+ // 'before', // before cursor for pagination
2121
+ // 'page_size': limit, // number of records per page
2122
+ };
2123
+ let market = undefined;
2124
+ if (symbol !== undefined) {
2125
+ market = this.market(symbol);
2126
+ request['product_ids'] = market['numericId']; // accepts a comma-separated list of ids
2127
+ }
2128
+ if (since !== undefined) {
2129
+ request['start_time'] = since.toString() + '000';
2130
+ }
2131
+ if (limit !== undefined) {
2132
+ request['page_size'] = limit;
2133
+ }
2134
+ const response = await this.privateGetFills(this.extend(request, params));
2135
+ //
2136
+ // {
2137
+ // "meta":{
2138
+ // "after":null,
2139
+ // "before":null,
2140
+ // "limit":10,
2141
+ // "total_count":2
2142
+ // },
2143
+ // "result":[
2144
+ // {
2145
+ // "commission":"0.008335000000000000",
2146
+ // "created_at":"2020-11-16T19:07:19Z",
2147
+ // "fill_type":"normal",
2148
+ // "id":"e7ff05c233a74245b72381f8dd91d1ce",
2149
+ // "meta_data":{
2150
+ // "effective_commission_rate":"0.0005",
2151
+ // "order_price":"16249",
2152
+ // "order_size":1,
2153
+ // "order_type":"market_order",
2154
+ // "order_unfilled_size":0,
2155
+ // "trading_fee_credits_used":"0"
2156
+ // },
2157
+ // "order_id":"152999629",
2158
+ // "price":"16669",
2159
+ // "product":{
2160
+ // "contract_type":"perpetual_futures",
2161
+ // "contract_unit_currency":"BTC",
2162
+ // "contract_value":"0.001",
2163
+ // "id":139,
2164
+ // "notional_type":"vanilla",
2165
+ // "quoting_asset":{"minimum_precision":2,"precision":6,"symbol":"USDT"},
2166
+ // "settling_asset":{"minimum_precision":2,"precision":6,"symbol":"USDT"},
2167
+ // "symbol":"BTCUSDT",
2168
+ // "tick_size":"0.5",
2169
+ // "underlying_asset":{"minimum_precision":4,"precision":8,"symbol":"BTC"}
2170
+ // },
2171
+ // "product_id":139,
2172
+ // "role":"taker",
2173
+ // "side":"sell",
2174
+ // "size":1
2175
+ // }
2176
+ // ],
2177
+ // "success":true
2178
+ // }
2179
+ //
2180
+ const result = this.safeValue(response, 'result', []);
2181
+ return this.parseTrades(result, market, since, limit);
2182
+ }
2183
+ async fetchLedger(code = undefined, since = undefined, limit = undefined, params = {}) {
2184
+ /**
2185
+ * @method
2186
+ * @name delta#fetchLedger
2187
+ * @description fetch the history of changes, actions done by the user or operations that altered balance of the user
2188
+ * @see https://docs.delta.exchange/#get-wallet-transactions
2189
+ * @param {string} code unified currency code, default is undefined
2190
+ * @param {int} [since] timestamp in ms of the earliest ledger entry, default is undefined
2191
+ * @param {int} [limit] max number of ledger entrys to return, default is undefined
2192
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2193
+ * @returns {object} a [ledger structure]{@link https://docs.ccxt.com/#/?id=ledger-structure}
2194
+ */
2195
+ await this.loadMarkets();
2196
+ const request = {
2197
+ // 'asset_id': currency['numericId'],
2198
+ // 'end_time': this.seconds (),
2199
+ // 'after': 'string', // after cursor for pagination
2200
+ // 'before': 'string', // before cursor for pagination
2201
+ // 'page_size': limit,
2202
+ };
2203
+ let currency = undefined;
2204
+ if (code !== undefined) {
2205
+ currency = this.currency(code);
2206
+ request['asset_id'] = currency['numericId'];
2207
+ }
2208
+ if (limit !== undefined) {
2209
+ request['page_size'] = limit;
2210
+ }
2211
+ const response = await this.privateGetWalletTransactions(this.extend(request, params));
2212
+ //
2213
+ // {
2214
+ // "meta":{"after":null,"before":null,"limit":10,"total_count":1},
2215
+ // "result":[
2216
+ // {
2217
+ // "amount":"29.889184",
2218
+ // "asset_id":5,
2219
+ // "balance":"29.889184",
2220
+ // "created_at":"2020-11-15T21:25:01Z",
2221
+ // "meta_data":{
2222
+ // "deposit_id":3884,
2223
+ // "transaction_id":"0x41a60174849828530abb5008e98fc63c9b598288743ec4ba9620bcce900a3b8d"
2224
+ // },
2225
+ // "transaction_type":"deposit",
2226
+ // "user_id":22142,
2227
+ // "uuid":"70bb5679da3c4637884e2dc63efaa846"
2228
+ // }
2229
+ // ],
2230
+ // "success":true
2231
+ // }
2232
+ //
2233
+ const result = this.safeValue(response, 'result', []);
2234
+ return this.parseLedger(result, currency, since, limit);
2235
+ }
2236
+ parseLedgerEntryType(type) {
2237
+ const types = {
2238
+ 'pnl': 'pnl',
2239
+ 'deposit': 'transaction',
2240
+ 'withdrawal': 'transaction',
2241
+ 'commission': 'fee',
2242
+ 'conversion': 'trade',
2243
+ // 'perpetual_futures_funding': 'perpetual_futures_funding',
2244
+ // 'withdrawal_cancellation': 'withdrawal_cancellation',
2245
+ 'referral_bonus': 'referral',
2246
+ 'commission_rebate': 'rebate',
2247
+ // 'promo_credit': 'promo_credit',
2248
+ };
2249
+ return this.safeString(types, type, type);
2250
+ }
2251
+ parseLedgerEntry(item, currency = undefined) {
2252
+ //
2253
+ // {
2254
+ // "amount":"29.889184",
2255
+ // "asset_id":5,
2256
+ // "balance":"29.889184",
2257
+ // "created_at":"2020-11-15T21:25:01Z",
2258
+ // "meta_data":{
2259
+ // "deposit_id":3884,
2260
+ // "transaction_id":"0x41a60174849828530abb5008e98fc63c9b598288743ec4ba9620bcce900a3b8d"
2261
+ // },
2262
+ // "transaction_type":"deposit",
2263
+ // "user_id":22142,
2264
+ // "uuid":"70bb5679da3c4637884e2dc63efaa846"
2265
+ // }
2266
+ //
2267
+ const id = this.safeString(item, 'uuid');
2268
+ let direction = undefined;
2269
+ const account = undefined;
2270
+ const metaData = this.safeValue(item, 'meta_data', {});
2271
+ const referenceId = this.safeString(metaData, 'transaction_id');
2272
+ const referenceAccount = undefined;
2273
+ let type = this.safeString(item, 'transaction_type');
2274
+ if ((type === 'deposit') || (type === 'commission_rebate') || (type === 'referral_bonus') || (type === 'pnl') || (type === 'withdrawal_cancellation') || (type === 'promo_credit')) {
2275
+ direction = 'in';
2276
+ }
2277
+ else if ((type === 'withdrawal') || (type === 'commission') || (type === 'conversion') || (type === 'perpetual_futures_funding')) {
2278
+ direction = 'out';
2279
+ }
2280
+ type = this.parseLedgerEntryType(type);
2281
+ const currencyId = this.safeInteger(item, 'asset_id');
2282
+ const currenciesByNumericId = this.safeValue(this.options, 'currenciesByNumericId');
2283
+ currency = this.safeValue(currenciesByNumericId, currencyId, currency);
2284
+ const code = (currency === undefined) ? undefined : currency['code'];
2285
+ const amount = this.safeString(item, 'amount');
2286
+ const timestamp = this.parse8601(this.safeString(item, 'created_at'));
2287
+ const after = this.safeString(item, 'balance');
2288
+ const before = Precise["default"].stringMax('0', Precise["default"].stringSub(after, amount));
2289
+ const status = 'ok';
2290
+ return {
2291
+ 'info': item,
2292
+ 'id': id,
2293
+ 'direction': direction,
2294
+ 'account': account,
2295
+ 'referenceId': referenceId,
2296
+ 'referenceAccount': referenceAccount,
2297
+ 'type': type,
2298
+ 'currency': code,
2299
+ 'amount': this.parseNumber(amount),
2300
+ 'before': this.parseNumber(before),
2301
+ 'after': this.parseNumber(after),
2302
+ 'status': status,
2303
+ 'timestamp': timestamp,
2304
+ 'datetime': this.iso8601(timestamp),
2305
+ 'fee': undefined,
2306
+ };
2307
+ }
2308
+ async fetchDepositAddress(code, params = {}) {
2309
+ /**
2310
+ * @method
2311
+ * @name delta#fetchDepositAddress
2312
+ * @description fetch the deposit address for a currency associated with this account
2313
+ * @param {string} code unified currency code
2314
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2315
+ * @param {string} [params.network] unified network code
2316
+ * @returns {object} an [address structure]{@link https://docs.ccxt.com/#/?id=address-structure}
2317
+ */
2318
+ await this.loadMarkets();
2319
+ const currency = this.currency(code);
2320
+ const request = {
2321
+ 'asset_symbol': currency['id'],
2322
+ };
2323
+ const networkCode = this.safeStringUpper(params, 'network');
2324
+ if (networkCode !== undefined) {
2325
+ request['network'] = this.networkCodeToId(networkCode, code);
2326
+ params = this.omit(params, 'network');
2327
+ }
2328
+ const response = await this.privateGetDepositsAddress(this.extend(request, params));
2329
+ //
2330
+ // {
2331
+ // "success": true,
2332
+ // "result": {
2333
+ // "id": 1915615,
2334
+ // "user_id": 27854758,
2335
+ // "address": "TXYB4GdKsXKEWbeSNPsmGZu4ZVCkhVh1Zz",
2336
+ // "memo": "",
2337
+ // "status": "active",
2338
+ // "updated_at": "2023-01-12T06:03:46.000Z",
2339
+ // "created_at": "2023-01-12T06:03:46.000Z",
2340
+ // "asset_symbol": "USDT",
2341
+ // "network": "TRC20(TRON)",
2342
+ // "custodian": "fireblocks"
2343
+ // }
2344
+ // }
2345
+ //
2346
+ const result = this.safeValue(response, 'result', {});
2347
+ return this.parseDepositAddress(result, currency);
2348
+ }
2349
+ parseDepositAddress(depositAddress, currency = undefined) {
2350
+ //
2351
+ // {
2352
+ // "id": 1915615,
2353
+ // "user_id": 27854758,
2354
+ // "address": "TXYB4GdKsXKEWbeSNPsmGZu4ZVCkhVh1Zz",
2355
+ // "memo": "",
2356
+ // "status": "active",
2357
+ // "updated_at": "2023-01-12T06:03:46.000Z",
2358
+ // "created_at": "2023-01-12T06:03:46.000Z",
2359
+ // "asset_symbol": "USDT",
2360
+ // "network": "TRC20(TRON)",
2361
+ // "custodian": "fireblocks"
2362
+ // }
2363
+ //
2364
+ const address = this.safeString(depositAddress, 'address');
2365
+ const marketId = this.safeString(depositAddress, 'asset_symbol');
2366
+ const networkId = this.safeString(depositAddress, 'network');
2367
+ this.checkAddress(address);
2368
+ return {
2369
+ 'currency': this.safeCurrencyCode(marketId, currency),
2370
+ 'address': address,
2371
+ 'tag': this.safeString(depositAddress, 'memo'),
2372
+ 'network': this.networkIdToCode(networkId),
2373
+ 'info': depositAddress,
2374
+ };
2375
+ }
2376
+ async fetchFundingRate(symbol, params = {}) {
2377
+ /**
2378
+ * @method
2379
+ * @name delta#fetchFundingRate
2380
+ * @description fetch the current funding rate
2381
+ * @see https://docs.delta.exchange/#get-ticker-for-a-product-by-symbol
2382
+ * @param {string} symbol unified market symbol
2383
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2384
+ * @returns {object} a [funding rate structure]{@link https://docs.ccxt.com/#/?id=funding-rate-structure}
2385
+ */
2386
+ await this.loadMarkets();
2387
+ const market = this.market(symbol);
2388
+ if (!market['swap']) {
2389
+ throw new errors.BadSymbol(this.id + ' fetchFundingRate() supports swap contracts only');
2390
+ }
2391
+ const request = {
2392
+ 'symbol': market['id'],
2393
+ };
2394
+ const response = await this.publicGetTickersSymbol(this.extend(request, params));
2395
+ //
2396
+ // {
2397
+ // "result": {
2398
+ // "close": 30600.5,
2399
+ // "contract_type": "perpetual_futures",
2400
+ // "funding_rate": "0.00602961",
2401
+ // "greeks": null,
2402
+ // "high": 30803.0,
2403
+ // "low": 30265.5,
2404
+ // "mark_basis": "-0.45601594",
2405
+ // "mark_price": "30600.10481568",
2406
+ // "oi": "469.9190",
2407
+ // "oi_change_usd_6h": "2226314.9900",
2408
+ // "oi_contracts": "469919",
2409
+ // "oi_value": "469.9190",
2410
+ // "oi_value_symbol": "BTC",
2411
+ // "oi_value_usd": "14385640.6802",
2412
+ // "open": 30458.5,
2413
+ // "price_band": {
2414
+ // "lower_limit": "29067.08312627",
2415
+ // "upper_limit": "32126.77608693"
2416
+ // },
2417
+ // "product_id": 139,
2418
+ // "quotes": {
2419
+ // "ask_iv": null,
2420
+ // "ask_size": "965",
2421
+ // "best_ask": "30600.5",
2422
+ // "best_bid": "30599.5",
2423
+ // "bid_iv": null,
2424
+ // "bid_size": "196",
2425
+ // "impact_mid_price": null,
2426
+ // "mark_iv": "-0.44931641"
2427
+ // },
2428
+ // "size": 1226303,
2429
+ // "spot_price": "30612.85362773",
2430
+ // "symbol": "BTCUSDT",
2431
+ // "timestamp": 1689136597460456,
2432
+ // "turnover": 37392218.45999999,
2433
+ // "turnover_symbol": "USDT",
2434
+ // "turnover_usd": 37392218.45999999,
2435
+ // "volume": 1226.3029999999485
2436
+ // },
2437
+ // "success": true
2438
+ // }
2439
+ //
2440
+ const result = this.safeValue(response, 'result', {});
2441
+ return this.parseFundingRate(result, market);
2442
+ }
2443
+ async fetchFundingRates(symbols = undefined, params = {}) {
2444
+ /**
2445
+ * @method
2446
+ * @name delta#fetchFundingRates
2447
+ * @description fetch the funding rate for multiple markets
2448
+ * @see https://docs.delta.exchange/#get-tickers-for-products
2449
+ * @param {string[]|undefined} symbols list of unified market symbols
2450
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2451
+ * @returns {object} a dictionary of [funding rates structures]{@link https://docs.ccxt.com/#/?id=funding-rates-structure}, indexe by market symbols
2452
+ */
2453
+ await this.loadMarkets();
2454
+ symbols = this.marketSymbols(symbols);
2455
+ const request = {
2456
+ 'contract_types': 'perpetual_futures',
2457
+ };
2458
+ const response = await this.publicGetTickers(this.extend(request, params));
2459
+ //
2460
+ // {
2461
+ // "result": [
2462
+ // {
2463
+ // "close": 30600.5,
2464
+ // "contract_type": "perpetual_futures",
2465
+ // "funding_rate": "0.00602961",
2466
+ // "greeks": null,
2467
+ // "high": 30803.0,
2468
+ // "low": 30265.5,
2469
+ // "mark_basis": "-0.45601594",
2470
+ // "mark_price": "30600.10481568",
2471
+ // "oi": "469.9190",
2472
+ // "oi_change_usd_6h": "2226314.9900",
2473
+ // "oi_contracts": "469919",
2474
+ // "oi_value": "469.9190",
2475
+ // "oi_value_symbol": "BTC",
2476
+ // "oi_value_usd": "14385640.6802",
2477
+ // "open": 30458.5,
2478
+ // "price_band": {
2479
+ // "lower_limit": "29067.08312627",
2480
+ // "upper_limit": "32126.77608693"
2481
+ // },
2482
+ // "product_id": 139,
2483
+ // "quotes": {
2484
+ // "ask_iv": null,
2485
+ // "ask_size": "965",
2486
+ // "best_ask": "30600.5",
2487
+ // "best_bid": "30599.5",
2488
+ // "bid_iv": null,
2489
+ // "bid_size": "196",
2490
+ // "impact_mid_price": null,
2491
+ // "mark_iv": "-0.44931641"
2492
+ // },
2493
+ // "size": 1226303,
2494
+ // "spot_price": "30612.85362773",
2495
+ // "symbol": "BTCUSDT",
2496
+ // "timestamp": 1689136597460456,
2497
+ // "turnover": 37392218.45999999,
2498
+ // "turnover_symbol": "USDT",
2499
+ // "turnover_usd": 37392218.45999999,
2500
+ // "volume": 1226.3029999999485
2501
+ // },
2502
+ // ],
2503
+ // "success":true
2504
+ // }
2505
+ //
2506
+ const rates = this.safeValue(response, 'result', []);
2507
+ const result = this.parseFundingRates(rates);
2508
+ return this.filterByArray(result, 'symbol', symbols);
2509
+ }
2510
+ parseFundingRate(contract, market = undefined) {
2511
+ //
2512
+ // {
2513
+ // "close": 30600.5,
2514
+ // "contract_type": "perpetual_futures",
2515
+ // "funding_rate": "0.00602961",
2516
+ // "greeks": null,
2517
+ // "high": 30803.0,
2518
+ // "low": 30265.5,
2519
+ // "mark_basis": "-0.45601594",
2520
+ // "mark_price": "30600.10481568",
2521
+ // "oi": "469.9190",
2522
+ // "oi_change_usd_6h": "2226314.9900",
2523
+ // "oi_contracts": "469919",
2524
+ // "oi_value": "469.9190",
2525
+ // "oi_value_symbol": "BTC",
2526
+ // "oi_value_usd": "14385640.6802",
2527
+ // "open": 30458.5,
2528
+ // "price_band": {
2529
+ // "lower_limit": "29067.08312627",
2530
+ // "upper_limit": "32126.77608693"
2531
+ // },
2532
+ // "product_id": 139,
2533
+ // "quotes": {
2534
+ // "ask_iv": null,
2535
+ // "ask_size": "965",
2536
+ // "best_ask": "30600.5",
2537
+ // "best_bid": "30599.5",
2538
+ // "bid_iv": null,
2539
+ // "bid_size": "196",
2540
+ // "impact_mid_price": null,
2541
+ // "mark_iv": "-0.44931641"
2542
+ // },
2543
+ // "size": 1226303,
2544
+ // "spot_price": "30612.85362773",
2545
+ // "symbol": "BTCUSDT",
2546
+ // "timestamp": 1689136597460456,
2547
+ // "turnover": 37392218.45999999,
2548
+ // "turnover_symbol": "USDT",
2549
+ // "turnover_usd": 37392218.45999999,
2550
+ // "volume": 1226.3029999999485
2551
+ // }
2552
+ //
2553
+ const timestamp = this.safeIntegerProduct(contract, 'timestamp', 0.001);
2554
+ const marketId = this.safeString(contract, 'symbol');
2555
+ const fundingRateString = this.safeString(contract, 'funding_rate');
2556
+ const fundingRate = Precise["default"].stringDiv(fundingRateString, '100');
2557
+ return {
2558
+ 'info': contract,
2559
+ 'symbol': this.safeSymbol(marketId, market),
2560
+ 'markPrice': this.safeNumber(contract, 'mark_price'),
2561
+ 'indexPrice': this.safeNumber(contract, 'spot_price'),
2562
+ 'interestRate': undefined,
2563
+ 'estimatedSettlePrice': undefined,
2564
+ 'timestamp': timestamp,
2565
+ 'datetime': this.iso8601(timestamp),
2566
+ 'fundingRate': this.parseNumber(fundingRate),
2567
+ 'fundingTimestamp': undefined,
2568
+ 'fundingDatetime': undefined,
2569
+ 'nextFundingRate': undefined,
2570
+ 'nextFundingTimestamp': undefined,
2571
+ 'nextFundingDatetime': undefined,
2572
+ 'previousFundingRate': undefined,
2573
+ 'previousFundingTimestamp': undefined,
2574
+ 'previousFundingDatetime': undefined,
2575
+ };
2576
+ }
2577
+ async addMargin(symbol, amount, params = {}) {
2578
+ /**
2579
+ * @method
2580
+ * @name delta#addMargin
2581
+ * @description add margin
2582
+ * @see https://docs.delta.exchange/#add-remove-position-margin
2583
+ * @param {string} symbol unified market symbol
2584
+ * @param {float} amount amount of margin to add
2585
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2586
+ * @returns {object} a [margin structure]{@link https://docs.ccxt.com/#/?id=add-margin-structure}
2587
+ */
2588
+ return await this.modifyMarginHelper(symbol, amount, 'add', params);
2589
+ }
2590
+ async reduceMargin(symbol, amount, params = {}) {
2591
+ /**
2592
+ * @method
2593
+ * @name delta#reduceMargin
2594
+ * @description remove margin from a position
2595
+ * @see https://docs.delta.exchange/#add-remove-position-margin
2596
+ * @param {string} symbol unified market symbol
2597
+ * @param {float} amount the amount of margin to remove
2598
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2599
+ * @returns {object} a [margin structure]{@link https://docs.ccxt.com/#/?id=reduce-margin-structure}
2600
+ */
2601
+ return await this.modifyMarginHelper(symbol, amount, 'reduce', params);
2602
+ }
2603
+ async modifyMarginHelper(symbol, amount, type, params = {}) {
2604
+ await this.loadMarkets();
2605
+ const market = this.market(symbol);
2606
+ amount = amount.toString();
2607
+ if (type === 'reduce') {
2608
+ amount = Precise["default"].stringMul(amount, '-1');
2609
+ }
2610
+ const request = {
2611
+ 'product_id': market['numericId'],
2612
+ 'delta_margin': amount,
2613
+ };
2614
+ const response = await this.privatePostPositionsChangeMargin(this.extend(request, params));
2615
+ //
2616
+ // {
2617
+ // "result": {
2618
+ // "auto_topup": false,
2619
+ // "bankruptcy_price": "24934.12",
2620
+ // "commission": "0.01197072",
2621
+ // "created_at": "2023-07-20T03:49:09.159401Z",
2622
+ // "entry_price": "29926.8",
2623
+ // "liquidation_price": "25083.754",
2624
+ // "margin": "4.99268",
2625
+ // "margin_mode": "isolated",
2626
+ // "product_id": 84,
2627
+ // "product_symbol": "BTCUSDT",
2628
+ // "realized_cashflow": "0",
2629
+ // "realized_funding": "0",
2630
+ // "realized_pnl": "0",
2631
+ // "size": 1,
2632
+ // "updated_at": "2023-07-20T03:49:09.159401Z",
2633
+ // "user_id": 30084879
2634
+ // },
2635
+ // "success": true
2636
+ // }
2637
+ //
2638
+ const result = this.safeValue(response, 'result', {});
2639
+ return this.parseMarginModification(result, market);
2640
+ }
2641
+ parseMarginModification(data, market = undefined) {
2642
+ //
2643
+ // {
2644
+ // "auto_topup": false,
2645
+ // "bankruptcy_price": "24934.12",
2646
+ // "commission": "0.01197072",
2647
+ // "created_at": "2023-07-20T03:49:09.159401Z",
2648
+ // "entry_price": "29926.8",
2649
+ // "liquidation_price": "25083.754",
2650
+ // "margin": "4.99268",
2651
+ // "margin_mode": "isolated",
2652
+ // "product_id": 84,
2653
+ // "product_symbol": "BTCUSDT",
2654
+ // "realized_cashflow": "0",
2655
+ // "realized_funding": "0",
2656
+ // "realized_pnl": "0",
2657
+ // "size": 1,
2658
+ // "updated_at": "2023-07-20T03:49:09.159401Z",
2659
+ // "user_id": 30084879
2660
+ // }
2661
+ //
2662
+ const marketId = this.safeString(data, 'product_symbol');
2663
+ market = this.safeMarket(marketId, market);
2664
+ return {
2665
+ 'info': data,
2666
+ 'type': undefined,
2667
+ 'amount': undefined,
2668
+ 'total': this.safeNumber(data, 'margin'),
2669
+ 'code': undefined,
2670
+ 'symbol': market['symbol'],
2671
+ 'status': undefined,
2672
+ };
2673
+ }
2674
+ async fetchOpenInterest(symbol, params = {}) {
2675
+ /**
2676
+ * @method
2677
+ * @name delta#fetchOpenInterest
2678
+ * @description retrieves the open interest of a derivative market
2679
+ * @see https://docs.delta.exchange/#get-ticker-for-a-product-by-symbol
2680
+ * @param {string} symbol unified market symbol
2681
+ * @param {object} [params] exchange specific parameters
2682
+ * @returns {object} an open interest structure{@link https://docs.ccxt.com/#/?id=open-interest-structure}
2683
+ */
2684
+ await this.loadMarkets();
2685
+ const market = this.market(symbol);
2686
+ if (!market['contract']) {
2687
+ throw new errors.BadRequest(this.id + ' fetchOpenInterest() supports contract markets only');
2688
+ }
2689
+ const request = {
2690
+ 'symbol': market['id'],
2691
+ };
2692
+ const response = await this.publicGetTickersSymbol(this.extend(request, params));
2693
+ //
2694
+ // {
2695
+ // "result": {
2696
+ // "close": 894.0,
2697
+ // "contract_type": "call_options",
2698
+ // "greeks": {
2699
+ // "delta": "0.67324861",
2700
+ // "gamma": "0.00022178",
2701
+ // "rho": "4.34638266",
2702
+ // "spot": "30178.53195697",
2703
+ // "theta": "-35.64972577",
2704
+ // "vega": "16.34381277"
2705
+ // },
2706
+ // "high": 946.0,
2707
+ // "low": 893.0,
2708
+ // "mark_price": "1037.07582681",
2709
+ // "mark_vol": "0.35899491",
2710
+ // "oi": "0.0910",
2711
+ // "oi_change_usd_6h": "-90.5500",
2712
+ // "oi_contracts": "91",
2713
+ // "oi_value": "0.0910",
2714
+ // "oi_value_symbol": "BTC",
2715
+ // "oi_value_usd": "2746.3549",
2716
+ // "open": 946.0,
2717
+ // "price_band": {
2718
+ // "lower_limit": "133.37794509",
2719
+ // "upper_limit": "5663.66930164"
2720
+ // },
2721
+ // "product_id": 116171,
2722
+ // "quotes": {
2723
+ // "ask_iv": "0.36932389",
2724
+ // "ask_size": "1321",
2725
+ // "best_ask": "1054",
2726
+ // "best_bid": "1020",
2727
+ // "bid_iv": "0.34851914",
2728
+ // "bid_size": "2202",
2729
+ // "impact_mid_price": null,
2730
+ // "mark_iv": "0.35896335"
2731
+ // },
2732
+ // "size": 152,
2733
+ // "spot_price": "30178.53195697",
2734
+ // "strike_price": "29500",
2735
+ // "symbol": "C-BTC-29500-280723",
2736
+ // "timestamp": 1689834695286094,
2737
+ // "turnover": 4546.601744940001,
2738
+ // "turnover_symbol": "USDT",
2739
+ // "turnover_usd": 4546.601744940001,
2740
+ // "volume": 0.15200000000000002
2741
+ // },
2742
+ // "success": true
2743
+ // }
2744
+ //
2745
+ const result = this.safeValue(response, 'result', {});
2746
+ return this.parseOpenInterest(result, market);
2747
+ }
2748
+ parseOpenInterest(interest, market = undefined) {
2749
+ //
2750
+ // {
2751
+ // "close": 894.0,
2752
+ // "contract_type": "call_options",
2753
+ // "greeks": {
2754
+ // "delta": "0.67324861",
2755
+ // "gamma": "0.00022178",
2756
+ // "rho": "4.34638266",
2757
+ // "spot": "30178.53195697",
2758
+ // "theta": "-35.64972577",
2759
+ // "vega": "16.34381277"
2760
+ // },
2761
+ // "high": 946.0,
2762
+ // "low": 893.0,
2763
+ // "mark_price": "1037.07582681",
2764
+ // "mark_vol": "0.35899491",
2765
+ // "oi": "0.0910",
2766
+ // "oi_change_usd_6h": "-90.5500",
2767
+ // "oi_contracts": "91",
2768
+ // "oi_value": "0.0910",
2769
+ // "oi_value_symbol": "BTC",
2770
+ // "oi_value_usd": "2746.3549",
2771
+ // "open": 946.0,
2772
+ // "price_band": {
2773
+ // "lower_limit": "133.37794509",
2774
+ // "upper_limit": "5663.66930164"
2775
+ // },
2776
+ // "product_id": 116171,
2777
+ // "quotes": {
2778
+ // "ask_iv": "0.36932389",
2779
+ // "ask_size": "1321",
2780
+ // "best_ask": "1054",
2781
+ // "best_bid": "1020",
2782
+ // "bid_iv": "0.34851914",
2783
+ // "bid_size": "2202",
2784
+ // "impact_mid_price": null,
2785
+ // "mark_iv": "0.35896335"
2786
+ // },
2787
+ // "size": 152,
2788
+ // "spot_price": "30178.53195697",
2789
+ // "strike_price": "29500",
2790
+ // "symbol": "C-BTC-29500-280723",
2791
+ // "timestamp": 1689834695286094,
2792
+ // "turnover": 4546.601744940001,
2793
+ // "turnover_symbol": "USDT",
2794
+ // "turnover_usd": 4546.601744940001,
2795
+ // "volume": 0.15200000000000002
2796
+ // }
2797
+ //
2798
+ const timestamp = this.safeIntegerProduct(interest, 'timestamp', 0.001);
2799
+ const marketId = this.safeString(interest, 'symbol');
2800
+ return this.safeOpenInterest({
2801
+ 'symbol': this.safeSymbol(marketId, market),
2802
+ 'baseVolume': this.safeNumber(interest, 'oi_value'),
2803
+ 'quoteVolume': this.safeNumber(interest, 'oi_value_usd'),
2804
+ 'openInterestAmount': this.safeNumber(interest, 'oi_contracts'),
2805
+ 'openInterestValue': this.safeNumber(interest, 'oi'),
2806
+ 'timestamp': timestamp,
2807
+ 'datetime': this.iso8601(timestamp),
2808
+ 'info': interest,
2809
+ }, market);
2810
+ }
2811
+ async fetchLeverage(symbol, params = {}) {
2812
+ /**
2813
+ * @method
2814
+ * @name delta#fetchLeverage
2815
+ * @description fetch the set leverage for a market
2816
+ * @see https://docs.delta.exchange/#get-order-leverage
2817
+ * @param {string} symbol unified market symbol
2818
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2819
+ * @returns {object} a [leverage structure]{@link https://docs.ccxt.com/#/?id=leverage-structure}
2820
+ */
2821
+ await this.loadMarkets();
2822
+ const market = this.market(symbol);
2823
+ const request = {
2824
+ 'product_id': market['numericId'],
2825
+ };
2826
+ //
2827
+ // {
2828
+ // "result": {
2829
+ // "index_symbol": null,
2830
+ // "leverage": "10",
2831
+ // "margin_mode": "isolated",
2832
+ // "order_margin": "0",
2833
+ // "product_id": 84,
2834
+ // "user_id": 30084879
2835
+ // },
2836
+ // "success": true
2837
+ // }
2838
+ //
2839
+ return await this.privateGetProductsProductIdOrdersLeverage(this.extend(request, params));
2840
+ }
2841
+ async setLeverage(leverage, symbol = undefined, params = {}) {
2842
+ /**
2843
+ * @method
2844
+ * @name delta#setLeverage
2845
+ * @description set the level of leverage for a market
2846
+ * @see https://docs.delta.exchange/#change-order-leverage
2847
+ * @param {float} leverage the rate of leverage
2848
+ * @param {string} symbol unified market symbol
2849
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2850
+ * @returns {object} response from the exchange
2851
+ */
2852
+ if (symbol === undefined) {
2853
+ throw new errors.ArgumentsRequired(this.id + ' setLeverage() requires a symbol argument');
2854
+ }
2855
+ await this.loadMarkets();
2856
+ const market = this.market(symbol);
2857
+ const request = {
2858
+ 'product_id': market['numericId'],
2859
+ 'leverage': leverage,
2860
+ };
2861
+ //
2862
+ // {
2863
+ // "result": {
2864
+ // "leverage": "20",
2865
+ // "margin_mode": "isolated",
2866
+ // "order_margin": "0",
2867
+ // "product_id": 84
2868
+ // },
2869
+ // "success": true
2870
+ // }
2871
+ //
2872
+ return await this.privatePostProductsProductIdOrdersLeverage(this.extend(request, params));
2873
+ }
2874
+ async fetchSettlementHistory(symbol = undefined, since = undefined, limit = undefined, params = {}) {
2875
+ /**
2876
+ * @method
2877
+ * @name delta#fetchSettlementHistory
2878
+ * @description fetches historical settlement records
2879
+ * @see https://docs.delta.exchange/#get-product-settlement-prices
2880
+ * @param {string} symbol unified market symbol of the settlement history
2881
+ * @param {int} [since] timestamp in ms
2882
+ * @param {int} [limit] number of records
2883
+ * @param {object} [params] exchange specific params
2884
+ * @returns {object[]} a list of [settlement history objects]{@link https://docs.ccxt.com/#/?id=settlement-history-structure}
2885
+ */
2886
+ await this.loadMarkets();
2887
+ let market = undefined;
2888
+ if (symbol !== undefined) {
2889
+ market = this.market(symbol);
2890
+ }
2891
+ const request = {
2892
+ 'states': 'expired',
2893
+ };
2894
+ if (limit !== undefined) {
2895
+ request['page_size'] = limit;
2896
+ }
2897
+ const response = await this.publicGetProducts(this.extend(request, params));
2898
+ //
2899
+ // {
2900
+ // "result": [
2901
+ // {
2902
+ // "contract_value": "0.001",
2903
+ // "basis_factor_max_limit": "10.95",
2904
+ // "maker_commission_rate": "0.0003",
2905
+ // "launch_time": "2023-07-19T04:30:03Z",
2906
+ // "trading_status": "operational",
2907
+ // "product_specs": {
2908
+ // "backup_vol_expiry_time": 31536000,
2909
+ // "max_deviation_from_external_vol": 0.75,
2910
+ // "max_lower_deviation_from_external_vol": 0.75,
2911
+ // "max_upper_deviation_from_external_vol": 0.5,
2912
+ // "max_volatility": 3,
2913
+ // "min_volatility": 0.1,
2914
+ // "premium_commission_rate": 0.1,
2915
+ // "settlement_index_price": "29993.536675710806",
2916
+ // "vol_calculation_method": "orderbook",
2917
+ // "vol_expiry_time": 31536000
2918
+ // },
2919
+ // "description": "BTC call option expiring on 19-7-2023",
2920
+ // "settlement_price": "0",
2921
+ // "disruption_reason": null,
2922
+ // "settling_asset": {},
2923
+ // "initial_margin": "1",
2924
+ // "tick_size": "0.1",
2925
+ // "maintenance_margin": "0.5",
2926
+ // "id": 117542,
2927
+ // "notional_type": "vanilla",
2928
+ // "ui_config": {},
2929
+ // "contract_unit_currency": "BTC",
2930
+ // "symbol": "C-BTC-30900-190723",
2931
+ // "insurance_fund_margin_contribution": "1",
2932
+ // "price_band": "2",
2933
+ // "annualized_funding": "10.95",
2934
+ // "impact_size": 200,
2935
+ // "contract_type": "call_options",
2936
+ // "position_size_limit": 255633,
2937
+ // "max_leverage_notional": "200000",
2938
+ // "initial_margin_scaling_factor": "0.000002",
2939
+ // "strike_price": "30900",
2940
+ // "is_quanto": false,
2941
+ // "settlement_time": "2023-07-19T12:00:00Z",
2942
+ // "liquidation_penalty_factor": "0.5",
2943
+ // "funding_method": "mark_price",
2944
+ // "taker_commission_rate": "0.0003",
2945
+ // "default_leverage": "100.000000000000000000",
2946
+ // "state": "expired",
2947
+ // "auction_start_time": null,
2948
+ // "short_description": "BTC Call",
2949
+ // "quoting_asset": {},
2950
+ // "maintenance_margin_scaling_factor":"0.000002"
2951
+ // }
2952
+ // ],
2953
+ // "success": true
2954
+ // }
2955
+ //
2956
+ const result = this.safeValue(response, 'result', []);
2957
+ const settlements = this.parseSettlements(result, market);
2958
+ const sorted = this.sortBy(settlements, 'timestamp');
2959
+ return this.filterBySymbolSinceLimit(sorted, market['symbol'], since, limit);
2960
+ }
2961
+ parseSettlement(settlement, market) {
2962
+ //
2963
+ // {
2964
+ // "contract_value": "0.001",
2965
+ // "basis_factor_max_limit": "10.95",
2966
+ // "maker_commission_rate": "0.0003",
2967
+ // "launch_time": "2023-07-19T04:30:03Z",
2968
+ // "trading_status": "operational",
2969
+ // "product_specs": {
2970
+ // "backup_vol_expiry_time": 31536000,
2971
+ // "max_deviation_from_external_vol": 0.75,
2972
+ // "max_lower_deviation_from_external_vol": 0.75,
2973
+ // "max_upper_deviation_from_external_vol": 0.5,
2974
+ // "max_volatility": 3,
2975
+ // "min_volatility": 0.1,
2976
+ // "premium_commission_rate": 0.1,
2977
+ // "settlement_index_price": "29993.536675710806",
2978
+ // "vol_calculation_method": "orderbook",
2979
+ // "vol_expiry_time": 31536000
2980
+ // },
2981
+ // "description": "BTC call option expiring on 19-7-2023",
2982
+ // "settlement_price": "0",
2983
+ // "disruption_reason": null,
2984
+ // "settling_asset": {},
2985
+ // "initial_margin": "1",
2986
+ // "tick_size": "0.1",
2987
+ // "maintenance_margin": "0.5",
2988
+ // "id": 117542,
2989
+ // "notional_type": "vanilla",
2990
+ // "ui_config": {},
2991
+ // "contract_unit_currency": "BTC",
2992
+ // "symbol": "C-BTC-30900-190723",
2993
+ // "insurance_fund_margin_contribution": "1",
2994
+ // "price_band": "2",
2995
+ // "annualized_funding": "10.95",
2996
+ // "impact_size": 200,
2997
+ // "contract_type": "call_options",
2998
+ // "position_size_limit": 255633,
2999
+ // "max_leverage_notional": "200000",
3000
+ // "initial_margin_scaling_factor": "0.000002",
3001
+ // "strike_price": "30900",
3002
+ // "is_quanto": false,
3003
+ // "settlement_time": "2023-07-19T12:00:00Z",
3004
+ // "liquidation_penalty_factor": "0.5",
3005
+ // "funding_method": "mark_price",
3006
+ // "taker_commission_rate": "0.0003",
3007
+ // "default_leverage": "100.000000000000000000",
3008
+ // "state": "expired",
3009
+ // "auction_start_time": null,
3010
+ // "short_description": "BTC Call",
3011
+ // "quoting_asset": {},
3012
+ // "maintenance_margin_scaling_factor":"0.000002"
3013
+ // }
3014
+ //
3015
+ const datetime = this.safeString(settlement, 'settlement_time');
3016
+ const marketId = this.safeString(settlement, 'symbol');
3017
+ return {
3018
+ 'info': settlement,
3019
+ 'symbol': this.safeSymbol(marketId, market),
3020
+ 'price': this.safeNumber(settlement, 'settlement_price'),
3021
+ 'timestamp': this.parse8601(datetime),
3022
+ 'datetime': datetime,
3023
+ };
3024
+ }
3025
+ parseSettlements(settlements, market) {
3026
+ const result = [];
3027
+ for (let i = 0; i < settlements.length; i++) {
3028
+ result.push(this.parseSettlement(settlements[i], market));
3029
+ }
3030
+ return result;
3031
+ }
3032
+ async fetchGreeks(symbol, params = {}) {
3033
+ /**
3034
+ * @method
3035
+ * @name delta#fetchGreeks
3036
+ * @description fetches an option contracts greeks, financial metrics used to measure the factors that affect the price of an options contract
3037
+ * @see https://docs.delta.exchange/#get-ticker-for-a-product-by-symbol
3038
+ * @param {string} symbol unified symbol of the market to fetch greeks for
3039
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
3040
+ * @returns {object} a [greeks structure]{@link https://docs.ccxt.com/#/?id=greeks-structure}
3041
+ */
3042
+ await this.loadMarkets();
3043
+ const market = this.market(symbol);
3044
+ const request = {
3045
+ 'symbol': market['id'],
3046
+ };
3047
+ const response = await this.publicGetTickersSymbol(this.extend(request, params));
3048
+ //
3049
+ // {
3050
+ // "result": {
3051
+ // "close": 6793.0,
3052
+ // "contract_type": "call_options",
3053
+ // "greeks": {
3054
+ // "delta": "0.94739174",
3055
+ // "gamma": "0.00002206",
3056
+ // "rho": "11.00890725",
3057
+ // "spot": "36839.58124652",
3058
+ // "theta": "-18.18365310",
3059
+ // "vega": "7.85209698"
3060
+ // },
3061
+ // "high": 7556.0,
3062
+ // "low": 6793.0,
3063
+ // "mark_price": "6955.70698909",
3064
+ // "mark_vol": "0.66916863",
3065
+ // "oi": "1.8980",
3066
+ // "oi_change_usd_6h": "110.4600",
3067
+ // "oi_contracts": "1898",
3068
+ // "oi_value": "1.8980",
3069
+ // "oi_value_symbol": "BTC",
3070
+ // "oi_value_usd": "69940.7319",
3071
+ // "open": 7.2e3,
3072
+ // "price_band": {
3073
+ // "lower_limit": "5533.89814767",
3074
+ // "upper_limit": "11691.37688371"
3075
+ // },
3076
+ // "product_id": 129508,
3077
+ // "quotes": {
3078
+ // "ask_iv": "0.90180438",
3079
+ // "ask_size": "1898",
3080
+ // "best_ask": "7210",
3081
+ // "best_bid": "6913",
3082
+ // "bid_iv": "0.60881706",
3083
+ // "bid_size": "3163",
3084
+ // "impact_mid_price": null,
3085
+ // "mark_iv": "0.66973549"
3086
+ // },
3087
+ // "size": 5,
3088
+ // "spot_price": "36839.58153868",
3089
+ // "strike_price": "30000",
3090
+ // "symbol": "C-BTC-30000-241123",
3091
+ // "timestamp": 1699584998504530,
3092
+ // "turnover": 184.41206804,
3093
+ // "turnover_symbol": "USDT",
3094
+ // "turnover_usd": 184.41206804,
3095
+ // "volume": 0.005
3096
+ // },
3097
+ // "success": true
3098
+ // }
3099
+ //
3100
+ const result = this.safeValue(response, 'result', {});
3101
+ return this.parseGreeks(result, market);
3102
+ }
3103
+ parseGreeks(greeks, market = undefined) {
3104
+ //
3105
+ // {
3106
+ // "close": 6793.0,
3107
+ // "contract_type": "call_options",
3108
+ // "greeks": {
3109
+ // "delta": "0.94739174",
3110
+ // "gamma": "0.00002206",
3111
+ // "rho": "11.00890725",
3112
+ // "spot": "36839.58124652",
3113
+ // "theta": "-18.18365310",
3114
+ // "vega": "7.85209698"
3115
+ // },
3116
+ // "high": 7556.0,
3117
+ // "low": 6793.0,
3118
+ // "mark_price": "6955.70698909",
3119
+ // "mark_vol": "0.66916863",
3120
+ // "oi": "1.8980",
3121
+ // "oi_change_usd_6h": "110.4600",
3122
+ // "oi_contracts": "1898",
3123
+ // "oi_value": "1.8980",
3124
+ // "oi_value_symbol": "BTC",
3125
+ // "oi_value_usd": "69940.7319",
3126
+ // "open": 7.2e3,
3127
+ // "price_band": {
3128
+ // "lower_limit": "5533.89814767",
3129
+ // "upper_limit": "11691.37688371"
3130
+ // },
3131
+ // "product_id": 129508,
3132
+ // "quotes": {
3133
+ // "ask_iv": "0.90180438",
3134
+ // "ask_size": "1898",
3135
+ // "best_ask": "7210",
3136
+ // "best_bid": "6913",
3137
+ // "bid_iv": "0.60881706",
3138
+ // "bid_size": "3163",
3139
+ // "impact_mid_price": null,
3140
+ // "mark_iv": "0.66973549"
3141
+ // },
3142
+ // "size": 5,
3143
+ // "spot_price": "36839.58153868",
3144
+ // "strike_price": "30000",
3145
+ // "symbol": "C-BTC-30000-241123",
3146
+ // "timestamp": 1699584998504530,
3147
+ // "turnover": 184.41206804,
3148
+ // "turnover_symbol": "USDT",
3149
+ // "turnover_usd": 184.41206804,
3150
+ // "volume": 0.005
3151
+ // }
3152
+ //
3153
+ const timestamp = this.safeIntegerProduct(greeks, 'timestamp', 0.001);
3154
+ const marketId = this.safeString(greeks, 'symbol');
3155
+ const symbol = this.safeSymbol(marketId, market);
3156
+ const stats = this.safeValue(greeks, 'greeks', {});
3157
+ const quotes = this.safeValue(greeks, 'quotes', {});
3158
+ return {
3159
+ 'symbol': symbol,
3160
+ 'timestamp': timestamp,
3161
+ 'datetime': this.iso8601(timestamp),
3162
+ 'delta': this.safeNumber(stats, 'delta'),
3163
+ 'gamma': this.safeNumber(stats, 'gamma'),
3164
+ 'theta': this.safeNumber(stats, 'theta'),
3165
+ 'vega': this.safeNumber(stats, 'vega'),
3166
+ 'rho': this.safeNumber(stats, 'rho'),
3167
+ 'bidSize': this.safeNumber(quotes, 'bid_size'),
3168
+ 'askSize': this.safeNumber(quotes, 'ask_size'),
3169
+ 'bidImpliedVolatility': this.safeNumber(quotes, 'bid_iv'),
3170
+ 'askImpliedVolatility': this.safeNumber(quotes, 'ask_iv'),
3171
+ 'markImpliedVolatility': this.safeNumber(quotes, 'mark_iv'),
3172
+ 'bidPrice': this.safeNumber(quotes, 'best_bid'),
3173
+ 'askPrice': this.safeNumber(quotes, 'best_ask'),
3174
+ 'markPrice': this.safeNumber(greeks, 'mark_price'),
3175
+ 'lastPrice': undefined,
3176
+ 'underlyingPrice': this.safeNumber(greeks, 'spot_price'),
3177
+ 'info': greeks,
3178
+ };
3179
+ }
3180
+ async closeAllPositions(params = {}) {
3181
+ /**
3182
+ * @method
3183
+ * @name delta#closeAllPositions
3184
+ * @description closes all open positions for a market type
3185
+ * @see https://docs.delta.exchange/#close-all-positions
3186
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
3187
+ * @param {int} [params.user_id] the users id
3188
+ * @returns {object[]} A list of [position structures]{@link https://docs.ccxt.com/#/?id=position-structure}
3189
+ */
3190
+ await this.loadMarkets();
3191
+ const request = {
3192
+ 'close_all_portfolio': true,
3193
+ 'close_all_isolated': true,
3194
+ // 'user_id': 12345,
3195
+ };
3196
+ const response = await this.privatePostPositionsCloseAll(this.extend(request, params));
3197
+ //
3198
+ // {"result":{},"success":true}
3199
+ //
3200
+ const position = this.parsePosition(this.safeValue(response, 'result', {}));
3201
+ return [position];
3202
+ }
3203
+ sign(path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
3204
+ const requestPath = '/' + this.version + '/' + this.implodeParams(path, params);
3205
+ let url = this.urls['api'][api] + requestPath;
3206
+ const query = this.omit(params, this.extractParams(path));
3207
+ if (api === 'public') {
3208
+ if (Object.keys(query).length) {
3209
+ url += '?' + this.urlencode(query);
3210
+ }
3211
+ }
3212
+ else if (api === 'private') {
3213
+ this.checkRequiredCredentials();
3214
+ const timestamp = this.seconds().toString();
3215
+ headers = {
3216
+ 'api-key': this.apiKey,
3217
+ 'timestamp': timestamp,
3218
+ };
3219
+ let auth = method + timestamp + requestPath;
3220
+ if ((method === 'GET') || (method === 'DELETE')) {
3221
+ if (Object.keys(query).length) {
3222
+ const queryString = '?' + this.urlencode(query);
3223
+ auth += queryString;
3224
+ url += queryString;
3225
+ }
3226
+ }
3227
+ else {
3228
+ body = this.json(query);
3229
+ auth += body;
3230
+ headers['Content-Type'] = 'application/json';
3231
+ }
3232
+ const signature = this.hmac(this.encode(auth), this.encode(this.secret), sha256.sha256);
3233
+ headers['signature'] = signature;
3234
+ }
3235
+ return { 'url': url, 'method': method, 'body': body, 'headers': headers };
3236
+ }
3237
+ handleErrors(code, reason, url, method, headers, body, response, requestHeaders, requestBody) {
3238
+ if (response === undefined) {
3239
+ return undefined;
3240
+ }
3241
+ //
3242
+ // {"error":{"code":"insufficient_margin","context":{"available_balance":"0.000000000000000000","required_additional_balance":"1.618626000000000000000000000"}},"success":false}
3243
+ //
3244
+ const error = this.safeValue(response, 'error', {});
3245
+ const errorCode = this.safeString(error, 'code');
3246
+ if (errorCode !== undefined) {
3247
+ const feedback = this.id + ' ' + body;
3248
+ this.throwExactlyMatchedException(this.exceptions['exact'], errorCode, feedback);
3249
+ this.throwBroadlyMatchedException(this.exceptions['broad'], errorCode, feedback);
3250
+ throw new errors.ExchangeError(feedback); // unknown message
3251
+ }
3252
+ return undefined;
3253
+ }
3254
+ }
3255
+
3256
+ module.exports = delta;