ccxt 4.5.55 → 4.5.57

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 (321) hide show
  1. package/README.md +215 -10
  2. package/dist/ccxt.browser.min.js +10 -10
  3. package/dist/cjs/ccxt.js +6 -11
  4. package/dist/cjs/src/aftermath.js +10 -5
  5. package/dist/cjs/src/alpaca.js +2 -2
  6. package/dist/cjs/src/apex.js +26 -17
  7. package/dist/cjs/src/arkham.js +10 -7
  8. package/dist/cjs/src/ascendex.js +8 -5
  9. package/dist/cjs/src/aster.js +7 -4
  10. package/dist/cjs/src/backpack.js +4 -4
  11. package/dist/cjs/src/base/Exchange.js +72 -35
  12. package/dist/cjs/src/base/functions/io.js +25 -0
  13. package/dist/cjs/src/base/functions.js +1 -0
  14. package/dist/cjs/src/bigone.js +10 -7
  15. package/dist/cjs/src/binance.js +196 -198
  16. package/dist/cjs/src/bingx.js +7 -7
  17. package/dist/cjs/src/bitfinex.js +71 -58
  18. package/dist/cjs/src/bitflyer.js +2 -1
  19. package/dist/cjs/src/bitget.js +16 -5
  20. package/dist/cjs/src/bitmart.js +18 -10
  21. package/dist/cjs/src/bitmex.js +8 -5
  22. package/dist/cjs/src/bitopro.js +2 -2
  23. package/dist/cjs/src/bitrue.js +4 -3
  24. package/dist/cjs/src/bitso.js +7 -4
  25. package/dist/cjs/src/bitstamp.js +7 -4
  26. package/dist/cjs/src/bitteam.js +1 -1
  27. package/dist/cjs/src/bittrade.js +2 -2
  28. package/dist/cjs/src/bitvavo.js +457 -34
  29. package/dist/cjs/src/blofin.js +28 -4
  30. package/dist/cjs/src/bullish.js +6 -5
  31. package/dist/cjs/src/bybit.js +19 -17
  32. package/dist/cjs/src/bybiteu.js +1 -0
  33. package/dist/cjs/src/bydfi.js +1 -1
  34. package/dist/cjs/src/cex.js +3 -3
  35. package/dist/cjs/src/coinbase.js +75 -65
  36. package/dist/cjs/src/coinbaseexchange.js +4 -3
  37. package/dist/cjs/src/coinbaseinternational.js +17 -10
  38. package/dist/cjs/src/coinex.js +79 -77
  39. package/dist/cjs/src/coinmetro.js +1 -1
  40. package/dist/cjs/src/coinsph.js +5 -5
  41. package/dist/cjs/src/cryptocom.js +52 -54
  42. package/dist/cjs/src/cryptomus.js +43 -39
  43. package/dist/cjs/src/deepcoin.js +9 -5
  44. package/dist/cjs/src/delta.js +53 -53
  45. package/dist/cjs/src/deribit.js +35 -35
  46. package/dist/cjs/src/derive.js +31 -31
  47. package/dist/cjs/src/digifinex.js +45 -45
  48. package/dist/cjs/src/exmo.js +104 -122
  49. package/dist/cjs/src/extended.js +3497 -0
  50. package/dist/cjs/src/foxbit.js +72 -76
  51. package/dist/cjs/src/gate.js +53 -53
  52. package/dist/cjs/src/gemini.js +45 -45
  53. package/dist/cjs/src/grvt.js +17 -11
  54. package/dist/cjs/src/hashkey.js +56 -58
  55. package/dist/cjs/src/hibachi.js +1 -1
  56. package/dist/cjs/src/hitbtc.js +5 -14
  57. package/dist/cjs/src/hollaex.js +51 -54
  58. package/dist/cjs/src/htx.js +84 -72
  59. package/dist/cjs/src/hyperliquid.js +60 -55
  60. package/dist/cjs/src/indodax.js +4 -3
  61. package/dist/cjs/src/kraken.js +71 -71
  62. package/dist/cjs/src/krakenfutures.js +2 -1
  63. package/dist/cjs/src/kucoin.js +3 -2
  64. package/dist/cjs/src/latoken.js +30 -32
  65. package/dist/cjs/src/lbank.js +64 -60
  66. package/dist/cjs/src/lighter.js +36 -38
  67. package/dist/cjs/src/luno.js +36 -44
  68. package/dist/cjs/src/mercado.js +2 -1
  69. package/dist/cjs/src/mexc.js +72 -63
  70. package/dist/cjs/src/modetrade.js +51 -53
  71. package/dist/cjs/src/ndax.js +35 -37
  72. package/dist/cjs/src/okx.js +23 -5
  73. package/dist/cjs/src/onetrading.js +21 -23
  74. package/dist/cjs/src/p2b.js +8 -4
  75. package/dist/cjs/src/paradex.js +3 -2
  76. package/dist/cjs/src/phemex.js +47 -47
  77. package/dist/cjs/src/poloniex.js +19 -13
  78. package/dist/cjs/src/pro/alpaca.js +1 -1
  79. package/dist/cjs/src/pro/apex.js +11 -2
  80. package/dist/cjs/src/pro/arkham.js +1 -1
  81. package/dist/cjs/src/pro/aster.js +10 -9
  82. package/dist/cjs/src/pro/backpack.js +1 -1
  83. package/dist/cjs/src/pro/binance.js +6 -6
  84. package/dist/cjs/src/pro/bingx.js +7 -2
  85. package/dist/cjs/src/pro/bitget.js +1 -1
  86. package/dist/cjs/src/pro/bithumb.js +1 -1
  87. package/dist/cjs/src/pro/bitmart.js +10 -0
  88. package/dist/cjs/src/pro/bitmex.js +1 -1
  89. package/dist/cjs/src/pro/bitstamp.js +1 -1
  90. package/dist/cjs/src/pro/blockchaincom.js +1 -1
  91. package/dist/cjs/src/pro/bybit.js +1 -1
  92. package/dist/cjs/src/pro/cex.js +1 -1
  93. package/dist/cjs/src/pro/coinex.js +1 -1
  94. package/dist/cjs/src/pro/coinone.js +1 -1
  95. package/dist/cjs/src/pro/cryptocom.js +3 -1
  96. package/dist/cjs/src/pro/dydx.js +1 -1
  97. package/dist/cjs/src/pro/exmo.js +1 -1
  98. package/dist/cjs/src/pro/extended.js +865 -0
  99. package/dist/cjs/src/pro/gate.js +1 -1
  100. package/dist/cjs/src/pro/grvt.js +8 -0
  101. package/dist/cjs/src/pro/htx.js +4 -4
  102. package/dist/cjs/src/pro/independentreserve.js +1 -1
  103. package/dist/cjs/src/pro/krakenfutures.js +16 -4
  104. package/dist/cjs/src/pro/kucoin.js +1 -1
  105. package/dist/cjs/src/pro/luno.js +3 -3
  106. package/dist/cjs/src/pro/modetrade.js +3 -3
  107. package/dist/cjs/src/pro/okx.js +4 -4
  108. package/dist/cjs/src/pro/onetrading.js +1 -1
  109. package/dist/cjs/src/pro/toobit.js +1 -1
  110. package/dist/cjs/src/pro/weex.js +1 -1
  111. package/dist/cjs/src/pro/woo.js +4 -4
  112. package/dist/cjs/src/pro/woofipro.js +3 -3
  113. package/dist/cjs/src/pro/xt.js +1 -1
  114. package/dist/cjs/src/static_dependencies/starknet/utils/hash/classHash.js +7 -7
  115. package/dist/cjs/src/tokocrypto.js +1 -1
  116. package/dist/cjs/src/toobit.js +3 -3
  117. package/dist/cjs/src/upbit.js +3 -3
  118. package/dist/cjs/src/weex.js +57 -62
  119. package/dist/cjs/src/whitebit.js +61 -63
  120. package/dist/cjs/src/woo.js +66 -55
  121. package/dist/cjs/src/woofipro.js +54 -48
  122. package/dist/cjs/src/xt.js +3 -2
  123. package/dist/cjs/src/yobit.js +4 -2
  124. package/dist/cjs/src/zebpay.js +73 -75
  125. package/js/ccxt.d.ts +8 -14
  126. package/js/ccxt.js +6 -10
  127. package/js/src/abstract/bitvavo.d.ts +15 -7
  128. package/js/src/abstract/extended.d.ts +58 -0
  129. package/js/src/abstract/mexc.d.ts +1 -0
  130. package/js/src/aftermath.js +10 -5
  131. package/js/src/alpaca.js +2 -2
  132. package/js/src/apex.d.ts +1 -1
  133. package/js/src/apex.js +26 -17
  134. package/js/src/arkham.js +10 -7
  135. package/js/src/ascendex.js +8 -5
  136. package/js/src/aster.js +7 -4
  137. package/js/src/backpack.js +4 -4
  138. package/js/src/base/Exchange.d.ts +10 -6
  139. package/js/src/base/Exchange.js +72 -35
  140. package/js/src/base/functions/io.d.ts +7 -0
  141. package/js/src/base/functions/io.js +24 -0
  142. package/js/src/bigone.js +10 -7
  143. package/js/src/binance.d.ts +2 -0
  144. package/js/src/binance.js +200 -202
  145. package/js/src/bingx.js +7 -7
  146. package/js/src/bitfinex.d.ts +2 -0
  147. package/js/src/bitfinex.js +71 -58
  148. package/js/src/bitflyer.js +2 -1
  149. package/js/src/bitget.js +16 -5
  150. package/js/src/bitmart.js +18 -10
  151. package/js/src/bitmex.js +8 -5
  152. package/js/src/bitopro.js +2 -2
  153. package/js/src/bitrue.js +4 -3
  154. package/js/src/bitso.js +7 -4
  155. package/js/src/bitstamp.js +7 -4
  156. package/js/src/bitteam.js +1 -1
  157. package/js/src/bittrade.js +2 -2
  158. package/js/src/bitvavo.d.ts +114 -21
  159. package/js/src/bitvavo.js +457 -34
  160. package/js/src/blofin.d.ts +1 -0
  161. package/js/src/blofin.js +28 -4
  162. package/js/src/bullish.js +6 -5
  163. package/js/src/bybit.d.ts +1 -1
  164. package/js/src/bybit.js +19 -17
  165. package/js/src/bybiteu.js +1 -0
  166. package/js/src/bydfi.js +1 -1
  167. package/js/src/cex.js +3 -3
  168. package/js/src/coinbase.d.ts +63 -56
  169. package/js/src/coinbase.js +75 -65
  170. package/js/src/coinbaseexchange.js +4 -3
  171. package/js/src/coinbaseinternational.d.ts +1 -1
  172. package/js/src/coinbaseinternational.js +17 -10
  173. package/js/src/coinex.d.ts +2 -1
  174. package/js/src/coinex.js +79 -77
  175. package/js/src/coinmetro.d.ts +1 -1
  176. package/js/src/coinmetro.js +1 -1
  177. package/js/src/coinsph.js +5 -5
  178. package/js/src/cryptocom.d.ts +1 -0
  179. package/js/src/cryptocom.js +52 -54
  180. package/js/src/cryptomus.d.ts +2 -1
  181. package/js/src/cryptomus.js +43 -39
  182. package/js/src/deepcoin.js +9 -5
  183. package/js/src/delta.d.ts +1 -0
  184. package/js/src/delta.js +53 -53
  185. package/js/src/deribit.d.ts +1 -0
  186. package/js/src/deribit.js +35 -35
  187. package/js/src/derive.d.ts +1 -0
  188. package/js/src/derive.js +31 -31
  189. package/js/src/digifinex.d.ts +1 -0
  190. package/js/src/digifinex.js +45 -45
  191. package/js/src/exmo.d.ts +1 -0
  192. package/js/src/exmo.js +104 -122
  193. package/js/src/extended.d.ts +554 -0
  194. package/js/src/extended.js +3490 -0
  195. package/js/src/foxbit.d.ts +1 -0
  196. package/js/src/foxbit.js +72 -76
  197. package/js/src/gate.d.ts +1 -0
  198. package/js/src/gate.js +53 -53
  199. package/js/src/gemini.d.ts +2 -1
  200. package/js/src/gemini.js +45 -45
  201. package/js/src/grvt.d.ts +1 -1
  202. package/js/src/grvt.js +17 -11
  203. package/js/src/hashkey.d.ts +1 -0
  204. package/js/src/hashkey.js +56 -58
  205. package/js/src/hibachi.d.ts +1 -1
  206. package/js/src/hibachi.js +1 -1
  207. package/js/src/hitbtc.d.ts +0 -1
  208. package/js/src/hitbtc.js +5 -14
  209. package/js/src/hollaex.d.ts +1 -0
  210. package/js/src/hollaex.js +51 -54
  211. package/js/src/htx.d.ts +1 -0
  212. package/js/src/htx.js +84 -72
  213. package/js/src/hyperliquid.d.ts +5 -4
  214. package/js/src/hyperliquid.js +60 -55
  215. package/js/src/indodax.js +4 -3
  216. package/js/src/kraken.d.ts +2 -1
  217. package/js/src/kraken.js +71 -71
  218. package/js/src/krakenfutures.js +2 -1
  219. package/js/src/kucoin.js +3 -2
  220. package/js/src/latoken.d.ts +1 -0
  221. package/js/src/latoken.js +30 -32
  222. package/js/src/lbank.d.ts +1 -0
  223. package/js/src/lbank.js +64 -60
  224. package/js/src/lighter.d.ts +2 -1
  225. package/js/src/lighter.js +36 -38
  226. package/js/src/luno.d.ts +1 -0
  227. package/js/src/luno.js +36 -44
  228. package/js/src/mercado.js +2 -1
  229. package/js/src/mexc.d.ts +4 -3
  230. package/js/src/mexc.js +72 -63
  231. package/js/src/modetrade.d.ts +1 -0
  232. package/js/src/modetrade.js +51 -53
  233. package/js/src/ndax.d.ts +1 -0
  234. package/js/src/ndax.js +35 -37
  235. package/js/src/okx.js +23 -5
  236. package/js/src/onetrading.d.ts +2 -1
  237. package/js/src/onetrading.js +21 -23
  238. package/js/src/p2b.js +8 -4
  239. package/js/src/paradex.js +3 -2
  240. package/js/src/phemex.d.ts +1 -0
  241. package/js/src/phemex.js +47 -47
  242. package/js/src/poloniex.js +19 -13
  243. package/js/src/pro/alpaca.js +1 -1
  244. package/js/src/pro/apex.js +11 -2
  245. package/js/src/pro/arkham.js +1 -1
  246. package/js/src/pro/aster.js +10 -9
  247. package/js/src/pro/backpack.js +1 -1
  248. package/js/src/pro/binance.d.ts +1 -1
  249. package/js/src/pro/binance.js +6 -6
  250. package/js/src/pro/bingx.js +7 -2
  251. package/js/src/pro/bitget.js +1 -1
  252. package/js/src/pro/bithumb.js +1 -1
  253. package/js/src/pro/bitmart.js +10 -0
  254. package/js/src/pro/bitmex.js +1 -1
  255. package/js/src/pro/bitstamp.js +1 -1
  256. package/js/src/pro/blockchaincom.js +1 -1
  257. package/js/src/pro/bybit.js +1 -1
  258. package/js/src/pro/cex.js +1 -1
  259. package/js/src/pro/coinex.js +1 -1
  260. package/js/src/pro/coinone.js +1 -1
  261. package/js/src/pro/cryptocom.js +3 -1
  262. package/js/src/pro/dydx.js +1 -1
  263. package/js/src/pro/exmo.js +1 -1
  264. package/js/src/pro/extended.d.ts +126 -0
  265. package/js/src/pro/extended.js +858 -0
  266. package/js/src/pro/gate.js +1 -1
  267. package/js/src/pro/grvt.js +8 -0
  268. package/js/src/pro/htx.d.ts +4 -4
  269. package/js/src/pro/htx.js +4 -4
  270. package/js/src/pro/independentreserve.js +1 -1
  271. package/js/src/pro/krakenfutures.d.ts +4 -4
  272. package/js/src/pro/krakenfutures.js +16 -4
  273. package/js/src/pro/kucoin.js +1 -1
  274. package/js/src/pro/luno.d.ts +1 -1
  275. package/js/src/pro/luno.js +3 -3
  276. package/js/src/pro/modetrade.d.ts +3 -3
  277. package/js/src/pro/modetrade.js +3 -3
  278. package/js/src/pro/okx.d.ts +4 -4
  279. package/js/src/pro/okx.js +4 -4
  280. package/js/src/pro/onetrading.js +1 -1
  281. package/js/src/pro/toobit.js +1 -1
  282. package/js/src/pro/weex.js +1 -1
  283. package/js/src/pro/woo.d.ts +4 -4
  284. package/js/src/pro/woo.js +4 -4
  285. package/js/src/pro/woofipro.d.ts +3 -3
  286. package/js/src/pro/woofipro.js +3 -3
  287. package/js/src/pro/xt.js +1 -1
  288. package/js/src/tokocrypto.js +1 -1
  289. package/js/src/toobit.d.ts +1 -1
  290. package/js/src/toobit.js +3 -3
  291. package/js/src/upbit.js +3 -3
  292. package/js/src/weex.d.ts +1 -0
  293. package/js/src/weex.js +57 -62
  294. package/js/src/whitebit.d.ts +1 -0
  295. package/js/src/whitebit.js +61 -63
  296. package/js/src/woo.d.ts +1 -0
  297. package/js/src/woo.js +66 -55
  298. package/js/src/woofipro.d.ts +1 -0
  299. package/js/src/woofipro.js +54 -48
  300. package/js/src/xt.js +3 -2
  301. package/js/src/yobit.js +4 -2
  302. package/js/src/zebpay.d.ts +2 -1
  303. package/js/src/zebpay.js +73 -75
  304. package/package.json +25 -11
  305. package/dist/cjs/src/gateio.js +0 -18
  306. package/dist/cjs/src/oxfun.js +0 -2931
  307. package/dist/cjs/src/pro/gateio.js +0 -18
  308. package/dist/cjs/src/pro/oxfun.js +0 -1113
  309. package/js/src/abstract/gateio.d.ts +0 -346
  310. package/js/src/abstract/gateio.js +0 -5
  311. package/js/src/abstract/oxfun.d.ts +0 -37
  312. package/js/src/gateio.d.ts +0 -4
  313. package/js/src/gateio.js +0 -11
  314. package/js/src/oxfun.d.ts +0 -442
  315. package/js/src/oxfun.js +0 -2924
  316. package/js/src/pro/gateio.d.ts +0 -4
  317. package/js/src/pro/gateio.js +0 -11
  318. package/js/src/pro/oxfun.d.ts +0 -234
  319. package/js/src/pro/oxfun.js +0 -1106
  320. /package/dist/cjs/src/abstract/{oxfun.js → extended.js} +0 -0
  321. /package/js/src/abstract/{oxfun.js → extended.js} +0 -0
@@ -1,1106 +0,0 @@
1
- // ---------------------------------------------------------------------------
2
- import oxfunRest from '../oxfun.js';
3
- import { ArgumentsRequired, AuthenticationError, BadRequest } from '../base/errors.js';
4
- import { sha256 } from '../static_dependencies/noble-hashes/sha256.js';
5
- import { ArrayCache, ArrayCacheBySymbolById, ArrayCacheBySymbolBySide, ArrayCacheByTimestamp } from '../base/ws/Cache.js';
6
- // ---------------------------------------------------------------------------
7
- export default class oxfun extends oxfunRest {
8
- describe() {
9
- return this.deepExtend(super.describe(), {
10
- 'has': {
11
- 'ws': true,
12
- 'watchTrades': true,
13
- 'watchTradesForSymbols': true,
14
- 'watchOrderBook': true,
15
- 'watchOrderBookForSymbols': true,
16
- 'watchOHLCV': true,
17
- 'watchOHLCVForSymbols': true,
18
- 'watchOrders': true,
19
- 'watchMyTrades': false,
20
- 'watchTicker': true,
21
- 'watchTickers': true,
22
- 'watchBidsAsks': true,
23
- 'watchBalance': true,
24
- 'createOrderWs': true,
25
- 'editOrderWs': true,
26
- 'cancelOrderWs': true,
27
- 'cancelOrdersWs': true,
28
- },
29
- 'urls': {
30
- 'api': {
31
- 'ws': 'wss://api.ox.fun/v2/websocket',
32
- 'test': 'wss://stgapi.ox.fun/v2/websocket',
33
- },
34
- },
35
- 'options': {
36
- 'timeframes': {
37
- '1m': '60s',
38
- '3m': '180s',
39
- '5m': '300s',
40
- '15m': '900s',
41
- '30m': '1800s',
42
- '1h': '3600s',
43
- '2h': '7200s',
44
- '4h': '14400s',
45
- '6h': '21600s',
46
- '12h': '43200s',
47
- '1d': '86400s',
48
- },
49
- 'watchOrderBook': {
50
- 'channel': 'depth', // depth, depthL5, depthL10, depthL25
51
- },
52
- },
53
- 'streaming': {
54
- 'ping': this.ping,
55
- 'keepAlive': 50000,
56
- },
57
- });
58
- }
59
- async subscribeMultiple(messageHashes, argsArray, params = {}) {
60
- const url = this.urls['api']['ws'];
61
- const request = {
62
- 'op': 'subscribe',
63
- 'args': argsArray,
64
- };
65
- return await this.watchMultiple(url, messageHashes, this.extend(request, params), messageHashes);
66
- }
67
- /**
68
- * @method
69
- * @name oxfun#watchTrades
70
- * @description watches information on multiple trades made in a market
71
- * @see https://docs.ox.fun/?json#trade
72
- * @param {string} symbol unified market symbol of the market trades were made in
73
- * @param {int} [since] the earliest time in ms to fetch orders for
74
- * @param {int} [limit] the maximum number of trade structures to retrieve
75
- * @param {object} [params] extra parameters specific to the exchange API endpoint
76
- * @param {int|string} [params.tag] If given it will be echoed in the reply and the max size of tag is 32
77
- * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=trade-structure}
78
- */
79
- async watchTrades(symbol, since = undefined, limit = undefined, params = {}) {
80
- return await this.watchTradesForSymbols([symbol], since, limit, params);
81
- }
82
- /**
83
- * @method
84
- * @name oxfun#watchTradesForSymbols
85
- * @description get the list of most recent trades for a particular symbol
86
- * @see https://docs.ox.fun/?json#trade
87
- * @param {string[]} symbols
88
- * @param {int} [since] timestamp in ms of the earliest trade to fetch
89
- * @param {int} [limit] the maximum amount of trades to fetch
90
- * @param {object} [params] extra parameters specific to the exchange API endpoint
91
- * @param {int|string} [params.tag] If given it will be echoed in the reply and the max size of tag is 32
92
- * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=public-trades}
93
- */
94
- async watchTradesForSymbols(symbols, since = undefined, limit = undefined, params = {}) {
95
- await this.loadMarkets();
96
- symbols = this.marketSymbols(symbols, undefined, false);
97
- const args = [];
98
- const messageHashes = [];
99
- for (let i = 0; i < symbols.length; i++) {
100
- const symbol = symbols[i];
101
- const messageHash = 'trades' + ':' + symbol;
102
- messageHashes.push(messageHash);
103
- const marketId = this.marketId(symbol);
104
- const arg = 'trade:' + marketId;
105
- args.push(arg);
106
- }
107
- const trades = await this.subscribeMultiple(messageHashes, args, params);
108
- if (this.newUpdates) {
109
- const first = this.safeDict(trades, 0, {});
110
- const tradeSymbol = this.safeString(first, 'symbol');
111
- limit = trades.getLimit(tradeSymbol, limit);
112
- }
113
- return this.filterBySinceLimit(trades, since, limit, 'timestamp', true);
114
- }
115
- handleTrades(client, message) {
116
- //
117
- // {
118
- // table: 'trade',
119
- // data: [
120
- // {
121
- // side: 'SELL',
122
- // quantity: '0.074',
123
- // matchType: 'TAKER',
124
- // price: '3079.5',
125
- // marketCode: 'ETH-USD-SWAP-LIN',
126
- // tradeId: '400017157974517783',
127
- // timestamp: '1716124156643'
128
- // }
129
- // ]
130
- // }
131
- //
132
- const data = this.safeList(message, 'data', []);
133
- for (let i = 0; i < data.length; i++) {
134
- const trade = this.safeDict(data, i, {});
135
- const parsedTrade = this.parseWsTrade(trade);
136
- const symbol = this.safeString(parsedTrade, 'symbol');
137
- const messageHash = 'trades:' + symbol;
138
- if (!(symbol in this.trades)) {
139
- const tradesLimit = this.safeInteger(this.options, 'tradesLimit', 1000);
140
- this.trades[symbol] = new ArrayCache(tradesLimit);
141
- }
142
- const stored = this.trades[symbol];
143
- stored.append(parsedTrade);
144
- client.resolve(stored, messageHash);
145
- }
146
- }
147
- parseWsTrade(trade, market = undefined) {
148
- //
149
- // {
150
- // side: 'SELL',
151
- // quantity: '0.074',
152
- // matchType: 'TAKER',
153
- // price: '3079.5',
154
- // marketCode: 'ETH-USD-SWAP-LIN',
155
- // tradeId: '400017157974517783',
156
- // timestamp: '1716124156643'
157
- // }
158
- //
159
- const marketId = this.safeString(trade, 'marketCode');
160
- market = this.safeMarket(marketId, market);
161
- const timestamp = this.safeInteger(trade, 'timestamp');
162
- return this.safeTrade({
163
- 'info': trade,
164
- 'timestamp': timestamp,
165
- 'datetime': this.iso8601(timestamp),
166
- 'symbol': market['symbol'],
167
- 'id': this.safeString(trade, 'tradeId'),
168
- 'order': undefined,
169
- 'type': undefined,
170
- 'takerOrMaker': this.safeStringLower(trade, 'matchType'),
171
- 'side': this.safeStringLower(trade, 'side'),
172
- 'price': this.safeNumber(trade, 'price'),
173
- 'amount': this.safeNumber(trade, 'quantity'),
174
- 'cost': undefined,
175
- 'fee': undefined,
176
- });
177
- }
178
- /**
179
- * @method
180
- * @name oxfun#watchOHLCV
181
- * @description watches historical candlestick data containing the open, high, low, and close price, and the volume of a market
182
- * @see https://docs.ox.fun/?json#candles
183
- * @param {string} symbol unified symbol of the market to fetch OHLCV data for
184
- * @param {string} timeframe the length of time each candle represents
185
- * @param {int} [since] timestamp in ms of the earliest candle to fetch
186
- * @param {int} [limit] the maximum amount of candles to fetch
187
- * @param {object} [params] extra parameters specific to the exchange API endpoint
188
- * @param {int|string} [params.tag] If given it will be echoed in the reply and the max size of tag is 32
189
- * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
190
- */
191
- async watchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
192
- await this.loadMarkets();
193
- const market = this.market(symbol);
194
- const timeframes = this.safeDict(this.options, 'timeframes', {});
195
- const interval = this.safeString(timeframes, timeframe, timeframe);
196
- const args = 'candles' + interval + ':' + market['id'];
197
- const messageHash = 'ohlcv:' + symbol + ':' + timeframe;
198
- const url = this.urls['api']['ws'];
199
- const request = {
200
- 'op': 'subscribe',
201
- 'args': [args],
202
- };
203
- const ohlcvs = await this.watch(url, messageHash, this.extend(request, params), messageHash);
204
- if (this.newUpdates) {
205
- limit = ohlcvs.getLimit(symbol, limit);
206
- }
207
- return this.filterBySinceLimit(ohlcvs, since, limit, 0, true);
208
- }
209
- /**
210
- * @method
211
- * @name oxfun#watchOHLCVForSymbols
212
- * @description watches historical candlestick data containing the open, high, low, and close price, and the volume of a market
213
- * @see https://docs.ox.fun/?json#candles
214
- * @param {string[][]} symbolsAndTimeframes array of arrays containing unified symbols and timeframes to fetch OHLCV data for, example [['BTC/USDT', '1m'], ['LTC/USDT', '5m']]
215
- * @param {int} [since] timestamp in ms of the earliest candle to fetch
216
- * @param {int} [limit] the maximum amount of candles to fetch
217
- * @param {object} [params] extra parameters specific to the exchange API endpoint
218
- * @param {int|string} [params.tag] If given it will be echoed in the reply and the max size of tag is 32
219
- * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
220
- */
221
- async watchOHLCVForSymbols(symbolsAndTimeframes, since = undefined, limit = undefined, params = {}) {
222
- const symbolsLength = symbolsAndTimeframes.length;
223
- if (symbolsLength === 0 || !Array.isArray(symbolsAndTimeframes[0])) {
224
- throw new ArgumentsRequired(this.id + " watchOHLCVForSymbols() requires a an array of symbols and timeframes, like [['BTC/USDT:OX', '1m'], ['OX/USDT', '5m']]");
225
- }
226
- await this.loadMarkets();
227
- const args = [];
228
- const messageHashes = [];
229
- const timeframes = this.safeDict(this.options, 'timeframes', {});
230
- for (let i = 0; i < symbolsAndTimeframes.length; i++) {
231
- const symbolAndTimeframe = symbolsAndTimeframes[i];
232
- const sym = symbolAndTimeframe[0];
233
- const tf = symbolAndTimeframe[1];
234
- const marketId = this.marketId(sym);
235
- const interval = this.safeString(timeframes, tf, tf);
236
- const arg = 'candles' + interval + ':' + marketId;
237
- args.push(arg);
238
- const messageHash = 'multi:ohlcv:' + sym + ':' + tf;
239
- messageHashes.push(messageHash);
240
- }
241
- const [symbol, timeframe, candles] = await this.subscribeMultiple(messageHashes, args, params);
242
- if (this.newUpdates) {
243
- limit = candles.getLimit(symbol, limit);
244
- }
245
- const filtered = this.filterBySinceLimit(candles, since, limit, 0, true);
246
- return this.createOHLCVObject(symbol, timeframe, filtered);
247
- }
248
- handleOHLCV(client, message) {
249
- //
250
- // {
251
- // "table": "candles60s",
252
- // "data": [
253
- // {
254
- // "marketCode": "BTC-USD-SWAP-LIN",
255
- // "candle": [
256
- // "1594313762698", //timestamp
257
- // "9633.1", //open
258
- // "9693.9", //high
259
- // "9238.1", //low
260
- // "9630.2", //close
261
- // "45247", //volume in OX
262
- // "5.3" //volume in Contracts
263
- // ]
264
- // }
265
- // ]
266
- // }
267
- //
268
- const table = this.safeString(message, 'table');
269
- const parts = table.split('candles');
270
- const timeframeId = this.safeString(parts, 1, '');
271
- const timeframe = this.findTimeframe(timeframeId);
272
- const messageData = this.safeList(message, 'data', []);
273
- const data = this.safeDict(messageData, 0, {});
274
- const marketId = this.safeString(data, 'marketCode');
275
- const market = this.safeMarket(marketId);
276
- const symbol = this.safeSymbol(marketId, market);
277
- if (!(symbol in this.ohlcvs)) {
278
- this.ohlcvs[symbol] = {};
279
- }
280
- if (!(timeframe in this.ohlcvs[symbol])) {
281
- const limit = this.safeInteger(this.options, 'OHLCVLimit', 1000);
282
- this.ohlcvs[symbol][timeframe] = new ArrayCacheByTimestamp(limit);
283
- }
284
- const candle = this.safeList(data, 'candle', []);
285
- const parsed = this.parseWsOHLCV(candle, market);
286
- const stored = this.ohlcvs[symbol][timeframe];
287
- stored.append(parsed);
288
- const messageHash = 'ohlcv:' + symbol + ':' + timeframe;
289
- client.resolve(stored, messageHash);
290
- // for multiOHLCV we need special object, as opposed to other "multi"
291
- // methods, because OHLCV response item does not contain symbol
292
- // or timeframe, thus otherwise it would be unrecognizable
293
- const messageHashForMulti = 'multi:' + messageHash;
294
- client.resolve([symbol, timeframe, stored], messageHashForMulti);
295
- }
296
- parseWsOHLCV(ohlcv, market = undefined) {
297
- //
298
- // [
299
- // "1594313762698", //timestamp
300
- // "9633.1", //open
301
- // "9693.9", //high
302
- // "9238.1", //low
303
- // "9630.2", //close
304
- // "45247", //volume in OX
305
- // "5.3" //volume in Contracts
306
- // ]
307
- //
308
- return [
309
- this.safeInteger(ohlcv, 0),
310
- this.safeNumber(ohlcv, 1),
311
- this.safeNumber(ohlcv, 2),
312
- this.safeNumber(ohlcv, 3),
313
- this.safeNumber(ohlcv, 4),
314
- this.safeNumber(ohlcv, 6),
315
- ];
316
- }
317
- /**
318
- * @method
319
- * @name oxfun#watchOrderBook
320
- * @description watches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
321
- * @see https://docs.ox.fun/?json#fixed-size-order-book
322
- * @see https://docs.ox.fun/?json#full-order-book
323
- * @param {string} symbol unified symbol of the market to fetch the order book for
324
- * @param {int} [limit] the maximum amount of order book entries to return
325
- * @param {object} [params] extra parameters specific to the exchange API endpoint
326
- * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/?id=order-book-structure} indexed by market symbols
327
- */
328
- async watchOrderBook(symbol, limit = undefined, params = {}) {
329
- return await this.watchOrderBookForSymbols([symbol], limit, params);
330
- }
331
- /**
332
- * @method
333
- * @name oxfun#watchOrderBookForSymbols
334
- * @description watches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
335
- * @see https://docs.ox.fun/?json#fixed-size-order-book
336
- * @see https://docs.ox.fun/?json#full-order-book
337
- * @param {string[]} symbols unified array of symbols
338
- * @param {int} [limit] the maximum amount of order book entries to return
339
- * @param {object} [params] extra parameters specific to the exchange API endpoint
340
- * @param {int|string} [params.tag] If given it will be echoed in the reply and the max size of tag is 32
341
- * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/?id=order-book-structure} indexed by market symbols
342
- */
343
- async watchOrderBookForSymbols(symbols, limit = undefined, params = {}) {
344
- await this.loadMarkets();
345
- symbols = this.marketSymbols(symbols);
346
- let channel = 'depth';
347
- const options = this.safeDict(this.options, 'watchOrderBook', {});
348
- const defaultChannel = this.safeString(options, 'channel');
349
- if (defaultChannel !== undefined) {
350
- channel = defaultChannel;
351
- }
352
- else if (limit !== undefined) {
353
- if (limit <= 5) {
354
- channel = 'depthL5';
355
- }
356
- else if (limit <= 10) {
357
- channel = 'depthL10';
358
- }
359
- else if (limit <= 25) {
360
- channel = 'depthL25';
361
- }
362
- }
363
- const args = [];
364
- const messageHashes = [];
365
- for (let i = 0; i < symbols.length; i++) {
366
- const symbol = symbols[i];
367
- const messageHash = 'orderbook:' + symbol;
368
- messageHashes.push(messageHash);
369
- const marketId = this.marketId(symbol);
370
- const arg = channel + ':' + marketId;
371
- args.push(arg);
372
- }
373
- const orderbook = await this.subscribeMultiple(messageHashes, args, params);
374
- return orderbook.limit();
375
- }
376
- handleOrderBook(client, message) {
377
- //
378
- // {
379
- // "table": "depth",
380
- // "data": {
381
- // "seqNum": "100170478917895032",
382
- // "asks": [
383
- // [ 0.01, 100500 ],
384
- // ...
385
- // ],
386
- // "bids": [
387
- // [ 69.69696, 69 ],
388
- // ...
389
- // ],
390
- // "checksum": 261021645,
391
- // "marketCode": "OX-USDT",
392
- // "timestamp": 1716204786184
393
- // },
394
- // "action": "partial"
395
- // }
396
- //
397
- const data = this.safeDict(message, 'data', {});
398
- const marketId = this.safeString(data, 'marketCode');
399
- const symbol = this.safeSymbol(marketId);
400
- const timestamp = this.safeInteger(data, 'timestamp');
401
- const messageHash = 'orderbook:' + symbol;
402
- if (!(symbol in this.orderbooks)) {
403
- this.orderbooks[symbol] = this.orderBook({});
404
- }
405
- const orderbook = this.orderbooks[symbol];
406
- const snapshot = this.parseOrderBook(data, symbol, timestamp, 'asks', 'bids');
407
- orderbook.reset(snapshot);
408
- orderbook['nonce'] = this.safeInteger(data, 'seqNum');
409
- this.orderbooks[symbol] = orderbook;
410
- client.resolve(orderbook, messageHash);
411
- }
412
- /**
413
- * @method
414
- * @name oxfun#watchTicker
415
- * @see https://docs.ox.fun/?json#ticker
416
- * @description watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
417
- * @param {string} symbol unified symbol of the market to fetch the ticker for
418
- * @param {object} [params] extra parameters specific to the exchange API endpoint
419
- * @param {int|string} [params.tag] If given it will be echoed in the reply and the max size of tag is 32
420
- * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/?id=ticker-structure}
421
- */
422
- async watchTicker(symbol, params = {}) {
423
- const ticker = await this.watchTickers([symbol], params);
424
- return this.safeValue(ticker, symbol);
425
- }
426
- /**
427
- * @method
428
- * @name oxfun#watchTickers
429
- * @see https://docs.ox.fun/?json#ticker
430
- * @description watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for all markets of a specific list
431
- * @param {string[]} [symbols] unified symbol of the market to fetch the ticker for
432
- * @param {object} [params] extra parameters specific to the exchange API endpoint
433
- * @param {int|string} [params.tag] If given it will be echoed in the reply and the max size of tag is 32
434
- * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/?id=ticker-structure}
435
- */
436
- async watchTickers(symbols = undefined, params = {}) {
437
- await this.loadMarkets();
438
- const allSymbols = (symbols === undefined);
439
- let sym = symbols;
440
- const args = [];
441
- if (allSymbols) {
442
- sym = this.symbols;
443
- args.push('ticker:all');
444
- }
445
- const messageHashes = [];
446
- for (let i = 0; i < sym.length; i++) {
447
- const symbol = sym[i];
448
- const messageHash = 'tickers' + ':' + symbol;
449
- messageHashes.push(messageHash);
450
- const marketId = this.marketId(symbol);
451
- if (!allSymbols) {
452
- args.push('ticker:' + marketId);
453
- }
454
- }
455
- const newTicker = await this.subscribeMultiple(messageHashes, args, params);
456
- if (this.newUpdates) {
457
- const result = {};
458
- result[newTicker['symbol']] = newTicker;
459
- return result;
460
- }
461
- return this.filterByArray(this.tickers, 'symbol', symbols);
462
- }
463
- handleTicker(client, message) {
464
- //
465
- // {
466
- // "table": "ticker",
467
- // "data": [
468
- // {
469
- // "last": "3088.6",
470
- // "open24h": "3087.2",
471
- // "high24h": "3142.0",
472
- // "low24h": "3053.9",
473
- // "volume24h": "450512672.1800",
474
- // "currencyVolume24h": "1458.579",
475
- // "openInterest": "3786.801",
476
- // "marketCode": "ETH-USD-SWAP-LIN",
477
- // "timestamp": "1716212747050",
478
- // "lastQty": "0.813",
479
- // "markPrice": "3088.6",
480
- // "lastMarkPrice": "3088.6",
481
- // "indexPrice": "3086.5"
482
- // },
483
- // ...
484
- // ]
485
- // }
486
- //
487
- const data = this.safeList(message, 'data', []);
488
- for (let i = 0; i < data.length; i++) {
489
- const rawTicker = this.safeDict(data, i, {});
490
- const ticker = this.parseTicker(rawTicker);
491
- const symbol = ticker['symbol'];
492
- const messageHash = 'tickers:' + symbol;
493
- this.tickers[symbol] = ticker;
494
- client.resolve(ticker, messageHash);
495
- }
496
- }
497
- /**
498
- * @method
499
- * @name oxfun#watchBidsAsks
500
- * @see https://docs.ox.fun/?json#best-bid-ask
501
- * @description watches best bid & ask for symbols
502
- * @param {string[]} symbols unified symbol of the market to fetch the ticker for
503
- * @param {object} [params] extra parameters specific to the exchange API endpoint
504
- * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/?id=ticker-structure}
505
- */
506
- async watchBidsAsks(symbols = undefined, params = {}) {
507
- await this.loadMarkets();
508
- symbols = this.marketSymbols(symbols, undefined, false);
509
- const messageHashes = [];
510
- const args = [];
511
- for (let i = 0; i < symbols.length; i++) {
512
- const market = this.market(symbols[i]);
513
- args.push('bestBidAsk:' + market['id']);
514
- messageHashes.push('bidask:' + market['symbol']);
515
- }
516
- const newTickers = await this.subscribeMultiple(messageHashes, args, params);
517
- if (this.newUpdates) {
518
- const tickers = {};
519
- tickers[newTickers['symbol']] = newTickers;
520
- return tickers;
521
- }
522
- return this.filterByArray(this.bidsasks, 'symbol', symbols);
523
- }
524
- handleBidAsk(client, message) {
525
- //
526
- // {
527
- // "table": "bestBidAsk",
528
- // "data": {
529
- // "ask": [
530
- // 19045.0,
531
- // 1.0
532
- // ],
533
- // "checksum": 3790706311,
534
- // "marketCode": "BTC-USD-SWAP-LIN",
535
- // "bid": [
536
- // 19015.0,
537
- // 1.0
538
- // ],
539
- // "timestamp": "1665456882928"
540
- // }
541
- // }
542
- //
543
- const data = this.safeDict(message, 'data', {});
544
- const parsedTicker = this.parseWsBidAsk(data);
545
- const symbol = parsedTicker['symbol'];
546
- this.bidsasks[symbol] = parsedTicker;
547
- const messageHash = 'bidask:' + symbol;
548
- client.resolve(parsedTicker, messageHash);
549
- }
550
- parseWsBidAsk(ticker, market = undefined) {
551
- const marketId = this.safeString(ticker, 'marketCode');
552
- market = this.safeMarket(marketId, market);
553
- const symbol = this.safeString(market, 'symbol');
554
- const timestamp = this.safeInteger(ticker, 'timestamp');
555
- const ask = this.safeList(ticker, 'ask', []);
556
- const bid = this.safeList(ticker, 'bid', []);
557
- return this.safeTicker({
558
- 'symbol': symbol,
559
- 'timestamp': timestamp,
560
- 'datetime': this.iso8601(timestamp),
561
- 'ask': this.safeNumber(ask, 0),
562
- 'askVolume': this.safeNumber(ask, 1),
563
- 'bid': this.safeNumber(bid, 0),
564
- 'bidVolume': this.safeNumber(bid, 1),
565
- 'info': ticker,
566
- }, market);
567
- }
568
- /**
569
- * @method
570
- * @name oxfun#watchBalance
571
- * @see https://docs.ox.fun/?json#balance-channel
572
- * @description watch balance and get the amount of funds available for trading or funds locked in orders
573
- * @param {object} [params] extra parameters specific to the exchange API endpoint
574
- * @param {int|string} [params.tag] If given it will be echoed in the reply and the max size of tag is 32
575
- * @returns {object} a [balance structure]{@link https://docs.ccxt.com/?id=balance-structure}
576
- */
577
- async watchBalance(params = {}) {
578
- await this.loadMarkets();
579
- this.authenticate();
580
- const args = 'balance:all';
581
- const messageHash = 'balance';
582
- const url = this.urls['api']['ws'];
583
- const request = {
584
- 'op': 'subscribe',
585
- 'args': [args],
586
- };
587
- return await this.watch(url, messageHash, this.extend(request, params), messageHash);
588
- }
589
- handleBalance(client, message) {
590
- //
591
- // {
592
- // "table": "balance",
593
- // "accountId": "106464",
594
- // "timestamp": "1716549132780",
595
- // "tradeType": "PORTFOLIO",
596
- // "data": [
597
- // {
598
- // "instrumentId": "xOX",
599
- // "total": "23.375591220",
600
- // "available": "23.375591220",
601
- // "reserved": "0",
602
- // "quantityLastUpdated": "1716509744262",
603
- // "locked": "0"
604
- // },
605
- // ...
606
- // ]
607
- // }
608
- //
609
- const balances = this.safeList(message, 'data');
610
- const timestamp = this.safeInteger(message, 'timestamp');
611
- this.balance['info'] = message;
612
- this.balance['timestamp'] = timestamp;
613
- this.balance['datetime'] = this.iso8601(timestamp);
614
- for (let i = 0; i < balances.length; i++) {
615
- const balance = this.safeDict(balances, i, {});
616
- const currencyId = this.safeString(balance, 'instrumentId');
617
- const code = this.safeCurrencyCode(currencyId);
618
- if (!(code in this.balance)) {
619
- this.balance[code] = this.account();
620
- }
621
- const account = this.balance[code];
622
- account['total'] = this.safeString(balance, 'total');
623
- account['used'] = this.safeString(balance, 'reserved');
624
- account['free'] = this.safeString(balance, 'available');
625
- this.balance[code] = account;
626
- }
627
- this.balance = this.safeBalance(this.balance);
628
- client.resolve(this.balance, 'balance');
629
- }
630
- /**
631
- * @method
632
- * @name oxfun#watchPositions
633
- * @see https://docs.ox.fun/?json#position-channel
634
- * @description watch all open positions
635
- * @param {string[]|undefined} symbols list of unified market symbols
636
- * @param since
637
- * @param limit
638
- * @param {object} params extra parameters specific to the exchange API endpoint
639
- * @param {int|string} [params.tag] If given it will be echoed in the reply and the max size of tag is 32
640
- * @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/en/latest/manual.html#position-structure}
641
- */
642
- async watchPositions(symbols = undefined, since = undefined, limit = undefined, params = {}) {
643
- await this.loadMarkets();
644
- await this.authenticate();
645
- const allSymbols = (symbols === undefined);
646
- let sym = symbols;
647
- const args = [];
648
- if (allSymbols) {
649
- sym = this.symbols;
650
- args.push('position:all');
651
- }
652
- const messageHashes = [];
653
- for (let i = 0; i < sym.length; i++) {
654
- const symbol = sym[i];
655
- const messageHash = 'positions' + ':' + symbol;
656
- messageHashes.push(messageHash);
657
- const marketId = this.marketId(symbol);
658
- if (!allSymbols) {
659
- args.push('position:' + marketId);
660
- }
661
- }
662
- const newPositions = await this.subscribeMultiple(messageHashes, args, params);
663
- if (this.newUpdates) {
664
- return newPositions;
665
- }
666
- return this.filterBySymbolsSinceLimit(this.positions, symbols, since, limit, true);
667
- }
668
- handlePositions(client, message) {
669
- //
670
- // {
671
- // "table": "position",
672
- // "accountId": "106464",
673
- // "timestamp": "1716550771582",
674
- // "data": [
675
- // {
676
- // "instrumentId": "ETH-USD-SWAP-LIN",
677
- // "quantity": "0.01",
678
- // "lastUpdated": "1716550757299",
679
- // "contractValCurrency": "ETH",
680
- // "entryPrice": "3709.6",
681
- // "positionPnl": "-5.000",
682
- // "estLiquidationPrice": "743.4",
683
- // "margin": "0",
684
- // "leverage": "0"
685
- // }
686
- // ]
687
- // }
688
- //
689
- if (this.positions === undefined) {
690
- this.positions = new ArrayCacheBySymbolBySide();
691
- }
692
- const cache = this.positions;
693
- const data = this.safeList(message, 'data', []);
694
- for (let i = 0; i < data.length; i++) {
695
- const rawPosition = this.safeDict(data, i, {});
696
- const position = this.parseWsPosition(rawPosition);
697
- const symbol = position['symbol'];
698
- const messageHash = 'positions:' + symbol;
699
- cache.append(position);
700
- client.resolve(position, messageHash);
701
- }
702
- }
703
- parseWsPosition(position, market = undefined) {
704
- //
705
- // {
706
- // "instrumentId": "ETH-USD-SWAP-LIN",
707
- // "quantity": "0.01",
708
- // "lastUpdated": "1716550757299",
709
- // "contractValCurrency": "ETH",
710
- // "entryPrice": "3709.6",
711
- // "positionPnl": "-5.000",
712
- // "estLiquidationPrice": "743.4",
713
- // "margin": "0", // Currently always reports 0
714
- // "leverage": "0" // Currently always reports 0
715
- // }
716
- //
717
- const marketId = this.safeString(position, 'instrumentId');
718
- market = this.safeMarket(marketId, market);
719
- return this.safePosition({
720
- 'info': position,
721
- 'id': undefined,
722
- 'symbol': market['symbol'],
723
- 'notional': undefined,
724
- 'marginMode': 'cross',
725
- 'liquidationPrice': this.safeNumber(position, 'estLiquidationPrice'),
726
- 'entryPrice': this.safeNumber(position, 'entryPrice'),
727
- 'unrealizedPnl': this.safeNumber(position, 'positionPnl'),
728
- 'realizedPnl': undefined,
729
- 'percentage': undefined,
730
- 'contracts': this.safeNumber(position, 'quantity'),
731
- 'contractSize': undefined,
732
- 'markPrice': undefined,
733
- 'lastPrice': undefined,
734
- 'side': undefined,
735
- 'hedged': undefined,
736
- 'timestamp': undefined,
737
- 'datetime': undefined,
738
- 'lastUpdateTimestamp': this.safeInteger(position, 'lastUpdated'),
739
- 'maintenanceMargin': undefined,
740
- 'maintenanceMarginPercentage': undefined,
741
- 'collateral': undefined,
742
- 'initialMargin': undefined,
743
- 'initialMarginPercentage': undefined,
744
- 'leverage': undefined,
745
- 'marginRatio': undefined,
746
- 'stopLossPrice': undefined,
747
- 'takeProfitPrice': undefined,
748
- });
749
- }
750
- /**
751
- * @method
752
- * @name oxfun#watchOrders
753
- * @description watches information on multiple orders made by the user
754
- * @see https://docs.ox.fun/?json#order-channel
755
- * @param {string} symbol unified market symbol of the market orders were made in
756
- * @param {int} [since] the earliest time in ms to fetch orders for
757
- * @param {int} [limit] the maximum number of order structures to retrieve
758
- * @param {object} [params] extra parameters specific to the exchange API endpoint
759
- * @param {int|string} [params.tag] If given it will be echoed in the reply and the max size of tag is 32
760
- * @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
761
- */
762
- async watchOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
763
- await this.loadMarkets();
764
- await this.authenticate();
765
- let messageHash = 'orders';
766
- let args = 'order:';
767
- const market = this.safeMarket(symbol);
768
- if (symbol === undefined) {
769
- args += 'all';
770
- }
771
- else {
772
- messageHash += ':' + symbol;
773
- args += ':' + market['id'];
774
- }
775
- const request = {
776
- 'op': 'subscribe',
777
- 'args': [
778
- args,
779
- ],
780
- };
781
- const url = this.urls['api']['ws'];
782
- const orders = await this.watch(url, messageHash, request, messageHash);
783
- if (this.newUpdates) {
784
- limit = orders.getLimit(symbol, limit);
785
- }
786
- return this.filterBySymbolSinceLimit(orders, symbol, since, limit, true);
787
- }
788
- handleOrders(client, message) {
789
- //
790
- // {
791
- // "table": "order",
792
- // "data": [
793
- // {
794
- // "accountId": "106464",
795
- // "clientOrderId": "1716713676233",
796
- // "orderId": "1000116921319",
797
- // "price": "1000.0",
798
- // "quantity": "0.01",
799
- // "amount": "0.0",
800
- // "side": "BUY",
801
- // "status": "OPEN",
802
- // "marketCode": "ETH-USD-SWAP-LIN",
803
- // "timeInForce": "MAKER_ONLY",
804
- // "timestamp": "1716713677834",
805
- // "remainQuantity": "0.01",
806
- // "limitPrice": "1000.0",
807
- // "notice": "OrderOpened",
808
- // "orderType": "LIMIT",
809
- // "isTriggered": "false",
810
- // "displayQuantity": "0.01"
811
- // }
812
- // ]
813
- // }
814
- //
815
- const data = this.safeList(message, 'data', []);
816
- let messageHash = 'orders';
817
- if (this.orders === undefined) {
818
- const limit = this.safeInteger(this.options, 'ordersLimit', 1000);
819
- this.orders = new ArrayCacheBySymbolById(limit);
820
- }
821
- const orders = this.orders;
822
- for (let i = 0; i < data.length; i++) {
823
- const order = this.safeDict(data, i, {});
824
- const parsedOrder = this.parseOrder(order);
825
- orders.append(parsedOrder);
826
- messageHash += ':' + parsedOrder['symbol'];
827
- client.resolve(this.orders, messageHash);
828
- }
829
- }
830
- /**
831
- * @method
832
- * @name oxfun#createOrderWs
833
- * @see https://docs.ox.fun/?json#order-commands
834
- * @description create a trade order
835
- * @param {string} symbol unified symbol of the market to create an order in
836
- * @param {string} type 'market', 'limit', 'STOP_LIMIT' or 'STOP_MARKET'
837
- * @param {string} side 'buy' or 'sell'
838
- * @param {float} amount how much of currency you want to trade in units of base currency
839
- * @param {float} [price] the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
840
- * @param {object} [params] extra parameters specific to the exchange API endpoint
841
- * @param {int} [params.clientOrderId] a unique id for the order
842
- * @param {int} [params.timestamp] in milliseconds. If an order reaches the matching engine and the current timestamp exceeds timestamp + recvWindow, then the order will be rejected.
843
- * @param {int} [params.recvWindow] in milliseconds. If an order reaches the matching engine and the current timestamp exceeds timestamp + recvWindow, then the order will be rejected. If timestamp is provided without recvWindow, then a default recvWindow of 1000ms is used.
844
- * @param {float} [params.cost] the quote quantity that can be used as an alternative for the amount for market buy orders
845
- * @param {float} [params.triggerPrice] The price at which a trigger order is triggered at
846
- * @param {float} [params.limitPrice] Limit price for the STOP_LIMIT order
847
- * @param {bool} [params.postOnly] if true, the order will only be posted if it will be a maker order
848
- * @param {string} [params.timeInForce] GTC (default), IOC, FOK, PO, MAKER_ONLY or MAKER_ONLY_REPRICE (reprices order to the best maker only price if the specified price were to lead to a taker trade)
849
- * @param {string} [params.selfTradePreventionMode] NONE, EXPIRE_MAKER, EXPIRE_TAKER or EXPIRE_BOTH for more info check here {@link https://docs.ox.fun/?json#self-trade-prevention-modes}
850
- * @param {string} [params.displayQuantity] for an iceberg order, pass both quantity and displayQuantity fields in the order request
851
- * @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
852
- */
853
- async createOrderWs(symbol, type, side, amount, price = undefined, params = {}) {
854
- await this.loadMarkets();
855
- await this.authenticate();
856
- const messageHash = this.nonce().toString();
857
- const request = {
858
- 'op': 'placeorder',
859
- 'tag': messageHash,
860
- };
861
- params = this.omit(params, 'tag');
862
- const orderRequest = this.createOrderRequest(symbol, type, side, amount, price, params);
863
- const timestamp = this.safeInteger(orderRequest, 'timestamp');
864
- if (timestamp === undefined) {
865
- orderRequest['timestamp'] = this.milliseconds();
866
- }
867
- request['data'] = orderRequest;
868
- const url = this.urls['api']['ws'];
869
- return await this.watch(url, messageHash, request, messageHash);
870
- }
871
- /**
872
- * @method
873
- * @name oxfun#editOrderWs
874
- * @description edit a trade order
875
- * @see https://docs.ox.fun/?json#modify-order
876
- * @param {string} id order id
877
- * @param {string} symbol unified symbol of the market to create an order in
878
- * @param {string} type 'market' or 'limit'
879
- * @param {string} side 'buy' or 'sell'
880
- * @param {float} amount how much of the currency you want to trade in units of the base currency
881
- * @param {float|undefined} [price] the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
882
- * @param {object} [params] extra parameters specific to the exchange API endpoint
883
- * @param {int} [params.timestamp] in milliseconds. If an order reaches the matching engine and the current timestamp exceeds timestamp + recvWindow, then the order will be rejected.
884
- * @param {int} [params.recvWindow] in milliseconds. If an order reaches the matching engine and the current timestamp exceeds timestamp + recvWindow, then the order will be rejected. If timestamp is provided without recvWindow, then a default recvWindow of 1000ms is used.
885
- * @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
886
- */
887
- async editOrderWs(id, symbol, type, side, amount = undefined, price = undefined, params = {}) {
888
- await this.loadMarkets();
889
- await this.authenticate();
890
- const messageHash = this.nonce().toString();
891
- const request = {
892
- 'op': 'modifyorder',
893
- 'tag': messageHash,
894
- };
895
- params = this.omit(params, 'tag');
896
- let orderRequest = this.createOrderRequest(symbol, type, side, amount, price, params);
897
- orderRequest = this.extend(orderRequest, { 'orderId': id });
898
- const timestamp = this.safeInteger(orderRequest, 'timestamp');
899
- if (timestamp === undefined) {
900
- orderRequest['timestamp'] = this.milliseconds();
901
- }
902
- request['data'] = orderRequest;
903
- const url = this.urls['api']['ws'];
904
- return await this.watch(url, messageHash, request, messageHash);
905
- }
906
- handlePlaceOrders(client, message) {
907
- //
908
- // {
909
- // "event": "placeorder",
910
- // "submitted": true,
911
- // "tag": "1716934577",
912
- // "timestamp": "1716932973899",
913
- // "data": {
914
- // "marketCode": "ETH-USD-SWAP-LIN",
915
- // "side": "BUY",
916
- // "orderType": "LIMIT",
917
- // "quantity": "0.010",
918
- // "timeInForce": "GTC",
919
- // "price": "400.0",
920
- // "limitPrice": "400.0",
921
- // "orderId": "1000117429736",
922
- // "source": 13
923
- // }
924
- // }
925
- //
926
- //
927
- // Failure response format
928
- // {
929
- // "event": "placeorder",
930
- // "submitted": false,
931
- // "message": "JSON data format is invalid",
932
- // "code": "20009",
933
- // "timestamp": "1716932877381"
934
- // }
935
- //
936
- const messageHash = this.safeString(message, 'tag');
937
- const submitted = this.safeBool(message, 'submitted');
938
- // filter out partial errors
939
- if (!submitted) {
940
- const method = this.safeString(message, 'event');
941
- const stringMsg = this.json(message);
942
- const code = this.safeInteger(message, 'code');
943
- this.handleErrors(code, '', client.url, method, {}, stringMsg, message, {}, {});
944
- }
945
- const data = this.safeValue(message, 'data', {});
946
- const order = this.parseOrder(data);
947
- client.resolve(order, messageHash);
948
- }
949
- /**
950
- * @method
951
- * @name oxfun#cancelOrderWs
952
- * @see https://docs.ox.fun/?json#cancel-order
953
- * @description cancels an open order
954
- * @param {string} id order id
955
- * @param {string} symbol unified market symbol, default is undefined
956
- * @param {object} [params] extra parameters specific to the exchange API endpoint
957
- * @returns {object} an list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
958
- */
959
- async cancelOrderWs(id, symbol = undefined, params = {}) {
960
- if (symbol === undefined) {
961
- throw new ArgumentsRequired(this.id + ' cancelOrderWs() requires a symbol argument');
962
- }
963
- await this.loadMarkets();
964
- await this.authenticate();
965
- const messageHash = this.nonce().toString();
966
- const data = {
967
- 'marketCode': this.marketId(symbol),
968
- 'orderId': id,
969
- };
970
- const request = {
971
- 'op': 'cancelorder',
972
- 'tag': messageHash,
973
- 'data': data,
974
- };
975
- const url = this.urls['api']['ws'];
976
- return await this.watch(url, messageHash, request, messageHash);
977
- }
978
- /**
979
- * @method
980
- * @name oxfun#cancelOrdersWs
981
- * @see https://www.okx.com/docs-v5/en/#order-book-trading-trade-ws-mass-cancel-order
982
- * @description cancel multiple orders
983
- * @param {string[]} ids order ids
984
- * @param {string} symbol unified market symbol, default is undefined
985
- * @param {object} [params] extra parameters specific to the exchange API endpoint
986
- * @returns {object} an list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
987
- */
988
- async cancelOrdersWs(ids, symbol = undefined, params = {}) {
989
- const idsLength = ids.length;
990
- if (idsLength > 20) {
991
- throw new BadRequest(this.id + ' cancelOrdersWs() accepts up to 20 ids at a time');
992
- }
993
- if (symbol === undefined) {
994
- throw new ArgumentsRequired(this.id + ' cancelOrdersWs() requires a symbol argument');
995
- }
996
- await this.loadMarkets();
997
- await this.authenticate();
998
- const messageHash = this.nonce().toString();
999
- const marketId = this.marketId(symbol);
1000
- const dataArray = [];
1001
- for (let i = 0; i < idsLength; i++) {
1002
- const data = {
1003
- 'instId': marketId,
1004
- 'ordId': ids[i],
1005
- };
1006
- dataArray.push(data);
1007
- }
1008
- const request = {
1009
- 'op': 'cancelorders',
1010
- 'tag': messageHash,
1011
- 'dataArray': dataArray,
1012
- };
1013
- const url = this.urls['api']['ws'];
1014
- return await this.watch(url, messageHash, this.deepExtend(request, params), messageHash);
1015
- }
1016
- async authenticate(params = {}) {
1017
- const url = this.urls['api']['ws'];
1018
- const client = this.client(url);
1019
- const messageHash = 'authenticated';
1020
- const future = client.reusableFuture(messageHash);
1021
- const authenticated = this.safeDict(client.subscriptions, messageHash);
1022
- if (authenticated === undefined) {
1023
- this.checkRequiredCredentials();
1024
- const timestamp = this.milliseconds();
1025
- const payload = timestamp.toString() + 'GET/auth/self/verify';
1026
- const signature = this.hmac(this.encode(payload), this.encode(this.secret), sha256, 'base64');
1027
- const request = {
1028
- 'op': 'login',
1029
- 'data': {
1030
- 'apiKey': this.apiKey,
1031
- 'timestamp': timestamp,
1032
- 'signature': signature,
1033
- },
1034
- };
1035
- const message = this.extend(request, params);
1036
- this.watch(url, messageHash, message, messageHash);
1037
- }
1038
- return await future;
1039
- }
1040
- handleAuthenticationMessage(client, message) {
1041
- const authenticated = this.safeBool(message, 'success', false);
1042
- const messageHash = 'authenticated';
1043
- if (authenticated) {
1044
- // we resolve the future here permanently so authentication only happens once
1045
- const future = this.safeDict(client.futures, messageHash);
1046
- future.resolve(true);
1047
- }
1048
- else {
1049
- const error = new AuthenticationError(this.json(message));
1050
- client.reject(error, messageHash);
1051
- if (messageHash in client.subscriptions) {
1052
- delete client.subscriptions[messageHash];
1053
- }
1054
- }
1055
- }
1056
- ping(client) {
1057
- return 'ping';
1058
- }
1059
- handlePong(client, message) {
1060
- client.lastPong = this.milliseconds();
1061
- return message;
1062
- }
1063
- handleMessage(client, message) {
1064
- if (message === 'pong') {
1065
- this.handlePong(client, message);
1066
- return;
1067
- }
1068
- const table = this.safeString(message, 'table');
1069
- const data = this.safeList(message, 'data', []);
1070
- const event = this.safeString(message, 'event');
1071
- if ((table !== undefined) && (data !== undefined)) {
1072
- if (table === 'trade') {
1073
- this.handleTrades(client, message);
1074
- }
1075
- if (table === 'ticker') {
1076
- this.handleTicker(client, message);
1077
- }
1078
- if (table.indexOf('candles') > -1) {
1079
- this.handleOHLCV(client, message);
1080
- }
1081
- if (table.indexOf('depth') > -1) {
1082
- this.handleOrderBook(client, message);
1083
- }
1084
- if (table.indexOf('balance') > -1) {
1085
- this.handleBalance(client, message);
1086
- }
1087
- if (table.indexOf('position') > -1) {
1088
- this.handlePositions(client, message);
1089
- }
1090
- if (table.indexOf('order') > -1) {
1091
- this.handleOrders(client, message);
1092
- }
1093
- if (table === 'bestBidAsk') {
1094
- this.handleBidAsk(client, message);
1095
- }
1096
- }
1097
- else {
1098
- if (event === 'login') {
1099
- this.handleAuthenticationMessage(client, message);
1100
- }
1101
- if ((event === 'placeorder') || (event === 'modifyorder') || (event === 'cancelorder')) {
1102
- this.handlePlaceOrders(client, message);
1103
- }
1104
- }
1105
- }
1106
- }