ccxt-look 1.81.50

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 (264) hide show
  1. package/.cache/eslintcache +1 -0
  2. package/.dockerignore +6 -0
  3. package/.eslintignore +1 -0
  4. package/.gitattributes +5 -0
  5. package/.readthedocs.yaml +16 -0
  6. package/CONTRIBUTING.md +1049 -0
  7. package/LICENSE.txt +21 -0
  8. package/README.md +537 -0
  9. package/SECURITY.md +5 -0
  10. package/build/cleanup-old-tags.js +94 -0
  11. package/build/countries.js +256 -0
  12. package/build/export-exchanges.js +520 -0
  13. package/build/fs.js +51 -0
  14. package/build/transpile.js +1772 -0
  15. package/build/vss.js +78 -0
  16. package/ccxt.browser.js +7 -0
  17. package/ccxt.d.ts +692 -0
  18. package/ccxt.js +171 -0
  19. package/cleanup.sh +2 -0
  20. package/composer-install.sh +20 -0
  21. package/dist/ccxt.browser.js +208383 -0
  22. package/gource.sh +3 -0
  23. package/index.html +7 -0
  24. package/js/.eslintrc +87 -0
  25. package/js/aax.js +2686 -0
  26. package/js/ascendex.js +2584 -0
  27. package/js/base/.eslintrc.js +43 -0
  28. package/js/base/Exchange.js +2371 -0
  29. package/js/base/Precise.js +283 -0
  30. package/js/base/errorHierarchy.js +47 -0
  31. package/js/base/errors.js +55 -0
  32. package/js/base/functions/crypto.js +158 -0
  33. package/js/base/functions/encode.js +118 -0
  34. package/js/base/functions/generic.js +270 -0
  35. package/js/base/functions/misc.js +138 -0
  36. package/js/base/functions/number.js +329 -0
  37. package/js/base/functions/platform.js +38 -0
  38. package/js/base/functions/string.js +21 -0
  39. package/js/base/functions/throttle.js +79 -0
  40. package/js/base/functions/time.js +210 -0
  41. package/js/base/functions/type.js +66 -0
  42. package/js/base/functions.js +28 -0
  43. package/js/bequant.js +32 -0
  44. package/js/bibox.js +1407 -0
  45. package/js/bigone.js +1366 -0
  46. package/js/binance.js +5652 -0
  47. package/js/binancecoinm.js +46 -0
  48. package/js/binanceus.js +46 -0
  49. package/js/binanceusdm.js +49 -0
  50. package/js/bit2c.js +535 -0
  51. package/js/bitbank.js +842 -0
  52. package/js/bitbay.js +16 -0
  53. package/js/bitbns.js +1073 -0
  54. package/js/bitcoincom.js +15 -0
  55. package/js/bitfinex.js +1433 -0
  56. package/js/bitfinex2.js +2025 -0
  57. package/js/bitflyer.js +840 -0
  58. package/js/bitforex.js +614 -0
  59. package/js/bitget.js +2397 -0
  60. package/js/bithumb.js +980 -0
  61. package/js/bitmart.js +2516 -0
  62. package/js/bitmex.js +1809 -0
  63. package/js/bitopro.js +1443 -0
  64. package/js/bitpanda.js +1782 -0
  65. package/js/bitrue.js +1747 -0
  66. package/js/bitso.js +1062 -0
  67. package/js/bitstamp.js +1757 -0
  68. package/js/bitstamp1.js +343 -0
  69. package/js/bittrex.js +1876 -0
  70. package/js/bitvavo.js +1579 -0
  71. package/js/bkex.js +1233 -0
  72. package/js/bl3p.js +346 -0
  73. package/js/blockchaincom.js +969 -0
  74. package/js/btcalpha.js +680 -0
  75. package/js/btcbox.js +477 -0
  76. package/js/btcmarkets.js +1022 -0
  77. package/js/btctradeua.js +466 -0
  78. package/js/btcturk.js +734 -0
  79. package/js/buda.js +946 -0
  80. package/js/bw.js +1265 -0
  81. package/js/bybit.js +3372 -0
  82. package/js/bytetrade.js +1336 -0
  83. package/js/cdax.js +1646 -0
  84. package/js/cex.js +1410 -0
  85. package/js/coinbase.js +1342 -0
  86. package/js/coinbaseprime.js +31 -0
  87. package/js/coinbasepro.js +1466 -0
  88. package/js/coincheck.js +755 -0
  89. package/js/coinex.js +3400 -0
  90. package/js/coinfalcon.js +880 -0
  91. package/js/coinmate.js +794 -0
  92. package/js/coinone.js +816 -0
  93. package/js/coinspot.js +345 -0
  94. package/js/crex24.js +1636 -0
  95. package/js/cryptocom.js +1832 -0
  96. package/js/currencycom.js +1748 -0
  97. package/js/delta.js +1547 -0
  98. package/js/deribit.js +2148 -0
  99. package/js/digifinex.js +1585 -0
  100. package/js/eqonex.js +1660 -0
  101. package/js/exmo.js +1670 -0
  102. package/js/fairdesk.js +1231 -0
  103. package/js/flowbtc.js +35 -0
  104. package/js/fmfwio.js +34 -0
  105. package/js/ftx.js +2751 -0
  106. package/js/ftxus.js +38 -0
  107. package/js/gateio.js +4174 -0
  108. package/js/gemini.js +1397 -0
  109. package/js/hitbtc.js +1343 -0
  110. package/js/hitbtc3.js +2329 -0
  111. package/js/hollaex.js +1486 -0
  112. package/js/huobi.js +5706 -0
  113. package/js/huobijp.js +1710 -0
  114. package/js/huobipro.js +18 -0
  115. package/js/idex.js +1439 -0
  116. package/js/independentreserve.js +649 -0
  117. package/js/indodax.js +742 -0
  118. package/js/itbit.js +722 -0
  119. package/js/kraken.js +2179 -0
  120. package/js/kucoin.js +2571 -0
  121. package/js/kucoinfutures.js +1771 -0
  122. package/js/kuna.js +809 -0
  123. package/js/latoken.js +1445 -0
  124. package/js/lbank.js +760 -0
  125. package/js/liquid.js +1432 -0
  126. package/js/luno.js +873 -0
  127. package/js/lykke.js +1147 -0
  128. package/js/mercado.js +771 -0
  129. package/js/mexc.js +3151 -0
  130. package/js/ndax.js +2233 -0
  131. package/js/novadax.js +1318 -0
  132. package/js/oceanex.js +816 -0
  133. package/js/okcoin.js +3841 -0
  134. package/js/okex.js +16 -0
  135. package/js/okex5.js +16 -0
  136. package/js/okx.js +4795 -0
  137. package/js/paymium.js +498 -0
  138. package/js/phemex.js +2957 -0
  139. package/js/poloniex.js +1674 -0
  140. package/js/probit.js +1346 -0
  141. package/js/qtrade.js +1588 -0
  142. package/js/ripio.js +1061 -0
  143. package/js/static_dependencies/BN/bn.js +3526 -0
  144. package/js/static_dependencies/README.md +1 -0
  145. package/js/static_dependencies/crypto-js/crypto-js.js +5988 -0
  146. package/js/static_dependencies/elliptic/lib/elliptic/curve/base.js +375 -0
  147. package/js/static_dependencies/elliptic/lib/elliptic/curve/edwards.js +433 -0
  148. package/js/static_dependencies/elliptic/lib/elliptic/curve/index.js +8 -0
  149. package/js/static_dependencies/elliptic/lib/elliptic/curve/mont.js +180 -0
  150. package/js/static_dependencies/elliptic/lib/elliptic/curve/short.js +938 -0
  151. package/js/static_dependencies/elliptic/lib/elliptic/curves.js +204 -0
  152. package/js/static_dependencies/elliptic/lib/elliptic/ec/index.js +240 -0
  153. package/js/static_dependencies/elliptic/lib/elliptic/ec/key.js +119 -0
  154. package/js/static_dependencies/elliptic/lib/elliptic/ec/signature.js +24 -0
  155. package/js/static_dependencies/elliptic/lib/elliptic/eddsa/index.js +145 -0
  156. package/js/static_dependencies/elliptic/lib/elliptic/eddsa/key.js +100 -0
  157. package/js/static_dependencies/elliptic/lib/elliptic/eddsa/signature.js +65 -0
  158. package/js/static_dependencies/elliptic/lib/elliptic/precomputed/secp256k1.js +780 -0
  159. package/js/static_dependencies/elliptic/lib/elliptic/utils.js +214 -0
  160. package/js/static_dependencies/elliptic/lib/elliptic.js +22 -0
  161. package/js/static_dependencies/elliptic/lib/hmac-drbg/hmac-drbg.js +114 -0
  162. package/js/static_dependencies/fetch-ponyfill/fetch-node.js +39 -0
  163. package/js/static_dependencies/node-fetch/index.js +1564 -0
  164. package/js/static_dependencies/node-rsa/NodeRSA.js +223 -0
  165. package/js/static_dependencies/node-rsa/asn1/ber/errors.js +13 -0
  166. package/js/static_dependencies/node-rsa/asn1/ber/index.js +21 -0
  167. package/js/static_dependencies/node-rsa/asn1/ber/reader.js +262 -0
  168. package/js/static_dependencies/node-rsa/asn1/ber/types.js +36 -0
  169. package/js/static_dependencies/node-rsa/asn1/index.js +17 -0
  170. package/js/static_dependencies/node-rsa/encryptEngines/js.js +34 -0
  171. package/js/static_dependencies/node-rsa/formats/components.js +71 -0
  172. package/js/static_dependencies/node-rsa/formats/formats.js +31 -0
  173. package/js/static_dependencies/node-rsa/formats/pkcs1.js +148 -0
  174. package/js/static_dependencies/node-rsa/formats/pkcs8.js +187 -0
  175. package/js/static_dependencies/node-rsa/libs/jsbn.js +1252 -0
  176. package/js/static_dependencies/node-rsa/libs/rsa.js +147 -0
  177. package/js/static_dependencies/node-rsa/schemes/pkcs1.js +176 -0
  178. package/js/static_dependencies/node-rsa/schemes/schemes.js +21 -0
  179. package/js/static_dependencies/node-rsa/utils.js +98 -0
  180. package/js/static_dependencies/qs/formats.js +18 -0
  181. package/js/static_dependencies/qs/index.js +11 -0
  182. package/js/static_dependencies/qs/parse.js +242 -0
  183. package/js/static_dependencies/qs/stringify.js +269 -0
  184. package/js/static_dependencies/qs/utils.js +230 -0
  185. package/js/stex.js +1925 -0
  186. package/js/test/.eslintrc.js +42 -0
  187. package/js/test/Exchange/test.balance.js +61 -0
  188. package/js/test/Exchange/test.borrowRate.js +32 -0
  189. package/js/test/Exchange/test.currency.js +52 -0
  190. package/js/test/Exchange/test.fetchBalance.js +23 -0
  191. package/js/test/Exchange/test.fetchBorrowInterest.js +59 -0
  192. package/js/test/Exchange/test.fetchBorrowRate.js +32 -0
  193. package/js/test/Exchange/test.fetchBorrowRates.js +28 -0
  194. package/js/test/Exchange/test.fetchClosedOrders.js +32 -0
  195. package/js/test/Exchange/test.fetchCurrencies.js +35 -0
  196. package/js/test/Exchange/test.fetchDeposits.js +31 -0
  197. package/js/test/Exchange/test.fetchFundingFees.js +19 -0
  198. package/js/test/Exchange/test.fetchFundingRateHistory.js +40 -0
  199. package/js/test/Exchange/test.fetchL2OrderBook.js +23 -0
  200. package/js/test/Exchange/test.fetchLedger.js +42 -0
  201. package/js/test/Exchange/test.fetchLeverageTiers.js +33 -0
  202. package/js/test/Exchange/test.fetchMarketLeverageTiers.js +22 -0
  203. package/js/test/Exchange/test.fetchMarkets.js +33 -0
  204. package/js/test/Exchange/test.fetchMyTrades.js +42 -0
  205. package/js/test/Exchange/test.fetchOHLCV.js +46 -0
  206. package/js/test/Exchange/test.fetchOpenOrders.js +36 -0
  207. package/js/test/Exchange/test.fetchOrderBook.js +25 -0
  208. package/js/test/Exchange/test.fetchOrderBooks.js +35 -0
  209. package/js/test/Exchange/test.fetchOrders.js +41 -0
  210. package/js/test/Exchange/test.fetchPositions.js +47 -0
  211. package/js/test/Exchange/test.fetchStatus.js +35 -0
  212. package/js/test/Exchange/test.fetchTicker.js +38 -0
  213. package/js/test/Exchange/test.fetchTickers.js +49 -0
  214. package/js/test/Exchange/test.fetchTrades.js +39 -0
  215. package/js/test/Exchange/test.fetchTradingFee.js +18 -0
  216. package/js/test/Exchange/test.fetchTradingFees.js +22 -0
  217. package/js/test/Exchange/test.fetchTransactions.js +31 -0
  218. package/js/test/Exchange/test.fetchWithdrawals.js +31 -0
  219. package/js/test/Exchange/test.ledgerItem.js +46 -0
  220. package/js/test/Exchange/test.leverageTier.js +33 -0
  221. package/js/test/Exchange/test.loadMarkets.js +35 -0
  222. package/js/test/Exchange/test.market.js +129 -0
  223. package/js/test/Exchange/test.ohlcv.js +33 -0
  224. package/js/test/Exchange/test.order.js +62 -0
  225. package/js/test/Exchange/test.orderbook.js +61 -0
  226. package/js/test/Exchange/test.position.js +21 -0
  227. package/js/test/Exchange/test.throttle.js +94 -0
  228. package/js/test/Exchange/test.ticker.js +95 -0
  229. package/js/test/Exchange/test.trade.js +68 -0
  230. package/js/test/Exchange/test.tradingFee.js +34 -0
  231. package/js/test/Exchange/test.transaction.js +35 -0
  232. package/js/test/base/.eslintrc +38 -0
  233. package/js/test/base/functions/test.crypto.js +110 -0
  234. package/js/test/base/functions/test.datetime.js +62 -0
  235. package/js/test/base/functions/test.generic.js +152 -0
  236. package/js/test/base/functions/test.number.js +362 -0
  237. package/js/test/base/functions/test.time.js +56 -0
  238. package/js/test/base/functions/test.type.js +53 -0
  239. package/js/test/base/test.base.js +193 -0
  240. package/js/test/errors/test.InsufficientFunds.js +86 -0
  241. package/js/test/errors/test.InvalidNonce.js +64 -0
  242. package/js/test/errors/test.InvalidOrder.js +35 -0
  243. package/js/test/errors/test.OrderNotFound.js +39 -0
  244. package/js/test/test.js +426 -0
  245. package/js/test/test.timeout_hang.js +12 -0
  246. package/js/therock.js +1431 -0
  247. package/js/tidebit.js +632 -0
  248. package/js/tidex.js +939 -0
  249. package/js/timex.js +1283 -0
  250. package/js/upbit.js +1622 -0
  251. package/js/vcc.js +1353 -0
  252. package/js/wavesexchange.js +2185 -0
  253. package/js/wazirx.js +732 -0
  254. package/js/whitebit.js +1352 -0
  255. package/js/woo.js +1577 -0
  256. package/js/xena.js +1948 -0
  257. package/js/yobit.js +1129 -0
  258. package/js/zaif.js +647 -0
  259. package/js/zb.js +4088 -0
  260. package/js/zipmex.js +40 -0
  261. package/js/zonda.js +1497 -0
  262. package/multilang.sh +159 -0
  263. package/package.json +591 -0
  264. package/postinstall.js +103 -0
package/js/bitget.js ADDED
@@ -0,0 +1,2397 @@
1
+ 'use strict';
2
+
3
+ // ---------------------------------------------------------------------------
4
+
5
+ const Exchange = require ('./base/Exchange');
6
+ const { ExchangeError, ExchangeNotAvailable, OnMaintenance, ArgumentsRequired, BadRequest, AccountSuspended, InvalidAddress, PermissionDenied, DDoSProtection, InsufficientFunds, InvalidNonce, CancelPending, InvalidOrder, OrderNotFound, AuthenticationError, RequestTimeout, BadSymbol, RateLimitExceeded } = require ('./base/errors');
7
+ const { TICK_SIZE } = require ('./base/functions/number');
8
+ const Precise = require ('./base/Precise');
9
+
10
+ // ---------------------------------------------------------------------------
11
+
12
+ module.exports = class bitget extends Exchange {
13
+ describe () {
14
+ return this.deepExtend (super.describe (), {
15
+ 'id': 'bitget',
16
+ 'name': 'Bitget',
17
+ 'countries': [ 'SG' ],
18
+ 'version': 'v1',
19
+ 'rateLimit': 50, // up to 3000 requests per 5 minutes ≈ 600 requests per minute ≈ 10 requests per second ≈ 100 ms
20
+ 'has': {
21
+ 'CORS': undefined,
22
+ 'spot': true,
23
+ 'margin': false,
24
+ 'swap': undefined, // has but unimplemented
25
+ 'future': undefined, // has but unimplemented
26
+ 'option': false,
27
+ 'cancelOrder': true,
28
+ 'cancelOrders': true,
29
+ 'createOrder': true,
30
+ 'fetchAccounts': false,
31
+ 'fetchBalance': true,
32
+ 'fetchBorrowRate': false,
33
+ 'fetchBorrowRateHistories': false,
34
+ 'fetchBorrowRateHistory': false,
35
+ 'fetchBorrowRates': false,
36
+ 'fetchBorrowRatesPerSymbol': false,
37
+ 'fetchClosedOrders': true,
38
+ 'fetchCurrencies': true,
39
+ 'fetchDeposits': false,
40
+ 'fetchLedger': true,
41
+ 'fetchMarkets': true,
42
+ 'fetchMyTrades': true,
43
+ 'fetchOHLCV': true,
44
+ 'fetchOpenOrders': true,
45
+ 'fetchOrder': true,
46
+ 'fetchOrderBook': true,
47
+ 'fetchOrderTrades': true,
48
+ 'fetchPosition': true,
49
+ 'fetchPositions': true,
50
+ 'fetchTicker': true,
51
+ 'fetchTickers': true,
52
+ 'fetchTime': true,
53
+ 'fetchTrades': true,
54
+ 'fetchTradingFee': true,
55
+ 'fetchTradingFees': true,
56
+ 'fetchTransfer': false,
57
+ 'fetchTransfers': undefined,
58
+ 'fetchWithdrawal': false,
59
+ 'fetchWithdrawals': false,
60
+ 'setLeverage': true,
61
+ 'setMarginMode': true,
62
+ 'transfer': false,
63
+ 'withdraw': false,
64
+ },
65
+ 'timeframes': {
66
+ 'spot': {
67
+ '1m': '1min',
68
+ '5m': '5min',
69
+ '15m': '15min',
70
+ '30m': '30min',
71
+ '1h': '1h',
72
+ '4h': '4h',
73
+ '12h': '12h',
74
+ '1d': '1day',
75
+ '1w': '7day', // not documented on the website
76
+ },
77
+ 'swap': {
78
+ '1m': '60',
79
+ '5m': '300',
80
+ '15m': '900',
81
+ '30m': '1800',
82
+ '1h': '3600',
83
+ '4h': '14400',
84
+ '12h': '43200',
85
+ '1d': '86400',
86
+ '1w': '604800',
87
+ },
88
+ },
89
+ 'hostname': 'bitget.com',
90
+ 'urls': {
91
+ 'logo': 'https://user-images.githubusercontent.com/51840849/88317935-a8a21c80-cd22-11ea-8e2b-4b9fac5975eb.jpg',
92
+ 'api': {
93
+ 'spot': 'https://api.{hostname}',
94
+ 'mix': 'https://api.{hostname}',
95
+ },
96
+ 'www': 'https://www.bitget.com',
97
+ 'doc': [
98
+ 'https://bitgetlimited.github.io/apidoc/en/swap',
99
+ 'https://bitgetlimited.github.io/apidoc/en/spot',
100
+ ],
101
+ 'fees': 'https://www.bitget.cc/zh-CN/rate?tab=1',
102
+ 'test': {
103
+ 'rest': 'https://testnet.bitget.com',
104
+ },
105
+ 'referral': 'https://www.bitget.com/expressly?languageType=0&channelCode=ccxt&vipCode=tg9j',
106
+ },
107
+ 'api': {
108
+ 'public': {
109
+ 'spot': {
110
+ 'get': {
111
+ 'public/time': 1,
112
+ 'public/currencies': 1,
113
+ 'public/products': 1,
114
+ 'public/product': 1,
115
+ 'market/ticker': 1,
116
+ 'market/tickers': 1,
117
+ 'market/fills': 1,
118
+ 'market/candles': 1,
119
+ 'market/depth': 1,
120
+ },
121
+ },
122
+ 'mix': {
123
+ 'get': {
124
+ 'market/contracts': 1,
125
+ 'market/depth': 1,
126
+ 'market/ticker': 1,
127
+ 'market/tickers': 1,
128
+ 'market/fills': 1,
129
+ 'market/candles': 1,
130
+ 'market/index': 1,
131
+ 'market/funding-time': 1,
132
+ 'market/history-fundRate': 1,
133
+ 'market/current-fundRate': 1,
134
+ 'market/open-interest': 1,
135
+ 'market/mark-price': 1,
136
+ 'market/symbol-leverage': 1,
137
+ },
138
+ },
139
+ },
140
+ 'private': {
141
+ 'spot': {
142
+ 'get': {
143
+ 'account/assets': 2,
144
+ 'account/transferRecords': 1,
145
+ },
146
+ 'post': {
147
+ 'account/bills': 2,
148
+ 'trade/orders': 2,
149
+ 'trade/batch-orders': 4,
150
+ 'trade/cancel-order': 2,
151
+ 'trade/cancel-batch-orders': 4,
152
+ 'trade/orderInfo': 1,
153
+ 'trade/open-orders': 1,
154
+ 'trade/history': 1,
155
+ 'trade/fills': 1,
156
+ },
157
+ },
158
+ 'mix': {
159
+ 'get': {
160
+ 'account/account': 2,
161
+ 'account/accounts': 2,
162
+ 'account/open-count': 1,
163
+ 'order/current': 2,
164
+ 'order/history': 2,
165
+ 'order/detail': 2,
166
+ 'order/fills': 2,
167
+ 'position/singlePosition': 2,
168
+ 'position/allPosition': 2,
169
+ 'trace/currentTrack': 2,
170
+ 'trace/followerOrder': 2,
171
+ 'trace/historyTrack': 2,
172
+ 'trace/summary': 2,
173
+ 'trace/profitSettleTokenIdGroup': 2,
174
+ 'trace/profitDateGroupList': 2,
175
+ 'trade/profitDateList': 2,
176
+ 'trace/waitProfitDateList': 2,
177
+ 'trace/traderSymbols': 2,
178
+ },
179
+ 'post': {
180
+ 'account/setLeverage': 8,
181
+ 'account/setMargin': 8,
182
+ 'account/setMarginMode': 8,
183
+ 'order/placeOrder': 2,
184
+ 'order/batch-orders': 2,
185
+ 'order/cancel-order': 2,
186
+ 'order/cancel-batch-orders': 2,
187
+ 'plan/placePlan': 2,
188
+ 'plan/modifyPlan': 2,
189
+ 'plan/modifyPlanPreset': 2,
190
+ 'plan/placeTPSL': 2,
191
+ 'plan/modifyTPSLPlan': 2,
192
+ 'plan/cancelPlan': 2,
193
+ 'plan/currentPlan': 2,
194
+ 'plan/historyPlan': 2,
195
+ 'trace/closeTrackOrder': 2,
196
+ 'trace/setUpCopySymbols': 2,
197
+ },
198
+ },
199
+ },
200
+ },
201
+ 'fees': {
202
+ 'spot': {
203
+ 'taker': this.parseNumber ('0.002'),
204
+ 'maker': this.parseNumber ('0.002'),
205
+ },
206
+ 'swap': {
207
+ 'taker': this.parseNumber ('0.0006'),
208
+ 'maker': this.parseNumber ('0.0004'),
209
+ },
210
+ },
211
+ 'requiredCredentials': {
212
+ 'apiKey': true,
213
+ 'secret': true,
214
+ 'password': true,
215
+ },
216
+ 'exceptions': {
217
+ // http error codes
218
+ // 400 Bad Request — Invalid request format
219
+ // 401 Unauthorized — Invalid API Key
220
+ // 403 Forbidden — You do not have access to the requested resource
221
+ // 404 Not Found
222
+ // 500 Internal Server Error — We had a problem with our server
223
+ 'exact': {
224
+ '1': ExchangeError, // { "code": 1, "message": "System error" }
225
+ // undocumented
226
+ 'failure to get a peer from the ring-balancer': ExchangeNotAvailable, // { "message": "failure to get a peer from the ring-balancer" }
227
+ '4010': PermissionDenied, // { "code": 4010, "message": "For the security of your funds, withdrawals are not permitted within 24 hours after changing fund password / mobile number / Google Authenticator settings " }
228
+ // common
229
+ // '0': ExchangeError, // 200 successful,when the order placement / cancellation / operation is successful
230
+ '4001': ExchangeError, // no data received in 30s
231
+ '4002': ExchangeError, // Buffer full. cannot write data
232
+ // --------------------------------------------------------
233
+ '30001': AuthenticationError, // { "code": 30001, "message": 'request header "OK_ACCESS_KEY" cannot be blank'}
234
+ '30002': AuthenticationError, // { "code": 30002, "message": 'request header "OK_ACCESS_SIGN" cannot be blank'}
235
+ '30003': AuthenticationError, // { "code": 30003, "message": 'request header "OK_ACCESS_TIMESTAMP" cannot be blank'}
236
+ '30004': AuthenticationError, // { "code": 30004, "message": 'request header "OK_ACCESS_PASSPHRASE" cannot be blank'}
237
+ '30005': InvalidNonce, // { "code": 30005, "message": "invalid OK_ACCESS_TIMESTAMP" }
238
+ '30006': AuthenticationError, // { "code": 30006, "message": "invalid OK_ACCESS_KEY" }
239
+ '30007': BadRequest, // { "code": 30007, "message": 'invalid Content_Type, please use "application/json" format'}
240
+ '30008': RequestTimeout, // { "code": 30008, "message": "timestamp request expired" }
241
+ '30009': ExchangeError, // { "code": 30009, "message": "system error" }
242
+ '30010': AuthenticationError, // { "code": 30010, "message": "API validation failed" }
243
+ '30011': PermissionDenied, // { "code": 30011, "message": "invalid IP" }
244
+ '30012': AuthenticationError, // { "code": 30012, "message": "invalid authorization" }
245
+ '30013': AuthenticationError, // { "code": 30013, "message": "invalid sign" }
246
+ '30014': DDoSProtection, // { "code": 30014, "message": "request too frequent" }
247
+ '30015': AuthenticationError, // { "code": 30015, "message": 'request header "OK_ACCESS_PASSPHRASE" incorrect'}
248
+ '30016': ExchangeError, // { "code": 30015, "message": "you are using v1 apiKey, please use v1 endpoint. If you would like to use v3 endpoint, please subscribe to v3 apiKey" }
249
+ '30017': ExchangeError, // { "code": 30017, "message": "apikey's broker id does not match" }
250
+ '30018': ExchangeError, // { "code": 30018, "message": "apikey's domain does not match" }
251
+ '30019': ExchangeNotAvailable, // { "code": 30019, "message": "Api is offline or unavailable" }
252
+ '30020': BadRequest, // { "code": 30020, "message": "body cannot be blank" }
253
+ '30021': BadRequest, // { "code": 30021, "message": "Json data format error" }, { "code": 30021, "message": "json data format error" }
254
+ '30022': PermissionDenied, // { "code": 30022, "message": "Api has been frozen" }
255
+ '30023': BadRequest, // { "code": 30023, "message": "{0} parameter cannot be blank" }
256
+ '30024': BadSymbol, // {"code":30024,"message":"\"instrument_id\" is an invalid parameter"}
257
+ '30025': BadRequest, // { "code": 30025, "message": "{0} parameter category error" }
258
+ '30026': DDoSProtection, // { "code": 30026, "message": "requested too frequent" }
259
+ '30027': AuthenticationError, // { "code": 30027, "message": "login failure" }
260
+ '30028': PermissionDenied, // { "code": 30028, "message": "unauthorized execution" }
261
+ '30029': AccountSuspended, // { "code": 30029, "message": "account suspended" }
262
+ '30030': ExchangeError, // { "code": 30030, "message": "endpoint request failed. Please try again" }
263
+ '30031': BadRequest, // { "code": 30031, "message": "token does not exist" }
264
+ '30032': BadSymbol, // { "code": 30032, "message": "pair does not exist" }
265
+ '30033': BadRequest, // { "code": 30033, "message": "exchange domain does not exist" }
266
+ '30034': ExchangeError, // { "code": 30034, "message": "exchange ID does not exist" }
267
+ '30035': ExchangeError, // { "code": 30035, "message": "trading is not supported in this website" }
268
+ '30036': ExchangeError, // { "code": 30036, "message": "no relevant data" }
269
+ '30037': ExchangeNotAvailable, // { "code": 30037, "message": "endpoint is offline or unavailable" }
270
+ // '30038': AuthenticationError, // { "code": 30038, "message": "user does not exist" }
271
+ '30038': OnMaintenance, // {"client_oid":"","code":"30038","error_code":"30038","error_message":"Matching engine is being upgraded. Please try in about 1 minute.","message":"Matching engine is being upgraded. Please try in about 1 minute.","order_id":"-1","result":false}
272
+ // futures
273
+ '32001': AccountSuspended, // { "code": 32001, "message": "futures account suspended" }
274
+ '32002': PermissionDenied, // { "code": 32002, "message": "futures account does not exist" }
275
+ '32003': CancelPending, // { "code": 32003, "message": "canceling, please wait" }
276
+ '32004': ExchangeError, // { "code": 32004, "message": "you have no unfilled orders" }
277
+ '32005': InvalidOrder, // { "code": 32005, "message": "max order quantity" }
278
+ '32006': InvalidOrder, // { "code": 32006, "message": "the order price or trigger price exceeds USD 1 million" }
279
+ '32007': InvalidOrder, // { "code": 32007, "message": "leverage level must be the same for orders on the same side of the contract" }
280
+ '32008': InvalidOrder, // { "code": 32008, "message": "Max. positions to open (cross margin)" }
281
+ '32009': InvalidOrder, // { "code": 32009, "message": "Max. positions to open (fixed margin)" }
282
+ '32010': ExchangeError, // { "code": 32010, "message": "leverage cannot be changed with open positions" }
283
+ '32011': ExchangeError, // { "code": 32011, "message": "futures status error" }
284
+ '32012': ExchangeError, // { "code": 32012, "message": "futures order update error" }
285
+ '32013': ExchangeError, // { "code": 32013, "message": "token type is blank" }
286
+ '32014': ExchangeError, // { "code": 32014, "message": "your number of contracts closing is larger than the number of contracts available" }
287
+ '32015': ExchangeError, // { "code": 32015, "message": "margin ratio is lower than 100% before opening positions" }
288
+ '32016': ExchangeError, // { "code": 32016, "message": "margin ratio is lower than 100% after opening position" }
289
+ '32017': ExchangeError, // { "code": 32017, "message": "no BBO" }
290
+ '32018': ExchangeError, // { "code": 32018, "message": "the order quantity is less than 1, please try again" }
291
+ '32019': ExchangeError, // { "code": 32019, "message": "the order price deviates from the price of the previous minute by more than 3%" }
292
+ '32020': ExchangeError, // { "code": 32020, "message": "the price is not in the range of the price limit" }
293
+ '32021': ExchangeError, // { "code": 32021, "message": "leverage error" }
294
+ '32022': ExchangeError, // { "code": 32022, "message": "this function is not supported in your country or region according to the regulations" }
295
+ '32023': ExchangeError, // { "code": 32023, "message": "this account has outstanding loan" }
296
+ '32024': ExchangeError, // { "code": 32024, "message": "order cannot be placed during delivery" }
297
+ '32025': ExchangeError, // { "code": 32025, "message": "order cannot be placed during settlement" }
298
+ '32026': ExchangeError, // { "code": 32026, "message": "your account is restricted from opening positions" }
299
+ '32027': ExchangeError, // { "code": 32027, "message": "cancelled over 20 orders" }
300
+ '32028': AccountSuspended, // { "code": 32028, "message": "account is suspended and liquidated" }
301
+ '32029': ExchangeError, // { "code": 32029, "message": "order info does not exist" }
302
+ '32030': InvalidOrder, // The order cannot be cancelled
303
+ '32031': ArgumentsRequired, // client_oid or order_id is required.
304
+ '32038': AuthenticationError, // User does not exist
305
+ '32040': ExchangeError, // User have open contract orders or position
306
+ '32044': ExchangeError, // { "code": 32044, "message": "The margin ratio after submitting this order is lower than the minimum requirement ({0}) for your tier." }
307
+ '32045': ExchangeError, // String of commission over 1 million
308
+ '32046': ExchangeError, // Each user can hold up to 10 trade plans at the same time
309
+ '32047': ExchangeError, // system error
310
+ '32048': InvalidOrder, // Order strategy track range error
311
+ '32049': ExchangeError, // Each user can hold up to 10 track plans at the same time
312
+ '32050': InvalidOrder, // Order strategy rang error
313
+ '32051': InvalidOrder, // Order strategy ice depth error
314
+ '32052': ExchangeError, // String of commission over 100 thousand
315
+ '32053': ExchangeError, // Each user can hold up to 6 ice plans at the same time
316
+ '32057': ExchangeError, // The order price is zero. Market-close-all function cannot be executed
317
+ '32054': ExchangeError, // Trade not allow
318
+ '32055': InvalidOrder, // cancel order error
319
+ '32056': ExchangeError, // iceberg per order average should between {0}-{1} contracts
320
+ '32058': ExchangeError, // Each user can hold up to 6 initiative plans at the same time
321
+ '32059': InvalidOrder, // Total amount should exceed per order amount
322
+ '32060': InvalidOrder, // Order strategy type error
323
+ '32061': InvalidOrder, // Order strategy initiative limit error
324
+ '32062': InvalidOrder, // Order strategy initiative range error
325
+ '32063': InvalidOrder, // Order strategy initiative rate error
326
+ '32064': ExchangeError, // Time Stringerval of orders should set between 5-120s
327
+ '32065': ExchangeError, // Close amount exceeds the limit of Market-close-all (999 for BTC, and 9999 for the rest tokens)
328
+ '32066': ExchangeError, // You have open orders. Please cancel all open orders before changing your leverage level.
329
+ '32067': ExchangeError, // Account equity < required margin in this setting. Please adjust your leverage level again.
330
+ '32068': ExchangeError, // The margin for this position will fall short of the required margin in this setting. Please adjust your leverage level or increase your margin to proceed.
331
+ '32069': ExchangeError, // Target leverage level too low. Your account balance is insufficient to cover the margin required. Please adjust the leverage level again.
332
+ '32070': ExchangeError, // Please check open position or unfilled order
333
+ '32071': ExchangeError, // Your current liquidation mode does not support this action.
334
+ '32072': ExchangeError, // The highest available margin for your order’s tier is {0}. Please edit your margin and place a new order.
335
+ '32073': ExchangeError, // The action does not apply to the token
336
+ '32074': ExchangeError, // The number of contracts of your position, open orders, and the current order has exceeded the maximum order limit of this asset.
337
+ '32075': ExchangeError, // Account risk rate breach
338
+ '32076': ExchangeError, // Liquidation of the holding position(s) at market price will require cancellation of all pending close orders of the contracts.
339
+ '32077': ExchangeError, // Your margin for this asset in futures account is insufficient and the position has been taken over for liquidation. (You will not be able to place orders, close positions, transfer funds, or add margin during this period of time. Your account will be restored after the liquidation is complete.)
340
+ '32078': ExchangeError, // Please cancel all open orders before switching the liquidation mode(Please cancel all open orders before switching the liquidation mode)
341
+ '32079': ExchangeError, // Your open positions are at high risk.(Please add margin or reduce positions before switching the mode)
342
+ '32080': ExchangeError, // Funds cannot be transferred out within 30 minutes after futures settlement
343
+ '32083': ExchangeError, // The number of contracts should be a positive multiple of %%. Please place your order again
344
+ // token and margin trading
345
+ '33001': PermissionDenied, // { "code": 33001, "message": "margin account for this pair is not enabled yet" }
346
+ '33002': AccountSuspended, // { "code": 33002, "message": "margin account for this pair is suspended" }
347
+ '33003': InsufficientFunds, // { "code": 33003, "message": "no loan balance" }
348
+ '33004': ExchangeError, // { "code": 33004, "message": "loan amount cannot be smaller than the minimum limit" }
349
+ '33005': ExchangeError, // { "code": 33005, "message": "repayment amount must exceed 0" }
350
+ '33006': ExchangeError, // { "code": 33006, "message": "loan order not found" }
351
+ '33007': ExchangeError, // { "code": 33007, "message": "status not found" }
352
+ '33008': InsufficientFunds, // { "code": 33008, "message": "loan amount cannot exceed the maximum limit" }
353
+ '33009': ExchangeError, // { "code": 33009, "message": "user ID is blank" }
354
+ '33010': ExchangeError, // { "code": 33010, "message": "you cannot cancel an order during session 2 of call auction" }
355
+ '33011': ExchangeError, // { "code": 33011, "message": "no new market data" }
356
+ '33012': ExchangeError, // { "code": 33012, "message": "order cancellation failed" }
357
+ '33013': InvalidOrder, // { "code": 33013, "message": "order placement failed" }
358
+ '33014': OrderNotFound, // { "code": 33014, "message": "order does not exist" }
359
+ '33015': InvalidOrder, // { "code": 33015, "message": "exceeded maximum limit" }
360
+ '33016': ExchangeError, // { "code": 33016, "message": "margin trading is not open for this token" }
361
+ '33017': InsufficientFunds, // { "code": 33017, "message": "insufficient balance" }
362
+ '33018': ExchangeError, // { "code": 33018, "message": "this parameter must be smaller than 1" }
363
+ '33020': ExchangeError, // { "code": 33020, "message": "request not supported" }
364
+ '33021': BadRequest, // { "code": 33021, "message": "token and the pair do not match" }
365
+ '33022': InvalidOrder, // { "code": 33022, "message": "pair and the order do not match" }
366
+ '33023': ExchangeError, // { "code": 33023, "message": "you can only place market orders during call auction" }
367
+ '33024': InvalidOrder, // { "code": 33024, "message": "trading amount too small" }
368
+ '33025': InvalidOrder, // { "code": 33025, "message": "base token amount is blank" }
369
+ '33026': ExchangeError, // { "code": 33026, "message": "transaction completed" }
370
+ '33027': InvalidOrder, // { "code": 33027, "message": "cancelled order or order cancelling" }
371
+ '33028': InvalidOrder, // { "code": 33028, "message": "the decimal places of the trading price exceeded the limit" }
372
+ '33029': InvalidOrder, // { "code": 33029, "message": "the decimal places of the trading size exceeded the limit" }
373
+ '33034': ExchangeError, // { "code": 33034, "message": "You can only place limit order after Call Auction has started" }
374
+ '33035': ExchangeError, // This type of order cannot be canceled(This type of order cannot be canceled)
375
+ '33036': ExchangeError, // Exceeding the limit of entrust order
376
+ '33037': ExchangeError, // The buy order price should be lower than 130% of the trigger price
377
+ '33038': ExchangeError, // The sell order price should be higher than 70% of the trigger price
378
+ '33039': ExchangeError, // The limit of callback rate is 0 < x <= 5%
379
+ '33040': ExchangeError, // The trigger price of a buy order should be lower than the latest transaction price
380
+ '33041': ExchangeError, // The trigger price of a sell order should be higher than the latest transaction price
381
+ '33042': ExchangeError, // The limit of price variance is 0 < x <= 1%
382
+ '33043': ExchangeError, // The total amount must be larger than 0
383
+ '33044': ExchangeError, // The average amount should be 1/1000 * total amount <= x <= total amount
384
+ '33045': ExchangeError, // The price should not be 0, including trigger price, order price, and price limit
385
+ '33046': ExchangeError, // Price variance should be 0 < x <= 1%
386
+ '33047': ExchangeError, // Sweep ratio should be 0 < x <= 100%
387
+ '33048': ExchangeError, // Per order limit: Total amount/1000 < x <= Total amount
388
+ '33049': ExchangeError, // Total amount should be X > 0
389
+ '33050': ExchangeError, // Time interval should be 5 <= x <= 120s
390
+ '33051': ExchangeError, // cancel order number not higher limit: plan and track entrust no more than 10, ice and time entrust no more than 6
391
+ '33059': BadRequest, // { "code": 33059, "message": "client_oid or order_id is required" }
392
+ '33060': BadRequest, // { "code": 33060, "message": "Only fill in either parameter client_oid or order_id" }
393
+ '33061': ExchangeError, // Value of a single market price order cannot exceed 100,000 USD
394
+ '33062': ExchangeError, // The leverage ratio is too high. The borrowed position has exceeded the maximum position of this leverage ratio. Please readjust the leverage ratio
395
+ '33063': ExchangeError, // Leverage multiple is too low, there is insufficient margin in the account, please readjust the leverage ratio
396
+ '33064': ExchangeError, // The setting of the leverage ratio cannot be less than 2, please readjust the leverage ratio
397
+ '33065': ExchangeError, // Leverage ratio exceeds maximum leverage ratio, please readjust leverage ratio
398
+ // account
399
+ '21009': ExchangeError, // Funds cannot be transferred out within 30 minutes after swap settlement(Funds cannot be transferred out within 30 minutes after swap settlement)
400
+ '34001': PermissionDenied, // { "code": 34001, "message": "withdrawal suspended" }
401
+ '34002': InvalidAddress, // { "code": 34002, "message": "please add a withdrawal address" }
402
+ '34003': ExchangeError, // { "code": 34003, "message": "sorry, this token cannot be withdrawn to xx at the moment" }
403
+ '34004': ExchangeError, // { "code": 34004, "message": "withdrawal fee is smaller than minimum limit" }
404
+ '34005': ExchangeError, // { "code": 34005, "message": "withdrawal fee exceeds the maximum limit" }
405
+ '34006': ExchangeError, // { "code": 34006, "message": "withdrawal amount is lower than the minimum limit" }
406
+ '34007': ExchangeError, // { "code": 34007, "message": "withdrawal amount exceeds the maximum limit" }
407
+ '34008': InsufficientFunds, // { "code": 34008, "message": "insufficient balance" }
408
+ '34009': ExchangeError, // { "code": 34009, "message": "your withdrawal amount exceeds the daily limit" }
409
+ '34010': ExchangeError, // { "code": 34010, "message": "transfer amount must be larger than 0" }
410
+ '34011': ExchangeError, // { "code": 34011, "message": "conditions not met" }
411
+ '34012': ExchangeError, // { "code": 34012, "message": "the minimum withdrawal amount for NEO is 1, and the amount must be an integer" }
412
+ '34013': ExchangeError, // { "code": 34013, "message": "please transfer" }
413
+ '34014': ExchangeError, // { "code": 34014, "message": "transfer limited" }
414
+ '34015': ExchangeError, // { "code": 34015, "message": "subaccount does not exist" }
415
+ '34016': PermissionDenied, // { "code": 34016, "message": "transfer suspended" }
416
+ '34017': AccountSuspended, // { "code": 34017, "message": "account suspended" }
417
+ '34018': AuthenticationError, // { "code": 34018, "message": "incorrect trades password" }
418
+ '34019': PermissionDenied, // { "code": 34019, "message": "please bind your email before withdrawal" }
419
+ '34020': PermissionDenied, // { "code": 34020, "message": "please bind your funds password before withdrawal" }
420
+ '34021': InvalidAddress, // { "code": 34021, "message": "Not verified address" }
421
+ '34022': ExchangeError, // { "code": 34022, "message": "Withdrawals are not available for sub accounts" }
422
+ '34023': PermissionDenied, // { "code": 34023, "message": "Please enable futures trading before transferring your funds" }
423
+ '34026': ExchangeError, // transfer too frequently(transfer too frequently)
424
+ '34036': ExchangeError, // Parameter is incorrect, please refer to API documentation
425
+ '34037': ExchangeError, // Get the sub-account balance interface, account type is not supported
426
+ '34038': ExchangeError, // Since your C2C transaction is unusual, you are restricted from fund transfer. Please contact our customer support to cancel the restriction
427
+ '34039': ExchangeError, // You are now restricted from transferring out your funds due to abnormal trades on C2C Market. Please transfer your fund on our website or app instead to verify your identity
428
+ // swap
429
+ '35001': ExchangeError, // { "code": 35001, "message": "Contract does not exist" }
430
+ '35002': ExchangeError, // { "code": 35002, "message": "Contract settling" }
431
+ '35003': ExchangeError, // { "code": 35003, "message": "Contract paused" }
432
+ '35004': ExchangeError, // { "code": 35004, "message": "Contract pending settlement" }
433
+ '35005': AuthenticationError, // { "code": 35005, "message": "User does not exist" }
434
+ '35008': InvalidOrder, // { "code": 35008, "message": "Risk ratio too high" }
435
+ '35010': InvalidOrder, // { "code": 35010, "message": "Position closing too large" }
436
+ '35012': InvalidOrder, // { "code": 35012, "message": "Incorrect order size" }
437
+ '35014': InvalidOrder, // { "code": 35014, "message": "Order price is not within limit" }
438
+ '35015': InvalidOrder, // { "code": 35015, "message": "Invalid leverage level" }
439
+ '35017': ExchangeError, // { "code": 35017, "message": "Open orders exist" }
440
+ '35019': InvalidOrder, // { "code": 35019, "message": "Order size too large" }
441
+ '35020': InvalidOrder, // { "code": 35020, "message": "Order price too high" }
442
+ '35021': InvalidOrder, // { "code": 35021, "message": "Order size exceeded current tier limit" }
443
+ '35022': ExchangeError, // { "code": 35022, "message": "Contract status error" }
444
+ '35024': ExchangeError, // { "code": 35024, "message": "Contract not initialized" }
445
+ '35025': InsufficientFunds, // { "code": 35025, "message": "No account balance" }
446
+ '35026': ExchangeError, // { "code": 35026, "message": "Contract settings not initialized" }
447
+ '35029': OrderNotFound, // { "code": 35029, "message": "Order does not exist" }
448
+ '35030': InvalidOrder, // { "code": 35030, "message": "Order size too large" }
449
+ '35031': InvalidOrder, // { "code": 35031, "message": "Cancel order size too large" }
450
+ '35032': ExchangeError, // { "code": 35032, "message": "Invalid user status" }
451
+ '35037': ExchangeError, // No last traded price in cache
452
+ '35039': ExchangeError, // { "code": 35039, "message": "Open order quantity exceeds limit" }
453
+ '35040': InvalidOrder, // {"error_message":"Invalid order type","result":"true","error_code":"35040","order_id":"-1"}
454
+ '35044': ExchangeError, // { "code": 35044, "message": "Invalid order status" }
455
+ '35046': InsufficientFunds, // { "code": 35046, "message": "Negative account balance" }
456
+ '35047': InsufficientFunds, // { "code": 35047, "message": "Insufficient account balance" }
457
+ '35048': ExchangeError, // { "code": 35048, "message": "User contract is frozen and liquidating" }
458
+ '35049': InvalidOrder, // { "code": 35049, "message": "Invalid order type" }
459
+ '35050': InvalidOrder, // { "code": 35050, "message": "Position settings are blank" }
460
+ '35052': InsufficientFunds, // { "code": 35052, "message": "Insufficient cross margin" }
461
+ '35053': ExchangeError, // { "code": 35053, "message": "Account risk too high" }
462
+ '35055': InsufficientFunds, // { "code": 35055, "message": "Insufficient account balance" }
463
+ '35057': ExchangeError, // { "code": 35057, "message": "No last traded price" }
464
+ '35058': ExchangeError, // { "code": 35058, "message": "No limit" }
465
+ '35059': BadRequest, // { "code": 35059, "message": "client_oid or order_id is required" }
466
+ '35060': BadRequest, // { "code": 35060, "message": "Only fill in either parameter client_oid or order_id" }
467
+ '35061': BadRequest, // { "code": 35061, "message": "Invalid instrument_id" }
468
+ '35062': InvalidOrder, // { "code": 35062, "message": "Invalid match_price" }
469
+ '35063': InvalidOrder, // { "code": 35063, "message": "Invalid order_size" }
470
+ '35064': InvalidOrder, // { "code": 35064, "message": "Invalid client_oid" }
471
+ '35066': InvalidOrder, // Order interval error
472
+ '35067': InvalidOrder, // Time-weighted order ratio error
473
+ '35068': InvalidOrder, // Time-weighted order range error
474
+ '35069': InvalidOrder, // Time-weighted single transaction limit error
475
+ '35070': InvalidOrder, // Algo order type error
476
+ '35071': InvalidOrder, // Order total must be larger than single order limit
477
+ '35072': InvalidOrder, // Maximum 6 unfulfilled time-weighted orders can be held at the same time
478
+ '35073': InvalidOrder, // Order price is 0. Market-close-all not available
479
+ '35074': InvalidOrder, // Iceberg order single transaction average error
480
+ '35075': InvalidOrder, // Failed to cancel order
481
+ '35076': InvalidOrder, // LTC 20x leverage. Not allowed to open position
482
+ '35077': InvalidOrder, // Maximum 6 unfulfilled iceberg orders can be held at the same time
483
+ '35078': InvalidOrder, // Order amount exceeded 100,000
484
+ '35079': InvalidOrder, // Iceberg order price variance error
485
+ '35080': InvalidOrder, // Callback rate error
486
+ '35081': InvalidOrder, // Maximum 10 unfulfilled trail orders can be held at the same time
487
+ '35082': InvalidOrder, // Trail order callback rate error
488
+ '35083': InvalidOrder, // Each user can only hold a maximum of 10 unfulfilled stop-limit orders at the same time
489
+ '35084': InvalidOrder, // Order amount exceeded 1 million
490
+ '35085': InvalidOrder, // Order amount is not in the correct range
491
+ '35086': InvalidOrder, // Price exceeds 100 thousand
492
+ '35087': InvalidOrder, // Price exceeds 100 thousand
493
+ '35088': InvalidOrder, // Average amount error
494
+ '35089': InvalidOrder, // Price exceeds 100 thousand
495
+ '35090': ExchangeError, // No stop-limit orders available for cancelation
496
+ '35091': ExchangeError, // No trail orders available for cancellation
497
+ '35092': ExchangeError, // No iceberg orders available for cancellation
498
+ '35093': ExchangeError, // No trail orders available for cancellation
499
+ '35094': ExchangeError, // Stop-limit order last traded price error
500
+ '35095': BadRequest, // Instrument_id error
501
+ '35096': ExchangeError, // Algo order status error
502
+ '35097': ExchangeError, // Order status and order ID cannot exist at the same time
503
+ '35098': ExchangeError, // An order status or order ID must exist
504
+ '35099': ExchangeError, // Algo order ID error
505
+ // option
506
+ '36001': BadRequest, // Invalid underlying index.
507
+ '36002': BadRequest, // Instrument does not exist.
508
+ '36005': ExchangeError, // Instrument status is invalid.
509
+ '36101': AuthenticationError, // Account does not exist.
510
+ '36102': PermissionDenied, // Account status is invalid.
511
+ '36103': AccountSuspended, // Account is suspended due to ongoing liquidation.
512
+ '36104': PermissionDenied, // Account is not enabled for options trading.
513
+ '36105': PermissionDenied, // Please enable the account for option contract.
514
+ '36106': AccountSuspended, // Funds cannot be transferred in or out, as account is suspended.
515
+ '36107': PermissionDenied, // Funds cannot be transferred out within 30 minutes after option exercising or settlement.
516
+ '36108': InsufficientFunds, // Funds cannot be transferred in or out, as equity of the account is less than zero.
517
+ '36109': PermissionDenied, // Funds cannot be transferred in or out during option exercising or settlement.
518
+ '36201': PermissionDenied, // New order function is blocked.
519
+ '36202': PermissionDenied, // Account does not have permission to short option.
520
+ '36203': InvalidOrder, // Invalid format for client_oid.
521
+ '36204': ExchangeError, // Invalid format for request_id.
522
+ '36205': BadRequest, // Instrument id does not match underlying index.
523
+ '36206': BadRequest, // Order_id and client_oid can not be used at the same time.
524
+ '36207': InvalidOrder, // Either order price or fartouch price must be present.
525
+ '36208': InvalidOrder, // Either order price or size must be present.
526
+ '36209': InvalidOrder, // Either order_id or client_oid must be present.
527
+ '36210': InvalidOrder, // Either order_ids or client_oids must be present.
528
+ '36211': InvalidOrder, // Exceeding max batch size for order submission.
529
+ '36212': InvalidOrder, // Exceeding max batch size for oder cancellation.
530
+ '36213': InvalidOrder, // Exceeding max batch size for order amendment.
531
+ '36214': ExchangeError, // Instrument does not have valid bid/ask quote.
532
+ '36216': OrderNotFound, // Order does not exist.
533
+ '36217': InvalidOrder, // Order submission failed.
534
+ '36218': InvalidOrder, // Order cancellation failed.
535
+ '36219': InvalidOrder, // Order amendment failed.
536
+ '36220': InvalidOrder, // Order is pending cancel.
537
+ '36221': InvalidOrder, // Order qty is not valid multiple of lot size.
538
+ '36222': InvalidOrder, // Order price is breaching highest buy limit.
539
+ '36223': InvalidOrder, // Order price is breaching lowest sell limit.
540
+ '36224': InvalidOrder, // Exceeding max order size.
541
+ '36225': InvalidOrder, // Exceeding max open order count for instrument.
542
+ '36226': InvalidOrder, // Exceeding max open order count for underlying.
543
+ '36227': InvalidOrder, // Exceeding max open size across all orders for underlying
544
+ '36228': InvalidOrder, // Exceeding max available qty for instrument.
545
+ '36229': InvalidOrder, // Exceeding max available qty for underlying.
546
+ '36230': InvalidOrder, // Exceeding max position limit for underlying.
547
+ // --------------------------------------------------------
548
+ // swap
549
+ '400': BadRequest, // Bad Request
550
+ '401': AuthenticationError, // Unauthorized access
551
+ '403': PermissionDenied, // Access prohibited
552
+ '404': BadRequest, // Request address does not exist
553
+ '405': BadRequest, // The HTTP Method is not supported
554
+ '415': BadRequest, // The current media type is not supported
555
+ '429': DDoSProtection, // Too many requests
556
+ '500': ExchangeNotAvailable, // System busy
557
+ '1001': RateLimitExceeded, // The request is too frequent and has been throttled
558
+ '1002': ExchangeError, // {0} verifications within 24 hours
559
+ '1003': ExchangeError, // You failed more than {0} times today, the current operation is locked, please try again in 24 hours
560
+ // '00000': ExchangeError, // success
561
+ '40001': AuthenticationError, // ACCESS_KEY cannot be empty
562
+ '40002': AuthenticationError, // SECRET_KEY cannot be empty
563
+ '40003': AuthenticationError, // Signature cannot be empty
564
+ '40004': InvalidNonce, // Request timestamp expired
565
+ '40005': InvalidNonce, // Invalid ACCESS_TIMESTAMP
566
+ '40006': AuthenticationError, // Invalid ACCESS_KEY
567
+ '40007': BadRequest, // Invalid Content_Type
568
+ '40008': InvalidNonce, // Request timestamp expired
569
+ '40009': AuthenticationError, // sign signature error
570
+ '40010': AuthenticationError, // sign signature error
571
+ '40011': AuthenticationError, // ACCESS_PASSPHRASE cannot be empty
572
+ '40012': AuthenticationError, // apikey/password is incorrect
573
+ '40013': ExchangeError, // User status is abnormal
574
+ '40014': PermissionDenied, // Incorrect permissions
575
+ '40015': ExchangeError, // System is abnormal, please try again later
576
+ '40016': PermissionDenied, // The user must bind the phone or Google
577
+ '40017': ExchangeError, // Parameter verification failed
578
+ '40018': PermissionDenied, // Invalid IP
579
+ '40102': BadRequest, // Contract configuration does not exist, please check the parameters
580
+ '40103': BadRequest, // Request method cannot be empty
581
+ '40104': ExchangeError, // Lever adjustment failure
582
+ '40105': ExchangeError, // Abnormal access to current price limit data
583
+ '40106': ExchangeError, // Abnormal get next settlement time
584
+ '40107': ExchangeError, // Abnormal access to index price data
585
+ '40108': InvalidOrder, // Wrong order quantity
586
+ '40109': OrderNotFound, // The data of the order cannot be found, please confirm the order number
587
+ '40200': OnMaintenance, // Server upgrade, please try again later
588
+ '40201': InvalidOrder, // Order number cannot be empty
589
+ '40202': ExchangeError, // User information cannot be empty
590
+ '40203': BadRequest, // The amount of adjustment margin cannot be empty or negative
591
+ '40204': BadRequest, // Adjustment margin type cannot be empty
592
+ '40205': BadRequest, // Adjusted margin type data is wrong
593
+ '40206': BadRequest, // The direction of the adjustment margin cannot be empty
594
+ '40207': BadRequest, // The adjustment margin data is wrong
595
+ '40208': BadRequest, // The accuracy of the adjustment margin amount is incorrect
596
+ '40209': BadRequest, // The current page number is wrong, please confirm
597
+ '40300': ExchangeError, // User does not exist
598
+ '40301': PermissionDenied, // Permission has not been obtained yet. If you need to use it, please contact customer service
599
+ '40302': BadRequest, // Parameter abnormality
600
+ '40303': BadRequest, // Can only query up to 20,000 data
601
+ '40304': BadRequest, // Parameter type is abnormal
602
+ '40305': BadRequest, // Client_oid length is not greater than 50, and cannot be Martian characters
603
+ '40306': ExchangeError, // Batch processing orders can only process up to 20
604
+ '40308': OnMaintenance, // The contract is being temporarily maintained
605
+ '40309': BadSymbol, // The contract has been removed
606
+ '40400': ExchangeError, // Status check abnormal
607
+ '40401': ExchangeError, // The operation cannot be performed
608
+ '40402': BadRequest, // The opening direction cannot be empty
609
+ '40403': BadRequest, // Wrong opening direction format
610
+ '40404': BadRequest, // Whether to enable automatic margin call parameters cannot be empty
611
+ '40405': BadRequest, // Whether to enable the automatic margin call parameter type is wrong
612
+ '40406': BadRequest, // Whether to enable automatic margin call parameters is of unknown type
613
+ '40407': ExchangeError, // The query direction is not the direction entrusted by the plan
614
+ '40408': ExchangeError, // Wrong time range
615
+ '40409': ExchangeError, // Time format error
616
+ '40500': InvalidOrder, // Client_oid check error
617
+ '40501': ExchangeError, // Channel name error
618
+ '40502': ExchangeError, // If it is a copy user, you must pass the copy to whom
619
+ '40503': ExchangeError, // With the single type
620
+ '40504': ExchangeError, // Platform code must pass
621
+ '40505': ExchangeError, // Not the same as single type
622
+ '40506': AuthenticationError, // Platform signature error
623
+ '40507': AuthenticationError, // Api signature error
624
+ '40508': ExchangeError, // KOL is not authorized
625
+ '40509': ExchangeError, // Abnormal copy end
626
+ '40600': ExchangeError, // Copy function suspended
627
+ '40601': ExchangeError, // Followers cannot be KOL
628
+ '40602': ExchangeError, // The number of copies has reached the limit and cannot process the request
629
+ '40603': ExchangeError, // Abnormal copy end
630
+ '40604': ExchangeNotAvailable, // Server is busy, please try again later
631
+ '40605': ExchangeError, // Copy type, the copy number must be passed
632
+ '40606': ExchangeError, // The type of document number is wrong
633
+ '40607': ExchangeError, // Document number must be passed
634
+ '40608': ExchangeError, // No documented products currently supported
635
+ '40609': ExchangeError, // The contract product does not support copying
636
+ '40700': BadRequest, // Cursor parameters are incorrect
637
+ '40701': ExchangeError, // KOL is not authorized
638
+ '40702': ExchangeError, // Unauthorized copying user
639
+ '40703': ExchangeError, // Bill inquiry start and end time cannot be empty
640
+ '40704': ExchangeError, // Can only check the data of the last three months
641
+ '40705': BadRequest, // The start and end time cannot exceed 90 days
642
+ '40706': InvalidOrder, // Wrong order price
643
+ '40707': BadRequest, // Start time is greater than end time
644
+ '40708': BadRequest, // Parameter verification is abnormal
645
+ '40709': ExchangeError, // There is no position in this position, and no automatic margin call can be set
646
+ '40710': ExchangeError, // Abnormal account status
647
+ '40711': InsufficientFunds, // Insufficient contract account balance
648
+ '40712': InsufficientFunds, // Insufficient margin
649
+ '40713': ExchangeError, // Cannot exceed the maximum transferable margin amount
650
+ '40714': ExchangeError, // No direct margin call is allowed
651
+ // spot
652
+ 'invalid sign': AuthenticationError,
653
+ 'invalid currency': BadSymbol, // invalid trading pair
654
+ 'invalid symbol': BadSymbol,
655
+ 'invalid period': BadRequest, // invalid Kline type
656
+ 'invalid user': ExchangeError,
657
+ 'invalid amount': InvalidOrder,
658
+ 'invalid type': InvalidOrder, // {"status":"error","ts":1595700344504,"err_code":"invalid-parameter","err_msg":"invalid type"}
659
+ 'invalid orderId': InvalidOrder,
660
+ 'invalid record': ExchangeError,
661
+ 'invalid accountId': BadRequest,
662
+ 'invalid address': BadRequest,
663
+ 'accesskey not null': AuthenticationError, // {"status":"error","ts":1595704360508,"err_code":"invalid-parameter","err_msg":"accesskey not null"}
664
+ 'illegal accesskey': AuthenticationError,
665
+ 'sign not null': AuthenticationError,
666
+ 'req_time is too much difference from server time': InvalidNonce,
667
+ 'permissions not right': PermissionDenied, // {"status":"error","ts":1595704490084,"err_code":"invalid-parameter","err_msg":"permissions not right"}
668
+ 'illegal sign invalid': AuthenticationError, // {"status":"error","ts":1595684716042,"err_code":"invalid-parameter","err_msg":"illegal sign invalid"}
669
+ 'user locked': AccountSuspended,
670
+ 'Request Frequency Is Too High': RateLimitExceeded,
671
+ 'more than a daily rate of cash': BadRequest,
672
+ 'more than the maximum daily withdrawal amount': BadRequest,
673
+ 'need to bind email or mobile': ExchangeError,
674
+ 'user forbid': PermissionDenied,
675
+ 'User Prohibited Cash Withdrawal': PermissionDenied,
676
+ 'Cash Withdrawal Is Less Than The Minimum Value': BadRequest,
677
+ 'Cash Withdrawal Is More Than The Maximum Value': BadRequest,
678
+ 'the account with in 24 hours ban coin': PermissionDenied,
679
+ 'order cancel fail': BadRequest, // {"status":"error","ts":1595703343035,"err_code":"bad-request","err_msg":"order cancel fail"}
680
+ 'base symbol error': BadSymbol,
681
+ 'base date error': ExchangeError,
682
+ 'api signature not valid': AuthenticationError,
683
+ 'gateway internal error': ExchangeError,
684
+ 'audit failed': ExchangeError,
685
+ 'order queryorder invalid': BadRequest,
686
+ 'market no need price': InvalidOrder,
687
+ 'limit need price': InvalidOrder,
688
+ 'userid not equal to account_id': ExchangeError,
689
+ 'your balance is low': InsufficientFunds, // {"status":"error","ts":1595594160149,"err_code":"invalid-parameter","err_msg":"invalid size, valid range: [1,2000]"}
690
+ 'address invalid cointype': ExchangeError,
691
+ 'system exception': ExchangeError, // {"status":"error","ts":1595711862763,"err_code":"system exception","err_msg":"system exception"}
692
+ '50003': ExchangeError, // No record
693
+ '50004': BadSymbol, // The transaction pair is currently not supported or has been suspended
694
+ '50006': PermissionDenied, // The account is forbidden to withdraw. If you have any questions, please contact customer service.
695
+ '50007': PermissionDenied, // The account is forbidden to withdraw within 24 hours. If you have any questions, please contact customer service.
696
+ '50008': RequestTimeout, // network timeout
697
+ '50009': RateLimitExceeded, // The operation is too frequent, please try again later
698
+ '50010': ExchangeError, // The account is abnormally frozen. If you have any questions, please contact customer service.
699
+ '50014': InvalidOrder, // The transaction amount under minimum limits
700
+ '50015': InvalidOrder, // The transaction amount exceed maximum limits
701
+ '50016': InvalidOrder, // The price can't be higher than the current price
702
+ '50017': InvalidOrder, // Price under minimum limits
703
+ '50018': InvalidOrder, // The price exceed maximum limits
704
+ '50019': InvalidOrder, // The amount under minimum limits
705
+ '50020': InsufficientFunds, // Insufficient balance
706
+ '50021': InvalidOrder, // Price is under minimum limits
707
+ '50026': InvalidOrder, // Market price parameter error
708
+ 'invalid order query time': ExchangeError, // start time is greater than end time; or the time interval between start time and end time is greater than 48 hours
709
+ 'invalid start time': BadRequest, // start time is a date 30 days ago; or start time is a date in the future
710
+ 'invalid end time': BadRequest, // end time is a date 30 days ago; or end time is a date in the future
711
+ '20003': ExchangeError, // operation failed, {"status":"error","ts":1595730308979,"err_code":"bad-request","err_msg":"20003"}
712
+ '01001': ExchangeError, // order failed, {"status":"fail","err_code":"01001","err_msg":"系统异常,请稍后重试"}
713
+ },
714
+ 'broad': {
715
+ 'invalid size, valid range': ExchangeError,
716
+ },
717
+ },
718
+ 'precisionMode': TICK_SIZE,
719
+ 'commonCurrencies': {
720
+ 'JADE': 'Jade Protocol',
721
+ },
722
+ 'options': {
723
+ 'fetchMarkets': [
724
+ 'spot',
725
+ 'swap',
726
+ ],
727
+ 'defaultType': 'spot', // 'spot', 'swap'
728
+ 'defaultSubType': 'linear', // 'linear', 'inverse'
729
+ 'broker': {
730
+ 'spot': 'iauIBf#',
731
+ 'swap': 'iauIBf#',
732
+ },
733
+ },
734
+ });
735
+ }
736
+
737
+ async fetchTime (params = {}) {
738
+ const response = await this.publicSpotGetPublicTime (params);
739
+ //
740
+ // {
741
+ // code: '00000',
742
+ // msg: 'success',
743
+ // requestTime: 1645837773501,
744
+ // data: '1645837773501'
745
+ // }
746
+ //
747
+ return this.safeInteger (response, 'data');
748
+ }
749
+
750
+ async fetchMarkets (params = {}) {
751
+ const types = this.safeValue (this.options, 'fetchMarkets', [ 'spot', 'swap' ]);
752
+ let result = [];
753
+ for (let i = 0; i < types.length; i++) {
754
+ const type = types[i];
755
+ if (type === 'swap') {
756
+ const subTypes = [ 'umcbl', 'dmcbl' ];
757
+ for (let j = 0; j < subTypes.length; j++) {
758
+ const markets = await this.fetchMarketsByType (type, this.extend (params, {
759
+ 'productType': subTypes[j],
760
+ }));
761
+ result = this.arrayConcat (result, markets);
762
+ }
763
+ } else {
764
+ const markets = await this.fetchMarketsByType (types[i], params);
765
+ result = this.arrayConcat (result, markets);
766
+ }
767
+ }
768
+ return result;
769
+ }
770
+
771
+ parseMarkets (markets) {
772
+ const result = [];
773
+ for (let i = 0; i < markets.length; i++) {
774
+ result.push (this.parseMarket (markets[i]));
775
+ }
776
+ return result;
777
+ }
778
+
779
+ parseMarket (market) {
780
+ //
781
+ // spot
782
+ //
783
+ // {
784
+ // symbol: 'ALPHAUSDT_SPBL',
785
+ // symbolName: 'ALPHAUSDT',
786
+ // baseCoin: 'ALPHA',
787
+ // quoteCoin: 'USDT',
788
+ // minTradeAmount: '2',
789
+ // maxTradeAmount: '0',
790
+ // takerFeeRate: '0.001',
791
+ // makerFeeRate: '0.001',
792
+ // priceScale: '4',
793
+ // quantityScale: '4',
794
+ // status: 'online'
795
+ // }
796
+ //
797
+ // swap
798
+ //
799
+ // {
800
+ // symbol: 'BTCUSDT_UMCBL',
801
+ // makerFeeRate: '0.0002',
802
+ // takerFeeRate: '0.0006',
803
+ // feeRateUpRatio: '0.005',
804
+ // openCostUpRatio: '0.01',
805
+ // quoteCoin: 'USDT',
806
+ // baseCoin: 'BTC',
807
+ // buyLimitPriceRatio: '0.01',
808
+ // sellLimitPriceRatio: '0.01',
809
+ // supportMarginCoins: [ 'USDT' ],
810
+ // minTradeNum: '0.001',
811
+ // priceEndStep: '5',
812
+ // volumePlace: '3',
813
+ // pricePlace: '1'
814
+ // }
815
+ //
816
+ //
817
+ const marketId = this.safeString (market, 'symbol');
818
+ const quoteId = this.safeString (market, 'quoteCoin');
819
+ const baseId = this.safeString (market, 'baseCoin');
820
+ const quote = this.safeCurrencyCode (quoteId);
821
+ const base = this.safeCurrencyCode (baseId);
822
+ const supportMarginCoins = this.safeValue (market, 'supportMarginCoins', []);
823
+ const settleId = this.safeString (supportMarginCoins, 0);
824
+ const settle = this.safeCurrencyCode (settleId);
825
+ let symbol = base + '/' + quote;
826
+ const parts = marketId.split ('_');
827
+ const typeId = this.safeString (parts, 1);
828
+ let type = undefined;
829
+ let linear = undefined;
830
+ let inverse = undefined;
831
+ let swap = false;
832
+ let spot = false;
833
+ let contract = false;
834
+ let pricePrecision = undefined;
835
+ let amountPrecision = undefined;
836
+ if (typeId === 'SPBL') {
837
+ type = 'spot';
838
+ spot = true;
839
+ const priceScale = this.safeString (market, 'priceScale');
840
+ const amountScale = this.safeString (market, 'quantityScale');
841
+ pricePrecision = this.parseNumber (this.parsePrecision (priceScale));
842
+ amountPrecision = this.parseNumber (this.parsePrecision (amountScale));
843
+ } else {
844
+ type = 'swap';
845
+ swap = true;
846
+ contract = true;
847
+ symbol = symbol + ':' + settle;
848
+ if (typeId === 'UMCBL') {
849
+ linear = true;
850
+ inverse = false;
851
+ } else if (typeId === 'DMCBL') {
852
+ inverse = true;
853
+ linear = false;
854
+ }
855
+ const priceDecimals = this.safeInteger (market, 'pricePlace');
856
+ const amountDecimals = this.safeInteger (market, 'volumePlace');
857
+ const priceStep = this.safeString (market, 'priceEndStep');
858
+ const amountStep = this.safeString (market, 'minTradeNum');
859
+ const precisePrice = new Precise (priceStep);
860
+ precisePrice.decimals = this.sum (precisePrice.decimals, priceDecimals);
861
+ precisePrice.reduce ();
862
+ const priceString = precisePrice.toString ();
863
+ pricePrecision = this.parseNumber (priceString);
864
+ const preciseAmount = new Precise (amountStep);
865
+ preciseAmount.decimals = this.sum (preciseAmount.decimals, amountDecimals);
866
+ preciseAmount.reduce ();
867
+ const amountString = preciseAmount.toString ();
868
+ amountPrecision = this.parseNumber (amountString);
869
+ }
870
+ const status = this.safeString (market, 'status');
871
+ let active = undefined;
872
+ if (status !== undefined) {
873
+ active = status === 'online';
874
+ }
875
+ const maker = this.safeNumber (market, 'makerFeeRate');
876
+ const taker = this.safeNumber (market, 'takerFeeRate');
877
+ const precision = {
878
+ 'price': pricePrecision,
879
+ 'amount': amountPrecision,
880
+ };
881
+ const limits = {
882
+ 'amount': {
883
+ 'min': this.safeNumber (market, 'minTradeAmount'),
884
+ 'max': undefined,
885
+ },
886
+ 'price': {
887
+ 'min': undefined,
888
+ 'max': undefined,
889
+ },
890
+ 'cost': {
891
+ 'min': undefined,
892
+ 'max': undefined,
893
+ },
894
+ };
895
+ return {
896
+ 'info': market,
897
+ 'id': marketId,
898
+ 'symbol': symbol,
899
+ 'quoteId': quoteId,
900
+ 'baseId': baseId,
901
+ 'quote': quote,
902
+ 'base': base,
903
+ 'type': type,
904
+ 'spot': spot,
905
+ 'swap': swap,
906
+ 'future': false,
907
+ 'option': false,
908
+ 'margin': false,
909
+ 'contract': contract,
910
+ 'contractSize': undefined,
911
+ 'linear': linear,
912
+ 'inverse': inverse,
913
+ 'settleId': settleId,
914
+ 'settle': settle,
915
+ 'expiry': undefined,
916
+ 'expiryDatetime': undefined,
917
+ 'optionType': undefined,
918
+ 'strike': undefined,
919
+ 'active': active,
920
+ 'maker': maker,
921
+ 'taker': taker,
922
+ 'precision': precision,
923
+ 'limits': limits,
924
+ };
925
+ }
926
+
927
+ async fetchMarketsByType (type, params = {}) {
928
+ const method = this.getSupportedMapping (type, {
929
+ 'spot': 'publicSpotGetPublicProducts',
930
+ 'swap': 'publicMixGetMarketContracts',
931
+ });
932
+ const response = await this[method] (params);
933
+ //
934
+ // spot
935
+ // {
936
+ // code: '00000',
937
+ // msg: 'success',
938
+ // requestTime: 1645840064031,
939
+ // data: [
940
+ // {
941
+ // symbol: 'ALPHAUSDT_SPBL',
942
+ // symbolName: 'ALPHAUSDT',
943
+ // baseCoin: 'ALPHA',
944
+ // quoteCoin: 'USDT',
945
+ // minTradeAmount: '2',
946
+ // maxTradeAmount: '0',
947
+ // takerFeeRate: '0.001',
948
+ // makerFeeRate: '0.001',
949
+ // priceScale: '4',
950
+ // quantityScale: '4',
951
+ // status: 'online'
952
+ // }
953
+ // ]
954
+ // }
955
+ //
956
+ // swap
957
+ // {
958
+ // code: '00000',
959
+ // msg: 'success',
960
+ // requestTime: 1645840821493,
961
+ // data: [
962
+ // {
963
+ // symbol: 'BTCUSDT_UMCBL',
964
+ // makerFeeRate: '0.0002',
965
+ // takerFeeRate: '0.0006',
966
+ // feeRateUpRatio: '0.005',
967
+ // openCostUpRatio: '0.01',
968
+ // quoteCoin: 'USDT',
969
+ // baseCoin: 'BTC',
970
+ // buyLimitPriceRatio: '0.01',
971
+ // sellLimitPriceRatio: '0.01',
972
+ // supportMarginCoins: [Array],
973
+ // minTradeNum: '0.001',
974
+ // priceEndStep: '5',
975
+ // volumePlace: '3',
976
+ // pricePlace: '1'
977
+ // }
978
+ // ]
979
+ // }
980
+ //
981
+ const data = this.safeValue (response, 'data', []);
982
+ return this.parseMarkets (data);
983
+ }
984
+
985
+ async fetchCurrencies (params = {}) {
986
+ const response = await this.publicSpotGetPublicCurrencies (params);
987
+ //
988
+ // {
989
+ // code: '00000',
990
+ // msg: 'success',
991
+ // requestTime: 1645935668288,
992
+ // data: [
993
+ // {
994
+ // coinId: '230',
995
+ // coinName: 'KIN',
996
+ // transfer: 'false',
997
+ // chains: [
998
+ // {
999
+ // chain: 'SOL',
1000
+ // needTag: 'false',
1001
+ // withdrawable: 'true',
1002
+ // rechargeable: 'true',
1003
+ // withdrawFee: '187500',
1004
+ // depositConfirm: '100',
1005
+ // withdrawConfirm: '100',
1006
+ // minDepositAmount: '12500',
1007
+ // minWithdrawAmount: '250000',
1008
+ // browserUrl: 'https://explorer.solana.com/tx/'
1009
+ // }
1010
+ // ]
1011
+ // }
1012
+ // ]
1013
+ // }
1014
+ //
1015
+ const result = {};
1016
+ const data = this.safeValue (response, 'data', []);
1017
+ for (let i = 0; i < data.length; i++) {
1018
+ const entry = data[i];
1019
+ const id = this.safeString (entry, 'coinId');
1020
+ const code = this.safeCurrencyCode (this.safeString (entry, 'coinName'));
1021
+ const chains = this.safeValue (entry, 'chains', []);
1022
+ const networks = {};
1023
+ for (let j = 0; j < chains.length; j++) {
1024
+ const chain = chains[j];
1025
+ const networkId = this.safeString (chain, 'chain');
1026
+ const network = this.safeCurrencyCode (networkId);
1027
+ const withdrawEnabled = this.safeString (chain, 'withdrawable');
1028
+ const depositEnabled = this.safeString (chain, 'rechargeable');
1029
+ networks[network] = {
1030
+ 'info': chain,
1031
+ 'id': networkId,
1032
+ 'network': network,
1033
+ 'limits': {
1034
+ 'withdraw': {
1035
+ 'min': this.safeNumber (chain, 'minWithdrawAmount'),
1036
+ 'max': undefined,
1037
+ },
1038
+ 'deposit': {
1039
+ 'min': this.safeNumber (chain, 'minDepositAmount'),
1040
+ 'max': undefined,
1041
+ },
1042
+ },
1043
+ 'active': undefined,
1044
+ 'withdraw': withdrawEnabled === 'true',
1045
+ 'deposit': depositEnabled === 'true',
1046
+ 'fee': this.safeNumber (chain, 'withdrawFee'),
1047
+ };
1048
+ }
1049
+ result[code] = {
1050
+ 'info': entry,
1051
+ 'id': id,
1052
+ 'code': code,
1053
+ 'networks': networks,
1054
+ 'type': undefined,
1055
+ 'name': undefined,
1056
+ 'active': undefined,
1057
+ 'deposit': undefined,
1058
+ 'withdraw': undefined,
1059
+ 'fee': undefined,
1060
+ 'precision': undefined,
1061
+ 'limits': {
1062
+ 'amount': { 'min': undefined, 'max': undefined },
1063
+ 'withdraw': { 'min': undefined, 'max': undefined },
1064
+ },
1065
+ };
1066
+ }
1067
+ return result;
1068
+ }
1069
+
1070
+ async fetchOrderBook (symbol, limit = undefined, params = {}) {
1071
+ await this.loadMarkets ();
1072
+ const market = this.market (symbol);
1073
+ const [ marketType, query ] = this.handleMarketTypeAndParams ('fetchOrderBook', market, params);
1074
+ const method = this.getSupportedMapping (marketType, {
1075
+ 'spot': 'publicSpotGetMarketDepth',
1076
+ 'swap': 'publicMixGetMarketDepth',
1077
+ });
1078
+ const request = {
1079
+ 'symbol': market['id'],
1080
+ };
1081
+ if (limit !== undefined) {
1082
+ request['limit'] = limit;
1083
+ }
1084
+ const response = await this[method] (this.extend (request, query));
1085
+ //
1086
+ // {
1087
+ // code: '00000',
1088
+ // msg: 'success',
1089
+ // requestTime: 1645854610294,
1090
+ // data: {
1091
+ // asks: [ [ '39102', '11.026' ] ],
1092
+ // bids: [ [ '39100.5', '1.773' ] ],
1093
+ // timestamp: '1645854610294'
1094
+ // }
1095
+ // }
1096
+ //
1097
+ const data = this.safeValue (response, 'data');
1098
+ const timestamp = this.safeInteger (data, 'timestamp');
1099
+ return this.parseOrderBook (data, symbol, timestamp);
1100
+ }
1101
+
1102
+ parseTicker (ticker, market = undefined) {
1103
+ //
1104
+ // spot
1105
+ // {
1106
+ // symbol: 'BTCUSDT',
1107
+ // high24h: '40252.43',
1108
+ // low24h: '38548.54',
1109
+ // close: '39102.16',
1110
+ // quoteVol: '67295596.1458',
1111
+ // baseVol: '1723.4152',
1112
+ // usdtVol: '67295596.14578',
1113
+ // ts: '1645856170030',
1114
+ // buyOne: '39096.16',
1115
+ // sellOne: '39103.99'
1116
+ // }
1117
+ //
1118
+ // swap
1119
+ // {
1120
+ // symbol: 'BTCUSDT_UMCBL',
1121
+ // last: '39086',
1122
+ // bestAsk: '39087',
1123
+ // bestBid: '39086',
1124
+ // high24h: '40312',
1125
+ // low24h: '38524.5',
1126
+ // timestamp: '1645856591864',
1127
+ // priceChangePercent: '-0.00861',
1128
+ // baseVolume: '142251.757',
1129
+ // quoteVolume: '5552388715.9215',
1130
+ // usdtVolume: '5552388715.9215'
1131
+ // }
1132
+ //
1133
+ const marketId = this.safeString (ticker, 'symbol');
1134
+ const symbol = this.safeSymbol (marketId, market);
1135
+ const high = this.safeString (ticker, 'high24h');
1136
+ const low = this.safeString (ticker, 'low24h');
1137
+ const close = this.safeString2 (ticker, 'close', 'last');
1138
+ const quoteVolume = this.safeString2 (ticker, 'quoteVol', 'quoteVolume');
1139
+ const baseVolume = this.safeString2 (ticker, 'baseVol', 'baseVolume');
1140
+ const timestamp = this.safeInteger2 (ticker, 'ts', 'timestamp');
1141
+ const datetime = this.iso8601 (timestamp);
1142
+ const bid = this.safeString2 (ticker, 'buyOne', 'bestBid');
1143
+ const ask = this.safeString2 (ticker, 'sellOne', 'bestAsk');
1144
+ const percentage = Precise.stringMul (this.safeString (ticker, 'priceChangePercent'), '100');
1145
+ return this.safeTicker ({
1146
+ 'symbol': symbol,
1147
+ 'timestamp': timestamp,
1148
+ 'datetime': datetime,
1149
+ 'high': high,
1150
+ 'low': low,
1151
+ 'bid': bid,
1152
+ 'bidVolume': undefined,
1153
+ 'ask': ask,
1154
+ 'askVolume': undefined,
1155
+ 'vwap': undefined,
1156
+ 'open': undefined,
1157
+ 'close': close,
1158
+ 'last': undefined,
1159
+ 'previousClose': undefined,
1160
+ 'change': undefined,
1161
+ 'percentage': percentage,
1162
+ 'average': undefined,
1163
+ 'baseVolume': baseVolume,
1164
+ 'quoteVolume': quoteVolume,
1165
+ 'info': ticker,
1166
+ }, market, false);
1167
+ }
1168
+
1169
+ async fetchTicker (symbol, params = {}) {
1170
+ await this.loadMarkets ();
1171
+ const market = this.market (symbol);
1172
+ const request = {
1173
+ 'symbol': market['id'],
1174
+ };
1175
+ const [ marketType, query ] = this.handleMarketTypeAndParams ('fetchTicker', market, params);
1176
+ const method = this.getSupportedMapping (marketType, {
1177
+ 'spot': 'publicSpotGetMarketTicker',
1178
+ 'swap': 'publicMixGetMarketTicker',
1179
+ });
1180
+ const response = await this[method] (this.extend (request, query));
1181
+ //
1182
+ // {
1183
+ // code: '00000',
1184
+ // msg: 'success',
1185
+ // requestTime: '1645856138576',
1186
+ // data: {
1187
+ // symbol: 'BTCUSDT',
1188
+ // high24h: '40252.43',
1189
+ // low24h: '38548.54',
1190
+ // close: '39104.65',
1191
+ // quoteVol: '67221762.2184',
1192
+ // baseVol: '1721.527',
1193
+ // usdtVol: '67221762.218361',
1194
+ // ts: '1645856138031',
1195
+ // buyOne: '39102.55',
1196
+ // sellOne: '39110.56'
1197
+ // }
1198
+ // }
1199
+ //
1200
+ const data = this.safeValue (response, 'data');
1201
+ return this.parseTicker (data, market);
1202
+ }
1203
+
1204
+ async fetchTickers (symbols = undefined, params = {}) {
1205
+ const [ marketType, query ] = this.handleMarketTypeAndParams ('fetchTickers', undefined, params);
1206
+ const method = this.getSupportedMapping (marketType, {
1207
+ 'spot': 'publicSpotGetMarketTickers',
1208
+ 'swap': 'publicMixGetMarketTickers',
1209
+ });
1210
+ const request = {};
1211
+ if (method === 'publicMixGetMarketTickers') {
1212
+ const defaultSubType = this.safeString (this.options, 'defaultSubType');
1213
+ request['productType'] = (defaultSubType === 'linear') ? 'UMCBL' : 'DMCBL';
1214
+ }
1215
+ const response = await this[method] (this.extend (request, query));
1216
+ const data = this.safeValue (response, 'data');
1217
+ return this.parseTickers (data, symbols);
1218
+ }
1219
+
1220
+ parseTrade (trade, market = undefined) {
1221
+ //
1222
+ // spot
1223
+ // {
1224
+ // symbol: 'BTCUSDT_SPBL',
1225
+ // tradeId: '881371996363608065',
1226
+ // side: 'sell',
1227
+ // fillPrice: '39123.05',
1228
+ // fillQuantity: '0.0363',
1229
+ // fillTime: '1645861379709'
1230
+ // }
1231
+ //
1232
+ // swap
1233
+ // {
1234
+ // tradeId: '881373204067311617',
1235
+ // price: '39119.0',
1236
+ // size: '0.001',
1237
+ // side: 'buy',
1238
+ // timestamp: '1645861667648',
1239
+ // symbol: 'BTCUSDT_UMCBL'
1240
+ // }
1241
+ //
1242
+ // private
1243
+ // {
1244
+ // accountId: '6394957606',
1245
+ // symbol: 'LTCUSDT_SPBL',
1246
+ // orderId: '864752115272552448',
1247
+ // fillId: '864752115685969921',
1248
+ // orderType: 'limit',
1249
+ // side: 'buy',
1250
+ // fillPrice: '127.92000000',
1251
+ // fillQuantity: '0.10000000',
1252
+ // fillTotalAmount: '12.79200000',
1253
+ // feeCcy: 'LTC',
1254
+ // fees: '0.00000000',
1255
+ // cTime: '1641898891373'
1256
+ // }
1257
+ //
1258
+ // {
1259
+ // tradeId: '881640729552281602',
1260
+ // symbol: 'BTCUSDT_UMCBL',
1261
+ // orderId: '881640729145409536',
1262
+ // price: '38429.50',
1263
+ // sizeQty: '0.001',
1264
+ // fee: '0',
1265
+ // side: 'open_long',
1266
+ // fillAmount: '38.4295',
1267
+ // profit: '0',
1268
+ // cTime: '1645925450694'
1269
+ // }
1270
+ //
1271
+ const marketId = this.safeString (trade, 'symbol');
1272
+ const symbol = this.safeSymbol (marketId, market);
1273
+ const id = this.safeString2 (trade, 'tradeId', 'fillId');
1274
+ const order = this.safeString (trade, 'orderId');
1275
+ const side = this.safeString (trade, 'side');
1276
+ const price = this.safeString2 (trade, 'fillPrice', 'price');
1277
+ let amount = this.safeString2 (trade, 'fillQuantity', 'size');
1278
+ amount = this.safeString (trade, 'sizeQty', amount);
1279
+ let timestamp = this.safeInteger2 (trade, 'fillTime', 'timestamp');
1280
+ timestamp = this.safeInteger (trade, 'cTime', timestamp);
1281
+ let fee = undefined;
1282
+ const feeAmount = this.safeString (trade, 'fees');
1283
+ const type = this.safeString (trade, 'orderType');
1284
+ if (feeAmount !== undefined) {
1285
+ fee = {
1286
+ 'code': this.safeCurrencyCode (this.safeString (trade, 'feeCcy')),
1287
+ 'cost': feeAmount,
1288
+ };
1289
+ }
1290
+ const datetime = this.iso8601 (timestamp);
1291
+ return this.safeTrade ({
1292
+ 'info': trade,
1293
+ 'id': id,
1294
+ 'order': order,
1295
+ 'symbol': symbol,
1296
+ 'side': side,
1297
+ 'type': type,
1298
+ 'takerOrMaker': undefined,
1299
+ 'price': price,
1300
+ 'amount': amount,
1301
+ 'cost': undefined,
1302
+ 'fee': fee,
1303
+ 'timestamp': timestamp,
1304
+ 'datetime': datetime,
1305
+ }, market);
1306
+ }
1307
+
1308
+ async fetchTrades (symbol, limit = undefined, since = undefined, params = {}) {
1309
+ await this.loadMarkets ();
1310
+ const market = this.market (symbol);
1311
+ const request = {
1312
+ 'symbol': market['id'],
1313
+ };
1314
+ if (limit !== undefined) {
1315
+ request['limit'] = limit;
1316
+ }
1317
+ const [ marketType, query ] = this.handleMarketTypeAndParams ('fetchTrades', market, params);
1318
+ const method = this.getSupportedMapping (marketType, {
1319
+ 'spot': 'publicSpotGetMarketFills',
1320
+ 'swap': 'publicMixGetMarketFills',
1321
+ });
1322
+ const response = await this[method] (this.extend (request, query));
1323
+ //
1324
+ // {
1325
+ // code: '00000',
1326
+ // msg: 'success',
1327
+ // requestTime: '1645861382032',
1328
+ // data: [
1329
+ // {
1330
+ // symbol: 'BTCUSDT_SPBL',
1331
+ // tradeId: '881371996363608065',
1332
+ // side: 'sell',
1333
+ // fillPrice: '39123.05',
1334
+ // fillQuantity: '0.0363',
1335
+ // fillTime: '1645861379709'
1336
+ // }
1337
+ // ]
1338
+ // }
1339
+ //
1340
+ const data = this.safeValue (response, 'data', []);
1341
+ return this.parseTrades (data, market, since, limit);
1342
+ }
1343
+
1344
+ async fetchTradingFee (symbol, params = {}) {
1345
+ await this.loadMarkets ();
1346
+ const market = this.market (symbol);
1347
+ const request = {
1348
+ 'symbol': market['id'],
1349
+ };
1350
+ const response = await this.publicSpotGetPublicProduct (this.extend (request, params));
1351
+ //
1352
+ // {
1353
+ // code: '00000',
1354
+ // msg: 'success',
1355
+ // requestTime: '1646255374000',
1356
+ // data: {
1357
+ // symbol: 'ethusdt_SPBL',
1358
+ // symbolName: null,
1359
+ // baseCoin: 'ETH',
1360
+ // quoteCoin: 'USDT',
1361
+ // minTradeAmount: '0',
1362
+ // maxTradeAmount: '0',
1363
+ // takerFeeRate: '0.002',
1364
+ // makerFeeRate: '0.002',
1365
+ // priceScale: '2',
1366
+ // quantityScale: '4',
1367
+ // status: 'online'
1368
+ // }
1369
+ // }
1370
+ //
1371
+ const data = this.safeValue (response, 'data', {});
1372
+ return this.parseTradingFee (data, market);
1373
+ }
1374
+
1375
+ async fetchTradingFees (params = {}) {
1376
+ await this.loadMarkets ();
1377
+ const response = await this.publicSpotGetPublicProducts (params);
1378
+ //
1379
+ // {
1380
+ // code: '00000',
1381
+ // msg: 'success',
1382
+ // requestTime: '1646255662391',
1383
+ // data: [
1384
+ // {
1385
+ // symbol: 'ALPHAUSDT_SPBL',
1386
+ // symbolName: 'ALPHAUSDT',
1387
+ // baseCoin: 'ALPHA',
1388
+ // quoteCoin: 'USDT',
1389
+ // minTradeAmount: '2',
1390
+ // maxTradeAmount: '0',
1391
+ // takerFeeRate: '0.001',
1392
+ // makerFeeRate: '0.001',
1393
+ // priceScale: '4',
1394
+ // quantityScale: '4',
1395
+ // status: 'online'
1396
+ // },
1397
+ // ...
1398
+ // ]
1399
+ // }
1400
+ //
1401
+ const data = this.safeValue (response, 'data', []);
1402
+ const result = {};
1403
+ for (let i = 0; i < data.length; i++) {
1404
+ const feeInfo = data[i];
1405
+ const fee = this.parseTradingFee (feeInfo);
1406
+ const symbol = fee['symbol'];
1407
+ result[symbol] = fee;
1408
+ }
1409
+ return result;
1410
+ }
1411
+
1412
+ parseTradingFee (data, market = undefined) {
1413
+ const marketId = this.safeString (data, 'symbol');
1414
+ return {
1415
+ 'info': data,
1416
+ 'symbol': this.safeSymbol (marketId, market),
1417
+ 'maker': this.safeNumber (data, 'makerFeeRate'),
1418
+ 'taker': this.safeNumber (data, 'takerFeeRate'),
1419
+ };
1420
+ }
1421
+
1422
+ parseOHLCV (ohlcv, market = undefined, timeframe = '1m') {
1423
+ //
1424
+ // spot
1425
+ //
1426
+ // {
1427
+ // open: '57882.31',
1428
+ // high: '58967.24',
1429
+ // low: '57509.56',
1430
+ // close: '57598.96',
1431
+ // quoteVol: '439160536.605821',
1432
+ // baseVol: '7531.2927',
1433
+ // usdtVol: '439160536.605821',
1434
+ // ts: '1637337600000'
1435
+ // }
1436
+ //
1437
+ // swap
1438
+ //
1439
+ // [
1440
+ // "1645911960000",
1441
+ // "39406",
1442
+ // "39407",
1443
+ // "39374.5",
1444
+ // "39379",
1445
+ // "35.526",
1446
+ // "1399132.341"
1447
+ // ]
1448
+ //
1449
+ return [
1450
+ this.safeInteger2 (ohlcv, 0, 'ts'),
1451
+ this.safeNumber2 (ohlcv, 1, 'open'),
1452
+ this.safeNumber2 (ohlcv, 2, 'high'),
1453
+ this.safeNumber2 (ohlcv, 3, 'low'),
1454
+ this.safeNumber2 (ohlcv, 4, 'close'),
1455
+ this.safeNumber2 (ohlcv, 5, 'baseVol'),
1456
+ ];
1457
+ }
1458
+
1459
+ async fetchOHLCV (symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
1460
+ await this.loadMarkets ();
1461
+ const market = this.market (symbol);
1462
+ const request = {
1463
+ 'symbol': market['id'],
1464
+ };
1465
+ const [ marketType, query ] = this.handleMarketTypeAndParams ('fetchOHLCV', market, params);
1466
+ const method = this.getSupportedMapping (marketType, {
1467
+ 'spot': 'publicSpotGetMarketCandles',
1468
+ 'swap': 'publicMixGetMarketCandles',
1469
+ });
1470
+ if (market['type'] === 'spot') {
1471
+ request['period'] = this.timeframes['spot'][timeframe];
1472
+ if (limit !== undefined) {
1473
+ request['limit'] = limit;
1474
+ }
1475
+ if (since !== undefined) {
1476
+ request['after'] = since;
1477
+ }
1478
+ } else if (market['type'] === 'swap') {
1479
+ request['granularity'] = this.timeframes['swap'][timeframe];
1480
+ const duration = this.parseTimeframe (timeframe);
1481
+ const now = this.milliseconds ();
1482
+ if (limit === undefined) {
1483
+ limit = 100;
1484
+ }
1485
+ if (since === undefined) {
1486
+ request['startTime'] = now - (limit - 1) * (duration * 1000);
1487
+ request['endTime'] = now;
1488
+ } else {
1489
+ request['startTime'] = this.sum (since, duration * 1000);
1490
+ request['endTime'] = this.sum (since, limit * duration * 1000);
1491
+ }
1492
+ }
1493
+ const response = await this[method] (this.extend (request, query));
1494
+ // [ ["1645911960000","39406","39407","39374.5","39379","35.526","1399132.341"] ]
1495
+ const data = this.safeValue (response, 'data', response);
1496
+ return this.parseOHLCVs (data, market, timeframe, since, limit);
1497
+ }
1498
+
1499
+ async fetchBalance (params = {}) {
1500
+ await this.loadMarkets ();
1501
+ const [ marketType, query ] = this.handleMarketTypeAndParams ('fetchBalance', undefined, params);
1502
+ const method = this.getSupportedMapping (marketType, {
1503
+ 'spot': 'privateSpotGetAccountAssets',
1504
+ 'swap': 'privateMixGetAccountAccounts',
1505
+ });
1506
+ const request = {};
1507
+ if (marketType === 'swap') {
1508
+ const defaultSubType = this.safeString (this.options, 'defaultSubType');
1509
+ request['productType'] = (defaultSubType === 'linear') ? 'UMCBL' : 'DMCBL';
1510
+ }
1511
+ const response = await this[method] (this.extend (request, query));
1512
+ // spot
1513
+ // {
1514
+ // code: '00000',
1515
+ // msg: 'success',
1516
+ // requestTime: 1645928868827,
1517
+ // data: [
1518
+ // {
1519
+ // coinId: 1,
1520
+ // coinName: 'BTC',
1521
+ // available: '0.00070000',
1522
+ // frozen: '0.00000000',
1523
+ // lock: '0.00000000',
1524
+ // uTime: '1645921706000'
1525
+ // }
1526
+ // ]
1527
+ // }
1528
+ //
1529
+ // swap
1530
+ // {
1531
+ // code: '00000',
1532
+ // msg: 'success',
1533
+ // requestTime: 1645928929251,
1534
+ // data: [
1535
+ // {
1536
+ // marginCoin: 'USDT',
1537
+ // locked: '0',
1538
+ // available: '8.078525',
1539
+ // crossMaxAvailable: '8.078525',
1540
+ // fixedMaxAvailable: '8.078525',
1541
+ // maxTransferOut: '8.078525',
1542
+ // equity: '10.02508',
1543
+ // usdtEquity: '10.02508',
1544
+ // btcEquity: '0.00026057027'
1545
+ // }
1546
+ // ]
1547
+ // }
1548
+ const data = this.safeValue (response, 'data');
1549
+ return this.parseBalance (data);
1550
+ }
1551
+
1552
+ parseBalance (balance) {
1553
+ const result = { 'info': balance };
1554
+ for (let i = 0; i < balance.length; i++) {
1555
+ const entry = balance[i];
1556
+ const currencyId = this.safeString2 (entry, 'coinId', 'marginCoin');
1557
+ const code = this.safeCurrencyCode (currencyId);
1558
+ const account = this.account ();
1559
+ account['used'] = this.safeString2 (entry, 'lock', 'locked');
1560
+ account['free'] = this.safeString (entry, 'available');
1561
+ result[code] = account;
1562
+ }
1563
+ return this.safeBalance (result);
1564
+ }
1565
+
1566
+ parseOrderStatus (status) {
1567
+ const statuses = {
1568
+ 'new': 'open',
1569
+ 'full_fill': 'closed',
1570
+ 'filled': 'closed',
1571
+ };
1572
+ return this.safeString (statuses, status, status);
1573
+ }
1574
+
1575
+ parseOrder (order, market = undefined) {
1576
+ //
1577
+ // spot
1578
+ // {
1579
+ // accountId: '6394957606',
1580
+ // symbol: 'BTCUSDT_SPBL',
1581
+ // orderId: '881623995442958336',
1582
+ // clientOrderId: '135335e9-b054-4e43-b00a-499f11d3a5cc',
1583
+ // price: '39000.000000000000',
1584
+ // quantity: '0.000700000000',
1585
+ // orderType: 'limit',
1586
+ // side: 'buy',
1587
+ // status: 'new',
1588
+ // fillPrice: '0.000000000000',
1589
+ // fillQuantity: '0.000000000000',
1590
+ // fillTotalAmount: '0.000000000000',
1591
+ // cTime: '1645921460972'
1592
+ // }
1593
+ //
1594
+ // swap
1595
+ // {
1596
+ // symbol: 'BTCUSDT_UMCBL',
1597
+ // size: 0.001,
1598
+ // orderId: '881640729145409536',
1599
+ // clientOid: '881640729204129792',
1600
+ // filledQty: 0.001,
1601
+ // fee: 0,
1602
+ // price: null,
1603
+ // priceAvg: 38429.5,
1604
+ // state: 'filled',
1605
+ // side: 'open_long',
1606
+ // timeInForce: 'normal',
1607
+ // totalProfits: 0,
1608
+ // posSide: 'long',
1609
+ // marginCoin: 'USDT',
1610
+ // filledAmount: 38.4295,
1611
+ // orderType: 'market',
1612
+ // cTime: '1645925450611',
1613
+ // uTime: '1645925450746'
1614
+ // }
1615
+ //
1616
+ const marketId = this.safeString (order, 'symbol');
1617
+ market = this.safeMarket (marketId);
1618
+ const symbol = market['symbol'];
1619
+ const id = this.safeString (order, 'orderId');
1620
+ const price = this.safeString (order, 'price');
1621
+ const amount = this.safeString2 (order, 'quantity', 'size');
1622
+ const filled = this.safeString2 (order, 'fillQuantity', 'filledQty');
1623
+ const cost = this.safeString2 (order, 'fillTotalAmount', 'filledAmount');
1624
+ const average = this.safeString (order, 'fillPrice');
1625
+ const type = this.safeString (order, 'orderType');
1626
+ const timestamp = this.safeInteger (order, 'cTime');
1627
+ let side = this.safeString2 (order, 'side', 'posSide');
1628
+ if ((side === 'open_long') || (side === 'close_short')) {
1629
+ side = 'buy';
1630
+ } else {
1631
+ side = 'sell';
1632
+ }
1633
+ const clientOrderId = this.safeString2 (order, 'clientOrderId', 'clientOid');
1634
+ const fee = undefined;
1635
+ const rawStatus = this.safeString2 (order, 'status', 'state');
1636
+ const status = this.parseOrderStatus (rawStatus);
1637
+ const lastTradeTimestamp = this.safeInteger (order, 'uTime');
1638
+ return this.safeOrder ({
1639
+ 'info': order,
1640
+ 'id': id,
1641
+ 'clientOrderId': clientOrderId,
1642
+ 'timestamp': timestamp,
1643
+ 'datetime': this.iso8601 (timestamp),
1644
+ 'lastTradeTimestamp': lastTradeTimestamp,
1645
+ 'symbol': symbol,
1646
+ 'type': type,
1647
+ 'timeInForce': undefined,
1648
+ 'postOnly': undefined,
1649
+ 'side': side,
1650
+ 'price': price,
1651
+ 'stopPrice': undefined,
1652
+ 'average': average,
1653
+ 'cost': cost,
1654
+ 'amount': amount,
1655
+ 'filled': filled,
1656
+ 'remaining': undefined,
1657
+ 'status': status,
1658
+ 'fee': fee,
1659
+ 'trades': undefined,
1660
+ }, market);
1661
+ }
1662
+
1663
+ async createOrder (symbol, type, side, amount, price = undefined, params = {}) {
1664
+ await this.loadMarkets ();
1665
+ const market = this.market (symbol);
1666
+ const [ marketType, query ] = this.handleMarketTypeAndParams ('createOrder', market, params);
1667
+ const request = {
1668
+ 'symbol': market['id'],
1669
+ 'orderType': type,
1670
+ };
1671
+ if (type === 'limit') {
1672
+ request['price'] = price;
1673
+ }
1674
+ let clientOrderId = this.safeString2 (params, 'client_oid', 'clientOrderId');
1675
+ if (clientOrderId === undefined) {
1676
+ const broker = this.safeValue (this.options, 'broker');
1677
+ if (broker !== undefined) {
1678
+ const brokerId = this.safeString (broker, market['type']);
1679
+ if (brokerId !== undefined) {
1680
+ clientOrderId = brokerId + this.uuid22 ();
1681
+ }
1682
+ }
1683
+ }
1684
+ if (marketType === 'spot') {
1685
+ request['clientOrderId'] = clientOrderId;
1686
+ request['quantity'] = this.amountToPrecision (symbol, amount);
1687
+ request['side'] = side;
1688
+ request['force'] = 'gtc';
1689
+ } else {
1690
+ request['clientOid'] = clientOrderId;
1691
+ request['size'] = this.amountToPrecision (symbol, amount);
1692
+ const reduceOnly = this.safeValue (params, 'reduceOnly', false);
1693
+ if (reduceOnly) {
1694
+ request['side'] = (side === 'buy') ? 'close_short' : 'close_long';
1695
+ } else {
1696
+ request['side'] = (side === 'buy') ? 'open_long' : 'open_short';
1697
+ }
1698
+ request['marginCoin'] = market['settleId'];
1699
+ }
1700
+ const method = this.getSupportedMapping (marketType, {
1701
+ 'spot': 'privateSpotPostTradeOrders',
1702
+ 'swap': 'privateMixPostOrderPlaceOrder',
1703
+ });
1704
+ const response = await this[method] (this.extend (request, query));
1705
+ // spot
1706
+ // {"code":"00000","msg":"success","requestTime":1645932209602,"data":{"orderId":"881669078313766912","clientOrderId":"iauIBf#a45b595f96474d888d0ada"}}
1707
+ // swap
1708
+ const data = this.safeValue (response, 'data');
1709
+ return this.parseOrder (data, market);
1710
+ }
1711
+
1712
+ async cancelOrder (id, symbol = undefined, params = {}) {
1713
+ if (symbol === undefined) {
1714
+ throw new ArgumentsRequired (this.id + ' cancelOrder() requires a symbol argument for spot orders');
1715
+ }
1716
+ await this.loadMarkets ();
1717
+ const market = this.market (symbol);
1718
+ const [ marketType, query ] = this.handleMarketTypeAndParams ('cancelOrder', market, params);
1719
+ const method = this.getSupportedMapping (marketType, {
1720
+ 'spot': 'privateSpotPostTradeCancelOrder',
1721
+ 'swap': 'privateMixPostOrderCancelOrder',
1722
+ });
1723
+ const request = {
1724
+ 'symbol': market['id'],
1725
+ 'orderId': id,
1726
+ };
1727
+ if (marketType === 'swap') {
1728
+ request['marginCoin'] = market['settleId'];
1729
+ }
1730
+ const response = await this[method] (this.extend (request, query));
1731
+ return this.parseOrder (response, market);
1732
+ }
1733
+
1734
+ async cancelOrders (ids, symbol = undefined, params = {}) {
1735
+ if (symbol === undefined) {
1736
+ throw new ArgumentsRequired (this.id + ' cancelOrders() requires a symbol argument');
1737
+ }
1738
+ await this.loadMarkets ();
1739
+ const market = this.market (symbol);
1740
+ const type = this.safeString (params, 'type', market['type']);
1741
+ if (type === undefined) {
1742
+ throw new ArgumentsRequired (this.id + " cancelOrders() requires a type parameter (one of 'spot', 'swap').");
1743
+ }
1744
+ params = this.omit (params, 'type');
1745
+ const request = {};
1746
+ let method = undefined;
1747
+ if (type === 'spot') {
1748
+ method = 'apiPostOrderOrdersBatchcancel';
1749
+ request['method'] = 'batchcancel';
1750
+ const jsonIds = this.json (ids);
1751
+ const parts = jsonIds.split ('"');
1752
+ request['order_ids'] = parts.join ('');
1753
+ } else if (type === 'swap') {
1754
+ method = 'swapPostOrderCancelBatchOrders';
1755
+ request['symbol'] = market['id'];
1756
+ request['ids'] = ids;
1757
+ }
1758
+ const response = await this[method] (this.extend (request, params));
1759
+ //
1760
+ // spot
1761
+ //
1762
+ // {
1763
+ // "status": "ok",
1764
+ // "data": {
1765
+ // "success": [
1766
+ // "673451224205135872",
1767
+ // ],
1768
+ // "failed": [
1769
+ // {
1770
+ // "err-msg": "invalid record",
1771
+ // "order-id": "673451224205135873",
1772
+ // "err-code": "base record invalid"
1773
+ // }
1774
+ // ]
1775
+ // }
1776
+ // }
1777
+ //
1778
+ // swap
1779
+ //
1780
+ // {
1781
+ // "result":true,
1782
+ // "symbol":"cmt_btcusdt",
1783
+ // "order_ids":[
1784
+ // "258414711",
1785
+ // "478585558"
1786
+ // ],
1787
+ // "fail_infos":[
1788
+ // {
1789
+ // "order_id":"258414711",
1790
+ // "err_code":"401",
1791
+ // "err_msg":""
1792
+ // }
1793
+ // ]
1794
+ // }
1795
+ //
1796
+ return response;
1797
+ }
1798
+
1799
+ async fetchOrder (id, symbol = undefined, params = {}) {
1800
+ if (symbol === undefined) {
1801
+ throw new ArgumentsRequired (this.id + ' fetchOrder() requires a symbol argument');
1802
+ }
1803
+ await this.loadMarkets ();
1804
+ const market = this.market (symbol);
1805
+ const [ marketType, query ] = this.handleMarketTypeAndParams ('fetchOrder', market, params);
1806
+ const method = this.getSupportedMapping (marketType, {
1807
+ 'spot': 'privateSpotPostTradeOrderInfo',
1808
+ 'swap': 'privateMixGetOrderDetail',
1809
+ });
1810
+ const request = {
1811
+ 'symbol': market['id'],
1812
+ 'orderId': id,
1813
+ };
1814
+ const response = await this[method] (this.extend (request, query));
1815
+ // spot
1816
+ // {
1817
+ // code: '00000',
1818
+ // msg: 'success',
1819
+ // requestTime: '1645926849436',
1820
+ // data: [
1821
+ // {
1822
+ // accountId: '6394957606',
1823
+ // symbol: 'BTCUSDT_SPBL',
1824
+ // orderId: '881626139738935296',
1825
+ // clientOrderId: '525890c8-767e-4cd6-8585-38160ed7bb5e',
1826
+ // price: '38000.000000000000',
1827
+ // quantity: '0.000700000000',
1828
+ // orderType: 'limit',
1829
+ // side: 'buy',
1830
+ // status: 'new',
1831
+ // fillPrice: '0.000000000000',
1832
+ // fillQuantity: '0.000000000000',
1833
+ // fillTotalAmount: '0.000000000000',
1834
+ // cTime: '1645921972212'
1835
+ // }
1836
+ // ]
1837
+ // }
1838
+ //
1839
+ // swap
1840
+ // {
1841
+ // code: '00000',
1842
+ // msg: 'success',
1843
+ // requestTime: '1645926587877',
1844
+ // data: {
1845
+ // symbol: 'BTCUSDT_UMCBL',
1846
+ // size: '0.001',
1847
+ // orderId: '881640729145409536',
1848
+ // clientOid: '881640729204129792',
1849
+ // filledQty: '0.001',
1850
+ // fee: '0E-8',
1851
+ // price: null,
1852
+ // priceAvg: '38429.50',
1853
+ // state: 'filled',
1854
+ // side: 'open_long',
1855
+ // timeInForce: 'normal',
1856
+ // totalProfits: '0E-8',
1857
+ // posSide: 'long',
1858
+ // marginCoin: 'USDT',
1859
+ // filledAmount: '38.4295',
1860
+ // orderType: 'market',
1861
+ // cTime: '1645925450611',
1862
+ // uTime: '1645925450746'
1863
+ // }
1864
+ // }
1865
+ //
1866
+ const data = this.safeValue (response, 'data');
1867
+ const first = this.safeValue (data, 0, data);
1868
+ return this.parseOrder (first, market);
1869
+ }
1870
+
1871
+ async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
1872
+ if (symbol === undefined) {
1873
+ throw new ArgumentsRequired (this.id + ' fetchOpenOrders() requires a symbol argument');
1874
+ }
1875
+ await this.loadMarkets ();
1876
+ const market = this.market (symbol);
1877
+ const [ marketType, query ] = this.handleMarketTypeAndParams ('fetchOpenOrders', market, params);
1878
+ const request = {
1879
+ 'symbol': market['id'],
1880
+ };
1881
+ const method = this.getSupportedMapping (marketType, {
1882
+ 'spot': 'privateSpotPostTradeOpenOrders',
1883
+ 'swap': 'privateMixGetOrderCurrent',
1884
+ });
1885
+ const response = await this[method] (this.extend (request, query));
1886
+ //
1887
+ // spot
1888
+ // {
1889
+ // code: '00000',
1890
+ // msg: 'success',
1891
+ // requestTime: 1645921640193,
1892
+ // data: [
1893
+ // {
1894
+ // accountId: '6394957606',
1895
+ // symbol: 'BTCUSDT_SPBL',
1896
+ // orderId: '881623995442958336',
1897
+ // clientOrderId: '135335e9-b054-4e43-b00a-499f11d3a5cc',
1898
+ // price: '39000.000000000000',
1899
+ // quantity: '0.000700000000',
1900
+ // orderType: 'limit',
1901
+ // side: 'buy',
1902
+ // status: 'new',
1903
+ // fillPrice: '0.000000000000',
1904
+ // fillQuantity: '0.000000000000',
1905
+ // fillTotalAmount: '0.000000000000',
1906
+ // cTime: '1645921460972'
1907
+ // }
1908
+ // ]
1909
+ // }
1910
+ //
1911
+ // swap
1912
+ // {
1913
+ // code: '00000',
1914
+ // msg: 'success',
1915
+ // requestTime: 1645922324630,
1916
+ // data: [
1917
+ // {
1918
+ // symbol: 'BTCUSDT_UMCBL',
1919
+ // size: 0.001,
1920
+ // orderId: '881627074081226752',
1921
+ // clientOid: '881627074160918528',
1922
+ // filledQty: 0,
1923
+ // fee: 0,
1924
+ // price: 38000,
1925
+ // state: 'new',
1926
+ // side: 'open_long',
1927
+ // timeInForce: 'normal',
1928
+ // totalProfits: 0,
1929
+ // posSide: 'long',
1930
+ // marginCoin: 'USDT',
1931
+ // filledAmount: 0,
1932
+ // orderType: 'limit',
1933
+ // cTime: '1645922194995',
1934
+ // uTime: '1645922194995'
1935
+ // }
1936
+ // ]
1937
+ // }
1938
+ //
1939
+ const data = this.safeValue (response, 'data', []);
1940
+ return this.parseOrders (data, market, since, limit);
1941
+ }
1942
+
1943
+ async fetchClosedOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
1944
+ if (symbol === undefined) {
1945
+ throw new ArgumentsRequired (this.id + ' fetchClosedOrders() requires a symbol argument');
1946
+ }
1947
+ await this.loadMarkets ();
1948
+ const market = this.market (symbol);
1949
+ const [ marketType, query ] = this.handleMarketTypeAndParams ('fetchClosedOrders', market, params);
1950
+ const request = {
1951
+ 'symbol': market['id'],
1952
+ };
1953
+ const method = this.getSupportedMapping (marketType, {
1954
+ 'spot': 'privateSpotPostTradeHistory',
1955
+ 'swap': 'privateMixGetOrderHistory',
1956
+ });
1957
+ if (marketType === 'swap') {
1958
+ if (limit === undefined) {
1959
+ limit = 100;
1960
+ }
1961
+ request['pageSize'] = limit;
1962
+ if (since === undefined) {
1963
+ since = 0;
1964
+ }
1965
+ request['startTime'] = since;
1966
+ request['endTime'] = this.milliseconds ();
1967
+ }
1968
+ const response = await this[method] (this.extend (request, query));
1969
+ //
1970
+ // spot
1971
+ // {
1972
+ // code: '00000',
1973
+ // msg: 'success',
1974
+ // requestTime: 1645925335553,
1975
+ // data: [
1976
+ // {
1977
+ // accountId: '6394957606',
1978
+ // symbol: 'BTCUSDT_SPBL',
1979
+ // orderId: '881623995442958336',
1980
+ // clientOrderId: '135335e9-b054-4e43-b00a-499f11d3a5cc',
1981
+ // price: '39000.000000000000',
1982
+ // quantity: '0.000700000000',
1983
+ // orderType: 'limit',
1984
+ // side: 'buy',
1985
+ // status: 'full_fill',
1986
+ // fillPrice: '39000.000000000000',
1987
+ // fillQuantity: '0.000700000000',
1988
+ // fillTotalAmount: '27.300000000000',
1989
+ // cTime: '1645921460972'
1990
+ // }
1991
+ // ]
1992
+ // }
1993
+ //
1994
+ // swap
1995
+ // {
1996
+ // code: '00000',
1997
+ // msg: 'success',
1998
+ // requestTime: 1645925688701,
1999
+ // data: {
2000
+ // nextFlag: false,
2001
+ // endId: '881640729145409536',
2002
+ // orderList: [
2003
+ // {
2004
+ // symbol: 'BTCUSDT_UMCBL',
2005
+ // size: 0.001,
2006
+ // orderId: '881640729145409536',
2007
+ // clientOid: '881640729204129792',
2008
+ // filledQty: 0.001,
2009
+ // fee: 0,
2010
+ // price: null,
2011
+ // priceAvg: 38429.5,
2012
+ // state: 'filled',
2013
+ // side: 'open_long',
2014
+ // timeInForce: 'normal',
2015
+ // totalProfits: 0,
2016
+ // posSide: 'long',
2017
+ // marginCoin: 'USDT',
2018
+ // filledAmount: 38.4295,
2019
+ // orderType: 'market',
2020
+ // cTime: '1645925450611',
2021
+ // uTime: '1645925450746'
2022
+ // }
2023
+ // ]
2024
+ // }
2025
+ // }
2026
+ //
2027
+ const data = this.safeValue (response, 'data');
2028
+ const orderList = this.safeValue (data, 'orderList', data);
2029
+ return this.parseOrders (orderList, market, since, limit);
2030
+ }
2031
+
2032
+ async fetchLedger (code = undefined, since = undefined, limit = undefined, params = {}) {
2033
+ await this.loadMarkets ();
2034
+ let currency = undefined;
2035
+ const request = {};
2036
+ if (code !== undefined) {
2037
+ currency = this.currency (code);
2038
+ request['coinId'] = currency['id'];
2039
+ }
2040
+ const response = await this.privateSpotPostAccountBills (this.extend (request, params));
2041
+ //
2042
+ // {
2043
+ // code: '00000',
2044
+ // msg: 'success',
2045
+ // requestTime: '1645929886887',
2046
+ // data: [
2047
+ // {
2048
+ // billId: '881626974170554368',
2049
+ // coinId: '2',
2050
+ // coinName: 'USDT',
2051
+ // groupType: 'transfer',
2052
+ // bizType: 'transfer-out',
2053
+ // quantity: '-10.00000000',
2054
+ // balance: '73.36005300',
2055
+ // fees: '0.00000000',
2056
+ // cTime: '1645922171146'
2057
+ // }
2058
+ // ]
2059
+ // }
2060
+ //
2061
+ const data = this.safeValue (response, 'data');
2062
+ return this.parseLedger (data, currency, since, limit);
2063
+ }
2064
+
2065
+ parseLedgerEntry (item, currency = undefined) {
2066
+ //
2067
+ // {
2068
+ // billId: '881626974170554368',
2069
+ // coinId: '2',
2070
+ // coinName: 'USDT',
2071
+ // groupType: 'transfer',
2072
+ // bizType: 'transfer-out',
2073
+ // quantity: '-10.00000000',
2074
+ // balance: '73.36005300',
2075
+ // fees: '0.00000000',
2076
+ // cTime: '1645922171146'
2077
+ // }
2078
+ //
2079
+ const id = this.safeString (item, 'billId');
2080
+ const currencyId = this.safeString (item, 'coinId');
2081
+ const code = this.safeCurrencyCode (currencyId);
2082
+ const amount = this.parseNumber (Precise.stringAbs (this.safeString (item, 'quantity')));
2083
+ const timestamp = this.safeInteger (item, 'cTime');
2084
+ const bizType = this.safeString (item, 'bizType');
2085
+ let direction = undefined;
2086
+ if (bizType !== undefined) {
2087
+ const parts = bizType.split ('-');
2088
+ direction = parts[1];
2089
+ }
2090
+ const type = this.safeString (item, 'groupType');
2091
+ const fee = this.safeNumber (item, 'fees');
2092
+ const after = this.safeNumber (item, 'balance');
2093
+ return {
2094
+ 'info': item,
2095
+ 'id': id,
2096
+ 'timestamp': timestamp,
2097
+ 'datetime': this.iso8601 (timestamp),
2098
+ 'direction': direction,
2099
+ 'account': undefined,
2100
+ 'referenceId': undefined,
2101
+ 'referenceAccount': undefined,
2102
+ 'type': type,
2103
+ 'currency': code,
2104
+ 'amount': amount,
2105
+ 'before': undefined,
2106
+ 'after': after,
2107
+ 'status': undefined,
2108
+ 'fee': fee,
2109
+ };
2110
+ }
2111
+
2112
+ async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) {
2113
+ if (symbol === undefined) {
2114
+ throw new ArgumentsRequired (this.id + ' fetchMyTrades() requires a symbol argument');
2115
+ }
2116
+ await this.loadMarkets ();
2117
+ const market = this.market (symbol);
2118
+ if (market['swap']) {
2119
+ throw new BadSymbol (this.id + ' fetchMyTrades() only supports spot markets');
2120
+ }
2121
+ const request = {
2122
+ 'symbol': market['id'],
2123
+ };
2124
+ if (limit !== undefined) {
2125
+ request['limit'] = limit;
2126
+ }
2127
+ const response = await this.privateSpotPostTradeFills (this.extend (request, params));
2128
+ //
2129
+ // {
2130
+ // code: '00000',
2131
+ // msg: 'success',
2132
+ // requestTime: '1645918954082',
2133
+ // data: [
2134
+ // {
2135
+ // accountId: '6394957606',
2136
+ // symbol: 'LTCUSDT_SPBL',
2137
+ // orderId: '864752115272552448',
2138
+ // fillId: '864752115685969921',
2139
+ // orderType: 'limit',
2140
+ // side: 'buy',
2141
+ // fillPrice: '127.92000000',
2142
+ // fillQuantity: '0.10000000',
2143
+ // fillTotalAmount: '12.79200000',
2144
+ // feeCcy: 'LTC',
2145
+ // fees: '0.00000000',
2146
+ // cTime: '1641898891373'
2147
+ // }
2148
+ // ]
2149
+ // }
2150
+ //
2151
+ const data = this.safeValue (response, 'data');
2152
+ return this.parseTrades (data, market, since, limit);
2153
+ }
2154
+
2155
+ async fetchOrderTrades (id, symbol = undefined, since = undefined, limit = undefined, params = {}) {
2156
+ if (symbol === undefined) {
2157
+ throw new ArgumentsRequired (this.id + ' fetchOrderTrades() requires a symbol argument');
2158
+ }
2159
+ await this.loadMarkets ();
2160
+ const market = this.market (symbol);
2161
+ const [ marketType, query ] = this.handleMarketTypeAndParams ('fetchOrderTrades', market, params);
2162
+ const method = this.getSupportedMapping (marketType, {
2163
+ 'spot': 'privateSpotPostTradeFills',
2164
+ 'swap': 'privateMixGetOrderFills',
2165
+ });
2166
+ const request = {
2167
+ 'symbol': market['id'],
2168
+ 'orderId': id,
2169
+ };
2170
+ const response = await this[method] (this.extend (request, query));
2171
+ // spot
2172
+ //
2173
+ // swap
2174
+ // {
2175
+ // code: '00000',
2176
+ // msg: 'success',
2177
+ // requestTime: 1645927862710,
2178
+ // data: [
2179
+ // {
2180
+ // tradeId: '881640729552281602',
2181
+ // symbol: 'BTCUSDT_UMCBL',
2182
+ // orderId: '881640729145409536',
2183
+ // price: '38429.50',
2184
+ // sizeQty: '0.001',
2185
+ // fee: '0',
2186
+ // side: 'open_long',
2187
+ // fillAmount: '38.4295',
2188
+ // profit: '0',
2189
+ // cTime: '1645925450694'
2190
+ // }
2191
+ // ]
2192
+ // }
2193
+ //
2194
+ const data = this.safeValue (response, 'data');
2195
+ return await this.parseTrades (data, market, since, limit);
2196
+ }
2197
+
2198
+ async fetchPosition (symbol, params = {}) {
2199
+ await this.loadMarkets ();
2200
+ const market = this.market (symbol);
2201
+ const request = {
2202
+ 'symbol': market['id'],
2203
+ 'marginCoin': market['settleId'],
2204
+ };
2205
+ const response = await this.privateMixGetPositionSinglePosition (this.extend (request, params));
2206
+ //
2207
+ // {
2208
+ // code: '00000',
2209
+ // msg: 'success',
2210
+ // requestTime: '1645933957584',
2211
+ // data: [
2212
+ // {
2213
+ // marginCoin: 'USDT',
2214
+ // symbol: 'BTCUSDT_UMCBL',
2215
+ // holdSide: 'long',
2216
+ // openDelegateCount: '0',
2217
+ // margin: '1.921475',
2218
+ // available: '0.001',
2219
+ // locked: '0',
2220
+ // total: '0.001',
2221
+ // leverage: '20',
2222
+ // achievedProfits: '0',
2223
+ // averageOpenPrice: '38429.5',
2224
+ // marginMode: 'fixed',
2225
+ // holdMode: 'double_hold',
2226
+ // unrealizedPL: '0.1634',
2227
+ // liquidationPrice: '0',
2228
+ // keepMarginRate: '0.004',
2229
+ // cTime: '1645922194988'
2230
+ // }
2231
+ // ]
2232
+ // }
2233
+ //
2234
+ return response;
2235
+ }
2236
+
2237
+ async fetchPositions (symbols = undefined, params = {}) {
2238
+ await this.loadMarkets ();
2239
+ const defaultSubType = this.safeString (this.options, 'defaultSubType');
2240
+ const request = {
2241
+ 'productType': (defaultSubType === 'linear') ? 'UMCBL' : 'DMCBL',
2242
+ };
2243
+ const response = await this.privateMixGetPositionAllPosition (this.extend (request, params));
2244
+ //
2245
+ // {
2246
+ // code: '00000',
2247
+ // msg: 'success',
2248
+ // requestTime: '1645933905060',
2249
+ // data: [
2250
+ // {
2251
+ // marginCoin: 'USDT',
2252
+ // symbol: 'BTCUSDT_UMCBL',
2253
+ // holdSide: 'long',
2254
+ // openDelegateCount: '0',
2255
+ // margin: '1.921475',
2256
+ // available: '0.001',
2257
+ // locked: '0',
2258
+ // total: '0.001',
2259
+ // leverage: '20',
2260
+ // achievedProfits: '0',
2261
+ // averageOpenPrice: '38429.5',
2262
+ // marginMode: 'fixed',
2263
+ // holdMode: 'double_hold',
2264
+ // unrealizedPL: '0.14869',
2265
+ // liquidationPrice: '0',
2266
+ // keepMarginRate: '0.004',
2267
+ // cTime: '1645922194988'
2268
+ // }
2269
+ // ]
2270
+ // }
2271
+ return response;
2272
+ }
2273
+
2274
+ sign (path, api = [], method = 'GET', params = {}, headers = undefined, body = undefined) {
2275
+ const signed = api[0] === 'private';
2276
+ const endpoint = api[1];
2277
+ const pathPart = (endpoint === 'spot') ? '/api/spot/v1' : '/api/mix/v1';
2278
+ const request = '/' + this.implodeParams (path, params);
2279
+ const payload = pathPart + request;
2280
+ let url = this.implodeHostname (this.urls['api'][endpoint]) + payload;
2281
+ const query = this.omit (params, this.extractParams (path));
2282
+ if (!signed && (method === 'GET')) {
2283
+ const keys = Object.keys (query);
2284
+ if (keys.length) {
2285
+ url = url + '?' + this.urlencode (query);
2286
+ }
2287
+ }
2288
+ if (signed) {
2289
+ this.checkRequiredCredentials ();
2290
+ const timestamp = this.milliseconds ().toString ();
2291
+ let auth = timestamp + method + payload;
2292
+ if (method === 'POST') {
2293
+ body = this.json (params);
2294
+ auth += body;
2295
+ } else {
2296
+ if (Object.keys (params).length) {
2297
+ const query = '?' + this.urlencode (this.keysort (params));
2298
+ url += query;
2299
+ auth += query;
2300
+ }
2301
+ }
2302
+ const signature = this.hmac (this.encode (auth), this.encode (this.secret), 'sha256', 'base64');
2303
+ headers = {
2304
+ 'ACCESS-KEY': this.apiKey,
2305
+ 'ACCESS-SIGN': signature,
2306
+ 'ACCESS-TIMESTAMP': timestamp,
2307
+ 'ACCESS-PASSPHRASE': this.password,
2308
+ };
2309
+ if (method === 'POST') {
2310
+ headers['Content-Type'] = 'application/json';
2311
+ }
2312
+ }
2313
+ return { 'url': url, 'method': method, 'body': body, 'headers': headers };
2314
+ }
2315
+
2316
+ async setLeverage (leverage, symbol = undefined, params = {}) {
2317
+ if (symbol === undefined) {
2318
+ throw new ArgumentsRequired (this.id + ' setLeverage() requires a symbol argument');
2319
+ }
2320
+ const holdSide = this.safeString (params, 'holdSide');
2321
+ if (holdSide === undefined) {
2322
+ throw new ArgumentsRequired (this.id + ' setLeverage() requires a holdSide param');
2323
+ }
2324
+ await this.loadMarkets ();
2325
+ const market = this.market (symbol);
2326
+ const request = {
2327
+ 'symbol': market['id'],
2328
+ 'marginCoin': market['settleId'],
2329
+ 'leverage': leverage,
2330
+ 'holdSide': holdSide,
2331
+ };
2332
+ return await this.privateMixPostAccountSetLeverage (this.extend (request, params));
2333
+ }
2334
+
2335
+ async setMarginMode (marginType, symbol = undefined, params = {}) {
2336
+ if (symbol === undefined) {
2337
+ throw new ArgumentsRequired (this.id + ' setMarginMode() requires a symbol argument');
2338
+ }
2339
+ marginType = marginType.toLowerCase ();
2340
+ if ((marginType !== 'fixed') && (marginType !== 'crossed')) {
2341
+ throw new ArgumentsRequired (this.id + ' setMarginMode() marginType must be "fixed" or "crossed"');
2342
+ }
2343
+ await this.loadMarkets ();
2344
+ const market = this.market (symbol);
2345
+ const request = {
2346
+ 'symbol': market['id'],
2347
+ 'marginCoin': market['settleId'],
2348
+ 'marginMode': marginType,
2349
+ };
2350
+ return await this.privateMixPostAccountSetMarginMode (this.extend (request, params));
2351
+ }
2352
+
2353
+ handleErrors (code, reason, url, method, headers, body, response, requestHeaders, requestBody) {
2354
+ if (!response) {
2355
+ return; // fallback to default error handler
2356
+ }
2357
+ //
2358
+ // spot
2359
+ //
2360
+ // {"status":"fail","err_code":"01001","err_msg":"系统异常,请稍后重试"}
2361
+ // {"status":"error","ts":1595594160149,"err_code":"invalid-parameter","err_msg":"invalid size, valid range: [1,2000]"}
2362
+ // {"status":"error","ts":1595684716042,"err_code":"invalid-parameter","err_msg":"illegal sign invalid"}
2363
+ // {"status":"error","ts":1595700216275,"err_code":"bad-request","err_msg":"your balance is low!"}
2364
+ // {"status":"error","ts":1595700344504,"err_code":"invalid-parameter","err_msg":"invalid type"}
2365
+ // {"status":"error","ts":1595703343035,"err_code":"bad-request","err_msg":"order cancel fail"}
2366
+ // {"status":"error","ts":1595704360508,"err_code":"invalid-parameter","err_msg":"accesskey not null"}
2367
+ // {"status":"error","ts":1595704490084,"err_code":"invalid-parameter","err_msg":"permissions not right"}
2368
+ // {"status":"error","ts":1595711862763,"err_code":"system exception","err_msg":"system exception"}
2369
+ // {"status":"error","ts":1595730308979,"err_code":"bad-request","err_msg":"20003"}
2370
+ //
2371
+ // swap
2372
+ //
2373
+ // {"code":"40015","msg":"","requestTime":1595698564931,"data":null}
2374
+ // {"code":"40017","msg":"Order id must not be blank","requestTime":1595702477835,"data":null}
2375
+ // {"code":"40017","msg":"Order Type must not be blank","requestTime":1595698516162,"data":null}
2376
+ // {"code":"40301","msg":"","requestTime":1595667662503,"data":null}
2377
+ // {"code":"40017","msg":"Contract code must not be blank","requestTime":1595703151651,"data":null}
2378
+ // {"code":"40108","msg":"","requestTime":1595885064600,"data":null}
2379
+ // {"order_id":"513468410013679613","client_oid":null,"symbol":"ethusd","result":false,"err_code":"order_no_exist_error","err_msg":"订单不存在!"}
2380
+ //
2381
+ const message = this.safeString (response, 'err_msg');
2382
+ const errorCode = this.safeString2 (response, 'code', 'err_code');
2383
+ const feedback = this.id + ' ' + body;
2384
+ const nonEmptyMessage = ((message !== undefined) && (message !== ''));
2385
+ if (nonEmptyMessage) {
2386
+ this.throwExactlyMatchedException (this.exceptions['exact'], message, feedback);
2387
+ this.throwBroadlyMatchedException (this.exceptions['broad'], message, feedback);
2388
+ }
2389
+ const nonZeroErrorCode = (errorCode !== undefined) && (errorCode !== '00000');
2390
+ if (nonZeroErrorCode) {
2391
+ this.throwExactlyMatchedException (this.exceptions['exact'], errorCode, feedback);
2392
+ }
2393
+ if (nonZeroErrorCode || nonEmptyMessage) {
2394
+ throw new ExchangeError (feedback); // unknown message
2395
+ }
2396
+ }
2397
+ };