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.
- package/.cache/eslintcache +1 -0
- package/.dockerignore +6 -0
- package/.eslintignore +1 -0
- package/.gitattributes +5 -0
- package/.readthedocs.yaml +16 -0
- package/CONTRIBUTING.md +1049 -0
- package/LICENSE.txt +21 -0
- package/README.md +537 -0
- package/SECURITY.md +5 -0
- package/build/cleanup-old-tags.js +94 -0
- package/build/countries.js +256 -0
- package/build/export-exchanges.js +520 -0
- package/build/fs.js +51 -0
- package/build/transpile.js +1772 -0
- package/build/vss.js +78 -0
- package/ccxt.browser.js +7 -0
- package/ccxt.d.ts +692 -0
- package/ccxt.js +171 -0
- package/cleanup.sh +2 -0
- package/composer-install.sh +20 -0
- package/dist/ccxt.browser.js +208383 -0
- package/gource.sh +3 -0
- package/index.html +7 -0
- package/js/.eslintrc +87 -0
- package/js/aax.js +2686 -0
- package/js/ascendex.js +2584 -0
- package/js/base/.eslintrc.js +43 -0
- package/js/base/Exchange.js +2371 -0
- package/js/base/Precise.js +283 -0
- package/js/base/errorHierarchy.js +47 -0
- package/js/base/errors.js +55 -0
- package/js/base/functions/crypto.js +158 -0
- package/js/base/functions/encode.js +118 -0
- package/js/base/functions/generic.js +270 -0
- package/js/base/functions/misc.js +138 -0
- package/js/base/functions/number.js +329 -0
- package/js/base/functions/platform.js +38 -0
- package/js/base/functions/string.js +21 -0
- package/js/base/functions/throttle.js +79 -0
- package/js/base/functions/time.js +210 -0
- package/js/base/functions/type.js +66 -0
- package/js/base/functions.js +28 -0
- package/js/bequant.js +32 -0
- package/js/bibox.js +1407 -0
- package/js/bigone.js +1366 -0
- package/js/binance.js +5652 -0
- package/js/binancecoinm.js +46 -0
- package/js/binanceus.js +46 -0
- package/js/binanceusdm.js +49 -0
- package/js/bit2c.js +535 -0
- package/js/bitbank.js +842 -0
- package/js/bitbay.js +16 -0
- package/js/bitbns.js +1073 -0
- package/js/bitcoincom.js +15 -0
- package/js/bitfinex.js +1433 -0
- package/js/bitfinex2.js +2025 -0
- package/js/bitflyer.js +840 -0
- package/js/bitforex.js +614 -0
- package/js/bitget.js +2397 -0
- package/js/bithumb.js +980 -0
- package/js/bitmart.js +2516 -0
- package/js/bitmex.js +1809 -0
- package/js/bitopro.js +1443 -0
- package/js/bitpanda.js +1782 -0
- package/js/bitrue.js +1747 -0
- package/js/bitso.js +1062 -0
- package/js/bitstamp.js +1757 -0
- package/js/bitstamp1.js +343 -0
- package/js/bittrex.js +1876 -0
- package/js/bitvavo.js +1579 -0
- package/js/bkex.js +1233 -0
- package/js/bl3p.js +346 -0
- package/js/blockchaincom.js +969 -0
- package/js/btcalpha.js +680 -0
- package/js/btcbox.js +477 -0
- package/js/btcmarkets.js +1022 -0
- package/js/btctradeua.js +466 -0
- package/js/btcturk.js +734 -0
- package/js/buda.js +946 -0
- package/js/bw.js +1265 -0
- package/js/bybit.js +3372 -0
- package/js/bytetrade.js +1336 -0
- package/js/cdax.js +1646 -0
- package/js/cex.js +1410 -0
- package/js/coinbase.js +1342 -0
- package/js/coinbaseprime.js +31 -0
- package/js/coinbasepro.js +1466 -0
- package/js/coincheck.js +755 -0
- package/js/coinex.js +3400 -0
- package/js/coinfalcon.js +880 -0
- package/js/coinmate.js +794 -0
- package/js/coinone.js +816 -0
- package/js/coinspot.js +345 -0
- package/js/crex24.js +1636 -0
- package/js/cryptocom.js +1832 -0
- package/js/currencycom.js +1748 -0
- package/js/delta.js +1547 -0
- package/js/deribit.js +2148 -0
- package/js/digifinex.js +1585 -0
- package/js/eqonex.js +1660 -0
- package/js/exmo.js +1670 -0
- package/js/fairdesk.js +1231 -0
- package/js/flowbtc.js +35 -0
- package/js/fmfwio.js +34 -0
- package/js/ftx.js +2751 -0
- package/js/ftxus.js +38 -0
- package/js/gateio.js +4174 -0
- package/js/gemini.js +1397 -0
- package/js/hitbtc.js +1343 -0
- package/js/hitbtc3.js +2329 -0
- package/js/hollaex.js +1486 -0
- package/js/huobi.js +5706 -0
- package/js/huobijp.js +1710 -0
- package/js/huobipro.js +18 -0
- package/js/idex.js +1439 -0
- package/js/independentreserve.js +649 -0
- package/js/indodax.js +742 -0
- package/js/itbit.js +722 -0
- package/js/kraken.js +2179 -0
- package/js/kucoin.js +2571 -0
- package/js/kucoinfutures.js +1771 -0
- package/js/kuna.js +809 -0
- package/js/latoken.js +1445 -0
- package/js/lbank.js +760 -0
- package/js/liquid.js +1432 -0
- package/js/luno.js +873 -0
- package/js/lykke.js +1147 -0
- package/js/mercado.js +771 -0
- package/js/mexc.js +3151 -0
- package/js/ndax.js +2233 -0
- package/js/novadax.js +1318 -0
- package/js/oceanex.js +816 -0
- package/js/okcoin.js +3841 -0
- package/js/okex.js +16 -0
- package/js/okex5.js +16 -0
- package/js/okx.js +4795 -0
- package/js/paymium.js +498 -0
- package/js/phemex.js +2957 -0
- package/js/poloniex.js +1674 -0
- package/js/probit.js +1346 -0
- package/js/qtrade.js +1588 -0
- package/js/ripio.js +1061 -0
- package/js/static_dependencies/BN/bn.js +3526 -0
- package/js/static_dependencies/README.md +1 -0
- package/js/static_dependencies/crypto-js/crypto-js.js +5988 -0
- package/js/static_dependencies/elliptic/lib/elliptic/curve/base.js +375 -0
- package/js/static_dependencies/elliptic/lib/elliptic/curve/edwards.js +433 -0
- package/js/static_dependencies/elliptic/lib/elliptic/curve/index.js +8 -0
- package/js/static_dependencies/elliptic/lib/elliptic/curve/mont.js +180 -0
- package/js/static_dependencies/elliptic/lib/elliptic/curve/short.js +938 -0
- package/js/static_dependencies/elliptic/lib/elliptic/curves.js +204 -0
- package/js/static_dependencies/elliptic/lib/elliptic/ec/index.js +240 -0
- package/js/static_dependencies/elliptic/lib/elliptic/ec/key.js +119 -0
- package/js/static_dependencies/elliptic/lib/elliptic/ec/signature.js +24 -0
- package/js/static_dependencies/elliptic/lib/elliptic/eddsa/index.js +145 -0
- package/js/static_dependencies/elliptic/lib/elliptic/eddsa/key.js +100 -0
- package/js/static_dependencies/elliptic/lib/elliptic/eddsa/signature.js +65 -0
- package/js/static_dependencies/elliptic/lib/elliptic/precomputed/secp256k1.js +780 -0
- package/js/static_dependencies/elliptic/lib/elliptic/utils.js +214 -0
- package/js/static_dependencies/elliptic/lib/elliptic.js +22 -0
- package/js/static_dependencies/elliptic/lib/hmac-drbg/hmac-drbg.js +114 -0
- package/js/static_dependencies/fetch-ponyfill/fetch-node.js +39 -0
- package/js/static_dependencies/node-fetch/index.js +1564 -0
- package/js/static_dependencies/node-rsa/NodeRSA.js +223 -0
- package/js/static_dependencies/node-rsa/asn1/ber/errors.js +13 -0
- package/js/static_dependencies/node-rsa/asn1/ber/index.js +21 -0
- package/js/static_dependencies/node-rsa/asn1/ber/reader.js +262 -0
- package/js/static_dependencies/node-rsa/asn1/ber/types.js +36 -0
- package/js/static_dependencies/node-rsa/asn1/index.js +17 -0
- package/js/static_dependencies/node-rsa/encryptEngines/js.js +34 -0
- package/js/static_dependencies/node-rsa/formats/components.js +71 -0
- package/js/static_dependencies/node-rsa/formats/formats.js +31 -0
- package/js/static_dependencies/node-rsa/formats/pkcs1.js +148 -0
- package/js/static_dependencies/node-rsa/formats/pkcs8.js +187 -0
- package/js/static_dependencies/node-rsa/libs/jsbn.js +1252 -0
- package/js/static_dependencies/node-rsa/libs/rsa.js +147 -0
- package/js/static_dependencies/node-rsa/schemes/pkcs1.js +176 -0
- package/js/static_dependencies/node-rsa/schemes/schemes.js +21 -0
- package/js/static_dependencies/node-rsa/utils.js +98 -0
- package/js/static_dependencies/qs/formats.js +18 -0
- package/js/static_dependencies/qs/index.js +11 -0
- package/js/static_dependencies/qs/parse.js +242 -0
- package/js/static_dependencies/qs/stringify.js +269 -0
- package/js/static_dependencies/qs/utils.js +230 -0
- package/js/stex.js +1925 -0
- package/js/test/.eslintrc.js +42 -0
- package/js/test/Exchange/test.balance.js +61 -0
- package/js/test/Exchange/test.borrowRate.js +32 -0
- package/js/test/Exchange/test.currency.js +52 -0
- package/js/test/Exchange/test.fetchBalance.js +23 -0
- package/js/test/Exchange/test.fetchBorrowInterest.js +59 -0
- package/js/test/Exchange/test.fetchBorrowRate.js +32 -0
- package/js/test/Exchange/test.fetchBorrowRates.js +28 -0
- package/js/test/Exchange/test.fetchClosedOrders.js +32 -0
- package/js/test/Exchange/test.fetchCurrencies.js +35 -0
- package/js/test/Exchange/test.fetchDeposits.js +31 -0
- package/js/test/Exchange/test.fetchFundingFees.js +19 -0
- package/js/test/Exchange/test.fetchFundingRateHistory.js +40 -0
- package/js/test/Exchange/test.fetchL2OrderBook.js +23 -0
- package/js/test/Exchange/test.fetchLedger.js +42 -0
- package/js/test/Exchange/test.fetchLeverageTiers.js +33 -0
- package/js/test/Exchange/test.fetchMarketLeverageTiers.js +22 -0
- package/js/test/Exchange/test.fetchMarkets.js +33 -0
- package/js/test/Exchange/test.fetchMyTrades.js +42 -0
- package/js/test/Exchange/test.fetchOHLCV.js +46 -0
- package/js/test/Exchange/test.fetchOpenOrders.js +36 -0
- package/js/test/Exchange/test.fetchOrderBook.js +25 -0
- package/js/test/Exchange/test.fetchOrderBooks.js +35 -0
- package/js/test/Exchange/test.fetchOrders.js +41 -0
- package/js/test/Exchange/test.fetchPositions.js +47 -0
- package/js/test/Exchange/test.fetchStatus.js +35 -0
- package/js/test/Exchange/test.fetchTicker.js +38 -0
- package/js/test/Exchange/test.fetchTickers.js +49 -0
- package/js/test/Exchange/test.fetchTrades.js +39 -0
- package/js/test/Exchange/test.fetchTradingFee.js +18 -0
- package/js/test/Exchange/test.fetchTradingFees.js +22 -0
- package/js/test/Exchange/test.fetchTransactions.js +31 -0
- package/js/test/Exchange/test.fetchWithdrawals.js +31 -0
- package/js/test/Exchange/test.ledgerItem.js +46 -0
- package/js/test/Exchange/test.leverageTier.js +33 -0
- package/js/test/Exchange/test.loadMarkets.js +35 -0
- package/js/test/Exchange/test.market.js +129 -0
- package/js/test/Exchange/test.ohlcv.js +33 -0
- package/js/test/Exchange/test.order.js +62 -0
- package/js/test/Exchange/test.orderbook.js +61 -0
- package/js/test/Exchange/test.position.js +21 -0
- package/js/test/Exchange/test.throttle.js +94 -0
- package/js/test/Exchange/test.ticker.js +95 -0
- package/js/test/Exchange/test.trade.js +68 -0
- package/js/test/Exchange/test.tradingFee.js +34 -0
- package/js/test/Exchange/test.transaction.js +35 -0
- package/js/test/base/.eslintrc +38 -0
- package/js/test/base/functions/test.crypto.js +110 -0
- package/js/test/base/functions/test.datetime.js +62 -0
- package/js/test/base/functions/test.generic.js +152 -0
- package/js/test/base/functions/test.number.js +362 -0
- package/js/test/base/functions/test.time.js +56 -0
- package/js/test/base/functions/test.type.js +53 -0
- package/js/test/base/test.base.js +193 -0
- package/js/test/errors/test.InsufficientFunds.js +86 -0
- package/js/test/errors/test.InvalidNonce.js +64 -0
- package/js/test/errors/test.InvalidOrder.js +35 -0
- package/js/test/errors/test.OrderNotFound.js +39 -0
- package/js/test/test.js +426 -0
- package/js/test/test.timeout_hang.js +12 -0
- package/js/therock.js +1431 -0
- package/js/tidebit.js +632 -0
- package/js/tidex.js +939 -0
- package/js/timex.js +1283 -0
- package/js/upbit.js +1622 -0
- package/js/vcc.js +1353 -0
- package/js/wavesexchange.js +2185 -0
- package/js/wazirx.js +732 -0
- package/js/whitebit.js +1352 -0
- package/js/woo.js +1577 -0
- package/js/xena.js +1948 -0
- package/js/yobit.js +1129 -0
- package/js/zaif.js +647 -0
- package/js/zb.js +4088 -0
- package/js/zipmex.js +40 -0
- package/js/zonda.js +1497 -0
- package/multilang.sh +159 -0
- package/package.json +591 -0
- package/postinstall.js +103 -0
package/js/mexc.js
ADDED
|
@@ -0,0 +1,3151 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
|
|
5
|
+
const Exchange = require ('./base/Exchange');
|
|
6
|
+
const { AccountNotEnabled, InvalidAddress, ExchangeError, BadRequest, AuthenticationError, RateLimitExceeded, BadSymbol, InvalidOrder, InsufficientFunds, ArgumentsRequired, OrderNotFound, PermissionDenied, NotSupported } = require ('./base/errors');
|
|
7
|
+
const { TICK_SIZE } = require ('./base/functions/number');
|
|
8
|
+
const Precise = require ('./base/Precise');
|
|
9
|
+
|
|
10
|
+
// ---------------------------------------------------------------------------
|
|
11
|
+
|
|
12
|
+
module.exports = class mexc extends Exchange {
|
|
13
|
+
describe () {
|
|
14
|
+
return this.deepExtend (super.describe (), {
|
|
15
|
+
'id': 'mexc',
|
|
16
|
+
'name': 'MEXC Global',
|
|
17
|
+
'countries': [ 'SC' ], // Seychelles
|
|
18
|
+
'rateLimit': 50, // default rate limit is 20 times per second
|
|
19
|
+
'version': 'v2',
|
|
20
|
+
'certified': true,
|
|
21
|
+
'has': {
|
|
22
|
+
'CORS': undefined,
|
|
23
|
+
'spot': true,
|
|
24
|
+
'margin': undefined, // has but unimplemented
|
|
25
|
+
'swap': true,
|
|
26
|
+
'future': false,
|
|
27
|
+
'option': false,
|
|
28
|
+
'addMargin': true,
|
|
29
|
+
'cancelAllOrders': true,
|
|
30
|
+
'cancelOrder': true,
|
|
31
|
+
'createMarketOrder': false,
|
|
32
|
+
'createOrder': true,
|
|
33
|
+
'createReduceOnlyOrder': false,
|
|
34
|
+
'createStopLimitOrder': true,
|
|
35
|
+
'createStopMarketOrder': false,
|
|
36
|
+
'createStopOrder': true,
|
|
37
|
+
'fetchBalance': true,
|
|
38
|
+
'fetchCanceledOrders': true,
|
|
39
|
+
'fetchClosedOrders': true,
|
|
40
|
+
'fetchCurrencies': true,
|
|
41
|
+
'fetchDepositAddress': true,
|
|
42
|
+
'fetchDepositAddressesByNetwork': true,
|
|
43
|
+
'fetchDeposits': true,
|
|
44
|
+
'fetchFundingHistory': true,
|
|
45
|
+
'fetchFundingRate': true,
|
|
46
|
+
'fetchFundingRateHistory': true,
|
|
47
|
+
'fetchFundingRates': false,
|
|
48
|
+
'fetchIndexOHLCV': true,
|
|
49
|
+
'fetchLeverage': undefined,
|
|
50
|
+
'fetchLeverageTiers': true,
|
|
51
|
+
'fetchMarketLeverageTiers': 'emulated',
|
|
52
|
+
'fetchMarkets': true,
|
|
53
|
+
'fetchMarkOHLCV': true,
|
|
54
|
+
'fetchMyTrades': true,
|
|
55
|
+
'fetchOHLCV': true,
|
|
56
|
+
'fetchOpenOrders': true,
|
|
57
|
+
'fetchOrder': true,
|
|
58
|
+
'fetchOrderBook': true,
|
|
59
|
+
'fetchOrderTrades': true,
|
|
60
|
+
'fetchPosition': true,
|
|
61
|
+
'fetchPositions': true,
|
|
62
|
+
'fetchPositionsRisk': false,
|
|
63
|
+
'fetchPremiumIndexOHLCV': true,
|
|
64
|
+
'fetchStatus': true,
|
|
65
|
+
'fetchTicker': true,
|
|
66
|
+
'fetchTickers': true,
|
|
67
|
+
'fetchTime': true,
|
|
68
|
+
'fetchTrades': true,
|
|
69
|
+
'fetchTradingFee': false,
|
|
70
|
+
'fetchTradingFees': true,
|
|
71
|
+
'fetchTransfer': true,
|
|
72
|
+
'fetchTransfers': true,
|
|
73
|
+
'fetchWithdrawals': true,
|
|
74
|
+
'reduceMargin': true,
|
|
75
|
+
'setLeverage': true,
|
|
76
|
+
'setMarginMode': false,
|
|
77
|
+
'transfer': true,
|
|
78
|
+
'withdraw': true,
|
|
79
|
+
},
|
|
80
|
+
'timeframes': {
|
|
81
|
+
'1m': '1m',
|
|
82
|
+
'5m': '5m',
|
|
83
|
+
'15m': '15m',
|
|
84
|
+
'30m': '30m',
|
|
85
|
+
'1h': '1h',
|
|
86
|
+
'1d': '1d',
|
|
87
|
+
'1w': '1w',
|
|
88
|
+
'1M': '1M',
|
|
89
|
+
},
|
|
90
|
+
'urls': {
|
|
91
|
+
'logo': 'https://user-images.githubusercontent.com/1294454/137283979-8b2a818d-8633-461b-bfca-de89e8c446b2.jpg',
|
|
92
|
+
'api': {
|
|
93
|
+
'spot': {
|
|
94
|
+
'public': 'https://www.mexc.com/open/api/v2',
|
|
95
|
+
'private': 'https://www.mexc.com/open/api/v2',
|
|
96
|
+
},
|
|
97
|
+
'contract': {
|
|
98
|
+
'public': 'https://contract.mexc.com/api/v1/contract',
|
|
99
|
+
'private': 'https://contract.mexc.com/api/v1/private',
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
'www': 'https://www.mexc.com/',
|
|
103
|
+
'doc': [
|
|
104
|
+
'https://mxcdevelop.github.io/APIDoc/',
|
|
105
|
+
],
|
|
106
|
+
'fees': [
|
|
107
|
+
'https://www.mexc.com/fee',
|
|
108
|
+
],
|
|
109
|
+
'referral': 'https://m.mexc.com/auth/signup?inviteCode=1FQ1G',
|
|
110
|
+
},
|
|
111
|
+
'api': {
|
|
112
|
+
'contract': {
|
|
113
|
+
'public': {
|
|
114
|
+
'get': {
|
|
115
|
+
'ping': 2,
|
|
116
|
+
'detail': 2,
|
|
117
|
+
'support_currencies': 2,
|
|
118
|
+
'depth/{symbol}': 2,
|
|
119
|
+
'depth_commits/{symbol}/{limit}': 2,
|
|
120
|
+
'index_price/{symbol}': 2,
|
|
121
|
+
'fair_price/{symbol}': 2,
|
|
122
|
+
'funding_rate/{symbol}': 2,
|
|
123
|
+
'kline/{symbol}': 2,
|
|
124
|
+
'kline/index_price/{symbol}': 2,
|
|
125
|
+
'kline/fair_price/{symbol}': 2,
|
|
126
|
+
'deals/{symbol}': 2,
|
|
127
|
+
'ticker': 2,
|
|
128
|
+
'risk_reverse': 2,
|
|
129
|
+
'risk_reverse/history': 2,
|
|
130
|
+
'funding_rate/history': 2,
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
'private': {
|
|
134
|
+
'get': {
|
|
135
|
+
'account/assets': 2,
|
|
136
|
+
'account/asset/{currency}': 2,
|
|
137
|
+
'account/transfer_record': 2,
|
|
138
|
+
'position/list/history_positions': 2,
|
|
139
|
+
'position/open_positions': 2,
|
|
140
|
+
'position/funding_records': 2,
|
|
141
|
+
'order/list/open_orders/{symbol}': 2,
|
|
142
|
+
'order/list/history_orders': 2,
|
|
143
|
+
'order/external/{symbol}/{external_oid}': 2,
|
|
144
|
+
'order/get/{order_id}': 2,
|
|
145
|
+
'order/batch_query': 8,
|
|
146
|
+
'order/deal_details/{order_id}': 2,
|
|
147
|
+
'order/list/order_deals': 2,
|
|
148
|
+
'planorder/list/orders': 2,
|
|
149
|
+
'stoporder/list/orders': 2,
|
|
150
|
+
'stoporder/order_details/{stop_order_id}': 2,
|
|
151
|
+
'account/risk_limit': 2,
|
|
152
|
+
'account/tiered_fee_rate': 2,
|
|
153
|
+
},
|
|
154
|
+
'post': {
|
|
155
|
+
'position/change_margin': 2,
|
|
156
|
+
'position/change_leverage': 2,
|
|
157
|
+
'order/submit': 2,
|
|
158
|
+
'order/submit_batch': 40,
|
|
159
|
+
'order/cancel': 2,
|
|
160
|
+
'order/cancel_with_external': 2,
|
|
161
|
+
'order/cancel_all': 2,
|
|
162
|
+
'account/change_risk_level': 2,
|
|
163
|
+
'planorder/place': 2,
|
|
164
|
+
'planorder/cancel': 2,
|
|
165
|
+
'planorder/cancel_all': 2,
|
|
166
|
+
'stoporder/cancel': 2,
|
|
167
|
+
'stoporder/cancel_all': 2,
|
|
168
|
+
'stoporder/change_price': 2,
|
|
169
|
+
'stoporder/change_plan_price': 2,
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
'spot': {
|
|
174
|
+
'public': {
|
|
175
|
+
'get': {
|
|
176
|
+
'market/symbols': 1,
|
|
177
|
+
'market/coin/list': 2,
|
|
178
|
+
'common/timestamp': 1,
|
|
179
|
+
'common/ping': 1,
|
|
180
|
+
'market/ticker': 1,
|
|
181
|
+
'market/depth': 1,
|
|
182
|
+
'market/deals': 1,
|
|
183
|
+
'market/kline': 1,
|
|
184
|
+
'market/api_default_symbols': 2,
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
|
+
'private': {
|
|
188
|
+
'get': {
|
|
189
|
+
'account/info': 1,
|
|
190
|
+
'order/open_orders': 1,
|
|
191
|
+
'order/list': 1,
|
|
192
|
+
'order/query': 1,
|
|
193
|
+
'order/deals': 1,
|
|
194
|
+
'order/deal_detail': 1,
|
|
195
|
+
'asset/deposit/address/list': 2,
|
|
196
|
+
'asset/deposit/list': 2,
|
|
197
|
+
'asset/address/list': 2,
|
|
198
|
+
'asset/withdraw/list': 2,
|
|
199
|
+
'asset/internal/transfer/record': 10,
|
|
200
|
+
'account/balance': 10,
|
|
201
|
+
'asset/internal/transfer/info': 10,
|
|
202
|
+
'market/api_symbols': 2,
|
|
203
|
+
},
|
|
204
|
+
'post': {
|
|
205
|
+
'order/place': 1,
|
|
206
|
+
'order/place_batch': 1,
|
|
207
|
+
'asset/withdraw': 2,
|
|
208
|
+
'asset/internal/transfer': 10,
|
|
209
|
+
},
|
|
210
|
+
'delete': {
|
|
211
|
+
'order/cancel': 1,
|
|
212
|
+
'order/cancel_by_symbol': 1,
|
|
213
|
+
'asset/withdraw': 2,
|
|
214
|
+
},
|
|
215
|
+
},
|
|
216
|
+
},
|
|
217
|
+
},
|
|
218
|
+
'precisionMode': TICK_SIZE,
|
|
219
|
+
'fees': {
|
|
220
|
+
'trading': {
|
|
221
|
+
'tierBased': false,
|
|
222
|
+
'percentage': true,
|
|
223
|
+
'maker': 0.2 / 100, // maker / taker
|
|
224
|
+
'taker': 0.2 / 100,
|
|
225
|
+
},
|
|
226
|
+
},
|
|
227
|
+
'options': {
|
|
228
|
+
'timeframes': {
|
|
229
|
+
'spot': {
|
|
230
|
+
'1m': '1m',
|
|
231
|
+
'5m': '5m',
|
|
232
|
+
'15m': '15m',
|
|
233
|
+
'30m': '30m',
|
|
234
|
+
'1h': '1h',
|
|
235
|
+
'1d': '1d',
|
|
236
|
+
'1M': '1M',
|
|
237
|
+
},
|
|
238
|
+
'contract': {
|
|
239
|
+
'1m': 'Min1',
|
|
240
|
+
'5m': 'Min5',
|
|
241
|
+
'15m': 'Min15',
|
|
242
|
+
'30m': 'Min30',
|
|
243
|
+
'1h': 'Min60',
|
|
244
|
+
'4h': 'Hour4',
|
|
245
|
+
'8h': 'Hour8',
|
|
246
|
+
'1d': 'Day1',
|
|
247
|
+
'1w': 'Week1',
|
|
248
|
+
'1M': 'Month1',
|
|
249
|
+
},
|
|
250
|
+
},
|
|
251
|
+
'defaultType': 'spot', // spot, swap
|
|
252
|
+
'networks': {
|
|
253
|
+
'TRX': 'TRC-20',
|
|
254
|
+
'TRC20': 'TRC-20',
|
|
255
|
+
'ETH': 'ERC-20',
|
|
256
|
+
'ERC20': 'ERC-20',
|
|
257
|
+
'BEP20': 'BEP20(BSC)',
|
|
258
|
+
},
|
|
259
|
+
'accountsByType': {
|
|
260
|
+
'spot': 'MAIN',
|
|
261
|
+
'swap': 'CONTRACT',
|
|
262
|
+
},
|
|
263
|
+
'transfer': {
|
|
264
|
+
'accountsById': {
|
|
265
|
+
'MAIN': 'spot',
|
|
266
|
+
'CONTRACT': 'swap',
|
|
267
|
+
},
|
|
268
|
+
'status': {
|
|
269
|
+
'SUCCESS': 'ok',
|
|
270
|
+
'FAILED': 'failed',
|
|
271
|
+
'WAIT': 'pending',
|
|
272
|
+
},
|
|
273
|
+
},
|
|
274
|
+
'fetchOrdersByState': {
|
|
275
|
+
'method': 'spotPrivateGetOrderList', // contractPrivateGetPlanorderListOrders
|
|
276
|
+
},
|
|
277
|
+
'cancelOrder': {
|
|
278
|
+
'method': 'spotPrivateDeleteOrderCancel', // contractPrivatePostOrderCancel contractPrivatePostPlanorderCancel
|
|
279
|
+
},
|
|
280
|
+
},
|
|
281
|
+
'commonCurrencies': {
|
|
282
|
+
'BEYONDPROTOCOL': 'BEYOND',
|
|
283
|
+
'BIFI': 'BIFIF',
|
|
284
|
+
'BYN': 'BeyondFi',
|
|
285
|
+
'COFI': 'COFIX', // conflict with CoinFi
|
|
286
|
+
'DFI': 'DfiStarter',
|
|
287
|
+
'DFT': 'dFuture',
|
|
288
|
+
'DRK': 'DRK',
|
|
289
|
+
'EGC': 'Egoras Credit',
|
|
290
|
+
'FLUX1': 'FLUX', // switched places
|
|
291
|
+
'FLUX': 'FLUX1', // switched places
|
|
292
|
+
'FREE': 'FreeRossDAO', // conflict with FREE Coin
|
|
293
|
+
'GMT': 'GMT Token',
|
|
294
|
+
'HERO': 'Step Hero', // conflict with Metahero
|
|
295
|
+
'MIMO': 'Mimosa',
|
|
296
|
+
'PROS': 'Pros.Finance', // conflict with Prosper
|
|
297
|
+
'SIN': 'Sin City Token',
|
|
298
|
+
'STEPN': 'GMT',
|
|
299
|
+
},
|
|
300
|
+
'exceptions': {
|
|
301
|
+
'exact': {
|
|
302
|
+
'400': BadRequest, // Invalid parameter
|
|
303
|
+
'401': AuthenticationError, // Invalid signature, fail to pass the validation
|
|
304
|
+
'402': AuthenticationError, // {"success":false,"code":402,"message":"API key expired!"}
|
|
305
|
+
'403': PermissionDenied, // {"msg":"no permission to access the endpoint","code":403}
|
|
306
|
+
'429': RateLimitExceeded, // too many requests, rate limit rule is violated
|
|
307
|
+
'703': PermissionDenied, // Require trade read permission!
|
|
308
|
+
'1000': AccountNotEnabled, // {"success":false,"code":1000,"message":"Please open contract account first!"}
|
|
309
|
+
'1002': InvalidOrder, // {"success":false,"code":1002,"message":"Contract not allow place order!"}
|
|
310
|
+
'10072': AuthenticationError, // Invalid access key
|
|
311
|
+
'10073': AuthenticationError, // Invalid request time
|
|
312
|
+
'10075': PermissionDenied, // {"msg":"IP [xxx.xxx.xxx.xxx] not in the ip white list","code":10075}
|
|
313
|
+
'10101': InsufficientFunds, // {"code":10101,"msg":"Insufficient balance"}
|
|
314
|
+
'10216': InvalidAddress, // {"code":10216,"msg":"No available deposit address"}
|
|
315
|
+
'10232': BadSymbol, // {"code":10232,"msg":"The currency not exist"}
|
|
316
|
+
'30000': BadSymbol, // Trading is suspended for the requested symbol
|
|
317
|
+
'30001': InvalidOrder, // Current trading type (bid or ask) is not allowed
|
|
318
|
+
'30002': InvalidOrder, // Invalid trading amount, smaller than the symbol minimum trading amount
|
|
319
|
+
'30003': InvalidOrder, // Invalid trading amount, greater than the symbol maximum trading amount
|
|
320
|
+
'30004': InsufficientFunds, // Insufficient balance
|
|
321
|
+
'30005': InvalidOrder, // Oversell error
|
|
322
|
+
'30010': InvalidOrder, // Price out of allowed range
|
|
323
|
+
'30016': BadSymbol, // Market is closed
|
|
324
|
+
'30019': InvalidOrder, // Orders count over limit for batch processing
|
|
325
|
+
'30020': BadSymbol, // Restricted symbol, API access is not allowed for the time being
|
|
326
|
+
'30021': BadSymbol, // Invalid symbol
|
|
327
|
+
'33333': BadSymbol, // {"code":33333,"msg":"currency can not be null"}
|
|
328
|
+
},
|
|
329
|
+
'broad': {
|
|
330
|
+
'price and quantity must be positive': InvalidOrder, // {"msg":"price and quantity must be positive","code":400}
|
|
331
|
+
},
|
|
332
|
+
},
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
async fetchTime (params = {}) {
|
|
337
|
+
const [ marketType, query ] = this.handleMarketTypeAndParams ('fetchTime', undefined, params);
|
|
338
|
+
const method = this.getSupportedMapping (marketType, {
|
|
339
|
+
'spot': 'spotPublicGetCommonTimestamp',
|
|
340
|
+
'swap': 'contractPublicGetPing',
|
|
341
|
+
});
|
|
342
|
+
const response = await this[method] (this.extend (query));
|
|
343
|
+
//
|
|
344
|
+
// spot
|
|
345
|
+
//
|
|
346
|
+
// {
|
|
347
|
+
// "code":200,
|
|
348
|
+
// "data":1633375641837
|
|
349
|
+
// }
|
|
350
|
+
//
|
|
351
|
+
// contract
|
|
352
|
+
//
|
|
353
|
+
// {
|
|
354
|
+
// "success":true,
|
|
355
|
+
// "code":0,
|
|
356
|
+
// "data":1634095541710
|
|
357
|
+
// }
|
|
358
|
+
//
|
|
359
|
+
return this.safeInteger (response, 'data');
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
async fetchStatus (params = {}) {
|
|
363
|
+
const response = await this.spotPublicGetCommonPing (params);
|
|
364
|
+
//
|
|
365
|
+
// { "code":200 }
|
|
366
|
+
//
|
|
367
|
+
const code = this.safeInteger (response, 'code');
|
|
368
|
+
const status = (code === 200) ? 'ok' : 'maintenance';
|
|
369
|
+
return {
|
|
370
|
+
'status': status,
|
|
371
|
+
'updated': this.milliseconds (),
|
|
372
|
+
'eta': undefined,
|
|
373
|
+
'url': undefined,
|
|
374
|
+
'info': response,
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
async fetchCurrencies (params = {}) {
|
|
379
|
+
const response = await this.spotPublicGetMarketCoinList (params);
|
|
380
|
+
//
|
|
381
|
+
// {
|
|
382
|
+
// "code":200,
|
|
383
|
+
// "data":[
|
|
384
|
+
// {
|
|
385
|
+
// "currency":"AGLD",
|
|
386
|
+
// "coins":[
|
|
387
|
+
// {
|
|
388
|
+
// "chain":"ERC20",
|
|
389
|
+
// "precision":18,
|
|
390
|
+
// "fee":8.09,
|
|
391
|
+
// "is_withdraw_enabled":true,
|
|
392
|
+
// "is_deposit_enabled":true,
|
|
393
|
+
// "deposit_min_confirm":16,
|
|
394
|
+
// "withdraw_limit_max":500000.0,
|
|
395
|
+
// "withdraw_limit_min":14.0
|
|
396
|
+
// }
|
|
397
|
+
// ],
|
|
398
|
+
// "full_name":"Adventure Gold"
|
|
399
|
+
// },
|
|
400
|
+
// ]
|
|
401
|
+
// }
|
|
402
|
+
//
|
|
403
|
+
const data = this.safeValue (response, 'data', []);
|
|
404
|
+
const result = {};
|
|
405
|
+
for (let i = 0; i < data.length; i++) {
|
|
406
|
+
const currency = data[i];
|
|
407
|
+
const id = this.safeString (currency, 'currency');
|
|
408
|
+
const code = this.safeCurrencyCode (id);
|
|
409
|
+
const name = this.safeString (currency, 'full_name');
|
|
410
|
+
let currencyActive = false;
|
|
411
|
+
let currencyPrecision = undefined;
|
|
412
|
+
let currencyFee = undefined;
|
|
413
|
+
let currencyWithdrawMin = undefined;
|
|
414
|
+
let currencyWithdrawMax = undefined;
|
|
415
|
+
const networks = {};
|
|
416
|
+
const chains = this.safeValue (currency, 'coins', []);
|
|
417
|
+
let depositEnabled = false;
|
|
418
|
+
let withdrawEnabled = false;
|
|
419
|
+
for (let j = 0; j < chains.length; j++) {
|
|
420
|
+
const chain = chains[j];
|
|
421
|
+
const networkId = this.safeString (chain, 'chain');
|
|
422
|
+
const network = this.safeNetwork (networkId);
|
|
423
|
+
const isDepositEnabled = this.safeValue (chain, 'is_deposit_enabled', false);
|
|
424
|
+
const isWithdrawEnabled = this.safeValue (chain, 'is_withdraw_enabled', false);
|
|
425
|
+
const active = (isDepositEnabled && isWithdrawEnabled);
|
|
426
|
+
currencyActive = active || currencyActive;
|
|
427
|
+
const precisionDigits = this.safeInteger (chain, 'precision');
|
|
428
|
+
const precision = 1 / Math.pow (10, precisionDigits);
|
|
429
|
+
const withdrawMin = this.safeString (chain, 'withdraw_limit_min');
|
|
430
|
+
const withdrawMax = this.safeString (chain, 'withdraw_limit_max');
|
|
431
|
+
currencyWithdrawMin = (currencyWithdrawMin === undefined) ? withdrawMin : currencyWithdrawMin;
|
|
432
|
+
currencyWithdrawMax = (currencyWithdrawMax === undefined) ? withdrawMax : currencyWithdrawMax;
|
|
433
|
+
if (Precise.stringGt (currencyWithdrawMin, withdrawMin)) {
|
|
434
|
+
currencyWithdrawMin = withdrawMin;
|
|
435
|
+
}
|
|
436
|
+
if (Precise.stringLt (currencyWithdrawMax, withdrawMax)) {
|
|
437
|
+
currencyWithdrawMax = withdrawMax;
|
|
438
|
+
}
|
|
439
|
+
if (isDepositEnabled) {
|
|
440
|
+
depositEnabled = true;
|
|
441
|
+
}
|
|
442
|
+
if (isWithdrawEnabled) {
|
|
443
|
+
withdrawEnabled = true;
|
|
444
|
+
}
|
|
445
|
+
networks[network] = {
|
|
446
|
+
'info': chain,
|
|
447
|
+
'id': networkId,
|
|
448
|
+
'network': network,
|
|
449
|
+
'active': active,
|
|
450
|
+
'deposit': isDepositEnabled,
|
|
451
|
+
'withdraw': isWithdrawEnabled,
|
|
452
|
+
'fee': this.safeNumber (chain, 'fee'),
|
|
453
|
+
'precision': precision,
|
|
454
|
+
'limits': {
|
|
455
|
+
'withdraw': {
|
|
456
|
+
'min': withdrawMin,
|
|
457
|
+
'max': withdrawMax,
|
|
458
|
+
},
|
|
459
|
+
},
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
const networkKeys = Object.keys (networks);
|
|
463
|
+
const networkKeysLength = networkKeys.length;
|
|
464
|
+
if ((networkKeysLength === 1) || ('NONE' in networks)) {
|
|
465
|
+
const defaultNetwork = this.safeValue2 (networks, 'NONE', networkKeysLength - 1);
|
|
466
|
+
if (defaultNetwork !== undefined) {
|
|
467
|
+
currencyFee = defaultNetwork['fee'];
|
|
468
|
+
currencyPrecision = defaultNetwork['precision'];
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
result[code] = {
|
|
472
|
+
'id': id,
|
|
473
|
+
'code': code,
|
|
474
|
+
'info': currency,
|
|
475
|
+
'name': name,
|
|
476
|
+
'active': currencyActive,
|
|
477
|
+
'deposit': depositEnabled,
|
|
478
|
+
'withdraw': withdrawEnabled,
|
|
479
|
+
'fee': currencyFee,
|
|
480
|
+
'precision': currencyPrecision,
|
|
481
|
+
'limits': {
|
|
482
|
+
'amount': {
|
|
483
|
+
'min': undefined,
|
|
484
|
+
'max': undefined,
|
|
485
|
+
},
|
|
486
|
+
'withdraw': {
|
|
487
|
+
'min': currencyWithdrawMin,
|
|
488
|
+
'max': currencyWithdrawMax,
|
|
489
|
+
},
|
|
490
|
+
},
|
|
491
|
+
'networks': networks,
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
return result;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
async fetchMarkets (params = {}) {
|
|
498
|
+
const defaultType = this.safeString2 (this.options, 'fetchMarkets', 'defaultType', 'spot');
|
|
499
|
+
const type = this.safeString (params, 'type', defaultType);
|
|
500
|
+
const query = this.omit (params, 'type');
|
|
501
|
+
const spot = (type === 'spot');
|
|
502
|
+
const swap = (type === 'swap');
|
|
503
|
+
if (!spot && !swap) {
|
|
504
|
+
throw new ExchangeError (this.id + " does not support '" + type + "' type, set exchange.options['defaultType'] to 'spot', 'margin', 'delivery' or 'future'"); // eslint-disable-line quotes
|
|
505
|
+
}
|
|
506
|
+
if (spot) {
|
|
507
|
+
return await this.fetchSpotMarkets (query);
|
|
508
|
+
} else if (swap) {
|
|
509
|
+
return await this.fetchContractMarkets (query);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
async fetchContractMarkets (params = {}) {
|
|
514
|
+
const response = await this.contractPublicGetDetail (params);
|
|
515
|
+
//
|
|
516
|
+
// {
|
|
517
|
+
// "success":true,
|
|
518
|
+
// "code":0,
|
|
519
|
+
// "data":[
|
|
520
|
+
// {
|
|
521
|
+
// "symbol":"BTC_USDT",
|
|
522
|
+
// "displayName":"BTC_USDT永续",
|
|
523
|
+
// "displayNameEn":"BTC_USDT SWAP",
|
|
524
|
+
// "positionOpenType":3,
|
|
525
|
+
// "baseCoin":"BTC",
|
|
526
|
+
// "quoteCoin":"USDT",
|
|
527
|
+
// "settleCoin":"USDT",
|
|
528
|
+
// "contractSize":0.0001,
|
|
529
|
+
// "minLeverage":1,
|
|
530
|
+
// "maxLeverage":125,
|
|
531
|
+
// "priceScale":2,
|
|
532
|
+
// "volScale":0,
|
|
533
|
+
// "amountScale":4,
|
|
534
|
+
// "priceUnit":0.5,
|
|
535
|
+
// "volUnit":1,
|
|
536
|
+
// "minVol":1,
|
|
537
|
+
// "maxVol":1000000,
|
|
538
|
+
// "bidLimitPriceRate":0.1,
|
|
539
|
+
// "askLimitPriceRate":0.1,
|
|
540
|
+
// "takerFeeRate":0.0006,
|
|
541
|
+
// "makerFeeRate":0.0002,
|
|
542
|
+
// "maintenanceMarginRate":0.004,
|
|
543
|
+
// "initialMarginRate":0.008,
|
|
544
|
+
// "riskBaseVol":10000,
|
|
545
|
+
// "riskIncrVol":200000,
|
|
546
|
+
// "riskIncrMmr":0.004,
|
|
547
|
+
// "riskIncrImr":0.004,
|
|
548
|
+
// "riskLevelLimit":5,
|
|
549
|
+
// "priceCoefficientVariation":0.1,
|
|
550
|
+
// "indexOrigin":["BINANCE","GATEIO","HUOBI","MXC"],
|
|
551
|
+
// "state":0, // 0 enabled, 1 delivery, 2 completed, 3 offline, 4 pause
|
|
552
|
+
// "isNew":false,
|
|
553
|
+
// "isHot":true,
|
|
554
|
+
// "isHidden":false
|
|
555
|
+
// },
|
|
556
|
+
// ]
|
|
557
|
+
// }
|
|
558
|
+
//
|
|
559
|
+
const data = this.safeValue (response, 'data', []);
|
|
560
|
+
const result = [];
|
|
561
|
+
for (let i = 0; i < data.length; i++) {
|
|
562
|
+
const market = data[i];
|
|
563
|
+
const id = this.safeString (market, 'symbol');
|
|
564
|
+
const baseId = this.safeString (market, 'baseCoin');
|
|
565
|
+
const quoteId = this.safeString (market, 'quoteCoin');
|
|
566
|
+
const settleId = this.safeString (market, 'settleCoin');
|
|
567
|
+
const base = this.safeCurrencyCode (baseId);
|
|
568
|
+
const quote = this.safeCurrencyCode (quoteId);
|
|
569
|
+
const settle = this.safeCurrencyCode (settleId);
|
|
570
|
+
const state = this.safeString (market, 'state');
|
|
571
|
+
result.push ({
|
|
572
|
+
'id': id,
|
|
573
|
+
'symbol': base + '/' + quote + ':' + settle,
|
|
574
|
+
'base': base,
|
|
575
|
+
'quote': quote,
|
|
576
|
+
'settle': settle,
|
|
577
|
+
'baseId': baseId,
|
|
578
|
+
'quoteId': quoteId,
|
|
579
|
+
'settleId': settleId,
|
|
580
|
+
'type': 'swap',
|
|
581
|
+
'spot': false,
|
|
582
|
+
'margin': false,
|
|
583
|
+
'swap': true,
|
|
584
|
+
'future': false,
|
|
585
|
+
'option': false,
|
|
586
|
+
'active': (state === '0'),
|
|
587
|
+
'contract': true,
|
|
588
|
+
'linear': true,
|
|
589
|
+
'inverse': false,
|
|
590
|
+
'taker': this.safeNumber (market, 'takerFeeRate'),
|
|
591
|
+
'maker': this.safeNumber (market, 'makerFeeRate'),
|
|
592
|
+
'contractSize': this.safeNumber (market, 'contractSize'),
|
|
593
|
+
'expiry': undefined,
|
|
594
|
+
'expiryDatetime': undefined,
|
|
595
|
+
'strike': undefined,
|
|
596
|
+
'optionType': undefined,
|
|
597
|
+
'precision': {
|
|
598
|
+
'amount': this.safeNumber (market, 'volUnit'),
|
|
599
|
+
'price': this.safeNumber (market, 'priceUnit'),
|
|
600
|
+
},
|
|
601
|
+
'limits': {
|
|
602
|
+
'leverage': {
|
|
603
|
+
'min': this.safeNumber (market, 'minLeverage'),
|
|
604
|
+
'max': this.safeNumber (market, 'maxLeverage'),
|
|
605
|
+
},
|
|
606
|
+
'amount': {
|
|
607
|
+
'min': this.safeNumber (market, 'minVol'),
|
|
608
|
+
'max': this.safeNumber (market, 'maxVol'),
|
|
609
|
+
},
|
|
610
|
+
'price': {
|
|
611
|
+
'min': undefined,
|
|
612
|
+
'max': undefined,
|
|
613
|
+
},
|
|
614
|
+
'cost': {
|
|
615
|
+
'min': undefined,
|
|
616
|
+
'max': undefined,
|
|
617
|
+
},
|
|
618
|
+
},
|
|
619
|
+
'info': market,
|
|
620
|
+
});
|
|
621
|
+
}
|
|
622
|
+
return result;
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
async fetchSpotMarkets (params = {}) {
|
|
626
|
+
const response = await this.spotPublicGetMarketSymbols (params);
|
|
627
|
+
//
|
|
628
|
+
// {
|
|
629
|
+
// "code":200,
|
|
630
|
+
// "data":[
|
|
631
|
+
// {
|
|
632
|
+
// "symbol":"DFD_USDT",
|
|
633
|
+
// "state":"ENABLED",
|
|
634
|
+
// "countDownMark":1,
|
|
635
|
+
// "vcoinName":"DFD",
|
|
636
|
+
// "vcoinStatus":1,
|
|
637
|
+
// "price_scale":4,
|
|
638
|
+
// "quantity_scale":2,
|
|
639
|
+
// "min_amount":"5", // not an amount = cost
|
|
640
|
+
// "max_amount":"5000000",
|
|
641
|
+
// "maker_fee_rate":"0.002",
|
|
642
|
+
// "taker_fee_rate":"0.002",
|
|
643
|
+
// "limited":true,
|
|
644
|
+
// "etf_mark":0,
|
|
645
|
+
// "symbol_partition":"ASSESS"
|
|
646
|
+
// },
|
|
647
|
+
// ]
|
|
648
|
+
// }
|
|
649
|
+
//
|
|
650
|
+
const data = this.safeValue (response, 'data', []);
|
|
651
|
+
const result = [];
|
|
652
|
+
for (let i = 0; i < data.length; i++) {
|
|
653
|
+
const market = data[i];
|
|
654
|
+
const id = this.safeString (market, 'symbol');
|
|
655
|
+
const [ baseId, quoteId ] = id.split ('_');
|
|
656
|
+
const base = this.safeCurrencyCode (baseId);
|
|
657
|
+
const quote = this.safeCurrencyCode (quoteId);
|
|
658
|
+
const priceScale = this.safeString (market, 'price_scale');
|
|
659
|
+
const quantityScale = this.safeString (market, 'quantity_scale');
|
|
660
|
+
const state = this.safeString (market, 'state');
|
|
661
|
+
result.push ({
|
|
662
|
+
'id': id,
|
|
663
|
+
'symbol': base + '/' + quote,
|
|
664
|
+
'base': base,
|
|
665
|
+
'quote': quote,
|
|
666
|
+
'settle': undefined,
|
|
667
|
+
'baseId': baseId,
|
|
668
|
+
'quoteId': quoteId,
|
|
669
|
+
'settleId': undefined,
|
|
670
|
+
'type': 'spot',
|
|
671
|
+
'spot': true,
|
|
672
|
+
'margin': false,
|
|
673
|
+
'swap': false,
|
|
674
|
+
'future': false,
|
|
675
|
+
'option': false,
|
|
676
|
+
'active': (state === 'ENABLED'),
|
|
677
|
+
'contract': false,
|
|
678
|
+
'linear': undefined,
|
|
679
|
+
'inverse': undefined,
|
|
680
|
+
'taker': this.safeNumber (market, 'taker_fee_rate'),
|
|
681
|
+
'maker': this.safeNumber (market, 'maker_fee_rate'),
|
|
682
|
+
'contractSize': undefined,
|
|
683
|
+
'expiry': undefined,
|
|
684
|
+
'expiryDatetime': undefined,
|
|
685
|
+
'strike': undefined,
|
|
686
|
+
'optionType': undefined,
|
|
687
|
+
'precision': {
|
|
688
|
+
'amount': this.parseNumber (this.parsePrecision (quantityScale)),
|
|
689
|
+
'price': this.parseNumber (this.parsePrecision (priceScale)),
|
|
690
|
+
},
|
|
691
|
+
'limits': {
|
|
692
|
+
'leverage': {
|
|
693
|
+
'min': undefined,
|
|
694
|
+
'max': undefined,
|
|
695
|
+
},
|
|
696
|
+
'amount': {
|
|
697
|
+
'min': undefined,
|
|
698
|
+
'max': undefined,
|
|
699
|
+
},
|
|
700
|
+
'price': {
|
|
701
|
+
'min': undefined,
|
|
702
|
+
'max': undefined,
|
|
703
|
+
},
|
|
704
|
+
'cost': {
|
|
705
|
+
'min': this.safeNumber (market, 'min_amount'),
|
|
706
|
+
'max': this.safeNumber (market, 'max_amount'),
|
|
707
|
+
},
|
|
708
|
+
},
|
|
709
|
+
'info': market,
|
|
710
|
+
});
|
|
711
|
+
}
|
|
712
|
+
return result;
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
async fetchTickers (symbols = undefined, params = {}) {
|
|
716
|
+
await this.loadMarkets ();
|
|
717
|
+
const [ marketType, query ] = this.handleMarketTypeAndParams ('fetchTickers', undefined, params);
|
|
718
|
+
const method = this.getSupportedMapping (marketType, {
|
|
719
|
+
'spot': 'spotPublicGetMarketTicker',
|
|
720
|
+
'swap': 'contractPublicGetTicker',
|
|
721
|
+
});
|
|
722
|
+
const response = await this[method] (this.extend (query));
|
|
723
|
+
//
|
|
724
|
+
// {
|
|
725
|
+
// "success":true,
|
|
726
|
+
// "code":0,
|
|
727
|
+
// "data":[
|
|
728
|
+
// {
|
|
729
|
+
// "symbol":"NKN_USDT",
|
|
730
|
+
// "lastPrice":0.36199,
|
|
731
|
+
// "bid1":0.35908,
|
|
732
|
+
// "ask1":0.36277,
|
|
733
|
+
// "volume24":657754,
|
|
734
|
+
// "amount24":239024.53998,
|
|
735
|
+
// "holdVol":149969,
|
|
736
|
+
// "lower24Price":0.34957,
|
|
737
|
+
// "high24Price":0.37689,
|
|
738
|
+
// "riseFallRate":0.0117,
|
|
739
|
+
// "riseFallValue":0.00419,
|
|
740
|
+
// "indexPrice":0.36043,
|
|
741
|
+
// "fairPrice":0.36108,
|
|
742
|
+
// "fundingRate":0.000535,
|
|
743
|
+
// "maxBidPrice":0.43251,
|
|
744
|
+
// "minAskPrice":0.28834,
|
|
745
|
+
// "timestamp":1634163352075
|
|
746
|
+
// },
|
|
747
|
+
// ]
|
|
748
|
+
// }
|
|
749
|
+
//
|
|
750
|
+
const data = this.safeValue (response, 'data', []);
|
|
751
|
+
return this.parseTickers (data, symbols);
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
async fetchTicker (symbol, params = {}) {
|
|
755
|
+
await this.loadMarkets ();
|
|
756
|
+
const market = this.market (symbol);
|
|
757
|
+
const request = {
|
|
758
|
+
'symbol': market['id'],
|
|
759
|
+
};
|
|
760
|
+
let method = undefined;
|
|
761
|
+
if (market['spot']) {
|
|
762
|
+
method = 'spotPublicGetMarketTicker';
|
|
763
|
+
} else if (market['swap']) {
|
|
764
|
+
method = 'contractPublicGetTicker';
|
|
765
|
+
}
|
|
766
|
+
const response = await this[method] (this.extend (request, params));
|
|
767
|
+
//
|
|
768
|
+
// spot
|
|
769
|
+
//
|
|
770
|
+
// {
|
|
771
|
+
// "code":200,
|
|
772
|
+
// "data":[
|
|
773
|
+
// {
|
|
774
|
+
// "symbol":"BTC_USDT",
|
|
775
|
+
// "volume":"880.821523",
|
|
776
|
+
// "high":"49496.95", // highest price over the past 24 hours
|
|
777
|
+
// "low":"46918.4", // lowest
|
|
778
|
+
// "bid":"49297.64", // current buying price == the best price you can sell for
|
|
779
|
+
// "ask":"49297.75", // current selling price == the best price you can buy for
|
|
780
|
+
// "open":"48764.9", // open price 24h ago
|
|
781
|
+
// "last":"49297.73", // last = close
|
|
782
|
+
// "time":1633378200000, // timestamp
|
|
783
|
+
// "change_rate":"0.0109265" // (last / open) - 1
|
|
784
|
+
// }
|
|
785
|
+
// ]
|
|
786
|
+
// }
|
|
787
|
+
//
|
|
788
|
+
// swap / contract
|
|
789
|
+
//
|
|
790
|
+
// {
|
|
791
|
+
// "success":true,
|
|
792
|
+
// "code":0,
|
|
793
|
+
// "data":{
|
|
794
|
+
// "symbol":"ETH_USDT",
|
|
795
|
+
// "lastPrice":3581.3,
|
|
796
|
+
// "bid1":3581.25,
|
|
797
|
+
// "ask1":3581.5,
|
|
798
|
+
// "volume24":4045530,
|
|
799
|
+
// "amount24":141331823.5755,
|
|
800
|
+
// "holdVol":5832946,
|
|
801
|
+
// "lower24Price":3413.4,
|
|
802
|
+
// "high24Price":3588.7,
|
|
803
|
+
// "riseFallRate":0.0275,
|
|
804
|
+
// "riseFallValue":95.95,
|
|
805
|
+
// "indexPrice":3580.7852,
|
|
806
|
+
// "fairPrice":3581.08,
|
|
807
|
+
// "fundingRate":0.000063,
|
|
808
|
+
// "maxBidPrice":3938.85,
|
|
809
|
+
// "minAskPrice":3222.7,
|
|
810
|
+
// "timestamp":1634162885016
|
|
811
|
+
// }
|
|
812
|
+
// }
|
|
813
|
+
//
|
|
814
|
+
if (market['spot']) {
|
|
815
|
+
const data = this.safeValue (response, 'data', []);
|
|
816
|
+
const ticker = this.safeValue (data, 0);
|
|
817
|
+
return this.parseTicker (ticker, market);
|
|
818
|
+
} else if (market['swap']) {
|
|
819
|
+
const data = this.safeValue (response, 'data', {});
|
|
820
|
+
return this.parseTicker (data, market);
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
parseTicker (ticker, market = undefined) {
|
|
825
|
+
//
|
|
826
|
+
// spot
|
|
827
|
+
//
|
|
828
|
+
// {
|
|
829
|
+
// "symbol":"BTC_USDT",
|
|
830
|
+
// "volume":"880.821523",
|
|
831
|
+
// "high":"49496.95",
|
|
832
|
+
// "low":"46918.4",
|
|
833
|
+
// "bid":"49297.64",
|
|
834
|
+
// "ask":"49297.75",
|
|
835
|
+
// "open":"48764.9",
|
|
836
|
+
// "last":"49297.73",
|
|
837
|
+
// "time":1633378200000,
|
|
838
|
+
// "change_rate":"0.0109265"
|
|
839
|
+
// }
|
|
840
|
+
//
|
|
841
|
+
// contract
|
|
842
|
+
//
|
|
843
|
+
// {
|
|
844
|
+
// "symbol":"ETH_USDT",
|
|
845
|
+
// "lastPrice":3581.3,
|
|
846
|
+
// "bid1":3581.25,
|
|
847
|
+
// "ask1":3581.5,
|
|
848
|
+
// "volume24":4045530,
|
|
849
|
+
// "amount24":141331823.5755,
|
|
850
|
+
// "holdVol":5832946,
|
|
851
|
+
// "lower24Price":3413.4,
|
|
852
|
+
// "high24Price":3588.7,
|
|
853
|
+
// "riseFallRate":0.0275,
|
|
854
|
+
// "riseFallValue":95.95,
|
|
855
|
+
// "indexPrice":3580.7852,
|
|
856
|
+
// "fairPrice":3581.08,
|
|
857
|
+
// "fundingRate":0.000063,
|
|
858
|
+
// "maxBidPrice":3938.85,
|
|
859
|
+
// "minAskPrice":3222.7,
|
|
860
|
+
// "timestamp":1634162885016
|
|
861
|
+
// }
|
|
862
|
+
//
|
|
863
|
+
const timestamp = this.safeInteger2 (ticker, 'time', 'timestamp');
|
|
864
|
+
const marketId = this.safeString (ticker, 'symbol');
|
|
865
|
+
const symbol = this.safeSymbol (marketId, market, '_');
|
|
866
|
+
const baseVolume = this.safeString2 (ticker, 'volume', 'volume24');
|
|
867
|
+
const quoteVolume = this.safeString (ticker, 'amount24');
|
|
868
|
+
const open = this.safeString (ticker, 'open');
|
|
869
|
+
const last = this.safeString2 (ticker, 'last', 'lastPrice');
|
|
870
|
+
const change = this.safeString (ticker, 'riseFallValue');
|
|
871
|
+
const riseFallRate = this.safeString (ticker, 'riseFallRate');
|
|
872
|
+
const percentage = Precise.stringAdd (riseFallRate, '1');
|
|
873
|
+
return this.safeTicker ({
|
|
874
|
+
'symbol': symbol,
|
|
875
|
+
'timestamp': timestamp,
|
|
876
|
+
'datetime': this.iso8601 (timestamp),
|
|
877
|
+
'high': this.safeString2 (ticker, 'high', 'high24Price'),
|
|
878
|
+
'low': this.safeString2 (ticker, 'low', 'lower24Price'),
|
|
879
|
+
'bid': this.safeString2 (ticker, 'bid', 'bid1'),
|
|
880
|
+
'bidVolume': undefined,
|
|
881
|
+
'ask': this.safeString2 (ticker, 'ask', 'ask1'),
|
|
882
|
+
'askVolume': undefined,
|
|
883
|
+
'vwap': undefined,
|
|
884
|
+
'open': open,
|
|
885
|
+
'close': last,
|
|
886
|
+
'last': last,
|
|
887
|
+
'previousClose': undefined,
|
|
888
|
+
'change': change,
|
|
889
|
+
'percentage': percentage,
|
|
890
|
+
'average': undefined,
|
|
891
|
+
'baseVolume': baseVolume,
|
|
892
|
+
'quoteVolume': quoteVolume,
|
|
893
|
+
'info': ticker,
|
|
894
|
+
}, market, false);
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
async fetchOrderBook (symbol, limit = undefined, params = {}) {
|
|
898
|
+
await this.loadMarkets ();
|
|
899
|
+
const market = this.market (symbol);
|
|
900
|
+
const request = {
|
|
901
|
+
'symbol': market['id'],
|
|
902
|
+
};
|
|
903
|
+
let method = undefined;
|
|
904
|
+
if (market['spot']) {
|
|
905
|
+
method = 'spotPublicGetMarketDepth';
|
|
906
|
+
if (limit === undefined) {
|
|
907
|
+
limit = 100; // the spot api requires a limit
|
|
908
|
+
}
|
|
909
|
+
request['depth'] = limit;
|
|
910
|
+
} else if (market['swap']) {
|
|
911
|
+
method = 'contractPublicGetDepthSymbol';
|
|
912
|
+
if (limit !== undefined) {
|
|
913
|
+
request['limit'] = limit;
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
const response = await this[method] (this.extend (request, params));
|
|
917
|
+
//
|
|
918
|
+
// spot
|
|
919
|
+
//
|
|
920
|
+
// {
|
|
921
|
+
// "code":200,
|
|
922
|
+
// "data":{
|
|
923
|
+
// "asks":[
|
|
924
|
+
// {"price":"49060.56","quantity":"0.099842"},
|
|
925
|
+
// {"price":"49060.58","quantity":"0.016003"},
|
|
926
|
+
// {"price":"49060.6","quantity":"0.023677"}
|
|
927
|
+
// ],
|
|
928
|
+
// "bids":[
|
|
929
|
+
// {"price":"49060.45","quantity":"1.693009"},
|
|
930
|
+
// {"price":"49060.44","quantity":"0.000843"},
|
|
931
|
+
// {"price":"49059.98","quantity":"0.735"},
|
|
932
|
+
// ],
|
|
933
|
+
// "version":"202454074",
|
|
934
|
+
// }
|
|
935
|
+
// }
|
|
936
|
+
//
|
|
937
|
+
// swap / contract
|
|
938
|
+
//
|
|
939
|
+
// {
|
|
940
|
+
// "success":true,
|
|
941
|
+
// "code":0,
|
|
942
|
+
// "data":{
|
|
943
|
+
// "asks":[
|
|
944
|
+
// [3445.7,48379,1],
|
|
945
|
+
// [3445.75,34994,1],
|
|
946
|
+
// [3445.8,68634,2],
|
|
947
|
+
// ],
|
|
948
|
+
// "bids":[
|
|
949
|
+
// [3445.55,44081,1],
|
|
950
|
+
// [3445.5,24857,1],
|
|
951
|
+
// [3445.45,50272,1],
|
|
952
|
+
// ],
|
|
953
|
+
// "version":2827730444,
|
|
954
|
+
// "timestamp":1634117846232
|
|
955
|
+
// }
|
|
956
|
+
// }
|
|
957
|
+
//
|
|
958
|
+
const data = this.safeValue (response, 'data', {});
|
|
959
|
+
const priceKey = market['spot'] ? 'price' : 0;
|
|
960
|
+
const amountKey = market['spot'] ? 'quantity' : 1;
|
|
961
|
+
const timestamp = this.safeInteger (data, 'timestamp');
|
|
962
|
+
const orderbook = this.parseOrderBook (data, symbol, timestamp, 'bids', 'asks', priceKey, amountKey);
|
|
963
|
+
orderbook['nonce'] = this.safeInteger (data, 'version');
|
|
964
|
+
return orderbook;
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) {
|
|
968
|
+
await this.loadMarkets ();
|
|
969
|
+
const market = this.market (symbol);
|
|
970
|
+
const request = {
|
|
971
|
+
'symbol': market['id'],
|
|
972
|
+
};
|
|
973
|
+
if (limit !== undefined) {
|
|
974
|
+
request['limit'] = limit; // default 100, max 100
|
|
975
|
+
}
|
|
976
|
+
let method = undefined;
|
|
977
|
+
if (market['spot']) {
|
|
978
|
+
method = 'spotPublicGetMarketDeals';
|
|
979
|
+
} else if (market['swap']) {
|
|
980
|
+
method = 'contractPublicGetDealsSymbol';
|
|
981
|
+
}
|
|
982
|
+
const response = await this[method] (this.extend (request, params));
|
|
983
|
+
//
|
|
984
|
+
// spot
|
|
985
|
+
//
|
|
986
|
+
// {
|
|
987
|
+
// "code":200,
|
|
988
|
+
// "data":[
|
|
989
|
+
// {"trade_time":1633381766725,"trade_price":"0.068981","trade_quantity":"0.005","trade_type":"BID"},
|
|
990
|
+
// {"trade_time":1633381732705,"trade_price":"0.068979","trade_quantity":"0.006","trade_type":"BID"},
|
|
991
|
+
// {"trade_time":1633381694604,"trade_price":"0.068975","trade_quantity":"0.011","trade_type":"ASK"},
|
|
992
|
+
// ]
|
|
993
|
+
// }
|
|
994
|
+
//
|
|
995
|
+
// swap / contract
|
|
996
|
+
//
|
|
997
|
+
// {
|
|
998
|
+
// "success":true,
|
|
999
|
+
// "code":0,
|
|
1000
|
+
// "data":[
|
|
1001
|
+
// {"p":3598.85,"v":52,"T":1,"O":2,"M":2,"t":1634169038038},
|
|
1002
|
+
// {"p":3599.2,"v":15,"T":2,"O":3,"M":1,"t":1634169035603},
|
|
1003
|
+
// {"p":3600.15,"v":229,"T":2,"O":1,"M":2,"t":1634169026354},
|
|
1004
|
+
// ]
|
|
1005
|
+
// }
|
|
1006
|
+
//
|
|
1007
|
+
const data = this.safeValue (response, 'data', []);
|
|
1008
|
+
return this.parseTrades (data, market, since, limit);
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
parseTrade (trade, market = undefined) {
|
|
1012
|
+
//
|
|
1013
|
+
// public fetchTrades
|
|
1014
|
+
//
|
|
1015
|
+
// spot
|
|
1016
|
+
//
|
|
1017
|
+
// {
|
|
1018
|
+
// "trade_time":1633381766725,
|
|
1019
|
+
// "trade_price":"0.068981",
|
|
1020
|
+
// "trade_quantity":"0.005",
|
|
1021
|
+
// "trade_type":"BID"
|
|
1022
|
+
// }
|
|
1023
|
+
//
|
|
1024
|
+
// swap / contract
|
|
1025
|
+
//
|
|
1026
|
+
// {
|
|
1027
|
+
// "p":3598.85,
|
|
1028
|
+
// "v":52,
|
|
1029
|
+
// "T":1, // 1 buy, 2 sell
|
|
1030
|
+
// "O":2, // 1 opens a position, 2 does not open a position
|
|
1031
|
+
// "M":2, // self-trading, 1 yes, 2 no
|
|
1032
|
+
// "t":1634169038038
|
|
1033
|
+
// }
|
|
1034
|
+
//
|
|
1035
|
+
// private fetchMyTrades, fetchOrderTrades
|
|
1036
|
+
//
|
|
1037
|
+
// {
|
|
1038
|
+
// "id":"b160b8f072d9403e96289139d5544809",
|
|
1039
|
+
// "symbol":"USDC_USDT",
|
|
1040
|
+
// "quantity":"150",
|
|
1041
|
+
// "price":"0.9997",
|
|
1042
|
+
// "amount":"149.955",
|
|
1043
|
+
// "fee":"0.29991",
|
|
1044
|
+
// "trade_type":"ASK",
|
|
1045
|
+
// "order_id":"d798765285374222990bbd14decb86cd",
|
|
1046
|
+
// "is_taker":true,
|
|
1047
|
+
// "fee_currency":"USDT",
|
|
1048
|
+
// "create_time":1633984904000
|
|
1049
|
+
// }
|
|
1050
|
+
//
|
|
1051
|
+
let timestamp = this.safeInteger2 (trade, 'create_time', 'trade_time');
|
|
1052
|
+
timestamp = this.safeInteger (trade, 't', timestamp);
|
|
1053
|
+
const marketId = this.safeString (trade, 'symbol');
|
|
1054
|
+
market = this.safeMarket (marketId, market, '_');
|
|
1055
|
+
const symbol = market['symbol'];
|
|
1056
|
+
let priceString = this.safeString2 (trade, 'price', 'trade_price');
|
|
1057
|
+
priceString = this.safeString (trade, 'p', priceString);
|
|
1058
|
+
let amountString = this.safeString2 (trade, 'quantity', 'trade_quantity');
|
|
1059
|
+
amountString = this.safeString (trade, 'v', amountString);
|
|
1060
|
+
const costString = this.safeString (trade, 'amount');
|
|
1061
|
+
let side = this.safeString2 (trade, 'trade_type', 'T');
|
|
1062
|
+
if ((side === 'BID') || (side === '1')) {
|
|
1063
|
+
side = 'buy';
|
|
1064
|
+
} else if ((side === 'ASK') || (side === '2')) {
|
|
1065
|
+
side = 'sell';
|
|
1066
|
+
}
|
|
1067
|
+
let id = this.safeString2 (trade, 'id', 'trade_time');
|
|
1068
|
+
if (id === undefined) {
|
|
1069
|
+
id = this.safeString (trade, 't', id);
|
|
1070
|
+
if (id !== undefined) {
|
|
1071
|
+
id += '-' + market['id'] + '-' + amountString;
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
const feeCostString = this.safeString (trade, 'fee');
|
|
1075
|
+
let fee = undefined;
|
|
1076
|
+
if (feeCostString !== undefined) {
|
|
1077
|
+
const feeCurrencyId = this.safeString (trade, 'fee_currency');
|
|
1078
|
+
const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId);
|
|
1079
|
+
fee = {
|
|
1080
|
+
'cost': feeCostString,
|
|
1081
|
+
'currency': feeCurrencyCode,
|
|
1082
|
+
};
|
|
1083
|
+
}
|
|
1084
|
+
const orderId = this.safeString (trade, 'order_id');
|
|
1085
|
+
const isTaker = this.safeValue (trade, 'is_taker', true);
|
|
1086
|
+
const takerOrMaker = isTaker ? 'taker' : 'maker';
|
|
1087
|
+
return this.safeTrade ({
|
|
1088
|
+
'info': trade,
|
|
1089
|
+
'id': id,
|
|
1090
|
+
'order': orderId,
|
|
1091
|
+
'timestamp': timestamp,
|
|
1092
|
+
'datetime': this.iso8601 (timestamp),
|
|
1093
|
+
'symbol': symbol,
|
|
1094
|
+
'type': undefined,
|
|
1095
|
+
'side': side,
|
|
1096
|
+
'takerOrMaker': takerOrMaker,
|
|
1097
|
+
'price': priceString,
|
|
1098
|
+
'amount': amountString,
|
|
1099
|
+
'cost': costString,
|
|
1100
|
+
'fee': fee,
|
|
1101
|
+
}, market);
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
async fetchTradingFees (params = {}) {
|
|
1105
|
+
await this.loadMarkets ();
|
|
1106
|
+
const response = await this.spotPublicGetMarketSymbols (params);
|
|
1107
|
+
//
|
|
1108
|
+
// {
|
|
1109
|
+
// "code":200,
|
|
1110
|
+
// "data":[
|
|
1111
|
+
// {
|
|
1112
|
+
// "symbol":"DFD_USDT",
|
|
1113
|
+
// "state":"ENABLED",
|
|
1114
|
+
// "countDownMark":1,
|
|
1115
|
+
// "vcoinName":"DFD",
|
|
1116
|
+
// "vcoinStatus":1,
|
|
1117
|
+
// "price_scale":4,
|
|
1118
|
+
// "quantity_scale":2,
|
|
1119
|
+
// "min_amount":"5", // not an amount = cost
|
|
1120
|
+
// "max_amount":"5000000",
|
|
1121
|
+
// "maker_fee_rate":"0.002",
|
|
1122
|
+
// "taker_fee_rate":"0.002",
|
|
1123
|
+
// "limited":true,
|
|
1124
|
+
// "etf_mark":0,
|
|
1125
|
+
// "symbol_partition":"ASSESS"
|
|
1126
|
+
// },
|
|
1127
|
+
// ...
|
|
1128
|
+
// ]
|
|
1129
|
+
// }
|
|
1130
|
+
//
|
|
1131
|
+
const data = this.safeValue (response, 'data', []);
|
|
1132
|
+
const result = {};
|
|
1133
|
+
for (let i = 0; i < data.length; i++) {
|
|
1134
|
+
const fee = data[i];
|
|
1135
|
+
const marketId = this.safeString (fee, 'symbol');
|
|
1136
|
+
const market = this.safeMarket (marketId, undefined, '_');
|
|
1137
|
+
const symbol = market['symbol'];
|
|
1138
|
+
result[symbol] = {
|
|
1139
|
+
'info': fee,
|
|
1140
|
+
'symbol': symbol,
|
|
1141
|
+
'maker': this.safeNumber (fee, 'maker_fee_rate'),
|
|
1142
|
+
'taker': this.safeNumber (fee, 'taker_fee_rate'),
|
|
1143
|
+
'percentage': true,
|
|
1144
|
+
'tierBased': false,
|
|
1145
|
+
};
|
|
1146
|
+
}
|
|
1147
|
+
return result;
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1150
|
+
async fetchOHLCV (symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
|
|
1151
|
+
await this.loadMarkets ();
|
|
1152
|
+
const market = this.market (symbol);
|
|
1153
|
+
const options = this.safeValue (this.options, 'timeframes', {});
|
|
1154
|
+
const timeframes = this.safeValue (options, market['type'], {});
|
|
1155
|
+
const timeframeValue = this.safeString (timeframes, timeframe);
|
|
1156
|
+
if (timeframeValue === undefined) {
|
|
1157
|
+
throw new NotSupported (this.id + ' fetchOHLCV() does not support ' + timeframe + ' timeframe for ' + market['type'] + ' markets');
|
|
1158
|
+
}
|
|
1159
|
+
const request = {
|
|
1160
|
+
'symbol': market['id'],
|
|
1161
|
+
'interval': timeframeValue,
|
|
1162
|
+
};
|
|
1163
|
+
let method = undefined;
|
|
1164
|
+
if (market['spot']) {
|
|
1165
|
+
method = 'spotPublicGetMarketKline';
|
|
1166
|
+
if (since !== undefined) {
|
|
1167
|
+
request['start_time'] = parseInt (since / 1000);
|
|
1168
|
+
}
|
|
1169
|
+
if (limit !== undefined) {
|
|
1170
|
+
request['limit'] = limit; // default 100
|
|
1171
|
+
}
|
|
1172
|
+
} else if (market['swap']) {
|
|
1173
|
+
method = 'contractPublicGetKlineSymbol';
|
|
1174
|
+
if (since !== undefined) {
|
|
1175
|
+
request['start'] = parseInt (since / 1000);
|
|
1176
|
+
}
|
|
1177
|
+
// request['end'] = this.seconds ();
|
|
1178
|
+
}
|
|
1179
|
+
const response = await this[method] (this.extend (request, params));
|
|
1180
|
+
//
|
|
1181
|
+
// spot
|
|
1182
|
+
//
|
|
1183
|
+
// {
|
|
1184
|
+
// "code":200,
|
|
1185
|
+
// "data":[
|
|
1186
|
+
// [1633377000,"49227.47","49186.21","49227.47","49169.48","0.5984809999999999","29434.259665989997"],
|
|
1187
|
+
// [1633377060,"49186.21","49187.03","49206.64","49169.18","0.3658478","17990.651234393"],
|
|
1188
|
+
// [1633377120,"49187.03","49227.2","49227.2","49174.4","0.0687651","3382.353190352"],
|
|
1189
|
+
// ],
|
|
1190
|
+
// }
|
|
1191
|
+
//
|
|
1192
|
+
// swap / contract
|
|
1193
|
+
//
|
|
1194
|
+
// {
|
|
1195
|
+
// "success":true,
|
|
1196
|
+
// "code":0,
|
|
1197
|
+
// "data":{
|
|
1198
|
+
// "time":[1634052300,1634052360,1634052420],
|
|
1199
|
+
// "open":[3492.2,3491.3,3495.65],
|
|
1200
|
+
// "close":[3491.3,3495.65,3495.2],
|
|
1201
|
+
// "high":[3495.85,3496.55,3499.4],
|
|
1202
|
+
// "low":[3491.15,3490.9,3494.2],
|
|
1203
|
+
// "vol":[1740.0,351.0,314.0],
|
|
1204
|
+
// "amount":[60793.623,12260.4885,10983.1375],
|
|
1205
|
+
// }
|
|
1206
|
+
// }
|
|
1207
|
+
//
|
|
1208
|
+
if (market['spot']) {
|
|
1209
|
+
const data = this.safeValue (response, 'data', []);
|
|
1210
|
+
return this.parseOHLCVs (data, market, timeframe, since, limit);
|
|
1211
|
+
} else if (market['swap']) {
|
|
1212
|
+
const data = this.safeValue (response, 'data', {});
|
|
1213
|
+
const result = this.convertTradingViewToOHLCV (data, 'time', 'open', 'high', 'low', 'close', 'vol');
|
|
1214
|
+
return this.parseOHLCVs (result, market, timeframe, since, limit);
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
|
|
1218
|
+
parseOHLCV (ohlcv, market = undefined) {
|
|
1219
|
+
//
|
|
1220
|
+
// the ordering in spot candles is OCHLV
|
|
1221
|
+
//
|
|
1222
|
+
// [
|
|
1223
|
+
// 1633377000, // 0 timestamp (unix seconds)
|
|
1224
|
+
// "49227.47", // 1 open price
|
|
1225
|
+
// "49186.21", // 2 closing price
|
|
1226
|
+
// "49227.47", // 3 high
|
|
1227
|
+
// "49169.48", // 4 low
|
|
1228
|
+
// "0.5984809999999999", // 5 base volume
|
|
1229
|
+
// "29434.259665989997", // 6 quote volume
|
|
1230
|
+
// ]
|
|
1231
|
+
//
|
|
1232
|
+
// the ordering in swap / contract candles is OHLCV
|
|
1233
|
+
//
|
|
1234
|
+
return [
|
|
1235
|
+
this.safeTimestamp (ohlcv, 0),
|
|
1236
|
+
this.safeNumber (ohlcv, 1),
|
|
1237
|
+
this.safeNumber (ohlcv, market['spot'] ? 3 : 2),
|
|
1238
|
+
this.safeNumber (ohlcv, market['spot'] ? 4 : 3),
|
|
1239
|
+
this.safeNumber (ohlcv, market['spot'] ? 2 : 4),
|
|
1240
|
+
this.safeNumber (ohlcv, 5),
|
|
1241
|
+
];
|
|
1242
|
+
}
|
|
1243
|
+
|
|
1244
|
+
async fetchPremiumIndexOHLCV (symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
|
|
1245
|
+
const request = {
|
|
1246
|
+
'price': 'premiumIndex',
|
|
1247
|
+
};
|
|
1248
|
+
return await this.fetchOHLCV (symbol, timeframe, since, limit, this.extend (request, params));
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1251
|
+
async fetchIndexOHLCV (symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
|
|
1252
|
+
const request = {
|
|
1253
|
+
'price': 'index',
|
|
1254
|
+
};
|
|
1255
|
+
return await this.fetchOHLCV (symbol, timeframe, since, limit, this.extend (request, params));
|
|
1256
|
+
}
|
|
1257
|
+
|
|
1258
|
+
async fetchMarkOHLCV (symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
|
|
1259
|
+
const request = {
|
|
1260
|
+
'price': 'mark',
|
|
1261
|
+
};
|
|
1262
|
+
return await this.fetchOHLCV (symbol, timeframe, since, limit, this.extend (request, params));
|
|
1263
|
+
}
|
|
1264
|
+
|
|
1265
|
+
async fetchBalance (params = {}) {
|
|
1266
|
+
await this.loadMarkets ();
|
|
1267
|
+
const [ marketType, query ] = this.handleMarketTypeAndParams ('fetchBalance', undefined, params);
|
|
1268
|
+
const method = this.getSupportedMapping (marketType, {
|
|
1269
|
+
'spot': 'spotPrivateGetAccountInfo',
|
|
1270
|
+
'margin': 'spotPrivateGetAccountInfo',
|
|
1271
|
+
'swap': 'contractPrivateGetAccountAssets',
|
|
1272
|
+
});
|
|
1273
|
+
const spot = (marketType === 'spot');
|
|
1274
|
+
const response = await this[method] (query);
|
|
1275
|
+
//
|
|
1276
|
+
// spot
|
|
1277
|
+
//
|
|
1278
|
+
// {
|
|
1279
|
+
// code: "200",
|
|
1280
|
+
// data: {
|
|
1281
|
+
// USDC: { frozen: "0", available: "150" }
|
|
1282
|
+
// }
|
|
1283
|
+
// }
|
|
1284
|
+
//
|
|
1285
|
+
// swap / contract
|
|
1286
|
+
//
|
|
1287
|
+
// {
|
|
1288
|
+
// "success":true,
|
|
1289
|
+
// "code":0,
|
|
1290
|
+
// "data":[
|
|
1291
|
+
// {"currency":"BSV","positionMargin":0,"availableBalance":0,"cashBalance":0,"frozenBalance":0,"equity":0,"unrealized":0,"bonus":0},
|
|
1292
|
+
// {"currency":"BCH","positionMargin":0,"availableBalance":0,"cashBalance":0,"frozenBalance":0,"equity":0,"unrealized":0,"bonus":0},
|
|
1293
|
+
// {"currency":"CRV","positionMargin":0,"availableBalance":0,"cashBalance":0,"frozenBalance":0,"equity":0,"unrealized":0,"bonus":0},
|
|
1294
|
+
// ]
|
|
1295
|
+
// }
|
|
1296
|
+
//
|
|
1297
|
+
const data = this.safeValue (response, 'data', {});
|
|
1298
|
+
const currentTime = this.milliseconds ();
|
|
1299
|
+
const result = {
|
|
1300
|
+
'info': response,
|
|
1301
|
+
'timestamp': currentTime,
|
|
1302
|
+
'datetime': this.iso8601 (currentTime),
|
|
1303
|
+
};
|
|
1304
|
+
if (spot) {
|
|
1305
|
+
const currencyIds = Object.keys (data);
|
|
1306
|
+
for (let i = 0; i < currencyIds.length; i++) {
|
|
1307
|
+
const currencyId = currencyIds[i];
|
|
1308
|
+
const code = this.safeCurrencyCode (currencyId);
|
|
1309
|
+
const balance = this.safeValue (data, currencyId, {});
|
|
1310
|
+
const account = this.account ();
|
|
1311
|
+
account['free'] = this.safeString (balance, 'available');
|
|
1312
|
+
account['used'] = this.safeString (balance, 'frozen');
|
|
1313
|
+
result[code] = account;
|
|
1314
|
+
}
|
|
1315
|
+
} else {
|
|
1316
|
+
for (let i = 0; i < data.length; i++) {
|
|
1317
|
+
const balance = data[i];
|
|
1318
|
+
const currencyId = this.safeString (balance, 'currency');
|
|
1319
|
+
const code = this.safeCurrencyCode (currencyId);
|
|
1320
|
+
const account = this.account ();
|
|
1321
|
+
account['free'] = this.safeString (balance, 'availableBalance');
|
|
1322
|
+
account['used'] = this.safeString (balance, 'frozenBalance');
|
|
1323
|
+
result[code] = account;
|
|
1324
|
+
}
|
|
1325
|
+
}
|
|
1326
|
+
return this.safeBalance (result);
|
|
1327
|
+
}
|
|
1328
|
+
|
|
1329
|
+
safeNetwork (networkId) {
|
|
1330
|
+
if (networkId.indexOf ('BSC') >= 0) {
|
|
1331
|
+
return 'BEP20';
|
|
1332
|
+
}
|
|
1333
|
+
const parts = networkId.split (' ');
|
|
1334
|
+
networkId = parts.join ('');
|
|
1335
|
+
networkId = networkId.replace ('-20', '20');
|
|
1336
|
+
const networksById = {
|
|
1337
|
+
'ETH': 'ETH',
|
|
1338
|
+
'ERC20': 'ERC20',
|
|
1339
|
+
'BEP20(BSC)': 'BEP20',
|
|
1340
|
+
'TRX': 'TRC20',
|
|
1341
|
+
};
|
|
1342
|
+
return this.safeString (networksById, networkId, networkId);
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1345
|
+
parseDepositAddress (depositAddress, currency = undefined) {
|
|
1346
|
+
//
|
|
1347
|
+
// {"chain":"ERC-20","address":"0x55cbd73db24eafcca97369e3f2db74b2490586e6"},
|
|
1348
|
+
// {"chain":"MATIC","address":"0x05aa3236f1970eae0f8feb17ec19435b39574d74"},
|
|
1349
|
+
// {"chain":"TRC20","address":"TGaPfhW41EXD3sAfs1grLF6DKfugfqANNw"},
|
|
1350
|
+
// {"chain":"SOL","address":"5FSpUKuh2gjw4mF89T2e7sEjzUA1SkRKjBChFqP43KhV"},
|
|
1351
|
+
// {"chain":"ALGO","address":"B3XTZND2JJTSYR7R2TQVCUDT4QSSYVAIZYDPWVBX34DGAYATBU3AUV43VU"}
|
|
1352
|
+
//
|
|
1353
|
+
//
|
|
1354
|
+
const address = this.safeString (depositAddress, 'address');
|
|
1355
|
+
const code = this.safeCurrencyCode (undefined, currency);
|
|
1356
|
+
const networkId = this.safeString (depositAddress, 'chain');
|
|
1357
|
+
const network = this.safeNetwork (networkId);
|
|
1358
|
+
this.checkAddress (address);
|
|
1359
|
+
return {
|
|
1360
|
+
'currency': code,
|
|
1361
|
+
'address': address,
|
|
1362
|
+
'tag': undefined,
|
|
1363
|
+
'network': network,
|
|
1364
|
+
'info': depositAddress,
|
|
1365
|
+
};
|
|
1366
|
+
}
|
|
1367
|
+
|
|
1368
|
+
async fetchDepositAddressesByNetwork (code, params = {}) {
|
|
1369
|
+
await this.loadMarkets ();
|
|
1370
|
+
const currency = this.currency (code);
|
|
1371
|
+
const request = {
|
|
1372
|
+
'currency': currency['id'],
|
|
1373
|
+
};
|
|
1374
|
+
const response = await this.spotPrivateGetAssetDepositAddressList (this.extend (request, params));
|
|
1375
|
+
//
|
|
1376
|
+
// {
|
|
1377
|
+
// "code":200,
|
|
1378
|
+
// "data":{
|
|
1379
|
+
// "currency":"USDC",
|
|
1380
|
+
// "chains":[
|
|
1381
|
+
// {"chain":"ERC-20","address":"0x55cbd73db24eafcca97369e3f2db74b2490586e6"},
|
|
1382
|
+
// {"chain":"MATIC","address":"0x05aa3236f1970eae0f8feb17ec19435b39574d74"},
|
|
1383
|
+
// {"chain":"TRC20","address":"TGaPfhW41EXD3sAfs1grLF6DKfugfqANNw"},
|
|
1384
|
+
// {"chain":"SOL","address":"5FSpUKuh2gjw4mF89T2e7sEjzUA1SkRKjBChFqP43KhV"},
|
|
1385
|
+
// {"chain":"ALGO","address":"B3XTZND2JJTSYR7R2TQVCUDT4QSSYVAIZYDPWVBX34DGAYATBU3AUV43VU"}
|
|
1386
|
+
// ]
|
|
1387
|
+
// }
|
|
1388
|
+
// }
|
|
1389
|
+
//
|
|
1390
|
+
const data = this.safeValue (response, 'data', {});
|
|
1391
|
+
const chains = this.safeValue (data, 'chains', []);
|
|
1392
|
+
const depositAddresses = [];
|
|
1393
|
+
for (let i = 0; i < chains.length; i++) {
|
|
1394
|
+
const depositAddress = this.parseDepositAddress (chains[i], currency);
|
|
1395
|
+
depositAddresses.push (depositAddress);
|
|
1396
|
+
}
|
|
1397
|
+
return this.indexBy (depositAddresses, 'network');
|
|
1398
|
+
}
|
|
1399
|
+
|
|
1400
|
+
async fetchDepositAddress (code, params = {}) {
|
|
1401
|
+
const rawNetwork = this.safeStringUpper (params, 'network');
|
|
1402
|
+
params = this.omit (params, 'network');
|
|
1403
|
+
const response = await this.fetchDepositAddressesByNetwork (code, params);
|
|
1404
|
+
const networks = this.safeValue (this.options, 'networks', {});
|
|
1405
|
+
const network = this.safeString (networks, rawNetwork, rawNetwork);
|
|
1406
|
+
let result = undefined;
|
|
1407
|
+
if (network === undefined) {
|
|
1408
|
+
result = this.safeValue (response, code);
|
|
1409
|
+
if (result === undefined) {
|
|
1410
|
+
const alias = this.safeString (networks, code, code);
|
|
1411
|
+
result = this.safeValue (response, alias);
|
|
1412
|
+
if (result === undefined) {
|
|
1413
|
+
const defaultNetwork = this.safeString (this.options, 'defaultNetwork', 'ERC20');
|
|
1414
|
+
result = this.safeValue (response, defaultNetwork);
|
|
1415
|
+
if (result === undefined) {
|
|
1416
|
+
const values = Object.values (response);
|
|
1417
|
+
result = this.safeValue (values, 0);
|
|
1418
|
+
if (result === undefined) {
|
|
1419
|
+
throw new InvalidAddress (this.id + ' fetchDepositAddress() cannot find deposit address for ' + code);
|
|
1420
|
+
}
|
|
1421
|
+
}
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1424
|
+
return result;
|
|
1425
|
+
}
|
|
1426
|
+
// TODO: add support for all aliases here
|
|
1427
|
+
result = this.safeValue (response, rawNetwork);
|
|
1428
|
+
if (result === undefined) {
|
|
1429
|
+
throw new InvalidAddress (this.id + ' fetchDepositAddress() cannot find ' + network + ' deposit address for ' + code);
|
|
1430
|
+
}
|
|
1431
|
+
return result;
|
|
1432
|
+
}
|
|
1433
|
+
|
|
1434
|
+
async fetchDeposits (code = undefined, since = undefined, limit = undefined, params = {}) {
|
|
1435
|
+
await this.loadMarkets ();
|
|
1436
|
+
const request = {
|
|
1437
|
+
// 'currency': currency['id'],
|
|
1438
|
+
// 'state': 'state',
|
|
1439
|
+
// 'start_time': since, // default 1 day
|
|
1440
|
+
// 'end_time': this.milliseconds (),
|
|
1441
|
+
// 'page_num': 1,
|
|
1442
|
+
// 'page_size': limit, // default 20, maximum 50
|
|
1443
|
+
};
|
|
1444
|
+
let currency = undefined;
|
|
1445
|
+
if (code !== undefined) {
|
|
1446
|
+
currency = this.currency (code);
|
|
1447
|
+
request['currency'] = currency['id'];
|
|
1448
|
+
}
|
|
1449
|
+
if (since !== undefined) {
|
|
1450
|
+
request['start_time'] = since;
|
|
1451
|
+
}
|
|
1452
|
+
if (limit !== undefined) {
|
|
1453
|
+
request['limit'] = limit;
|
|
1454
|
+
}
|
|
1455
|
+
const response = await this.spotPrivateGetAssetDepositList (this.extend (request, params));
|
|
1456
|
+
//
|
|
1457
|
+
// {
|
|
1458
|
+
// "code":200,
|
|
1459
|
+
// "data":{
|
|
1460
|
+
// "page_size":20,
|
|
1461
|
+
// "total_page":1,
|
|
1462
|
+
// "total_size":1,
|
|
1463
|
+
// "page_num":1,
|
|
1464
|
+
// "result_list":[
|
|
1465
|
+
// {
|
|
1466
|
+
// "currency":"USDC",
|
|
1467
|
+
// "amount":150.0,
|
|
1468
|
+
// "fee":0.0,
|
|
1469
|
+
// "confirmations":19,
|
|
1470
|
+
// "address":"0x55cbd73db24eafcca97369e3f2db74b2490586e6",
|
|
1471
|
+
// "state":"SUCCESS",
|
|
1472
|
+
// "tx_id":"0xc65a9b09e1b71def81bf8bb3ec724c0c1b2b4c82200c8c142e4ea4c1469fd789:0",
|
|
1473
|
+
// "require_confirmations":12,
|
|
1474
|
+
// "create_time":"2021-10-11T18:58:25.000+00:00",
|
|
1475
|
+
// "update_time":"2021-10-11T19:01:06.000+00:00"
|
|
1476
|
+
// }
|
|
1477
|
+
// ]
|
|
1478
|
+
// }
|
|
1479
|
+
// }
|
|
1480
|
+
//
|
|
1481
|
+
const data = this.safeValue (response, 'data', {});
|
|
1482
|
+
const resultList = this.safeValue (data, 'result_list', []);
|
|
1483
|
+
return this.parseTransactions (resultList, code, since, limit);
|
|
1484
|
+
}
|
|
1485
|
+
|
|
1486
|
+
async fetchWithdrawals (code = undefined, since = undefined, limit = undefined, params = {}) {
|
|
1487
|
+
await this.loadMarkets ();
|
|
1488
|
+
const request = {
|
|
1489
|
+
// 'withdrawal_id': '4b450616042a48c99dd45cacb4b092a7', // string
|
|
1490
|
+
// 'currency': currency['id'],
|
|
1491
|
+
// 'state': 'state',
|
|
1492
|
+
// 'start_time': since, // default 1 day
|
|
1493
|
+
// 'end_time': this.milliseconds (),
|
|
1494
|
+
// 'page_num': 1,
|
|
1495
|
+
// 'page_size': limit, // default 20, maximum 50
|
|
1496
|
+
};
|
|
1497
|
+
let currency = undefined;
|
|
1498
|
+
if (code !== undefined) {
|
|
1499
|
+
currency = this.currency (code);
|
|
1500
|
+
request['currency'] = currency['id'];
|
|
1501
|
+
}
|
|
1502
|
+
if (since !== undefined) {
|
|
1503
|
+
request['start_time'] = since;
|
|
1504
|
+
}
|
|
1505
|
+
if (limit !== undefined) {
|
|
1506
|
+
request['limit'] = limit;
|
|
1507
|
+
}
|
|
1508
|
+
const response = await this.spotPrivateGetAssetWithdrawList (this.extend (request, params));
|
|
1509
|
+
//
|
|
1510
|
+
// {
|
|
1511
|
+
// "code":200,
|
|
1512
|
+
// "data":{
|
|
1513
|
+
// "page_size":20,
|
|
1514
|
+
// "total_page":1,
|
|
1515
|
+
// "total_size":1,
|
|
1516
|
+
// "page_num":1,
|
|
1517
|
+
// "result_list":[
|
|
1518
|
+
// {
|
|
1519
|
+
// "id":"4b450616042a48c99dd45cacb4b092a7",
|
|
1520
|
+
// "currency":"USDT-TRX",
|
|
1521
|
+
// "address":"TRHKnx74Gb8UVcpDCMwzZVe4NqXfkdtPak",
|
|
1522
|
+
// "amount":30.0,
|
|
1523
|
+
// "fee":1.0,
|
|
1524
|
+
// "remark":"this is my first withdrawal remark",
|
|
1525
|
+
// "state":"WAIT",
|
|
1526
|
+
// "create_time":"2021-10-11T20:45:08.000+00:00"
|
|
1527
|
+
// }
|
|
1528
|
+
// ]
|
|
1529
|
+
// }
|
|
1530
|
+
// }
|
|
1531
|
+
//
|
|
1532
|
+
const data = this.safeValue (response, 'data', {});
|
|
1533
|
+
const resultList = this.safeValue (data, 'result_list', []);
|
|
1534
|
+
return this.parseTransactions (resultList, code, since, limit);
|
|
1535
|
+
}
|
|
1536
|
+
|
|
1537
|
+
parseTransaction (transaction, currency = undefined) {
|
|
1538
|
+
//
|
|
1539
|
+
// fetchDeposits
|
|
1540
|
+
//
|
|
1541
|
+
// {
|
|
1542
|
+
// "currency":"USDC",
|
|
1543
|
+
// "amount":150.0,
|
|
1544
|
+
// "fee":0.0,
|
|
1545
|
+
// "confirmations":19,
|
|
1546
|
+
// "address":"0x55cbd73db24eafcca97369e3f2db74b2490586e6",
|
|
1547
|
+
// "state":"SUCCESS",
|
|
1548
|
+
// "tx_id":"0xc65a9b09e1b71def81bf8bb3ec724c0c1b2b4c82200c8c142e4ea4c1469fd789:0",
|
|
1549
|
+
// "require_confirmations":12,
|
|
1550
|
+
// "create_time":"2021-10-11T18:58:25.000+00:00",
|
|
1551
|
+
// "update_time":"2021-10-11T19:01:06.000+00:00"
|
|
1552
|
+
// }
|
|
1553
|
+
//
|
|
1554
|
+
// fetchWithdrawals
|
|
1555
|
+
//
|
|
1556
|
+
// {
|
|
1557
|
+
// "id":"4b450616042a48c99dd45cacb4b092a7",
|
|
1558
|
+
// "currency":"USDT-TRX",
|
|
1559
|
+
// "address":"TRHKnx74Gb8UVcpDCMwzZVe4NqXfkdtPak",
|
|
1560
|
+
// "amount":30.0,
|
|
1561
|
+
// "fee":1.0,
|
|
1562
|
+
// "remark":"this is my first withdrawal remark",
|
|
1563
|
+
// "state":"WAIT",
|
|
1564
|
+
// "create_time":"2021-10-11T20:45:08.000+00:00"
|
|
1565
|
+
// }
|
|
1566
|
+
//
|
|
1567
|
+
const id = this.safeString (transaction, 'id');
|
|
1568
|
+
const type = (id === undefined) ? 'deposit' : 'withdrawal';
|
|
1569
|
+
const timestamp = this.parse8601 (this.safeString (transaction, 'create_time'));
|
|
1570
|
+
const updated = this.parse8601 (this.safeString (transaction, 'update_time'));
|
|
1571
|
+
let currencyId = this.safeString (transaction, 'currency');
|
|
1572
|
+
let network = undefined;
|
|
1573
|
+
if ((currencyId !== undefined) && (currencyId.indexOf ('-') >= 0)) {
|
|
1574
|
+
const parts = currencyId.split ('-');
|
|
1575
|
+
currencyId = this.safeString (parts, 0);
|
|
1576
|
+
const networkId = this.safeString (parts, 1);
|
|
1577
|
+
network = this.safeNetwork (networkId);
|
|
1578
|
+
}
|
|
1579
|
+
const code = this.safeCurrencyCode (currencyId, currency);
|
|
1580
|
+
const status = this.parseTransactionStatus (this.safeString (transaction, 'state'));
|
|
1581
|
+
let amountString = this.safeString (transaction, 'amount');
|
|
1582
|
+
const address = this.safeString (transaction, 'address');
|
|
1583
|
+
const txid = this.safeString (transaction, 'tx_id');
|
|
1584
|
+
let fee = undefined;
|
|
1585
|
+
const feeCostString = this.safeString (transaction, 'fee');
|
|
1586
|
+
if (feeCostString !== undefined) {
|
|
1587
|
+
fee = {
|
|
1588
|
+
'cost': this.parseNumber (feeCostString),
|
|
1589
|
+
'currency': code,
|
|
1590
|
+
};
|
|
1591
|
+
}
|
|
1592
|
+
if (type === 'withdrawal') {
|
|
1593
|
+
// mexc withdrawal amount includes the fee
|
|
1594
|
+
amountString = Precise.stringSub (amountString, feeCostString);
|
|
1595
|
+
}
|
|
1596
|
+
return {
|
|
1597
|
+
'info': transaction,
|
|
1598
|
+
'id': id,
|
|
1599
|
+
'txid': txid,
|
|
1600
|
+
'timestamp': timestamp,
|
|
1601
|
+
'datetime': this.iso8601 (timestamp),
|
|
1602
|
+
'network': network,
|
|
1603
|
+
'address': address,
|
|
1604
|
+
'addressTo': undefined,
|
|
1605
|
+
'addressFrom': undefined,
|
|
1606
|
+
'tag': undefined,
|
|
1607
|
+
'tagTo': undefined,
|
|
1608
|
+
'tagFrom': undefined,
|
|
1609
|
+
'type': type,
|
|
1610
|
+
'amount': this.parseNumber (amountString),
|
|
1611
|
+
'currency': code,
|
|
1612
|
+
'status': status,
|
|
1613
|
+
'updated': updated,
|
|
1614
|
+
'fee': fee,
|
|
1615
|
+
};
|
|
1616
|
+
}
|
|
1617
|
+
|
|
1618
|
+
parseTransactionStatus (status) {
|
|
1619
|
+
const statuses = {
|
|
1620
|
+
'WAIT': 'pending',
|
|
1621
|
+
'WAIT_PACKAGING': 'pending',
|
|
1622
|
+
'SUCCESS': 'ok',
|
|
1623
|
+
};
|
|
1624
|
+
return this.safeString (statuses, status, status);
|
|
1625
|
+
}
|
|
1626
|
+
|
|
1627
|
+
async fetchPosition (symbol, params = {}) {
|
|
1628
|
+
await this.loadMarkets ();
|
|
1629
|
+
const market = this.market (symbol);
|
|
1630
|
+
const request = {
|
|
1631
|
+
'symbol': market['id'],
|
|
1632
|
+
};
|
|
1633
|
+
const response = await this.fetchPositions (this.extend (request, params));
|
|
1634
|
+
const firstPosition = this.safeValue (response, 0);
|
|
1635
|
+
return this.parsePosition (firstPosition, market);
|
|
1636
|
+
}
|
|
1637
|
+
|
|
1638
|
+
async fetchPositions (symbols = undefined, params = {}) {
|
|
1639
|
+
await this.loadMarkets ();
|
|
1640
|
+
const response = await this.contractPrivateGetPositionOpenPositions (params);
|
|
1641
|
+
//
|
|
1642
|
+
// {
|
|
1643
|
+
// "success": true,
|
|
1644
|
+
// "code": 0,
|
|
1645
|
+
// "data": [
|
|
1646
|
+
// {
|
|
1647
|
+
// "positionId": 1394650,
|
|
1648
|
+
// "symbol": "ETH_USDT",
|
|
1649
|
+
// "positionType": 1,
|
|
1650
|
+
// "openType": 1,
|
|
1651
|
+
// "state": 1,
|
|
1652
|
+
// "holdVol": 1,
|
|
1653
|
+
// "frozenVol": 0,
|
|
1654
|
+
// "closeVol": 0,
|
|
1655
|
+
// "holdAvgPrice": 1217.3,
|
|
1656
|
+
// "openAvgPrice": 1217.3,
|
|
1657
|
+
// "closeAvgPrice": 0,
|
|
1658
|
+
// "liquidatePrice": 1211.2,
|
|
1659
|
+
// "oim": 0.1290338,
|
|
1660
|
+
// "im": 0.1290338,
|
|
1661
|
+
// "holdFee": 0,
|
|
1662
|
+
// "realised": -0.0073,
|
|
1663
|
+
// "leverage": 100,
|
|
1664
|
+
// "createTime": 1609991676000,
|
|
1665
|
+
// "updateTime": 1609991676000,
|
|
1666
|
+
// "autoAddIm": false
|
|
1667
|
+
// }
|
|
1668
|
+
// ]
|
|
1669
|
+
// }
|
|
1670
|
+
//
|
|
1671
|
+
const data = this.safeValue (response, 'data', []);
|
|
1672
|
+
return this.parsePositions (data);
|
|
1673
|
+
}
|
|
1674
|
+
|
|
1675
|
+
parsePosition (position, market = undefined) {
|
|
1676
|
+
//
|
|
1677
|
+
// {
|
|
1678
|
+
// "positionId": 1394650,
|
|
1679
|
+
// "symbol": "ETH_USDT",
|
|
1680
|
+
// "positionType": 1,
|
|
1681
|
+
// "openType": 1,
|
|
1682
|
+
// "state": 1,
|
|
1683
|
+
// "holdVol": 1,
|
|
1684
|
+
// "frozenVol": 0,
|
|
1685
|
+
// "closeVol": 0,
|
|
1686
|
+
// "holdAvgPrice": 1217.3,
|
|
1687
|
+
// "openAvgPrice": 1217.3,
|
|
1688
|
+
// "closeAvgPrice": 0,
|
|
1689
|
+
// "liquidatePrice": 1211.2,
|
|
1690
|
+
// "oim": 0.1290338,
|
|
1691
|
+
// "im": 0.1290338,
|
|
1692
|
+
// "holdFee": 0,
|
|
1693
|
+
// "realised": -0.0073,
|
|
1694
|
+
// "leverage": 100,
|
|
1695
|
+
// "createTime": 1609991676000,
|
|
1696
|
+
// "updateTime": 1609991676000,
|
|
1697
|
+
// "autoAddIm": false
|
|
1698
|
+
// }
|
|
1699
|
+
//
|
|
1700
|
+
market = this.safeMarket (this.safeString (position, 'symbol'), market);
|
|
1701
|
+
const symbol = market['symbol'];
|
|
1702
|
+
const contracts = this.safeString (position, 'holdVol');
|
|
1703
|
+
const entryPrice = this.safeNumber (position, 'openAvgPrice');
|
|
1704
|
+
const initialMargin = this.safeString (position, 'im');
|
|
1705
|
+
const rawSide = this.safeString (position, 'positionType');
|
|
1706
|
+
const side = (rawSide === '1') ? 'long' : 'short';
|
|
1707
|
+
const openType = this.safeString (position, 'margin_mode');
|
|
1708
|
+
const marginType = (openType === '1') ? 'isolated' : 'cross';
|
|
1709
|
+
const leverage = this.safeString (position, 'leverage');
|
|
1710
|
+
const liquidationPrice = this.safeNumber (position, 'liquidatePrice');
|
|
1711
|
+
const timestamp = this.safeNumber (position, 'updateTime');
|
|
1712
|
+
return {
|
|
1713
|
+
'info': position,
|
|
1714
|
+
'symbol': symbol,
|
|
1715
|
+
'contracts': this.parseNumber (contracts),
|
|
1716
|
+
'contractSize': undefined,
|
|
1717
|
+
'entryPrice': entryPrice,
|
|
1718
|
+
'collateral': undefined,
|
|
1719
|
+
'side': side,
|
|
1720
|
+
'unrealizedProfit': undefined,
|
|
1721
|
+
'leverage': this.parseNumber (leverage),
|
|
1722
|
+
'percentage': undefined,
|
|
1723
|
+
'marginType': marginType,
|
|
1724
|
+
'notional': undefined,
|
|
1725
|
+
'markPrice': undefined,
|
|
1726
|
+
'liquidationPrice': liquidationPrice,
|
|
1727
|
+
'initialMargin': this.parseNumber (initialMargin),
|
|
1728
|
+
'initialMarginPercentage': undefined,
|
|
1729
|
+
'maintenanceMargin': undefined,
|
|
1730
|
+
'maintenanceMarginPercentage': undefined,
|
|
1731
|
+
'marginRatio': undefined,
|
|
1732
|
+
'timestamp': timestamp,
|
|
1733
|
+
'datetime': this.iso8601 (timestamp),
|
|
1734
|
+
};
|
|
1735
|
+
}
|
|
1736
|
+
|
|
1737
|
+
parsePositions (positions) {
|
|
1738
|
+
const result = [];
|
|
1739
|
+
for (let i = 0; i < positions.length; i++) {
|
|
1740
|
+
result.push (this.parsePosition (positions[i]));
|
|
1741
|
+
}
|
|
1742
|
+
return result;
|
|
1743
|
+
}
|
|
1744
|
+
|
|
1745
|
+
async createOrder (symbol, type, side, amount, price = undefined, params = {}) {
|
|
1746
|
+
await this.loadMarkets ();
|
|
1747
|
+
const market = this.market (symbol);
|
|
1748
|
+
const [ marketType, query ] = this.handleMarketTypeAndParams ('createOrder', market, params);
|
|
1749
|
+
if (marketType === 'spot') {
|
|
1750
|
+
return await this.createSpotOrder (symbol, type, side, amount, price, query);
|
|
1751
|
+
} else if (marketType === 'swap') {
|
|
1752
|
+
return await this.createSwapOrder (symbol, type, side, amount, price, query);
|
|
1753
|
+
}
|
|
1754
|
+
}
|
|
1755
|
+
|
|
1756
|
+
async createSpotOrder (symbol, type, side, amount, price = undefined, params = {}) {
|
|
1757
|
+
await this.loadMarkets ();
|
|
1758
|
+
const market = this.market (symbol);
|
|
1759
|
+
let orderSide = undefined;
|
|
1760
|
+
if (side === 'buy') {
|
|
1761
|
+
orderSide = 'BID';
|
|
1762
|
+
} else if (side === 'sell') {
|
|
1763
|
+
orderSide = 'ASK';
|
|
1764
|
+
}
|
|
1765
|
+
let orderType = type.toUpperCase ();
|
|
1766
|
+
const postOnly = this.safeValue (params, 'postOnly', false);
|
|
1767
|
+
if (postOnly) {
|
|
1768
|
+
orderType = 'POST_ONLY';
|
|
1769
|
+
} else if (orderType === 'LIMIT') {
|
|
1770
|
+
orderType = 'LIMIT_ORDER';
|
|
1771
|
+
} else if ((orderType !== 'POST_ONLY') && (orderType !== 'IMMEDIATE_OR_CANCEL')) {
|
|
1772
|
+
throw new InvalidOrder (this.id + ' createOrder() does not support ' + type + ' order type, specify one of LIMIT, LIMIT_ORDER, POST_ONLY or IMMEDIATE_OR_CANCEL');
|
|
1773
|
+
}
|
|
1774
|
+
const request = {
|
|
1775
|
+
'symbol': market['id'],
|
|
1776
|
+
'price': this.priceToPrecision (symbol, price),
|
|
1777
|
+
'quantity': this.amountToPrecision (symbol, amount),
|
|
1778
|
+
'trade_type': orderSide,
|
|
1779
|
+
'order_type': orderType, // LIMIT_ORDER,POST_ONLY,IMMEDIATE_OR_CANCEL
|
|
1780
|
+
};
|
|
1781
|
+
const clientOrderId = this.safeString2 (params, 'clientOrderId', 'client_order_id');
|
|
1782
|
+
if (clientOrderId !== undefined) {
|
|
1783
|
+
request['client_order_id'] = clientOrderId;
|
|
1784
|
+
}
|
|
1785
|
+
params = this.omit (params, [ 'type', 'clientOrderId', 'client_order_id', 'postOnly' ]);
|
|
1786
|
+
const response = await this.spotPrivatePostOrderPlace (this.extend (request, params));
|
|
1787
|
+
//
|
|
1788
|
+
// {"code":200,"data":"2ff3163e8617443cb9c6fc19d42b1ca4"}
|
|
1789
|
+
//
|
|
1790
|
+
return this.parseOrder (response, market);
|
|
1791
|
+
}
|
|
1792
|
+
|
|
1793
|
+
async createSwapOrder (symbol, type, side, amount, price = undefined, params = {}) {
|
|
1794
|
+
await this.loadMarkets ();
|
|
1795
|
+
const market = this.market (symbol);
|
|
1796
|
+
const openType = this.safeInteger (params, 'openType');
|
|
1797
|
+
if (openType === undefined) {
|
|
1798
|
+
throw new ArgumentsRequired (this.id + ' createSwapOrder() requires an integer openType parameter, 1 for isolated margin, 2 for cross margin');
|
|
1799
|
+
}
|
|
1800
|
+
if ((type !== 'limit') && (type !== 'market') && (type !== 1) && (type !== 2) && (type !== 3) && (type !== 4) && (type !== 5) && (type !== 6)) {
|
|
1801
|
+
throw new InvalidOrder (this.id + ' createSwapOrder() order type must either limit, market, or 1 for limit orders, 2 for post-only orders, 3 for IOC orders, 4 for FOK orders, 5 for market orders or 6 to convert market price to current price');
|
|
1802
|
+
}
|
|
1803
|
+
const postOnly = this.safeValue (params, 'postOnly', false);
|
|
1804
|
+
if (postOnly) {
|
|
1805
|
+
type = 2;
|
|
1806
|
+
} else if (type === 'limit') {
|
|
1807
|
+
type = 1;
|
|
1808
|
+
} else if (type === 'market') {
|
|
1809
|
+
type = 6;
|
|
1810
|
+
}
|
|
1811
|
+
if ((side !== 1) && (side !== 2) && (side !== 3) && (side !== 4)) {
|
|
1812
|
+
throw new InvalidOrder (this.id + ' createSwapOrder() order side must be 1 open long, 2 close short, 3 open short or 4 close long');
|
|
1813
|
+
}
|
|
1814
|
+
const request = {
|
|
1815
|
+
'symbol': market['id'],
|
|
1816
|
+
// 'price': parseFloat (this.priceToPrecision (symbol, price)),
|
|
1817
|
+
'vol': parseFloat (this.amountToPrecision (symbol, amount)),
|
|
1818
|
+
// 'leverage': int, // required for isolated margin
|
|
1819
|
+
'side': side, // 1 open long, 2 close short, 3 open short, 4 close long
|
|
1820
|
+
//
|
|
1821
|
+
// supported order types
|
|
1822
|
+
//
|
|
1823
|
+
// 1 limit
|
|
1824
|
+
// 2 post only maker (PO)
|
|
1825
|
+
// 3 transact or cancel instantly (IOC)
|
|
1826
|
+
// 4 transact completely or cancel completely (FOK)
|
|
1827
|
+
// 5 market orders
|
|
1828
|
+
// 6 convert market price to current price
|
|
1829
|
+
//
|
|
1830
|
+
'type': type,
|
|
1831
|
+
'openType': openType, // 1 isolated, 2 cross
|
|
1832
|
+
// 'positionId': 1394650, // long, filling in this parameter when closing a position is recommended
|
|
1833
|
+
// 'externalOid': clientOrderId,
|
|
1834
|
+
// 'triggerPrice': 10.0, // Required for trigger order
|
|
1835
|
+
// 'triggerType': 1, // Required for trigger order 1: more than or equal, 2: less than or equal
|
|
1836
|
+
// 'executeCycle': 1, // Required for trigger order 1: 24 hours,2: 7 days
|
|
1837
|
+
// 'trend': 1, // Required for trigger order 1: latest price, 2: fair price, 3: index price
|
|
1838
|
+
// 'orderType': 1, // Required for trigger order 1: limit order,2:Post Only Maker,3: close or cancel instantly ,4: close or cancel completely,5: Market order
|
|
1839
|
+
};
|
|
1840
|
+
let method = 'contractPrivatePostOrderSubmit';
|
|
1841
|
+
const stopPrice = this.safeNumber2 (params, 'triggerPrice', 'stopPrice');
|
|
1842
|
+
params = this.omit (params, [ 'stopPrice', 'triggerPrice' ]);
|
|
1843
|
+
if (stopPrice !== undefined) {
|
|
1844
|
+
method = 'contractPrivatePostPlanorderPlace';
|
|
1845
|
+
request['triggerPrice'] = this.priceToPrecision (symbol, stopPrice);
|
|
1846
|
+
request['triggerType'] = this.safeInteger (params, 'triggerType', 1);
|
|
1847
|
+
request['executeCycle'] = this.safeInteger (params, 'executeCycle', 1);
|
|
1848
|
+
request['trend'] = this.safeInteger (params, 'trend', 1);
|
|
1849
|
+
request['orderType'] = this.safeInteger (params, 'orderType', 1);
|
|
1850
|
+
}
|
|
1851
|
+
if ((type !== 5) && (type !== 6) && (type !== 'market')) {
|
|
1852
|
+
request['price'] = parseFloat (this.priceToPrecision (symbol, price));
|
|
1853
|
+
}
|
|
1854
|
+
if (openType === 1) {
|
|
1855
|
+
const leverage = this.safeInteger (params, 'leverage');
|
|
1856
|
+
if (leverage === undefined) {
|
|
1857
|
+
throw new ArgumentsRequired (this.id + ' createSwapOrder() requires a leverage parameter for isolated margin orders');
|
|
1858
|
+
}
|
|
1859
|
+
}
|
|
1860
|
+
const clientOrderId = this.safeString2 (params, 'clientOrderId', 'externalOid');
|
|
1861
|
+
if (clientOrderId !== undefined) {
|
|
1862
|
+
request['externalOid'] = clientOrderId;
|
|
1863
|
+
}
|
|
1864
|
+
params = this.omit (params, [ 'clientOrderId', 'externalOid', 'postOnly' ]);
|
|
1865
|
+
const response = await this[method] (this.extend (request, params));
|
|
1866
|
+
//
|
|
1867
|
+
// Swap
|
|
1868
|
+
// {"code":200,"data":"2ff3163e8617443cb9c6fc19d42b1ca4"}
|
|
1869
|
+
//
|
|
1870
|
+
// Trigger
|
|
1871
|
+
// {"success":true,"code":0,"data":259208506303929856}
|
|
1872
|
+
//
|
|
1873
|
+
return this.parseOrder (response, market);
|
|
1874
|
+
}
|
|
1875
|
+
|
|
1876
|
+
async cancelOrder (id, symbol = undefined, params = {}) {
|
|
1877
|
+
if (symbol === undefined) {
|
|
1878
|
+
throw new ArgumentsRequired (this.id + ' cancelOrder() requires a symbol argument');
|
|
1879
|
+
}
|
|
1880
|
+
await this.loadMarkets ();
|
|
1881
|
+
const market = this.market (symbol);
|
|
1882
|
+
const options = this.safeValue (this.options, 'cancelOrder', {});
|
|
1883
|
+
const defaultMethod = this.safeString (options, 'method', 'spotPrivateDeleteOrderCancel');
|
|
1884
|
+
let method = this.safeString (params, 'method', defaultMethod);
|
|
1885
|
+
const stop = this.safeValue (params, 'stop');
|
|
1886
|
+
let request = {};
|
|
1887
|
+
if (market['type'] === 'spot') {
|
|
1888
|
+
method = 'spotPrivateDeleteOrderCancel';
|
|
1889
|
+
const clientOrderId = this.safeString2 (params, 'clientOrderId', 'client_order_ids');
|
|
1890
|
+
if (clientOrderId !== undefined) {
|
|
1891
|
+
params = this.omit (params, [ 'clientOrderId', 'client_order_ids' ]);
|
|
1892
|
+
request['client_order_ids'] = clientOrderId;
|
|
1893
|
+
} else {
|
|
1894
|
+
request['order_ids'] = id;
|
|
1895
|
+
}
|
|
1896
|
+
} else if (stop) {
|
|
1897
|
+
method = 'contractPrivatePostPlanorderCancel';
|
|
1898
|
+
request = [];
|
|
1899
|
+
if (Array.isArray (id)) {
|
|
1900
|
+
for (let i = 0; i < id.length; i++) {
|
|
1901
|
+
request.push ({
|
|
1902
|
+
'symbol': market['id'],
|
|
1903
|
+
'orderId': id[i],
|
|
1904
|
+
});
|
|
1905
|
+
}
|
|
1906
|
+
} else if (typeof id === 'string') {
|
|
1907
|
+
request.push ({
|
|
1908
|
+
'symbol': market['id'],
|
|
1909
|
+
'orderId': id,
|
|
1910
|
+
});
|
|
1911
|
+
}
|
|
1912
|
+
} else if (market['type'] === 'swap') {
|
|
1913
|
+
method = 'contractPrivatePostOrderCancel';
|
|
1914
|
+
request = [ id ];
|
|
1915
|
+
}
|
|
1916
|
+
const response = await this[method] (request); // dont extend with params, otherwise ARRAY will be turned into OBJECT
|
|
1917
|
+
//
|
|
1918
|
+
// Spot
|
|
1919
|
+
//
|
|
1920
|
+
// {"code":200,"data":{"965245851c444078a11a7d771323613b":"success"}}
|
|
1921
|
+
//
|
|
1922
|
+
// Swap
|
|
1923
|
+
//
|
|
1924
|
+
// {
|
|
1925
|
+
// "success": true,
|
|
1926
|
+
// "code": 0,
|
|
1927
|
+
// "data": [
|
|
1928
|
+
// {
|
|
1929
|
+
// "orderId": 268726891790294528,
|
|
1930
|
+
// "errorCode": 0,
|
|
1931
|
+
// "errorMsg": "success"
|
|
1932
|
+
// }
|
|
1933
|
+
// ]
|
|
1934
|
+
// }
|
|
1935
|
+
//
|
|
1936
|
+
// Trigger
|
|
1937
|
+
//
|
|
1938
|
+
// {
|
|
1939
|
+
// "success": true,
|
|
1940
|
+
// "code": 0
|
|
1941
|
+
// }
|
|
1942
|
+
//
|
|
1943
|
+
let data = this.safeValue (response, 'data', []);
|
|
1944
|
+
if (stop) {
|
|
1945
|
+
data = response;
|
|
1946
|
+
}
|
|
1947
|
+
return this.parseOrder (data, market);
|
|
1948
|
+
}
|
|
1949
|
+
|
|
1950
|
+
parseOrderStatus (status, market = undefined) {
|
|
1951
|
+
let statuses = {};
|
|
1952
|
+
if (market['type'] === 'spot') {
|
|
1953
|
+
statuses = {
|
|
1954
|
+
'NEW': 'open',
|
|
1955
|
+
'FILLED': 'closed',
|
|
1956
|
+
'PARTIALLY_FILLED': 'open',
|
|
1957
|
+
'CANCELED': 'canceled',
|
|
1958
|
+
'PARTIALLY_CANCELED': 'canceled',
|
|
1959
|
+
};
|
|
1960
|
+
} else if (market['type'] === 'swap') {
|
|
1961
|
+
statuses = {
|
|
1962
|
+
'2': 'open',
|
|
1963
|
+
'3': 'closed',
|
|
1964
|
+
'4': 'canceled',
|
|
1965
|
+
};
|
|
1966
|
+
} else {
|
|
1967
|
+
statuses = {
|
|
1968
|
+
'1': 'open',
|
|
1969
|
+
'2': 'canceled',
|
|
1970
|
+
'3': 'closed',
|
|
1971
|
+
};
|
|
1972
|
+
}
|
|
1973
|
+
return this.safeString (statuses, status, status);
|
|
1974
|
+
}
|
|
1975
|
+
|
|
1976
|
+
parseOrder (order, market = undefined) {
|
|
1977
|
+
//
|
|
1978
|
+
// createOrder
|
|
1979
|
+
//
|
|
1980
|
+
// spot
|
|
1981
|
+
//
|
|
1982
|
+
// {"code":200,"data":"2ff3163e8617443cb9c6fc19d42b1ca4"}
|
|
1983
|
+
//
|
|
1984
|
+
// swap / contract
|
|
1985
|
+
//
|
|
1986
|
+
// { "success": true, "code": 0, "data": 102057569836905984 }
|
|
1987
|
+
//
|
|
1988
|
+
// spot fetchOpenOrders
|
|
1989
|
+
//
|
|
1990
|
+
// {
|
|
1991
|
+
// "id":"965245851c444078a11a7d771323613b",
|
|
1992
|
+
// "symbol":"ETH_USDT",
|
|
1993
|
+
// "price":"3430",
|
|
1994
|
+
// "quantity":"0.01",
|
|
1995
|
+
// "state":"NEW",
|
|
1996
|
+
// "type":"BID",
|
|
1997
|
+
// "remain_quantity":"0.01",
|
|
1998
|
+
// "remain_amount":"34.3",
|
|
1999
|
+
// "create_time":1633989029039,
|
|
2000
|
+
// "client_order_id":"",
|
|
2001
|
+
// "order_type":"LIMIT_ORDER"
|
|
2002
|
+
// }
|
|
2003
|
+
//
|
|
2004
|
+
// swap fetchOpenOrders, fetchClosedOrders, fetchCanceledOrders
|
|
2005
|
+
//
|
|
2006
|
+
// {
|
|
2007
|
+
// "orderId": "266578267438402048",
|
|
2008
|
+
// "symbol": "BTC_USDT",
|
|
2009
|
+
// "positionId": 0,
|
|
2010
|
+
// "price": 30000,
|
|
2011
|
+
// "vol": 11,
|
|
2012
|
+
// "leverage": 20,
|
|
2013
|
+
// "side": 1,
|
|
2014
|
+
// "category": 1,
|
|
2015
|
+
// "orderType": 1,
|
|
2016
|
+
// "dealAvgPrice": 0,
|
|
2017
|
+
// "dealVol": 0,
|
|
2018
|
+
// "orderMargin": 1.6896,
|
|
2019
|
+
// "takerFee": 0,
|
|
2020
|
+
// "makerFee": 0,
|
|
2021
|
+
// "profit": 0,
|
|
2022
|
+
// "feeCurrency": "USDT",
|
|
2023
|
+
// "openType": 1,
|
|
2024
|
+
// "state": 2,
|
|
2025
|
+
// "externalOid": "_m_8d673a31c47642d9a59993aca61ae394",
|
|
2026
|
+
// "errorCode": 0,
|
|
2027
|
+
// "usedMargin": 0,
|
|
2028
|
+
// "createTime": 1649227612000,
|
|
2029
|
+
// "updateTime": 1649227611000,
|
|
2030
|
+
// "positionMode": 1
|
|
2031
|
+
// }
|
|
2032
|
+
//
|
|
2033
|
+
// spot fetchClosedOrders, fetchCanceledOrders, fetchOrder
|
|
2034
|
+
//
|
|
2035
|
+
// {
|
|
2036
|
+
// "id":"d798765285374222990bbd14decb86cd",
|
|
2037
|
+
// "symbol":"USDC_USDT",
|
|
2038
|
+
// "price":"0.9988",
|
|
2039
|
+
// "quantity":"150",
|
|
2040
|
+
// "state":"FILLED", // CANCELED
|
|
2041
|
+
// "type":"ASK", // BID
|
|
2042
|
+
// "deal_quantity":"150",
|
|
2043
|
+
// "deal_amount":"149.955",
|
|
2044
|
+
// "create_time":1633984904000,
|
|
2045
|
+
// "order_type":"MARKET_ORDER" // LIMIT_ORDER
|
|
2046
|
+
// }
|
|
2047
|
+
//
|
|
2048
|
+
// trigger fetchClosedOrders, fetchCanceledOrders, fetchOpenOrders
|
|
2049
|
+
//
|
|
2050
|
+
// {
|
|
2051
|
+
// "id": "266583973507973632",
|
|
2052
|
+
// "symbol": "BTC_USDT",
|
|
2053
|
+
// "leverage": 20,
|
|
2054
|
+
// "side": 1,
|
|
2055
|
+
// "triggerPrice": 30000,
|
|
2056
|
+
// "price": 31000,
|
|
2057
|
+
// "vol": 11,
|
|
2058
|
+
// "openType": 1,
|
|
2059
|
+
// "triggerType": 2,
|
|
2060
|
+
// "state": 2,
|
|
2061
|
+
// "executeCycle": 87600,
|
|
2062
|
+
// "trend": 1,
|
|
2063
|
+
// "orderType": 1,
|
|
2064
|
+
// "errorCode": 0,
|
|
2065
|
+
// "createTime": 1649228972000,
|
|
2066
|
+
// "updateTime": 1649230287000
|
|
2067
|
+
// }
|
|
2068
|
+
//
|
|
2069
|
+
// spot cancelOrder
|
|
2070
|
+
//
|
|
2071
|
+
// {"965245851c444078a11a7d771323613b":"success"}
|
|
2072
|
+
//
|
|
2073
|
+
// swap cancelOrder
|
|
2074
|
+
//
|
|
2075
|
+
// {
|
|
2076
|
+
// "orderId": 268726891790294528,
|
|
2077
|
+
// "errorCode": 0,
|
|
2078
|
+
// "errorMsg": "success"
|
|
2079
|
+
// }
|
|
2080
|
+
//
|
|
2081
|
+
// trigger cancelOrder
|
|
2082
|
+
//
|
|
2083
|
+
// {
|
|
2084
|
+
// "success": true,
|
|
2085
|
+
// "code": 0
|
|
2086
|
+
// }
|
|
2087
|
+
//
|
|
2088
|
+
let id = this.safeString2 (order, 'data', 'id');
|
|
2089
|
+
let status = undefined;
|
|
2090
|
+
if (id === undefined) {
|
|
2091
|
+
const keys = Object.keys (order);
|
|
2092
|
+
id = this.safeString (keys, 0);
|
|
2093
|
+
const state = this.safeString (order, id);
|
|
2094
|
+
if (state === 'success') {
|
|
2095
|
+
status = 'canceled';
|
|
2096
|
+
}
|
|
2097
|
+
}
|
|
2098
|
+
const state = this.safeString (order, 'state');
|
|
2099
|
+
const timestamp = this.safeInteger2 (order, 'create_time', 'createTime');
|
|
2100
|
+
const price = this.safeString (order, 'price');
|
|
2101
|
+
const amount = this.safeString2 (order, 'quantity', 'vol');
|
|
2102
|
+
const remaining = this.safeString (order, 'remain_quantity');
|
|
2103
|
+
const filled = this.safeString2 (order, 'deal_quantity', 'dealVol');
|
|
2104
|
+
const cost = this.safeString2 (order, 'deal_amount', 'dealAvgPrice');
|
|
2105
|
+
const marketId = this.safeString (order, 'symbol');
|
|
2106
|
+
const symbol = this.safeSymbol (marketId, market, '_');
|
|
2107
|
+
const sideCheck = this.safeInteger (order, 'side');
|
|
2108
|
+
let side = undefined;
|
|
2109
|
+
const bidOrAsk = this.safeString (order, 'type');
|
|
2110
|
+
if (bidOrAsk === 'BID') {
|
|
2111
|
+
side = 'buy';
|
|
2112
|
+
} else if (bidOrAsk === 'ASK') {
|
|
2113
|
+
side = 'sell';
|
|
2114
|
+
}
|
|
2115
|
+
if (sideCheck === 1) {
|
|
2116
|
+
side = 'open long';
|
|
2117
|
+
} else if (side === 2) {
|
|
2118
|
+
side = 'close short';
|
|
2119
|
+
} else if (side === 3) {
|
|
2120
|
+
side = 'open short';
|
|
2121
|
+
} else if (side === 4) {
|
|
2122
|
+
side = 'close long';
|
|
2123
|
+
}
|
|
2124
|
+
status = this.parseOrderStatus (state, market);
|
|
2125
|
+
let clientOrderId = this.safeString2 (order, 'client_order_id', 'orderId');
|
|
2126
|
+
if (clientOrderId === '') {
|
|
2127
|
+
clientOrderId = undefined;
|
|
2128
|
+
}
|
|
2129
|
+
let orderType = this.safeStringLower (order, 'order_type');
|
|
2130
|
+
if (orderType !== undefined) {
|
|
2131
|
+
orderType = orderType.replace ('_order', '');
|
|
2132
|
+
}
|
|
2133
|
+
return this.safeOrder ({
|
|
2134
|
+
'id': id,
|
|
2135
|
+
'clientOrderId': clientOrderId,
|
|
2136
|
+
'timestamp': timestamp,
|
|
2137
|
+
'datetime': this.iso8601 (timestamp),
|
|
2138
|
+
'lastTradeTimestamp': this.safeInteger (order, 'updateTime'),
|
|
2139
|
+
'status': status,
|
|
2140
|
+
'symbol': symbol,
|
|
2141
|
+
'type': orderType,
|
|
2142
|
+
'timeInForce': undefined,
|
|
2143
|
+
'side': side,
|
|
2144
|
+
'price': price,
|
|
2145
|
+
'stopPrice': undefined,
|
|
2146
|
+
'average': undefined,
|
|
2147
|
+
'amount': amount,
|
|
2148
|
+
'cost': cost,
|
|
2149
|
+
'filled': filled,
|
|
2150
|
+
'remaining': remaining,
|
|
2151
|
+
'fee': undefined,
|
|
2152
|
+
'trades': undefined,
|
|
2153
|
+
'info': order,
|
|
2154
|
+
}, market);
|
|
2155
|
+
}
|
|
2156
|
+
|
|
2157
|
+
async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
|
2158
|
+
if (symbol === undefined) {
|
|
2159
|
+
throw new ArgumentsRequired (this.id + ' fetchOpenOrders() requires a symbol argument');
|
|
2160
|
+
}
|
|
2161
|
+
await this.loadMarkets ();
|
|
2162
|
+
const market = this.market (symbol);
|
|
2163
|
+
const request = {
|
|
2164
|
+
'symbol': market['id'], // spot, swap
|
|
2165
|
+
// 'start_time': since, // spot
|
|
2166
|
+
// 'limit': limit, // spot default 50, max 1000
|
|
2167
|
+
// 'trade_type': 'BID', // spot BID / ASK
|
|
2168
|
+
// 'page_num': 1, // swap required default 1
|
|
2169
|
+
// 'page_size': limit, // swap required default 20 max 100
|
|
2170
|
+
// 'end_time': 1633988662382, // trigger order
|
|
2171
|
+
};
|
|
2172
|
+
const [ marketType, query ] = this.handleMarketTypeAndParams ('fetchOpenOrders', market, params);
|
|
2173
|
+
const method = this.getSupportedMapping (marketType, {
|
|
2174
|
+
'spot': 'spotPrivateGetOrderOpenOrders',
|
|
2175
|
+
'swap': 'contractPrivateGetOrderListOpenOrdersSymbol',
|
|
2176
|
+
});
|
|
2177
|
+
const stop = this.safeValue (params, 'stop');
|
|
2178
|
+
if (stop) {
|
|
2179
|
+
return await this.fetchOrdersByState ('1', symbol, since, limit, params);
|
|
2180
|
+
}
|
|
2181
|
+
const response = await this[method] (this.extend (request, query));
|
|
2182
|
+
//
|
|
2183
|
+
// Spot
|
|
2184
|
+
//
|
|
2185
|
+
// {
|
|
2186
|
+
// "code":200,
|
|
2187
|
+
// "data":[
|
|
2188
|
+
// {
|
|
2189
|
+
// "id":"965245851c444078a11a7d771323613b",
|
|
2190
|
+
// "symbol":"ETH_USDT",
|
|
2191
|
+
// "price":"3430",
|
|
2192
|
+
// "quantity":"0.01",
|
|
2193
|
+
// "state":"NEW",
|
|
2194
|
+
// "type":"BID",
|
|
2195
|
+
// "remain_quantity":"0.01",
|
|
2196
|
+
// "remain_amount":"34.3",
|
|
2197
|
+
// "create_time":1633989029039,
|
|
2198
|
+
// "client_order_id":"",
|
|
2199
|
+
// "order_type":"LIMIT_ORDER"
|
|
2200
|
+
// },
|
|
2201
|
+
// ]
|
|
2202
|
+
// }
|
|
2203
|
+
//
|
|
2204
|
+
// Swap
|
|
2205
|
+
//
|
|
2206
|
+
// {
|
|
2207
|
+
// "success": true,
|
|
2208
|
+
// "code": 0,
|
|
2209
|
+
// "data": [
|
|
2210
|
+
// {
|
|
2211
|
+
// "orderId": "266578267438402048",
|
|
2212
|
+
// "symbol": "BTC_USDT",
|
|
2213
|
+
// "positionId": 0,
|
|
2214
|
+
// "price": 30000,
|
|
2215
|
+
// "vol": 11,
|
|
2216
|
+
// "leverage": 20,
|
|
2217
|
+
// "side": 1,
|
|
2218
|
+
// "category": 1,
|
|
2219
|
+
// "orderType": 1,
|
|
2220
|
+
// "dealAvgPrice": 0,
|
|
2221
|
+
// "dealVol": 0,
|
|
2222
|
+
// "orderMargin": 1.6896,
|
|
2223
|
+
// "takerFee": 0,
|
|
2224
|
+
// "makerFee": 0,
|
|
2225
|
+
// "profit": 0,
|
|
2226
|
+
// "feeCurrency": "USDT",
|
|
2227
|
+
// "openType": 1,
|
|
2228
|
+
// "state": 2,
|
|
2229
|
+
// "externalOid": "_m_8d673a31c47642d9a59993aca61ae394",
|
|
2230
|
+
// "errorCode": 0,
|
|
2231
|
+
// "usedMargin": 0,
|
|
2232
|
+
// "createTime": 1649227612000,
|
|
2233
|
+
// "updateTime": 1649227611000,
|
|
2234
|
+
// "positionMode": 1
|
|
2235
|
+
// }
|
|
2236
|
+
// ]
|
|
2237
|
+
// }
|
|
2238
|
+
//
|
|
2239
|
+
// Trigger
|
|
2240
|
+
//
|
|
2241
|
+
// {
|
|
2242
|
+
// "success": true,
|
|
2243
|
+
// "code": 0,
|
|
2244
|
+
// "data": [
|
|
2245
|
+
// {
|
|
2246
|
+
// "id": "267198217203040768",
|
|
2247
|
+
// "symbol": "BTC_USDT",
|
|
2248
|
+
// "leverage": 20,
|
|
2249
|
+
// "side": 1,
|
|
2250
|
+
// "triggerPrice": 31111,
|
|
2251
|
+
// "price": 31115,
|
|
2252
|
+
// "vol": 2,
|
|
2253
|
+
// "openType": 1,
|
|
2254
|
+
// "triggerType": 2,
|
|
2255
|
+
// "state": 1,
|
|
2256
|
+
// "executeCycle": 87600,
|
|
2257
|
+
// "trend": 1,
|
|
2258
|
+
// "orderType": 1,
|
|
2259
|
+
// "errorCode": 0,
|
|
2260
|
+
// "createTime": 1649375419000,
|
|
2261
|
+
// "updateTime": 1649375419000
|
|
2262
|
+
// }
|
|
2263
|
+
// ]
|
|
2264
|
+
// }
|
|
2265
|
+
//
|
|
2266
|
+
const data = this.safeValue (response, 'data', []);
|
|
2267
|
+
return this.parseOrders (data, market, since, limit);
|
|
2268
|
+
}
|
|
2269
|
+
|
|
2270
|
+
async fetchOrder (id, symbol = undefined, params = {}) {
|
|
2271
|
+
if (symbol === undefined) {
|
|
2272
|
+
throw new ArgumentsRequired (this.id + ' fetchOrder() requires a symbol argument');
|
|
2273
|
+
}
|
|
2274
|
+
await this.loadMarkets ();
|
|
2275
|
+
const market = this.market (symbol);
|
|
2276
|
+
const [ marketType, query ] = this.handleMarketTypeAndParams ('fetchOrder', market, params);
|
|
2277
|
+
const request = {
|
|
2278
|
+
'order_ids': id,
|
|
2279
|
+
};
|
|
2280
|
+
const method = this.getSupportedMapping (marketType, {
|
|
2281
|
+
'spot': 'spotPrivateGetOrderQuery',
|
|
2282
|
+
'swap': 'contractPrivateGetOrderBatchQuery',
|
|
2283
|
+
});
|
|
2284
|
+
const response = await this[method] (this.extend (request, query));
|
|
2285
|
+
//
|
|
2286
|
+
// Spot
|
|
2287
|
+
//
|
|
2288
|
+
// {
|
|
2289
|
+
// "code":200,
|
|
2290
|
+
// "data":[
|
|
2291
|
+
// {
|
|
2292
|
+
// "id":"2ff3163e8617443cb9c6fc19d42b1ca4",
|
|
2293
|
+
// "symbol":"ETH_USDT",
|
|
2294
|
+
// "price":"3420",
|
|
2295
|
+
// "quantity":"0.01",
|
|
2296
|
+
// "state":"CANCELED",
|
|
2297
|
+
// "type":"BID",
|
|
2298
|
+
// "deal_quantity":"0",
|
|
2299
|
+
// "deal_amount":"0",
|
|
2300
|
+
// "create_time":1633988662000,
|
|
2301
|
+
// "order_type":"LIMIT_ORDER"
|
|
2302
|
+
// }
|
|
2303
|
+
// ]
|
|
2304
|
+
// }
|
|
2305
|
+
//
|
|
2306
|
+
// Swap
|
|
2307
|
+
//
|
|
2308
|
+
// {
|
|
2309
|
+
// "success": true,
|
|
2310
|
+
// "code": 0,
|
|
2311
|
+
// "data": [
|
|
2312
|
+
// {
|
|
2313
|
+
// "orderId": "259208506647860224",
|
|
2314
|
+
// "symbol": "BTC_USDT",
|
|
2315
|
+
// "positionId": 0,
|
|
2316
|
+
// "price": 30000,
|
|
2317
|
+
// "vol": 10,
|
|
2318
|
+
// "leverage": 20,
|
|
2319
|
+
// "side": 1,
|
|
2320
|
+
// "category": 1,
|
|
2321
|
+
// "orderType": 1,
|
|
2322
|
+
// "dealAvgPrice": 0,
|
|
2323
|
+
// "dealVol": 0,
|
|
2324
|
+
// "orderMargin": 1.536,
|
|
2325
|
+
// "takerFee": 0,
|
|
2326
|
+
// "makerFee": 0,
|
|
2327
|
+
// "profit": 0,
|
|
2328
|
+
// "feeCurrency": "USDT",
|
|
2329
|
+
// "openType": 1,
|
|
2330
|
+
// "state": 4,
|
|
2331
|
+
// "externalOid": "planorder_279208506303929856_10",
|
|
2332
|
+
// "errorCode": 0,
|
|
2333
|
+
// "usedMargin": 0,
|
|
2334
|
+
// "createTime": 1647470524000,
|
|
2335
|
+
// "updateTime": 1647470540000,
|
|
2336
|
+
// "positionMode": 1
|
|
2337
|
+
// }
|
|
2338
|
+
// ]
|
|
2339
|
+
// }
|
|
2340
|
+
//
|
|
2341
|
+
const data = this.safeValue (response, 'data', []);
|
|
2342
|
+
const firstOrder = this.safeValue (data, 0);
|
|
2343
|
+
if (firstOrder === undefined) {
|
|
2344
|
+
throw new OrderNotFound (this.id + ' fetchOrder() could not find the order id ' + id);
|
|
2345
|
+
}
|
|
2346
|
+
return this.parseOrder (firstOrder, market);
|
|
2347
|
+
}
|
|
2348
|
+
|
|
2349
|
+
async fetchOrdersByState (state, symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
|
2350
|
+
if (symbol === undefined) {
|
|
2351
|
+
throw new ArgumentsRequired (this.id + ' fetchOrdersByState() requires a symbol argument');
|
|
2352
|
+
}
|
|
2353
|
+
await this.loadMarkets ();
|
|
2354
|
+
const market = this.market (symbol);
|
|
2355
|
+
const request = {
|
|
2356
|
+
'symbol': market['id'],
|
|
2357
|
+
// 'start_time': since, // default 7 days, max 30 days
|
|
2358
|
+
// 'limit': limit, // default 50, max 1000
|
|
2359
|
+
// 'trade_type': 'BID', // BID / ASK
|
|
2360
|
+
'states': state, // NEW, FILLED, PARTIALLY_FILLED, CANCELED, PARTIALLY_CANCELED, trigger orders: 1 untriggered, 2 cancelled, 3 executed, 4 invalid, 5 execution failed
|
|
2361
|
+
// 'end_time': 1633988662000, // trigger orders
|
|
2362
|
+
// 'page_num': 1, // trigger orders default is 1
|
|
2363
|
+
// 'page_size': limit, // trigger orders default 20 max 100
|
|
2364
|
+
};
|
|
2365
|
+
const stop = this.safeValue (params, 'stop');
|
|
2366
|
+
const limitRequest = stop ? 'page_size' : 'limit';
|
|
2367
|
+
if (limit !== undefined) {
|
|
2368
|
+
request[limitRequest] = limit;
|
|
2369
|
+
}
|
|
2370
|
+
if (since !== undefined) {
|
|
2371
|
+
request['start_time'] = since;
|
|
2372
|
+
}
|
|
2373
|
+
const options = this.safeValue (this.options, 'fetchOrdersByState', {});
|
|
2374
|
+
const defaultMethod = this.safeString (options, 'method', 'spotPrivateGetOrderList');
|
|
2375
|
+
let method = this.safeString (params, 'method', defaultMethod);
|
|
2376
|
+
method = this.getSupportedMapping (market['type'], {
|
|
2377
|
+
'spot': 'spotPrivateGetOrderList',
|
|
2378
|
+
'swap': 'contractPrivateGetOrderListHistoryOrders',
|
|
2379
|
+
});
|
|
2380
|
+
if (stop) {
|
|
2381
|
+
method = 'contractPrivateGetPlanorderListOrders';
|
|
2382
|
+
}
|
|
2383
|
+
const query = this.omit (params, [ 'method', 'stop' ]);
|
|
2384
|
+
const response = await this[method] (this.extend (request, query));
|
|
2385
|
+
const data = this.safeValue (response, 'data', []);
|
|
2386
|
+
return this.parseOrders (data, market, since, limit);
|
|
2387
|
+
}
|
|
2388
|
+
|
|
2389
|
+
async fetchCanceledOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
|
2390
|
+
if (symbol === undefined) {
|
|
2391
|
+
throw new ArgumentsRequired (this.id + ' fetchCanceledOrders() requires a symbol argument');
|
|
2392
|
+
}
|
|
2393
|
+
await this.loadMarkets ();
|
|
2394
|
+
const market = this.market (symbol);
|
|
2395
|
+
const stop = this.safeValue (params, 'stop');
|
|
2396
|
+
let state = 'CANCELED';
|
|
2397
|
+
if (market['type'] === 'swap') {
|
|
2398
|
+
state = '4';
|
|
2399
|
+
} else if (stop) {
|
|
2400
|
+
state = '2';
|
|
2401
|
+
}
|
|
2402
|
+
return await this.fetchOrdersByState (state, symbol, since, limit, params);
|
|
2403
|
+
}
|
|
2404
|
+
|
|
2405
|
+
async fetchClosedOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
|
2406
|
+
if (symbol === undefined) {
|
|
2407
|
+
throw new ArgumentsRequired (this.id + ' fetchClosedOrders() requires a symbol argument');
|
|
2408
|
+
}
|
|
2409
|
+
await this.loadMarkets ();
|
|
2410
|
+
const market = this.market (symbol);
|
|
2411
|
+
const stop = this.safeValue (params, 'stop');
|
|
2412
|
+
let state = 'FILLED';
|
|
2413
|
+
if (stop || market['type'] === 'swap') {
|
|
2414
|
+
state = '3';
|
|
2415
|
+
}
|
|
2416
|
+
return await this.fetchOrdersByState (state, symbol, since, limit, params);
|
|
2417
|
+
}
|
|
2418
|
+
|
|
2419
|
+
async cancelAllOrders (symbol = undefined, params = {}) {
|
|
2420
|
+
await this.loadMarkets ();
|
|
2421
|
+
const market = this.market (symbol);
|
|
2422
|
+
const request = {
|
|
2423
|
+
'symbol': market['id'],
|
|
2424
|
+
};
|
|
2425
|
+
let method = this.getSupportedMapping (market['type'], {
|
|
2426
|
+
'spot': 'spotPrivateDeleteOrderCancelBySymbol',
|
|
2427
|
+
'swap': 'contractPrivatePostOrderCancelAll',
|
|
2428
|
+
});
|
|
2429
|
+
const stop = this.safeValue (params, 'stop');
|
|
2430
|
+
if (stop) {
|
|
2431
|
+
method = 'contractPrivatePostPlanorderCancelAll';
|
|
2432
|
+
}
|
|
2433
|
+
const query = this.omit (params, [ 'method', 'stop' ]);
|
|
2434
|
+
const response = await this[method] (this.extend (request, query));
|
|
2435
|
+
//
|
|
2436
|
+
// Spot
|
|
2437
|
+
//
|
|
2438
|
+
// {
|
|
2439
|
+
// "code": 200,
|
|
2440
|
+
// "data": [
|
|
2441
|
+
// {
|
|
2442
|
+
// "msg": "success",
|
|
2443
|
+
// "order_id": "75ecf99feef04538b78e4622beaba6eb",
|
|
2444
|
+
// "client_order_id": "a9329e86f2094b0d8b58e92c25029554"
|
|
2445
|
+
// },
|
|
2446
|
+
// {
|
|
2447
|
+
// "msg": "success",
|
|
2448
|
+
// "order_id": "139413c48f8b4c018f452ce796586bcf"
|
|
2449
|
+
// },
|
|
2450
|
+
// {
|
|
2451
|
+
// "msg": "success",
|
|
2452
|
+
// "order_id": "b58ef34c570e4917981f276d44091484"
|
|
2453
|
+
// }
|
|
2454
|
+
// ]
|
|
2455
|
+
// }
|
|
2456
|
+
//
|
|
2457
|
+
// Swap and Trigger
|
|
2458
|
+
//
|
|
2459
|
+
// {
|
|
2460
|
+
// "success": true,
|
|
2461
|
+
// "code": 0
|
|
2462
|
+
// }
|
|
2463
|
+
//
|
|
2464
|
+
return response;
|
|
2465
|
+
}
|
|
2466
|
+
|
|
2467
|
+
async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
|
2468
|
+
if (symbol === undefined) {
|
|
2469
|
+
throw new ArgumentsRequired (this.id + ' fetchMyTrades() requires a symbol argument');
|
|
2470
|
+
}
|
|
2471
|
+
await this.loadMarkets ();
|
|
2472
|
+
const market = this.market (symbol);
|
|
2473
|
+
const request = {
|
|
2474
|
+
'symbol': market['id'],
|
|
2475
|
+
// 'start_time': since, // default 7 days, max 30 days
|
|
2476
|
+
// 'limit': limit, // default 50, max 1000
|
|
2477
|
+
};
|
|
2478
|
+
if (since !== undefined) {
|
|
2479
|
+
request['start_time'] = since;
|
|
2480
|
+
}
|
|
2481
|
+
if (limit !== undefined) {
|
|
2482
|
+
request['limit'] = limit;
|
|
2483
|
+
}
|
|
2484
|
+
const response = await this.spotPrivateGetOrderDeals (this.extend (request, params));
|
|
2485
|
+
//
|
|
2486
|
+
// {
|
|
2487
|
+
// "code":200,
|
|
2488
|
+
// "data":[
|
|
2489
|
+
// {
|
|
2490
|
+
// "id":"b160b8f072d9403e96289139d5544809",
|
|
2491
|
+
// "symbol":"USDC_USDT",
|
|
2492
|
+
// "quantity":"150",
|
|
2493
|
+
// "price":"0.9997",
|
|
2494
|
+
// "amount":"149.955",
|
|
2495
|
+
// "fee":"0.29991",
|
|
2496
|
+
// "trade_type":"ASK",
|
|
2497
|
+
// "order_id":"d798765285374222990bbd14decb86cd",
|
|
2498
|
+
// "is_taker":true,
|
|
2499
|
+
// "fee_currency":"USDT",
|
|
2500
|
+
// "create_time":1633984904000
|
|
2501
|
+
// }
|
|
2502
|
+
// ]
|
|
2503
|
+
// }
|
|
2504
|
+
//
|
|
2505
|
+
const data = this.safeValue (response, 'data', []);
|
|
2506
|
+
return this.parseTrades (data, market, since, limit);
|
|
2507
|
+
}
|
|
2508
|
+
|
|
2509
|
+
async fetchOrderTrades (id, symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
|
2510
|
+
await this.loadMarkets ();
|
|
2511
|
+
let market = undefined;
|
|
2512
|
+
if (symbol !== undefined) {
|
|
2513
|
+
market = this.market (symbol);
|
|
2514
|
+
}
|
|
2515
|
+
const request = {
|
|
2516
|
+
'order_id': id,
|
|
2517
|
+
};
|
|
2518
|
+
const response = await this.spotPrivateGetOrderDealDetail (this.extend (request, params));
|
|
2519
|
+
//
|
|
2520
|
+
// {
|
|
2521
|
+
// "code":200,
|
|
2522
|
+
// "data":[
|
|
2523
|
+
// {
|
|
2524
|
+
// "id":"b160b8f072d9403e96289139d5544809",
|
|
2525
|
+
// "symbol":"USDC_USDT",
|
|
2526
|
+
// "quantity":"150",
|
|
2527
|
+
// "price":"0.9997",
|
|
2528
|
+
// "amount":"149.955",
|
|
2529
|
+
// "fee":"0.29991",
|
|
2530
|
+
// "trade_type":"ASK",
|
|
2531
|
+
// "order_id":"d798765285374222990bbd14decb86cd",
|
|
2532
|
+
// "is_taker":true,
|
|
2533
|
+
// "fee_currency":"USDT",
|
|
2534
|
+
// "create_time":1633984904000
|
|
2535
|
+
// }
|
|
2536
|
+
// ]
|
|
2537
|
+
// }
|
|
2538
|
+
//
|
|
2539
|
+
const data = this.safeValue (response, 'data', []);
|
|
2540
|
+
return this.parseTrades (data, market, since, limit);
|
|
2541
|
+
}
|
|
2542
|
+
|
|
2543
|
+
async modifyMarginHelper (symbol, amount, addOrReduce, params = {}) {
|
|
2544
|
+
const positionId = this.safeInteger (params, 'positionId');
|
|
2545
|
+
if (positionId === undefined) {
|
|
2546
|
+
throw new ArgumentsRequired (this.id + ' modifyMarginHelper() requires a positionId parameter');
|
|
2547
|
+
}
|
|
2548
|
+
await this.loadMarkets ();
|
|
2549
|
+
const market = this.market (symbol);
|
|
2550
|
+
amount = this.amountToPrecision (symbol, amount);
|
|
2551
|
+
const request = {
|
|
2552
|
+
'positionId': positionId,
|
|
2553
|
+
'amount': amount,
|
|
2554
|
+
'type': addOrReduce,
|
|
2555
|
+
};
|
|
2556
|
+
const response = await this.contractPrivatePostPositionChangeMargin (this.extend (request, params));
|
|
2557
|
+
//
|
|
2558
|
+
// {
|
|
2559
|
+
// "success": true,
|
|
2560
|
+
// "code": 0
|
|
2561
|
+
// }
|
|
2562
|
+
//
|
|
2563
|
+
const type = (addOrReduce === 'ADD') ? 'add' : 'reduce';
|
|
2564
|
+
return this.extend (this.parseModifyMargin (response, market), {
|
|
2565
|
+
'amount': this.safeNumber (amount),
|
|
2566
|
+
'type': type,
|
|
2567
|
+
});
|
|
2568
|
+
}
|
|
2569
|
+
|
|
2570
|
+
parseModifyMargin (data, market = undefined) {
|
|
2571
|
+
const statusRaw = this.safeString (data, 'success');
|
|
2572
|
+
const status = (statusRaw === true) ? 'ok' : 'failed';
|
|
2573
|
+
return {
|
|
2574
|
+
'info': data,
|
|
2575
|
+
'type': undefined,
|
|
2576
|
+
'amount': undefined,
|
|
2577
|
+
'code': undefined,
|
|
2578
|
+
'symbol': this.safeSymbol (undefined, market),
|
|
2579
|
+
'status': status,
|
|
2580
|
+
};
|
|
2581
|
+
}
|
|
2582
|
+
|
|
2583
|
+
async reduceMargin (symbol, amount, params = {}) {
|
|
2584
|
+
return await this.modifyMarginHelper (symbol, amount, 'SUB', params);
|
|
2585
|
+
}
|
|
2586
|
+
|
|
2587
|
+
async addMargin (symbol, amount, params = {}) {
|
|
2588
|
+
return await this.modifyMarginHelper (symbol, amount, 'ADD', params);
|
|
2589
|
+
}
|
|
2590
|
+
|
|
2591
|
+
async setLeverage (leverage, symbol = undefined, params = {}) {
|
|
2592
|
+
const positionId = this.safeInteger (params, 'positionId');
|
|
2593
|
+
if (positionId === undefined) {
|
|
2594
|
+
throw new ArgumentsRequired (this.id + ' setLeverage() requires a positionId parameter');
|
|
2595
|
+
}
|
|
2596
|
+
await this.loadMarkets ();
|
|
2597
|
+
const request = {
|
|
2598
|
+
'positionId': positionId,
|
|
2599
|
+
'leverage': leverage,
|
|
2600
|
+
};
|
|
2601
|
+
return await this.contractPrivatePostPositionChangeLeverage (this.extend (request, params));
|
|
2602
|
+
}
|
|
2603
|
+
|
|
2604
|
+
async fetchTransfer (id, code = undefined, params = {}) {
|
|
2605
|
+
const request = {
|
|
2606
|
+
'transact_id': id,
|
|
2607
|
+
};
|
|
2608
|
+
const response = await this.spotPrivateGetAssetInternalTransferInfo (this.extend (request, params));
|
|
2609
|
+
//
|
|
2610
|
+
// {
|
|
2611
|
+
// code: '200',
|
|
2612
|
+
// data: {
|
|
2613
|
+
// currency: 'USDT',
|
|
2614
|
+
// amount: '1',
|
|
2615
|
+
// transact_id: '954877a2ef54499db9b28a7cf9ebcf41',
|
|
2616
|
+
// from: 'MAIN',
|
|
2617
|
+
// to: 'CONTRACT',
|
|
2618
|
+
// transact_state: 'SUCCESS'
|
|
2619
|
+
// }
|
|
2620
|
+
// }
|
|
2621
|
+
//
|
|
2622
|
+
const data = this.safeValue (response, 'data', {});
|
|
2623
|
+
return this.parseTransfer (data);
|
|
2624
|
+
}
|
|
2625
|
+
|
|
2626
|
+
async fetchTransfers (code = undefined, since = undefined, limit = undefined, params = {}) {
|
|
2627
|
+
await this.loadMarkets ();
|
|
2628
|
+
const request = {};
|
|
2629
|
+
let currency = undefined;
|
|
2630
|
+
if (code !== undefined) {
|
|
2631
|
+
currency = this.currency (code);
|
|
2632
|
+
request['currency'] = currency['id'];
|
|
2633
|
+
}
|
|
2634
|
+
if (since !== undefined) {
|
|
2635
|
+
request['start_time'] = since;
|
|
2636
|
+
}
|
|
2637
|
+
if (limit !== undefined) {
|
|
2638
|
+
if (limit > 50) {
|
|
2639
|
+
throw new ExchangeError ('This exchange supports a maximum limit of 50');
|
|
2640
|
+
}
|
|
2641
|
+
request['page-size'] = limit;
|
|
2642
|
+
}
|
|
2643
|
+
const response = await this.spotPrivateGetAssetInternalTransferRecord (this.extend (request, params));
|
|
2644
|
+
//
|
|
2645
|
+
// {
|
|
2646
|
+
// code: '200',
|
|
2647
|
+
// data: {
|
|
2648
|
+
// total_page: '1',
|
|
2649
|
+
// total_size: '5',
|
|
2650
|
+
// result_list: [{
|
|
2651
|
+
// currency: 'USDT',
|
|
2652
|
+
// amount: '1',
|
|
2653
|
+
// transact_id: '954877a2ef54499db9b28a7cf9ebcf41',
|
|
2654
|
+
// from: 'MAIN',
|
|
2655
|
+
// to: 'CONTRACT',
|
|
2656
|
+
// transact_state: 'SUCCESS'
|
|
2657
|
+
// },
|
|
2658
|
+
// ...
|
|
2659
|
+
// ]
|
|
2660
|
+
// }
|
|
2661
|
+
// }
|
|
2662
|
+
//
|
|
2663
|
+
const data = this.safeValue (response, 'data', {});
|
|
2664
|
+
const resultList = this.safeValue (data, 'result_list', []);
|
|
2665
|
+
return this.parseTransfers (resultList, currency, since, limit);
|
|
2666
|
+
}
|
|
2667
|
+
|
|
2668
|
+
async transfer (code, amount, fromAccount, toAccount, params = {}) {
|
|
2669
|
+
await this.loadMarkets ();
|
|
2670
|
+
const currency = this.currency (code);
|
|
2671
|
+
const accountsByType = this.safeValue (this.options, 'accountsByType', {});
|
|
2672
|
+
const fromId = this.safeString (accountsByType, fromAccount, fromAccount);
|
|
2673
|
+
const toId = this.safeString (accountsByType, toAccount, toAccount);
|
|
2674
|
+
const request = {
|
|
2675
|
+
'currency': currency['id'],
|
|
2676
|
+
'amount': amount,
|
|
2677
|
+
'from': fromId,
|
|
2678
|
+
'to': toId,
|
|
2679
|
+
};
|
|
2680
|
+
const response = await this.spotPrivatePostAssetInternalTransfer (this.extend (request, params));
|
|
2681
|
+
//
|
|
2682
|
+
// {
|
|
2683
|
+
// code: '200',
|
|
2684
|
+
// data: {
|
|
2685
|
+
// currency: 'USDT',
|
|
2686
|
+
// amount: '1',
|
|
2687
|
+
// transact_id: 'b60c1df8e7b24b268858003f374ecb75',
|
|
2688
|
+
// from: 'MAIN',
|
|
2689
|
+
// to: 'CONTRACT',
|
|
2690
|
+
// transact_state: 'WAIT'
|
|
2691
|
+
// }
|
|
2692
|
+
// }
|
|
2693
|
+
//
|
|
2694
|
+
const data = this.safeValue (response, 'data', {});
|
|
2695
|
+
return this.parseTransfer (data, currency);
|
|
2696
|
+
}
|
|
2697
|
+
|
|
2698
|
+
parseTransfer (transfer, currency = undefined) {
|
|
2699
|
+
//
|
|
2700
|
+
// {
|
|
2701
|
+
// currency: 'USDT',
|
|
2702
|
+
// amount: '1',
|
|
2703
|
+
// transact_id: 'b60c1df8e7b24b268858003f374ecb75',
|
|
2704
|
+
// from: 'MAIN',
|
|
2705
|
+
// to: 'CONTRACT',
|
|
2706
|
+
// transact_state: 'WAIT'
|
|
2707
|
+
// }
|
|
2708
|
+
//
|
|
2709
|
+
const transferOptions = this.safeValue (this.options, 'transfer', {});
|
|
2710
|
+
const transferStatusById = this.safeValue (transferOptions, 'status', {});
|
|
2711
|
+
const currencyId = this.safeString (transfer, 'currency');
|
|
2712
|
+
const id = this.safeString (transfer, 'transact_id');
|
|
2713
|
+
const fromId = this.safeString (transfer, 'from');
|
|
2714
|
+
const toId = this.safeString (transfer, 'to');
|
|
2715
|
+
const accountsById = this.safeValue (transferOptions, 'accountsById', {});
|
|
2716
|
+
const fromAccount = this.safeString (accountsById, fromId);
|
|
2717
|
+
const toAccount = this.safeString (accountsById, toId);
|
|
2718
|
+
const statusId = this.safeString (transfer, 'transact_state');
|
|
2719
|
+
return {
|
|
2720
|
+
'info': transfer,
|
|
2721
|
+
'id': id,
|
|
2722
|
+
'timestamp': undefined,
|
|
2723
|
+
'datetime': undefined,
|
|
2724
|
+
'currency': this.safeCurrencyCode (currencyId, currency),
|
|
2725
|
+
'amount': this.safeNumber (transfer, 'amount'),
|
|
2726
|
+
'fromAccount': fromAccount,
|
|
2727
|
+
'toAccount': toAccount,
|
|
2728
|
+
'status': this.safeString (transferStatusById, statusId),
|
|
2729
|
+
};
|
|
2730
|
+
}
|
|
2731
|
+
|
|
2732
|
+
async withdraw (code, amount, address, tag = undefined, params = {}) {
|
|
2733
|
+
[ tag, params ] = this.handleWithdrawTagAndParams (tag, params);
|
|
2734
|
+
const networks = this.safeValue (this.options, 'networks', {});
|
|
2735
|
+
let network = this.safeString2 (params, 'network', 'chain'); // this line allows the user to specify either ERC20 or ETH
|
|
2736
|
+
network = this.safeString (networks, network, network); // handle ETH > ERC-20 alias
|
|
2737
|
+
this.checkAddress (address);
|
|
2738
|
+
await this.loadMarkets ();
|
|
2739
|
+
const currency = this.currency (code);
|
|
2740
|
+
if (tag !== undefined) {
|
|
2741
|
+
address += ':' + tag;
|
|
2742
|
+
}
|
|
2743
|
+
const request = {
|
|
2744
|
+
'currency': currency['id'],
|
|
2745
|
+
'address': address,
|
|
2746
|
+
'amount': amount,
|
|
2747
|
+
};
|
|
2748
|
+
if (network !== undefined) {
|
|
2749
|
+
request['chain'] = network;
|
|
2750
|
+
params = this.omit (params, [ 'network', 'chain' ]);
|
|
2751
|
+
}
|
|
2752
|
+
const response = await this.spotPrivatePostAssetWithdraw (this.extend (request, params));
|
|
2753
|
+
//
|
|
2754
|
+
// {
|
|
2755
|
+
// "code":200,
|
|
2756
|
+
// "data": {
|
|
2757
|
+
// "withdrawId":"25fb2831fb6d4fc7aa4094612a26c81d"
|
|
2758
|
+
// }
|
|
2759
|
+
// }
|
|
2760
|
+
//
|
|
2761
|
+
const data = this.safeValue (response, 'data', {});
|
|
2762
|
+
return {
|
|
2763
|
+
'info': data,
|
|
2764
|
+
'id': this.safeString (data, 'withdrawId'),
|
|
2765
|
+
};
|
|
2766
|
+
}
|
|
2767
|
+
|
|
2768
|
+
sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
|
|
2769
|
+
const [ section, access ] = api;
|
|
2770
|
+
let url = this.urls['api'][section][access] + '/' + this.implodeParams (path, params);
|
|
2771
|
+
params = this.omit (params, this.extractParams (path));
|
|
2772
|
+
if (access === 'public') {
|
|
2773
|
+
if (Object.keys (params).length) {
|
|
2774
|
+
url += '?' + this.urlencode (params);
|
|
2775
|
+
}
|
|
2776
|
+
} else {
|
|
2777
|
+
this.checkRequiredCredentials ();
|
|
2778
|
+
const timestamp = this.milliseconds ().toString ();
|
|
2779
|
+
let auth = '';
|
|
2780
|
+
headers = {
|
|
2781
|
+
'ApiKey': this.apiKey,
|
|
2782
|
+
'Request-Time': timestamp,
|
|
2783
|
+
'Content-Type': 'application/json',
|
|
2784
|
+
};
|
|
2785
|
+
if (method === 'POST') {
|
|
2786
|
+
auth = this.json (params);
|
|
2787
|
+
body = auth;
|
|
2788
|
+
} else {
|
|
2789
|
+
params = this.keysort (params);
|
|
2790
|
+
if (Object.keys (params).length) {
|
|
2791
|
+
auth += this.urlencode (params);
|
|
2792
|
+
url += '?' + auth;
|
|
2793
|
+
}
|
|
2794
|
+
}
|
|
2795
|
+
auth = this.apiKey + timestamp + auth;
|
|
2796
|
+
const signature = this.hmac (this.encode (auth), this.encode (this.secret), 'sha256');
|
|
2797
|
+
headers['Signature'] = signature;
|
|
2798
|
+
}
|
|
2799
|
+
return { 'url': url, 'method': method, 'body': body, 'headers': headers };
|
|
2800
|
+
}
|
|
2801
|
+
|
|
2802
|
+
handleErrors (code, reason, url, method, headers, body, response, requestHeaders, requestBody) {
|
|
2803
|
+
if (response === undefined) {
|
|
2804
|
+
return;
|
|
2805
|
+
}
|
|
2806
|
+
// {"code":10232,"msg":"The currency not exist"}
|
|
2807
|
+
// {"code":10216,"msg":"No available deposit address"}
|
|
2808
|
+
//
|
|
2809
|
+
// {
|
|
2810
|
+
// "success":true,
|
|
2811
|
+
// "code":0,
|
|
2812
|
+
// "data":1634095541710
|
|
2813
|
+
// }
|
|
2814
|
+
//
|
|
2815
|
+
const success = this.safeValue (response, 'success', false);
|
|
2816
|
+
if (success === true) {
|
|
2817
|
+
return;
|
|
2818
|
+
}
|
|
2819
|
+
const responseCode = this.safeString (response, 'code');
|
|
2820
|
+
if ((responseCode !== '200') && (responseCode !== '0')) {
|
|
2821
|
+
const feedback = this.id + ' ' + body;
|
|
2822
|
+
this.throwBroadlyMatchedException (this.exceptions['broad'], body, feedback);
|
|
2823
|
+
this.throwExactlyMatchedException (this.exceptions['exact'], responseCode, feedback);
|
|
2824
|
+
throw new ExchangeError (feedback);
|
|
2825
|
+
}
|
|
2826
|
+
}
|
|
2827
|
+
|
|
2828
|
+
async fetchFundingHistory (symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
|
2829
|
+
await this.loadMarkets ();
|
|
2830
|
+
let market = undefined;
|
|
2831
|
+
const request = {
|
|
2832
|
+
// 'symbol': market['id'],
|
|
2833
|
+
// 'position_id': positionId,
|
|
2834
|
+
// 'page_num': 1,
|
|
2835
|
+
// 'page_size': limit, // default 20, max 100
|
|
2836
|
+
};
|
|
2837
|
+
if (symbol !== undefined) {
|
|
2838
|
+
market = this.market (symbol);
|
|
2839
|
+
request['symbol'] = market['id'];
|
|
2840
|
+
}
|
|
2841
|
+
if (limit !== undefined) {
|
|
2842
|
+
request['page_size'] = limit;
|
|
2843
|
+
}
|
|
2844
|
+
const response = await this.contractPrivateGetPositionFundingRecords (this.extend (request, params));
|
|
2845
|
+
//
|
|
2846
|
+
// {
|
|
2847
|
+
// "success": true,
|
|
2848
|
+
// "code": 0,
|
|
2849
|
+
// "data": {
|
|
2850
|
+
// "pageSize": 20,
|
|
2851
|
+
// "totalCount": 2,
|
|
2852
|
+
// "totalPage": 1,
|
|
2853
|
+
// "currentPage": 1,
|
|
2854
|
+
// "resultList": [
|
|
2855
|
+
// {
|
|
2856
|
+
// "id": 7423910,
|
|
2857
|
+
// "symbol": "BTC_USDT",
|
|
2858
|
+
// "positionType": 1,
|
|
2859
|
+
// "positionValue": 29.30024,
|
|
2860
|
+
// "funding": 0.00076180624,
|
|
2861
|
+
// "rate": -0.000026,
|
|
2862
|
+
// "settleTime": 1643299200000
|
|
2863
|
+
// },
|
|
2864
|
+
// {
|
|
2865
|
+
// "id": 7416473,
|
|
2866
|
+
// "symbol": "BTC_USDT",
|
|
2867
|
+
// "positionType": 1,
|
|
2868
|
+
// "positionValue": 28.9188,
|
|
2869
|
+
// "funding": 0.0014748588,
|
|
2870
|
+
// "rate": -0.000051,
|
|
2871
|
+
// "settleTime": 1643270400000
|
|
2872
|
+
// }
|
|
2873
|
+
// ]
|
|
2874
|
+
// }
|
|
2875
|
+
// }
|
|
2876
|
+
//
|
|
2877
|
+
const data = this.safeValue (response, 'data', {});
|
|
2878
|
+
const resultList = this.safeValue (data, 'resultList', []);
|
|
2879
|
+
const result = [];
|
|
2880
|
+
for (let i = 0; i < resultList.length; i++) {
|
|
2881
|
+
const entry = resultList[i];
|
|
2882
|
+
const timestamp = this.safeString (entry, 'settleTime');
|
|
2883
|
+
result.push ({
|
|
2884
|
+
'info': entry,
|
|
2885
|
+
'symbol': symbol,
|
|
2886
|
+
'code': undefined,
|
|
2887
|
+
'timestamp': timestamp,
|
|
2888
|
+
'datetime': this.iso8601 (timestamp),
|
|
2889
|
+
'id': this.safeNumber (entry, 'id'),
|
|
2890
|
+
'amount': this.safeNumber (entry, 'funding'),
|
|
2891
|
+
});
|
|
2892
|
+
}
|
|
2893
|
+
return result;
|
|
2894
|
+
}
|
|
2895
|
+
|
|
2896
|
+
parseFundingRate (fundingRate, market = undefined) {
|
|
2897
|
+
//
|
|
2898
|
+
// {
|
|
2899
|
+
// "symbol": "BTC_USDT",
|
|
2900
|
+
// "fundingRate": 0.000014,
|
|
2901
|
+
// "maxFundingRate": 0.003,
|
|
2902
|
+
// "minFundingRate": -0.003,
|
|
2903
|
+
// "collectCycle": 8,
|
|
2904
|
+
// "nextSettleTime": 1643241600000,
|
|
2905
|
+
// "timestamp": 1643240373359
|
|
2906
|
+
// }
|
|
2907
|
+
//
|
|
2908
|
+
const nextFundingRate = this.safeNumber (fundingRate, 'fundingRate');
|
|
2909
|
+
const nextFundingTimestamp = this.safeInteger (fundingRate, 'nextSettleTime');
|
|
2910
|
+
const marketId = this.safeString (fundingRate, 'symbol');
|
|
2911
|
+
const symbol = this.safeSymbol (marketId, market);
|
|
2912
|
+
const timestamp = this.safeInteger (fundingRate, 'timestamp');
|
|
2913
|
+
const datetime = this.iso8601 (timestamp);
|
|
2914
|
+
return {
|
|
2915
|
+
'info': fundingRate,
|
|
2916
|
+
'symbol': symbol,
|
|
2917
|
+
'markPrice': undefined,
|
|
2918
|
+
'indexPrice': undefined,
|
|
2919
|
+
'interestRate': undefined,
|
|
2920
|
+
'estimatedSettlePrice': undefined,
|
|
2921
|
+
'timestamp': timestamp,
|
|
2922
|
+
'datetime': datetime,
|
|
2923
|
+
'fundingRate': undefined,
|
|
2924
|
+
'fundingTimestamp': undefined,
|
|
2925
|
+
'fundingDatetime': undefined,
|
|
2926
|
+
'nextFundingRate': nextFundingRate,
|
|
2927
|
+
'nextFundingTimestamp': nextFundingTimestamp,
|
|
2928
|
+
'nextFundingDatetime': this.iso8601 (nextFundingTimestamp),
|
|
2929
|
+
'previousFundingRate': undefined,
|
|
2930
|
+
'previousFundingTimestamp': undefined,
|
|
2931
|
+
'previousFundingDatetime': undefined,
|
|
2932
|
+
};
|
|
2933
|
+
}
|
|
2934
|
+
|
|
2935
|
+
async fetchFundingRate (symbol, params = {}) {
|
|
2936
|
+
await this.loadMarkets ();
|
|
2937
|
+
const market = this.market (symbol);
|
|
2938
|
+
const request = {
|
|
2939
|
+
'symbol': market['id'],
|
|
2940
|
+
};
|
|
2941
|
+
const response = await this.contractPublicGetFundingRateSymbol (this.extend (request, params));
|
|
2942
|
+
//
|
|
2943
|
+
// {
|
|
2944
|
+
// "success": true,
|
|
2945
|
+
// "code": 0,
|
|
2946
|
+
// "data": {
|
|
2947
|
+
// "symbol": "BTC_USDT",
|
|
2948
|
+
// "fundingRate": 0.000014,
|
|
2949
|
+
// "maxFundingRate": 0.003,
|
|
2950
|
+
// "minFundingRate": -0.003,
|
|
2951
|
+
// "collectCycle": 8,
|
|
2952
|
+
// "nextSettleTime": 1643241600000,
|
|
2953
|
+
// "timestamp": 1643240373359
|
|
2954
|
+
// }
|
|
2955
|
+
// }
|
|
2956
|
+
//
|
|
2957
|
+
const result = this.safeValue (response, 'data', {});
|
|
2958
|
+
return this.parseFundingRate (result, market);
|
|
2959
|
+
}
|
|
2960
|
+
|
|
2961
|
+
async fetchFundingRateHistory (symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
|
2962
|
+
//
|
|
2963
|
+
// Gets a history of funding rates with their timestamps
|
|
2964
|
+
// (param) symbol: Future currency pair
|
|
2965
|
+
// (param) limit: mexc limit is page_size default 20, maximum is 100
|
|
2966
|
+
// (param) since: not used by mexc
|
|
2967
|
+
// (param) params: Object containing more params for the request
|
|
2968
|
+
// return: [{symbol, fundingRate, timestamp, dateTime}]
|
|
2969
|
+
//
|
|
2970
|
+
if (symbol === undefined) {
|
|
2971
|
+
throw new ArgumentsRequired (this.id + ' fetchFundingRateHistory() requires a symbol argument');
|
|
2972
|
+
}
|
|
2973
|
+
await this.loadMarkets ();
|
|
2974
|
+
const market = this.market (symbol);
|
|
2975
|
+
const request = {
|
|
2976
|
+
'symbol': market['id'],
|
|
2977
|
+
// 'page_size': limit, // optional
|
|
2978
|
+
// 'page_num': 1, // optional, current page number, default is 1
|
|
2979
|
+
};
|
|
2980
|
+
if (limit !== undefined) {
|
|
2981
|
+
request['page_size'] = limit;
|
|
2982
|
+
}
|
|
2983
|
+
const response = await this.contractPublicGetFundingRateHistory (this.extend (request, params));
|
|
2984
|
+
//
|
|
2985
|
+
// {
|
|
2986
|
+
// "success": true,
|
|
2987
|
+
// "code": 0,
|
|
2988
|
+
// "data": {
|
|
2989
|
+
// "pageSize": 2,
|
|
2990
|
+
// "totalCount": 21,
|
|
2991
|
+
// "totalPage": 11,
|
|
2992
|
+
// "currentPage": 1,
|
|
2993
|
+
// "resultList": [
|
|
2994
|
+
// {
|
|
2995
|
+
// "symbol": "BTC_USDT",
|
|
2996
|
+
// "fundingRate": 0.000266,
|
|
2997
|
+
// "settleTime": 1609804800000
|
|
2998
|
+
// },
|
|
2999
|
+
// {
|
|
3000
|
+
// "symbol": "BTC_USDT",
|
|
3001
|
+
// "fundingRate": 0.00029,
|
|
3002
|
+
// "settleTime": 1609776000000
|
|
3003
|
+
// }
|
|
3004
|
+
// ]
|
|
3005
|
+
// }
|
|
3006
|
+
// }
|
|
3007
|
+
//
|
|
3008
|
+
const data = this.safeValue (response, 'data');
|
|
3009
|
+
const result = this.safeValue (data, 'resultList');
|
|
3010
|
+
const rates = [];
|
|
3011
|
+
for (let i = 0; i < result.length; i++) {
|
|
3012
|
+
const entry = result[i];
|
|
3013
|
+
const marketId = this.safeString (entry, 'symbol');
|
|
3014
|
+
const symbol = this.safeSymbol (marketId);
|
|
3015
|
+
const timestamp = this.safeString (entry, 'settleTime');
|
|
3016
|
+
rates.push ({
|
|
3017
|
+
'info': entry,
|
|
3018
|
+
'symbol': symbol,
|
|
3019
|
+
'fundingRate': this.safeNumber (entry, 'fundingRate'),
|
|
3020
|
+
'timestamp': timestamp,
|
|
3021
|
+
'datetime': this.iso8601 (timestamp),
|
|
3022
|
+
});
|
|
3023
|
+
}
|
|
3024
|
+
const sorted = this.sortBy (rates, 'timestamp');
|
|
3025
|
+
return this.filterBySymbolSinceLimit (sorted, market['symbol'], since, limit);
|
|
3026
|
+
}
|
|
3027
|
+
|
|
3028
|
+
async fetchLeverageTiers (symbols = undefined, params = {}) {
|
|
3029
|
+
await this.loadMarkets ();
|
|
3030
|
+
const response = await this.contractPublicGetDetail (params);
|
|
3031
|
+
//
|
|
3032
|
+
// {
|
|
3033
|
+
// "success":true,
|
|
3034
|
+
// "code":0,
|
|
3035
|
+
// "data":[
|
|
3036
|
+
// {
|
|
3037
|
+
// "symbol": "BTC_USDT",
|
|
3038
|
+
// "displayName": "BTC_USDT永续",
|
|
3039
|
+
// "displayNameEn": "BTC_USDT SWAP",
|
|
3040
|
+
// "positionOpenType": 3,
|
|
3041
|
+
// "baseCoin": "BTC",
|
|
3042
|
+
// "quoteCoin": "USDT",
|
|
3043
|
+
// "settleCoin": "USDT",
|
|
3044
|
+
// "contractSize": 0.0001,
|
|
3045
|
+
// "minLeverage": 1,
|
|
3046
|
+
// "maxLeverage": 125,
|
|
3047
|
+
// "priceScale": 2,
|
|
3048
|
+
// "volScale": 0,
|
|
3049
|
+
// "amountScale": 4,
|
|
3050
|
+
// "priceUnit": 0.5,
|
|
3051
|
+
// "volUnit": 1,
|
|
3052
|
+
// "minVol": 1,
|
|
3053
|
+
// "maxVol": 1000000,
|
|
3054
|
+
// "bidLimitPriceRate": 0.1,
|
|
3055
|
+
// "askLimitPriceRate": 0.1,
|
|
3056
|
+
// "takerFeeRate": 0.0006,
|
|
3057
|
+
// "makerFeeRate": 0.0002,
|
|
3058
|
+
// "maintenanceMarginRate": 0.004,
|
|
3059
|
+
// "initialMarginRate": 0.008,
|
|
3060
|
+
// "riskBaseVol": 10000,
|
|
3061
|
+
// "riskIncrVol": 200000,
|
|
3062
|
+
// "riskIncrMmr": 0.004,
|
|
3063
|
+
// "riskIncrImr": 0.004,
|
|
3064
|
+
// "riskLevelLimit": 5,
|
|
3065
|
+
// "priceCoefficientVariation": 0.1,
|
|
3066
|
+
// "indexOrigin": ["BINANCE","GATEIO","HUOBI","MXC"],
|
|
3067
|
+
// "state": 0, // 0 enabled, 1 delivery, 2 completed, 3 offline, 4 pause
|
|
3068
|
+
// "isNew": false,
|
|
3069
|
+
// "isHot": true,
|
|
3070
|
+
// "isHidden": false
|
|
3071
|
+
// },
|
|
3072
|
+
// ...
|
|
3073
|
+
// ]
|
|
3074
|
+
// }
|
|
3075
|
+
//
|
|
3076
|
+
const data = this.safeValue (response, 'data');
|
|
3077
|
+
return this.parseLeverageTiers (data, symbols, 'symbol');
|
|
3078
|
+
}
|
|
3079
|
+
|
|
3080
|
+
parseMarketLeverageTiers (info, market) {
|
|
3081
|
+
/**
|
|
3082
|
+
* @ignore
|
|
3083
|
+
* @method
|
|
3084
|
+
* @param {dict} info Exchange response for 1 market
|
|
3085
|
+
* @param {dict} market CCXT market
|
|
3086
|
+
*/
|
|
3087
|
+
//
|
|
3088
|
+
// {
|
|
3089
|
+
// "symbol": "BTC_USDT",
|
|
3090
|
+
// "displayName": "BTC_USDT永续",
|
|
3091
|
+
// "displayNameEn": "BTC_USDT SWAP",
|
|
3092
|
+
// "positionOpenType": 3,
|
|
3093
|
+
// "baseCoin": "BTC",
|
|
3094
|
+
// "quoteCoin": "USDT",
|
|
3095
|
+
// "settleCoin": "USDT",
|
|
3096
|
+
// "contractSize": 0.0001,
|
|
3097
|
+
// "minLeverage": 1,
|
|
3098
|
+
// "maxLeverage": 125,
|
|
3099
|
+
// "priceScale": 2,
|
|
3100
|
+
// "volScale": 0,
|
|
3101
|
+
// "amountScale": 4,
|
|
3102
|
+
// "priceUnit": 0.5,
|
|
3103
|
+
// "volUnit": 1,
|
|
3104
|
+
// "minVol": 1,
|
|
3105
|
+
// "maxVol": 1000000,
|
|
3106
|
+
// "bidLimitPriceRate": 0.1,
|
|
3107
|
+
// "askLimitPriceRate": 0.1,
|
|
3108
|
+
// "takerFeeRate": 0.0006,
|
|
3109
|
+
// "makerFeeRate": 0.0002,
|
|
3110
|
+
// "maintenanceMarginRate": 0.004,
|
|
3111
|
+
// "initialMarginRate": 0.008,
|
|
3112
|
+
// "riskBaseVol": 10000,
|
|
3113
|
+
// "riskIncrVol": 200000,
|
|
3114
|
+
// "riskIncrMmr": 0.004,
|
|
3115
|
+
// "riskIncrImr": 0.004,
|
|
3116
|
+
// "riskLevelLimit": 5,
|
|
3117
|
+
// "priceCoefficientVariation": 0.1,
|
|
3118
|
+
// "indexOrigin": ["BINANCE","GATEIO","HUOBI","MXC"],
|
|
3119
|
+
// "state": 0, // 0 enabled, 1 delivery, 2 completed, 3 offline, 4 pause
|
|
3120
|
+
// "isNew": false,
|
|
3121
|
+
// "isHot": true,
|
|
3122
|
+
// "isHidden": false
|
|
3123
|
+
// }
|
|
3124
|
+
//
|
|
3125
|
+
let maintenanceMarginRate = this.safeString (info, 'maintenanceMarginRate');
|
|
3126
|
+
let initialMarginRate = this.safeString (info, 'initialMarginRate');
|
|
3127
|
+
const maxVol = this.safeString (info, 'maxVol');
|
|
3128
|
+
const riskIncrVol = this.safeString (info, 'riskIncrVol');
|
|
3129
|
+
const riskIncrMmr = this.safeString (info, 'riskIncrMmr');
|
|
3130
|
+
const riskIncrImr = this.safeString (info, 'riskIncrImr');
|
|
3131
|
+
let floor = '0';
|
|
3132
|
+
const tiers = [];
|
|
3133
|
+
const quoteId = this.safeString (info, 'quoteCoin');
|
|
3134
|
+
while (Precise.stringLt (floor, maxVol)) {
|
|
3135
|
+
const cap = Precise.stringAdd (floor, riskIncrVol);
|
|
3136
|
+
tiers.push ({
|
|
3137
|
+
'tier': this.parseNumber (Precise.stringDiv (cap, riskIncrVol)),
|
|
3138
|
+
'currency': this.safeCurrencyCode (quoteId),
|
|
3139
|
+
'minNotional': this.parseNumber (floor),
|
|
3140
|
+
'maxNotional': this.parseNumber (cap),
|
|
3141
|
+
'maintenanceMarginRate': this.parseNumber (maintenanceMarginRate),
|
|
3142
|
+
'maxLeverage': this.parseNumber (Precise.stringDiv ('1', initialMarginRate)),
|
|
3143
|
+
'info': info,
|
|
3144
|
+
});
|
|
3145
|
+
initialMarginRate = Precise.stringAdd (initialMarginRate, riskIncrImr);
|
|
3146
|
+
maintenanceMarginRate = Precise.stringAdd (maintenanceMarginRate, riskIncrMmr);
|
|
3147
|
+
floor = cap;
|
|
3148
|
+
}
|
|
3149
|
+
return tiers;
|
|
3150
|
+
}
|
|
3151
|
+
};
|