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/okcoin.js
ADDED
@@ -0,0 +1,3841 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
// ---------------------------------------------------------------------------
|
4
|
+
|
5
|
+
const Exchange = require ('./base/Exchange');
|
6
|
+
const { ExchangeError, ExchangeNotAvailable, OnMaintenance, ArgumentsRequired, BadRequest, AccountSuspended, InvalidAddress, PermissionDenied, DDoSProtection, InsufficientFunds, InvalidNonce, CancelPending, InvalidOrder, OrderNotFound, AuthenticationError, RequestTimeout, NotSupported, BadSymbol, RateLimitExceeded } = require ('./base/errors');
|
7
|
+
const { TICK_SIZE, TRUNCATE } = require ('./base/functions/number');
|
8
|
+
const Precise = require ('./base/Precise');
|
9
|
+
|
10
|
+
// ---------------------------------------------------------------------------
|
11
|
+
|
12
|
+
module.exports = class okcoin extends Exchange {
|
13
|
+
describe () {
|
14
|
+
return this.deepExtend (super.describe (), {
|
15
|
+
'id': 'okcoin',
|
16
|
+
'name': 'OKCoin',
|
17
|
+
'countries': [ 'CN', 'US' ],
|
18
|
+
'version': 'v3',
|
19
|
+
// cheapest endpoint is 100 requests per 2 seconds
|
20
|
+
// 50 requests per second => 1000 / 50 = 20ms
|
21
|
+
'rateLimit': 20,
|
22
|
+
'pro': true,
|
23
|
+
'has': {
|
24
|
+
'CORS': undefined,
|
25
|
+
'spot': true,
|
26
|
+
'margin': undefined,
|
27
|
+
'swap': undefined,
|
28
|
+
'future': true,
|
29
|
+
'option': undefined,
|
30
|
+
'cancelOrder': true,
|
31
|
+
'createOrder': true,
|
32
|
+
'fetchBalance': true,
|
33
|
+
'fetchClosedOrders': true,
|
34
|
+
'fetchCurrencies': true, // see below
|
35
|
+
'fetchDepositAddress': true,
|
36
|
+
'fetchDeposits': true,
|
37
|
+
'fetchLedger': true,
|
38
|
+
'fetchMarkets': true,
|
39
|
+
'fetchMyTrades': true,
|
40
|
+
'fetchOHLCV': true,
|
41
|
+
'fetchOpenOrders': true,
|
42
|
+
'fetchOrder': true,
|
43
|
+
'fetchOrderBook': true,
|
44
|
+
'fetchOrders': undefined,
|
45
|
+
'fetchOrderTrades': true,
|
46
|
+
'fetchPosition': true,
|
47
|
+
'fetchPositions': true,
|
48
|
+
'fetchTicker': true,
|
49
|
+
'fetchTickers': true,
|
50
|
+
'fetchTime': true,
|
51
|
+
'fetchTrades': true,
|
52
|
+
'fetchTransactions': undefined,
|
53
|
+
'fetchWithdrawals': true,
|
54
|
+
'transfer': true,
|
55
|
+
'withdraw': true,
|
56
|
+
},
|
57
|
+
'timeframes': {
|
58
|
+
'1m': '60',
|
59
|
+
'3m': '180',
|
60
|
+
'5m': '300',
|
61
|
+
'15m': '900',
|
62
|
+
'30m': '1800',
|
63
|
+
'1h': '3600',
|
64
|
+
'2h': '7200',
|
65
|
+
'4h': '14400',
|
66
|
+
'6h': '21600',
|
67
|
+
'12h': '43200',
|
68
|
+
'1d': '86400',
|
69
|
+
'1w': '604800',
|
70
|
+
'1M': '2678400',
|
71
|
+
'3M': '8035200',
|
72
|
+
'6M': '16070400',
|
73
|
+
'1y': '31536000',
|
74
|
+
},
|
75
|
+
'hostname': 'okcoin.com',
|
76
|
+
'urls': {
|
77
|
+
'logo': 'https://user-images.githubusercontent.com/51840849/87295551-102fbf00-c50e-11ea-90a9-462eebba5829.jpg',
|
78
|
+
'api': {
|
79
|
+
'rest': 'https://www.{hostname}',
|
80
|
+
},
|
81
|
+
'www': 'https://www.okcoin.com',
|
82
|
+
'doc': 'https://www.okcoin.com/docs/en/',
|
83
|
+
'fees': 'https://www.okcoin.com/coin-fees',
|
84
|
+
'referral': 'https://www.okcoin.com/account/register?flag=activity&channelId=600001513',
|
85
|
+
'test': {
|
86
|
+
'rest': 'https://testnet.okex.com',
|
87
|
+
},
|
88
|
+
},
|
89
|
+
'api': {
|
90
|
+
'general': {
|
91
|
+
'get': {
|
92
|
+
'time': 8.3334,
|
93
|
+
},
|
94
|
+
},
|
95
|
+
'account': {
|
96
|
+
'get': {
|
97
|
+
'wallet': 8.3334,
|
98
|
+
'sub-account': 1000,
|
99
|
+
'asset-valuation': 1000,
|
100
|
+
'wallet/{currency}': 8.3334,
|
101
|
+
'withdrawal/history': 8.3334,
|
102
|
+
'withdrawal/history/{currency}': 8.3334,
|
103
|
+
'ledger': 5,
|
104
|
+
'deposit/address': 8.3334,
|
105
|
+
'deposit/history': 8.3334,
|
106
|
+
'deposit/history/{currency}': 8.3334,
|
107
|
+
'currencies': 8.3334,
|
108
|
+
'withdrawal/fee': 8.3334,
|
109
|
+
'deposit-lightning': 50,
|
110
|
+
'withdrawal-lightning': 50,
|
111
|
+
'fiat/deposit/detail': 5,
|
112
|
+
'fiat/deposit/details': 8.3334,
|
113
|
+
'fiat/withdraw/detail': 5,
|
114
|
+
'fiat/withdraw/details': 8.3334,
|
115
|
+
'fiat/channel': 8.3334,
|
116
|
+
},
|
117
|
+
'post': {
|
118
|
+
'transfer': 100, // 1 request per 2 seconds (per currency)
|
119
|
+
'withdrawal': 8.3334,
|
120
|
+
'fiat/cancel_deposit': 1,
|
121
|
+
'fiat/deposit': 8.3334,
|
122
|
+
'fiat/withdraw': 8.3334,
|
123
|
+
'fiat/cancel_withdrawal': 1,
|
124
|
+
},
|
125
|
+
},
|
126
|
+
// TODO fix signing issue in sign ()
|
127
|
+
// all other endpoints of the format
|
128
|
+
// api/account/v3/wallet
|
129
|
+
// otc endpoints actually of the format: (exchanged places)
|
130
|
+
// api/v3/otc/rfq/instruments
|
131
|
+
'otc': {
|
132
|
+
'get': {
|
133
|
+
'rfq/instruments': 50, // represents: GET api/v3/otc/rfq/instruments
|
134
|
+
'rfq/trade': 50,
|
135
|
+
'rfq/history': 50,
|
136
|
+
},
|
137
|
+
'post': {
|
138
|
+
'rfq/quote': 50,
|
139
|
+
'rfq/trade': 50,
|
140
|
+
},
|
141
|
+
},
|
142
|
+
// TODO fix signing issue as above
|
143
|
+
'users': {
|
144
|
+
'get': {
|
145
|
+
'subaccount-info': 20,
|
146
|
+
'account-info': 20,
|
147
|
+
'subaccount/apikey': 20,
|
148
|
+
},
|
149
|
+
'post': {
|
150
|
+
'create-subaccount': 5, // represents: POST api/v3/users/create-subaccount
|
151
|
+
'delete-subaccount': 5,
|
152
|
+
'subaccount/apikey': 50,
|
153
|
+
'subacount/delete-apikey': 20,
|
154
|
+
'subacount/modify-apikey': 20,
|
155
|
+
},
|
156
|
+
},
|
157
|
+
'earning': {
|
158
|
+
'get': {
|
159
|
+
'offers': 5,
|
160
|
+
'orders': 5,
|
161
|
+
'positions': 8.3334,
|
162
|
+
},
|
163
|
+
'post': {
|
164
|
+
'purchase': 5,
|
165
|
+
'redeem': 5,
|
166
|
+
'cancel': 5,
|
167
|
+
},
|
168
|
+
},
|
169
|
+
'spot': {
|
170
|
+
'get': {
|
171
|
+
'accounts': 5,
|
172
|
+
'accounts/{currency}': 5,
|
173
|
+
'accounts/{currency}/ledger': 5,
|
174
|
+
'orders': 10,
|
175
|
+
'orders_pending': 5,
|
176
|
+
'orders/{order_id}': 5,
|
177
|
+
'orders/{client_oid}': 5,
|
178
|
+
'trade_fee': 5,
|
179
|
+
'fills': 10,
|
180
|
+
'algo': 5,
|
181
|
+
// public
|
182
|
+
'instruments': 5,
|
183
|
+
'instruments/{instrument_id}/book': 5,
|
184
|
+
'instruments/ticker': 5,
|
185
|
+
'instruments/{instrument_id}/ticker': 5,
|
186
|
+
'instruments/{instrument_id}/trades': 5,
|
187
|
+
'instruments/{instrument_id}/candles': 5,
|
188
|
+
},
|
189
|
+
'post': {
|
190
|
+
'order_algo': 2.5,
|
191
|
+
'orders': 1,
|
192
|
+
'batch_orders': 2,
|
193
|
+
'cancel_orders/{order_id}': 1,
|
194
|
+
'cancel_orders/{client_oid}': 1,
|
195
|
+
'cancel_batch_algos': 5,
|
196
|
+
'cancel_batch_orders': 5,
|
197
|
+
'amend_order/{instrument_id}': 2.5,
|
198
|
+
'amend_batch_orders': 5,
|
199
|
+
},
|
200
|
+
},
|
201
|
+
'margin': {
|
202
|
+
'get': {
|
203
|
+
'accounts': 5,
|
204
|
+
'accounts/{instrument_id}': 5,
|
205
|
+
'accounts/{instrument_id}/ledger': 5,
|
206
|
+
'accounts/availability': 5,
|
207
|
+
'accounts/{instrument_id}/availability': 5,
|
208
|
+
'accounts/borrowed': 5,
|
209
|
+
'accounts/{instrument_id}/borrowed': 5,
|
210
|
+
'orders': 10,
|
211
|
+
'accounts/{instrument_id}/leverage': 1,
|
212
|
+
'orders/{order_id}': 5,
|
213
|
+
'orders/{client_oid}': 5,
|
214
|
+
'orders_pending': 5,
|
215
|
+
'fills': 10,
|
216
|
+
// public
|
217
|
+
'instruments/{instrument_id}/mark_price': 5,
|
218
|
+
},
|
219
|
+
'post': {
|
220
|
+
'accounts/borrow': 1,
|
221
|
+
'accounts/repayment': 1,
|
222
|
+
'orders': 1,
|
223
|
+
'batch_orders': 2,
|
224
|
+
'cancel_orders': 1,
|
225
|
+
'cancel_orders/{order_id}': 1,
|
226
|
+
'cancel_orders/{client_oid}': 1,
|
227
|
+
'cancel_batch_orders': 2,
|
228
|
+
'amend_order/{instrument_id}': 2.5,
|
229
|
+
'amend_batch_orders': 5,
|
230
|
+
'accounts/{instrument_id}/leverage': 1,
|
231
|
+
},
|
232
|
+
},
|
233
|
+
'system': {
|
234
|
+
'get': {
|
235
|
+
'status': 250,
|
236
|
+
},
|
237
|
+
},
|
238
|
+
'market': {
|
239
|
+
'get': {
|
240
|
+
'oracle': 250,
|
241
|
+
},
|
242
|
+
},
|
243
|
+
'futures': {
|
244
|
+
'get': [
|
245
|
+
'position',
|
246
|
+
'{instrument_id}/position',
|
247
|
+
'accounts',
|
248
|
+
'accounts/{underlying}',
|
249
|
+
'accounts/{underlying}/leverage',
|
250
|
+
'accounts/{underlying}/ledger',
|
251
|
+
'order_algo/{instrument_id}',
|
252
|
+
'orders/{instrument_id}',
|
253
|
+
'orders/{instrument_id}/{order_id}',
|
254
|
+
'orders/{instrument_id}/{client_oid}',
|
255
|
+
'fills',
|
256
|
+
'trade_fee',
|
257
|
+
'accounts/{instrument_id}/holds',
|
258
|
+
'order_algo/{instrument_id}',
|
259
|
+
// public
|
260
|
+
'instruments',
|
261
|
+
'instruments/{instrument_id}/book',
|
262
|
+
'instruments/ticker',
|
263
|
+
'instruments/{instrument_id}/ticker',
|
264
|
+
'instruments/{instrument_id}/trades',
|
265
|
+
'instruments/{instrument_id}/candles',
|
266
|
+
'instruments/{instrument_id}/history/candles',
|
267
|
+
'instruments/{instrument_id}/index',
|
268
|
+
'rate',
|
269
|
+
'instruments/{instrument_id}/estimated_price',
|
270
|
+
'instruments/{instrument_id}/open_interest',
|
271
|
+
'instruments/{instrument_id}/price_limit',
|
272
|
+
'instruments/{instrument_id}/mark_price',
|
273
|
+
'instruments/{instrument_id}/liquidation',
|
274
|
+
],
|
275
|
+
'post': [
|
276
|
+
'accounts/{underlying}/leverage',
|
277
|
+
'order',
|
278
|
+
'amend_order/{instrument_id}',
|
279
|
+
'orders',
|
280
|
+
'cancel_order/{instrument_id}/{order_id}',
|
281
|
+
'cancel_order/{instrument_id}/{client_oid}',
|
282
|
+
'cancel_batch_orders/{instrument_id}',
|
283
|
+
'accounts/margin_mode',
|
284
|
+
'close_position',
|
285
|
+
'cancel_all',
|
286
|
+
'order_algo',
|
287
|
+
'cancel_algos',
|
288
|
+
],
|
289
|
+
},
|
290
|
+
'swap': {
|
291
|
+
'get': [
|
292
|
+
'position',
|
293
|
+
'{instrument_id}/position',
|
294
|
+
'accounts',
|
295
|
+
'{instrument_id}/accounts',
|
296
|
+
'accounts/{instrument_id}/settings',
|
297
|
+
'accounts/{instrument_id}/ledger',
|
298
|
+
'orders/{instrument_id}',
|
299
|
+
'orders/{instrument_id}/{order_id}',
|
300
|
+
'orders/{instrument_id}/{client_oid}',
|
301
|
+
'fills',
|
302
|
+
'accounts/{instrument_id}/holds',
|
303
|
+
'trade_fee',
|
304
|
+
'order_algo/{instrument_id}',
|
305
|
+
// public
|
306
|
+
'instruments',
|
307
|
+
'instruments/{instrument_id}/depth',
|
308
|
+
'instruments/ticker',
|
309
|
+
'instruments/{instrument_id}/ticker',
|
310
|
+
'instruments/{instrument_id}/trades',
|
311
|
+
'instruments/{instrument_id}/candles',
|
312
|
+
'instruments/{instrument_id}/history/candles',
|
313
|
+
'instruments/{instrument_id}/index',
|
314
|
+
'rate',
|
315
|
+
'instruments/{instrument_id}/open_interest',
|
316
|
+
'instruments/{instrument_id}/price_limit',
|
317
|
+
'instruments/{instrument_id}/liquidation',
|
318
|
+
'instruments/{instrument_id}/funding_time',
|
319
|
+
'instruments/{instrument_id}/mark_price',
|
320
|
+
'instruments/{instrument_id}/historical_funding_rate',
|
321
|
+
],
|
322
|
+
'post': [
|
323
|
+
'accounts/{instrument_id}/leverage',
|
324
|
+
'order',
|
325
|
+
'amend_order/{instrument_id}',
|
326
|
+
'orders',
|
327
|
+
'cancel_order/{instrument_id}/{order_id}',
|
328
|
+
'cancel_order/{instrument_id}/{client_oid}',
|
329
|
+
'cancel_batch_orders/{instrument_id}',
|
330
|
+
'order_algo',
|
331
|
+
'cancel_algos',
|
332
|
+
'close_position',
|
333
|
+
'cancel_all',
|
334
|
+
'order_algo',
|
335
|
+
'cancel_algos',
|
336
|
+
],
|
337
|
+
},
|
338
|
+
'option': {
|
339
|
+
'get': [
|
340
|
+
'accounts',
|
341
|
+
'position',
|
342
|
+
'{underlying}/position',
|
343
|
+
'accounts/{underlying}',
|
344
|
+
'orders/{underlying}',
|
345
|
+
'fills/{underlying}',
|
346
|
+
'accounts/{underlying}/ledger',
|
347
|
+
'trade_fee',
|
348
|
+
'orders/{underlying}/{order_id}',
|
349
|
+
'orders/{underlying}/{client_oid}',
|
350
|
+
// public
|
351
|
+
'underlying',
|
352
|
+
'instruments/{underlying}',
|
353
|
+
'instruments/{underlying}/summary',
|
354
|
+
'instruments/{underlying}/summary/{instrument_id}',
|
355
|
+
'instruments/{instrument_id}/book',
|
356
|
+
'instruments/{instrument_id}/trades',
|
357
|
+
'instruments/{instrument_id}/ticker',
|
358
|
+
'instruments/{instrument_id}/candles',
|
359
|
+
],
|
360
|
+
'post': [
|
361
|
+
'order',
|
362
|
+
'orders',
|
363
|
+
'cancel_order/{underlying}/{order_id}',
|
364
|
+
'cancel_order/{underlying}/{client_oid}',
|
365
|
+
'cancel_batch_orders/{underlying}',
|
366
|
+
'amend_order/{underlying}',
|
367
|
+
'amend_batch_orders/{underlying}',
|
368
|
+
],
|
369
|
+
},
|
370
|
+
'information': {
|
371
|
+
'get': [
|
372
|
+
'{currency}/long_short_ratio',
|
373
|
+
'{currency}/volume',
|
374
|
+
'{currency}/taker',
|
375
|
+
'{currency}/sentiment',
|
376
|
+
'{currency}/margin',
|
377
|
+
],
|
378
|
+
},
|
379
|
+
'index': {
|
380
|
+
'get': [
|
381
|
+
'{instrument_id}/constituents',
|
382
|
+
],
|
383
|
+
},
|
384
|
+
},
|
385
|
+
'fees': {
|
386
|
+
'trading': {
|
387
|
+
'taker': 0.002,
|
388
|
+
'maker': 0.001,
|
389
|
+
},
|
390
|
+
'spot': {
|
391
|
+
'taker': 0.0015,
|
392
|
+
'maker': 0.0010,
|
393
|
+
},
|
394
|
+
},
|
395
|
+
'requiredCredentials': {
|
396
|
+
'apiKey': true,
|
397
|
+
'secret': true,
|
398
|
+
'password': true,
|
399
|
+
},
|
400
|
+
'exceptions': {
|
401
|
+
// http error codes
|
402
|
+
// 400 Bad Request — Invalid request format
|
403
|
+
// 401 Unauthorized — Invalid API Key
|
404
|
+
// 403 Forbidden — You do not have access to the requested resource
|
405
|
+
// 404 Not Found
|
406
|
+
// 429 Client Error: Too Many Requests for url
|
407
|
+
// 500 Internal Server Error — We had a problem with our server
|
408
|
+
'exact': {
|
409
|
+
'1': ExchangeError, // { "code": 1, "message": "System error" }
|
410
|
+
// undocumented
|
411
|
+
'failure to get a peer from the ring-balancer': ExchangeNotAvailable, // { "message": "failure to get a peer from the ring-balancer" }
|
412
|
+
'Server is busy, please try again.': ExchangeNotAvailable, // { "message": "Server is busy, please try again." }
|
413
|
+
'An unexpected error occurred': ExchangeError, // { "message": "An unexpected error occurred" }
|
414
|
+
'System error': ExchangeError, // {"error_message":"System error","message":"System error"}
|
415
|
+
'4010': PermissionDenied, // { "code": 4010, "message": "For the security of your funds, withdrawals are not permitted within 24 hours after changing fund password / mobile number / Google Authenticator settings " }
|
416
|
+
// common
|
417
|
+
// '0': ExchangeError, // 200 successful,when the order placement / cancellation / operation is successful
|
418
|
+
'4001': ExchangeError, // no data received in 30s
|
419
|
+
'4002': ExchangeError, // Buffer full. cannot write data
|
420
|
+
// --------------------------------------------------------
|
421
|
+
'30001': AuthenticationError, // { "code": 30001, "message": 'request header "OK_ACCESS_KEY" cannot be blank'}
|
422
|
+
'30002': AuthenticationError, // { "code": 30002, "message": 'request header "OK_ACCESS_SIGN" cannot be blank'}
|
423
|
+
'30003': AuthenticationError, // { "code": 30003, "message": 'request header "OK_ACCESS_TIMESTAMP" cannot be blank'}
|
424
|
+
'30004': AuthenticationError, // { "code": 30004, "message": 'request header "OK_ACCESS_PASSPHRASE" cannot be blank'}
|
425
|
+
'30005': InvalidNonce, // { "code": 30005, "message": "invalid OK_ACCESS_TIMESTAMP" }
|
426
|
+
'30006': AuthenticationError, // { "code": 30006, "message": "invalid OK_ACCESS_KEY" }
|
427
|
+
'30007': BadRequest, // { "code": 30007, "message": 'invalid Content_Type, please use "application/json" format'}
|
428
|
+
'30008': RequestTimeout, // { "code": 30008, "message": "timestamp request expired" }
|
429
|
+
'30009': ExchangeError, // { "code": 30009, "message": "system error" }
|
430
|
+
'30010': AuthenticationError, // { "code": 30010, "message": "API validation failed" }
|
431
|
+
'30011': PermissionDenied, // { "code": 30011, "message": "invalid IP" }
|
432
|
+
'30012': AuthenticationError, // { "code": 30012, "message": "invalid authorization" }
|
433
|
+
'30013': AuthenticationError, // { "code": 30013, "message": "invalid sign" }
|
434
|
+
'30014': DDoSProtection, // { "code": 30014, "message": "request too frequent" }
|
435
|
+
'30015': AuthenticationError, // { "code": 30015, "message": 'request header "OK_ACCESS_PASSPHRASE" incorrect'}
|
436
|
+
'30016': ExchangeError, // { "code": 30015, "message": "you are using v1 apiKey, please use v1 endpoint. If you would like to use v3 endpoint, please subscribe to v3 apiKey" }
|
437
|
+
'30017': ExchangeError, // { "code": 30017, "message": "apikey's broker id does not match" }
|
438
|
+
'30018': ExchangeError, // { "code": 30018, "message": "apikey's domain does not match" }
|
439
|
+
'30019': ExchangeNotAvailable, // { "code": 30019, "message": "Api is offline or unavailable" }
|
440
|
+
'30020': BadRequest, // { "code": 30020, "message": "body cannot be blank" }
|
441
|
+
'30021': BadRequest, // { "code": 30021, "message": "Json data format error" }, { "code": 30021, "message": "json data format error" }
|
442
|
+
'30022': PermissionDenied, // { "code": 30022, "message": "Api has been frozen" }
|
443
|
+
'30023': BadRequest, // { "code": 30023, "message": "{0} parameter cannot be blank" }
|
444
|
+
'30024': BadSymbol, // {"code":30024,"message":"\"instrument_id\" is an invalid parameter"}
|
445
|
+
'30025': BadRequest, // { "code": 30025, "message": "{0} parameter category error" }
|
446
|
+
'30026': DDoSProtection, // { "code": 30026, "message": "requested too frequent" }
|
447
|
+
'30027': AuthenticationError, // { "code": 30027, "message": "login failure" }
|
448
|
+
'30028': PermissionDenied, // { "code": 30028, "message": "unauthorized execution" }
|
449
|
+
'30029': AccountSuspended, // { "code": 30029, "message": "account suspended" }
|
450
|
+
'30030': ExchangeNotAvailable, // { "code": 30030, "message": "endpoint request failed. Please try again" }
|
451
|
+
'30031': BadRequest, // { "code": 30031, "message": "token does not exist" }
|
452
|
+
'30032': BadSymbol, // { "code": 30032, "message": "pair does not exist" }
|
453
|
+
'30033': BadRequest, // { "code": 30033, "message": "exchange domain does not exist" }
|
454
|
+
'30034': ExchangeError, // { "code": 30034, "message": "exchange ID does not exist" }
|
455
|
+
'30035': ExchangeError, // { "code": 30035, "message": "trading is not supported in this website" }
|
456
|
+
'30036': ExchangeError, // { "code": 30036, "message": "no relevant data" }
|
457
|
+
'30037': ExchangeNotAvailable, // { "code": 30037, "message": "endpoint is offline or unavailable" }
|
458
|
+
// '30038': AuthenticationError, // { "code": 30038, "message": "user does not exist" }
|
459
|
+
'30038': OnMaintenance, // {"client_oid":"","code":"30038","error_code":"30038","error_message":"Matching engine is being upgraded. Please try in about 1 minute.","message":"Matching engine is being upgraded. Please try in about 1 minute.","order_id":"-1","result":false}
|
460
|
+
'30044': RequestTimeout, // { "code":30044, "message":"Endpoint request timeout" }
|
461
|
+
// futures
|
462
|
+
'32001': AccountSuspended, // { "code": 32001, "message": "futures account suspended" }
|
463
|
+
'32002': PermissionDenied, // { "code": 32002, "message": "futures account does not exist" }
|
464
|
+
'32003': CancelPending, // { "code": 32003, "message": "canceling, please wait" }
|
465
|
+
'32004': ExchangeError, // { "code": 32004, "message": "you have no unfilled orders" }
|
466
|
+
'32005': InvalidOrder, // { "code": 32005, "message": "max order quantity" }
|
467
|
+
'32006': InvalidOrder, // { "code": 32006, "message": "the order price or trigger price exceeds USD 1 million" }
|
468
|
+
'32007': InvalidOrder, // { "code": 32007, "message": "leverage level must be the same for orders on the same side of the contract" }
|
469
|
+
'32008': InvalidOrder, // { "code": 32008, "message": "Max. positions to open (cross margin)" }
|
470
|
+
'32009': InvalidOrder, // { "code": 32009, "message": "Max. positions to open (fixed margin)" }
|
471
|
+
'32010': ExchangeError, // { "code": 32010, "message": "leverage cannot be changed with open positions" }
|
472
|
+
'32011': ExchangeError, // { "code": 32011, "message": "futures status error" }
|
473
|
+
'32012': ExchangeError, // { "code": 32012, "message": "futures order update error" }
|
474
|
+
'32013': ExchangeError, // { "code": 32013, "message": "token type is blank" }
|
475
|
+
'32014': ExchangeError, // { "code": 32014, "message": "your number of contracts closing is larger than the number of contracts available" }
|
476
|
+
'32015': ExchangeError, // { "code": 32015, "message": "margin ratio is lower than 100% before opening positions" }
|
477
|
+
'32016': ExchangeError, // { "code": 32016, "message": "margin ratio is lower than 100% after opening position" }
|
478
|
+
'32017': ExchangeError, // { "code": 32017, "message": "no BBO" }
|
479
|
+
'32018': ExchangeError, // { "code": 32018, "message": "the order quantity is less than 1, please try again" }
|
480
|
+
'32019': ExchangeError, // { "code": 32019, "message": "the order price deviates from the price of the previous minute by more than 3%" }
|
481
|
+
'32020': ExchangeError, // { "code": 32020, "message": "the price is not in the range of the price limit" }
|
482
|
+
'32021': ExchangeError, // { "code": 32021, "message": "leverage error" }
|
483
|
+
'32022': ExchangeError, // { "code": 32022, "message": "this function is not supported in your country or region according to the regulations" }
|
484
|
+
'32023': ExchangeError, // { "code": 32023, "message": "this account has outstanding loan" }
|
485
|
+
'32024': ExchangeError, // { "code": 32024, "message": "order cannot be placed during delivery" }
|
486
|
+
'32025': ExchangeError, // { "code": 32025, "message": "order cannot be placed during settlement" }
|
487
|
+
'32026': ExchangeError, // { "code": 32026, "message": "your account is restricted from opening positions" }
|
488
|
+
'32027': ExchangeError, // { "code": 32027, "message": "cancelled over 20 orders" }
|
489
|
+
'32028': ExchangeError, // { "code": 32028, "message": "account is suspended and liquidated" }
|
490
|
+
'32029': ExchangeError, // { "code": 32029, "message": "order info does not exist" }
|
491
|
+
'32030': InvalidOrder, // The order cannot be cancelled
|
492
|
+
'32031': ArgumentsRequired, // client_oid or order_id is required.
|
493
|
+
'32038': AuthenticationError, // User does not exist
|
494
|
+
'32040': ExchangeError, // User have open contract orders or position
|
495
|
+
'32044': ExchangeError, // { "code": 32044, "message": "The margin ratio after submitting this order is lower than the minimum requirement ({0}) for your tier." }
|
496
|
+
'32045': ExchangeError, // String of commission over 1 million
|
497
|
+
'32046': ExchangeError, // Each user can hold up to 10 trade plans at the same time
|
498
|
+
'32047': ExchangeError, // system error
|
499
|
+
'32048': InvalidOrder, // Order strategy track range error
|
500
|
+
'32049': ExchangeError, // Each user can hold up to 10 track plans at the same time
|
501
|
+
'32050': InvalidOrder, // Order strategy rang error
|
502
|
+
'32051': InvalidOrder, // Order strategy ice depth error
|
503
|
+
'32052': ExchangeError, // String of commission over 100 thousand
|
504
|
+
'32053': ExchangeError, // Each user can hold up to 6 ice plans at the same time
|
505
|
+
'32057': ExchangeError, // The order price is zero. Market-close-all function cannot be executed
|
506
|
+
'32054': ExchangeError, // Trade not allow
|
507
|
+
'32055': InvalidOrder, // cancel order error
|
508
|
+
'32056': ExchangeError, // iceberg per order average should between {0}-{1} contracts
|
509
|
+
'32058': ExchangeError, // Each user can hold up to 6 initiative plans at the same time
|
510
|
+
'32059': InvalidOrder, // Total amount should exceed per order amount
|
511
|
+
'32060': InvalidOrder, // Order strategy type error
|
512
|
+
'32061': InvalidOrder, // Order strategy initiative limit error
|
513
|
+
'32062': InvalidOrder, // Order strategy initiative range error
|
514
|
+
'32063': InvalidOrder, // Order strategy initiative rate error
|
515
|
+
'32064': ExchangeError, // Time Stringerval of orders should set between 5-120s
|
516
|
+
'32065': ExchangeError, // Close amount exceeds the limit of Market-close-all (999 for BTC, and 9999 for the rest tokens)
|
517
|
+
'32066': ExchangeError, // You have open orders. Please cancel all open orders before changing your leverage level.
|
518
|
+
'32067': ExchangeError, // Account equity < required margin in this setting. Please adjust your leverage level again.
|
519
|
+
'32068': ExchangeError, // The margin for this position will fall short of the required margin in this setting. Please adjust your leverage level or increase your margin to proceed.
|
520
|
+
'32069': ExchangeError, // Target leverage level too low. Your account balance is insufficient to cover the margin required. Please adjust the leverage level again.
|
521
|
+
'32070': ExchangeError, // Please check open position or unfilled order
|
522
|
+
'32071': ExchangeError, // Your current liquidation mode does not support this action.
|
523
|
+
'32072': ExchangeError, // The highest available margin for your order’s tier is {0}. Please edit your margin and place a new order.
|
524
|
+
'32073': ExchangeError, // The action does not apply to the token
|
525
|
+
'32074': ExchangeError, // The number of contracts of your position, open orders, and the current order has exceeded the maximum order limit of this asset.
|
526
|
+
'32075': ExchangeError, // Account risk rate breach
|
527
|
+
'32076': ExchangeError, // Liquidation of the holding position(s) at market price will require cancellation of all pending close orders of the contracts.
|
528
|
+
'32077': ExchangeError, // Your margin for this asset in futures account is insufficient and the position has been taken over for liquidation. (You will not be able to place orders, close positions, transfer funds, or add margin during this period of time. Your account will be restored after the liquidation is complete.)
|
529
|
+
'32078': ExchangeError, // Please cancel all open orders before switching the liquidation mode(Please cancel all open orders before switching the liquidation mode)
|
530
|
+
'32079': ExchangeError, // Your open positions are at high risk.(Please add margin or reduce positions before switching the mode)
|
531
|
+
'32080': ExchangeError, // Funds cannot be transferred out within 30 minutes after futures settlement
|
532
|
+
'32083': ExchangeError, // The number of contracts should be a positive multiple of %%. Please place your order again
|
533
|
+
// token and margin trading
|
534
|
+
'33001': PermissionDenied, // { "code": 33001, "message": "margin account for this pair is not enabled yet" }
|
535
|
+
'33002': AccountSuspended, // { "code": 33002, "message": "margin account for this pair is suspended" }
|
536
|
+
'33003': InsufficientFunds, // { "code": 33003, "message": "no loan balance" }
|
537
|
+
'33004': ExchangeError, // { "code": 33004, "message": "loan amount cannot be smaller than the minimum limit" }
|
538
|
+
'33005': ExchangeError, // { "code": 33005, "message": "repayment amount must exceed 0" }
|
539
|
+
'33006': ExchangeError, // { "code": 33006, "message": "loan order not found" }
|
540
|
+
'33007': ExchangeError, // { "code": 33007, "message": "status not found" }
|
541
|
+
'33008': InsufficientFunds, // { "code": 33008, "message": "loan amount cannot exceed the maximum limit" }
|
542
|
+
'33009': ExchangeError, // { "code": 33009, "message": "user ID is blank" }
|
543
|
+
'33010': ExchangeError, // { "code": 33010, "message": "you cannot cancel an order during session 2 of call auction" }
|
544
|
+
'33011': ExchangeError, // { "code": 33011, "message": "no new market data" }
|
545
|
+
'33012': ExchangeError, // { "code": 33012, "message": "order cancellation failed" }
|
546
|
+
'33013': InvalidOrder, // { "code": 33013, "message": "order placement failed" }
|
547
|
+
'33014': OrderNotFound, // { "code": 33014, "message": "order does not exist" }
|
548
|
+
'33015': InvalidOrder, // { "code": 33015, "message": "exceeded maximum limit" }
|
549
|
+
'33016': ExchangeError, // { "code": 33016, "message": "margin trading is not open for this token" }
|
550
|
+
'33017': InsufficientFunds, // { "code": 33017, "message": "insufficient balance" }
|
551
|
+
'33018': ExchangeError, // { "code": 33018, "message": "this parameter must be smaller than 1" }
|
552
|
+
'33020': ExchangeError, // { "code": 33020, "message": "request not supported" }
|
553
|
+
'33021': BadRequest, // { "code": 33021, "message": "token and the pair do not match" }
|
554
|
+
'33022': InvalidOrder, // { "code": 33022, "message": "pair and the order do not match" }
|
555
|
+
'33023': ExchangeError, // { "code": 33023, "message": "you can only place market orders during call auction" }
|
556
|
+
'33024': InvalidOrder, // { "code": 33024, "message": "trading amount too small" }
|
557
|
+
'33025': InvalidOrder, // { "code": 33025, "message": "base token amount is blank" }
|
558
|
+
'33026': ExchangeError, // { "code": 33026, "message": "transaction completed" }
|
559
|
+
'33027': InvalidOrder, // { "code": 33027, "message": "cancelled order or order cancelling" }
|
560
|
+
'33028': InvalidOrder, // { "code": 33028, "message": "the decimal places of the trading price exceeded the limit" }
|
561
|
+
'33029': InvalidOrder, // { "code": 33029, "message": "the decimal places of the trading size exceeded the limit" }
|
562
|
+
'33034': ExchangeError, // { "code": 33034, "message": "You can only place limit order after Call Auction has started" }
|
563
|
+
'33035': ExchangeError, // This type of order cannot be canceled(This type of order cannot be canceled)
|
564
|
+
'33036': ExchangeError, // Exceeding the limit of entrust order
|
565
|
+
'33037': ExchangeError, // The buy order price should be lower than 130% of the trigger price
|
566
|
+
'33038': ExchangeError, // The sell order price should be higher than 70% of the trigger price
|
567
|
+
'33039': ExchangeError, // The limit of callback rate is 0 < x <= 5%
|
568
|
+
'33040': ExchangeError, // The trigger price of a buy order should be lower than the latest transaction price
|
569
|
+
'33041': ExchangeError, // The trigger price of a sell order should be higher than the latest transaction price
|
570
|
+
'33042': ExchangeError, // The limit of price variance is 0 < x <= 1%
|
571
|
+
'33043': ExchangeError, // The total amount must be larger than 0
|
572
|
+
'33044': ExchangeError, // The average amount should be 1/1000 * total amount <= x <= total amount
|
573
|
+
'33045': ExchangeError, // The price should not be 0, including trigger price, order price, and price limit
|
574
|
+
'33046': ExchangeError, // Price variance should be 0 < x <= 1%
|
575
|
+
'33047': ExchangeError, // Sweep ratio should be 0 < x <= 100%
|
576
|
+
'33048': ExchangeError, // Per order limit: Total amount/1000 < x <= Total amount
|
577
|
+
'33049': ExchangeError, // Total amount should be X > 0
|
578
|
+
'33050': ExchangeError, // Time interval should be 5 <= x <= 120s
|
579
|
+
'33051': ExchangeError, // cancel order number not higher limit: plan and track entrust no more than 10, ice and time entrust no more than 6
|
580
|
+
'33059': BadRequest, // { "code": 33059, "message": "client_oid or order_id is required" }
|
581
|
+
'33060': BadRequest, // { "code": 33060, "message": "Only fill in either parameter client_oid or order_id" }
|
582
|
+
'33061': ExchangeError, // Value of a single market price order cannot exceed 100,000 USD
|
583
|
+
'33062': ExchangeError, // The leverage ratio is too high. The borrowed position has exceeded the maximum position of this leverage ratio. Please readjust the leverage ratio
|
584
|
+
'33063': ExchangeError, // Leverage multiple is too low, there is insufficient margin in the account, please readjust the leverage ratio
|
585
|
+
'33064': ExchangeError, // The setting of the leverage ratio cannot be less than 2, please readjust the leverage ratio
|
586
|
+
'33065': ExchangeError, // Leverage ratio exceeds maximum leverage ratio, please readjust leverage ratio
|
587
|
+
'33085': InvalidOrder, // The value of the position and buying order has reached the position limit, and no further buying is allowed.
|
588
|
+
// account
|
589
|
+
'21009': ExchangeError, // Funds cannot be transferred out within 30 minutes after swap settlement(Funds cannot be transferred out within 30 minutes after swap settlement)
|
590
|
+
'34001': PermissionDenied, // { "code": 34001, "message": "withdrawal suspended" }
|
591
|
+
'34002': InvalidAddress, // { "code": 34002, "message": "please add a withdrawal address" }
|
592
|
+
'34003': ExchangeError, // { "code": 34003, "message": "sorry, this token cannot be withdrawn to xx at the moment" }
|
593
|
+
'34004': ExchangeError, // { "code": 34004, "message": "withdrawal fee is smaller than minimum limit" }
|
594
|
+
'34005': ExchangeError, // { "code": 34005, "message": "withdrawal fee exceeds the maximum limit" }
|
595
|
+
'34006': ExchangeError, // { "code": 34006, "message": "withdrawal amount is lower than the minimum limit" }
|
596
|
+
'34007': ExchangeError, // { "code": 34007, "message": "withdrawal amount exceeds the maximum limit" }
|
597
|
+
'34008': InsufficientFunds, // { "code": 34008, "message": "insufficient balance" }
|
598
|
+
'34009': ExchangeError, // { "code": 34009, "message": "your withdrawal amount exceeds the daily limit" }
|
599
|
+
'34010': ExchangeError, // { "code": 34010, "message": "transfer amount must be larger than 0" }
|
600
|
+
'34011': ExchangeError, // { "code": 34011, "message": "conditions not met" }
|
601
|
+
'34012': ExchangeError, // { "code": 34012, "message": "the minimum withdrawal amount for NEO is 1, and the amount must be an integer" }
|
602
|
+
'34013': ExchangeError, // { "code": 34013, "message": "please transfer" }
|
603
|
+
'34014': ExchangeError, // { "code": 34014, "message": "transfer limited" }
|
604
|
+
'34015': ExchangeError, // { "code": 34015, "message": "subaccount does not exist" }
|
605
|
+
'34016': PermissionDenied, // { "code": 34016, "message": "transfer suspended" }
|
606
|
+
'34017': AccountSuspended, // { "code": 34017, "message": "account suspended" }
|
607
|
+
'34018': AuthenticationError, // { "code": 34018, "message": "incorrect trades password" }
|
608
|
+
'34019': PermissionDenied, // { "code": 34019, "message": "please bind your email before withdrawal" }
|
609
|
+
'34020': PermissionDenied, // { "code": 34020, "message": "please bind your funds password before withdrawal" }
|
610
|
+
'34021': InvalidAddress, // { "code": 34021, "message": "Not verified address" }
|
611
|
+
'34022': ExchangeError, // { "code": 34022, "message": "Withdrawals are not available for sub accounts" }
|
612
|
+
'34023': PermissionDenied, // { "code": 34023, "message": "Please enable futures trading before transferring your funds" }
|
613
|
+
'34026': RateLimitExceeded, // transfer too frequently(transfer too frequently)
|
614
|
+
'34036': ExchangeError, // Parameter is incorrect, please refer to API documentation
|
615
|
+
'34037': ExchangeError, // Get the sub-account balance interface, account type is not supported
|
616
|
+
'34038': ExchangeError, // Since your C2C transaction is unusual, you are restricted from fund transfer. Please contact our customer support to cancel the restriction
|
617
|
+
'34039': ExchangeError, // You are now restricted from transferring out your funds due to abnormal trades on C2C Market. Please transfer your fund on our website or app instead to verify your identity
|
618
|
+
// swap
|
619
|
+
'35001': ExchangeError, // { "code": 35001, "message": "Contract does not exist" }
|
620
|
+
'35002': ExchangeError, // { "code": 35002, "message": "Contract settling" }
|
621
|
+
'35003': ExchangeError, // { "code": 35003, "message": "Contract paused" }
|
622
|
+
'35004': ExchangeError, // { "code": 35004, "message": "Contract pending settlement" }
|
623
|
+
'35005': AuthenticationError, // { "code": 35005, "message": "User does not exist" }
|
624
|
+
'35008': InvalidOrder, // { "code": 35008, "message": "Risk ratio too high" }
|
625
|
+
'35010': InvalidOrder, // { "code": 35010, "message": "Position closing too large" }
|
626
|
+
'35012': InvalidOrder, // { "code": 35012, "message": "Incorrect order size" }
|
627
|
+
'35014': InvalidOrder, // { "code": 35014, "message": "Order price is not within limit" }
|
628
|
+
'35015': InvalidOrder, // { "code": 35015, "message": "Invalid leverage level" }
|
629
|
+
'35017': ExchangeError, // { "code": 35017, "message": "Open orders exist" }
|
630
|
+
'35019': InvalidOrder, // { "code": 35019, "message": "Order size too large" }
|
631
|
+
'35020': InvalidOrder, // { "code": 35020, "message": "Order price too high" }
|
632
|
+
'35021': InvalidOrder, // { "code": 35021, "message": "Order size exceeded current tier limit" }
|
633
|
+
'35022': BadRequest, // { "code": 35022, "message": "Contract status error" }
|
634
|
+
'35024': BadRequest, // { "code": 35024, "message": "Contract not initialized" }
|
635
|
+
'35025': InsufficientFunds, // { "code": 35025, "message": "No account balance" }
|
636
|
+
'35026': BadRequest, // { "code": 35026, "message": "Contract settings not initialized" }
|
637
|
+
'35029': OrderNotFound, // { "code": 35029, "message": "Order does not exist" }
|
638
|
+
'35030': InvalidOrder, // { "code": 35030, "message": "Order size too large" }
|
639
|
+
'35031': InvalidOrder, // { "code": 35031, "message": "Cancel order size too large" }
|
640
|
+
'35032': ExchangeError, // { "code": 35032, "message": "Invalid user status" }
|
641
|
+
'35037': ExchangeError, // No last traded price in cache
|
642
|
+
'35039': InsufficientFunds, // { "code": 35039, "message": "Open order quantity exceeds limit" }
|
643
|
+
'35040': InvalidOrder, // {"error_message":"Invalid order type","result":"true","error_code":"35040","order_id":"-1"}
|
644
|
+
'35044': ExchangeError, // { "code": 35044, "message": "Invalid order status" }
|
645
|
+
'35046': InsufficientFunds, // { "code": 35046, "message": "Negative account balance" }
|
646
|
+
'35047': InsufficientFunds, // { "code": 35047, "message": "Insufficient account balance" }
|
647
|
+
'35048': ExchangeError, // { "code": 35048, "message": "User contract is frozen and liquidating" }
|
648
|
+
'35049': InvalidOrder, // { "code": 35049, "message": "Invalid order type" }
|
649
|
+
'35050': InvalidOrder, // { "code": 35050, "message": "Position settings are blank" }
|
650
|
+
'35052': InsufficientFunds, // { "code": 35052, "message": "Insufficient cross margin" }
|
651
|
+
'35053': ExchangeError, // { "code": 35053, "message": "Account risk too high" }
|
652
|
+
'35055': InsufficientFunds, // { "code": 35055, "message": "Insufficient account balance" }
|
653
|
+
'35057': ExchangeError, // { "code": 35057, "message": "No last traded price" }
|
654
|
+
'35058': ExchangeError, // { "code": 35058, "message": "No limit" }
|
655
|
+
'35059': BadRequest, // { "code": 35059, "message": "client_oid or order_id is required" }
|
656
|
+
'35060': BadRequest, // { "code": 35060, "message": "Only fill in either parameter client_oid or order_id" }
|
657
|
+
'35061': BadRequest, // { "code": 35061, "message": "Invalid instrument_id" }
|
658
|
+
'35062': InvalidOrder, // { "code": 35062, "message": "Invalid match_price" }
|
659
|
+
'35063': InvalidOrder, // { "code": 35063, "message": "Invalid order_size" }
|
660
|
+
'35064': InvalidOrder, // { "code": 35064, "message": "Invalid client_oid" }
|
661
|
+
'35066': InvalidOrder, // Order interval error
|
662
|
+
'35067': InvalidOrder, // Time-weighted order ratio error
|
663
|
+
'35068': InvalidOrder, // Time-weighted order range error
|
664
|
+
'35069': InvalidOrder, // Time-weighted single transaction limit error
|
665
|
+
'35070': InvalidOrder, // Algo order type error
|
666
|
+
'35071': InvalidOrder, // Order total must be larger than single order limit
|
667
|
+
'35072': InvalidOrder, // Maximum 6 unfulfilled time-weighted orders can be held at the same time
|
668
|
+
'35073': InvalidOrder, // Order price is 0. Market-close-all not available
|
669
|
+
'35074': InvalidOrder, // Iceberg order single transaction average error
|
670
|
+
'35075': InvalidOrder, // Failed to cancel order
|
671
|
+
'35076': InvalidOrder, // LTC 20x leverage. Not allowed to open position
|
672
|
+
'35077': InvalidOrder, // Maximum 6 unfulfilled iceberg orders can be held at the same time
|
673
|
+
'35078': InvalidOrder, // Order amount exceeded 100,000
|
674
|
+
'35079': InvalidOrder, // Iceberg order price variance error
|
675
|
+
'35080': InvalidOrder, // Callback rate error
|
676
|
+
'35081': InvalidOrder, // Maximum 10 unfulfilled trail orders can be held at the same time
|
677
|
+
'35082': InvalidOrder, // Trail order callback rate error
|
678
|
+
'35083': InvalidOrder, // Each user can only hold a maximum of 10 unfulfilled stop-limit orders at the same time
|
679
|
+
'35084': InvalidOrder, // Order amount exceeded 1 million
|
680
|
+
'35085': InvalidOrder, // Order amount is not in the correct range
|
681
|
+
'35086': InvalidOrder, // Price exceeds 100 thousand
|
682
|
+
'35087': InvalidOrder, // Price exceeds 100 thousand
|
683
|
+
'35088': InvalidOrder, // Average amount error
|
684
|
+
'35089': InvalidOrder, // Price exceeds 100 thousand
|
685
|
+
'35090': ExchangeError, // No stop-limit orders available for cancelation
|
686
|
+
'35091': ExchangeError, // No trail orders available for cancellation
|
687
|
+
'35092': ExchangeError, // No iceberg orders available for cancellation
|
688
|
+
'35093': ExchangeError, // No trail orders available for cancellation
|
689
|
+
'35094': ExchangeError, // Stop-limit order last traded price error
|
690
|
+
'35095': BadRequest, // Instrument_id error
|
691
|
+
'35096': ExchangeError, // Algo order status error
|
692
|
+
'35097': ExchangeError, // Order status and order ID cannot exist at the same time
|
693
|
+
'35098': ExchangeError, // An order status or order ID must exist
|
694
|
+
'35099': ExchangeError, // Algo order ID error
|
695
|
+
'35102': RateLimitExceeded, // {"error_message":"The operation that close all at market price is too frequent","result":"true","error_code":"35102","order_id":"-1"}
|
696
|
+
// option
|
697
|
+
'36001': BadRequest, // Invalid underlying index.
|
698
|
+
'36002': BadRequest, // Instrument does not exist.
|
699
|
+
'36005': ExchangeError, // Instrument status is invalid.
|
700
|
+
'36101': AuthenticationError, // Account does not exist.
|
701
|
+
'36102': PermissionDenied, // Account status is invalid.
|
702
|
+
'36103': PermissionDenied, // Account is suspended due to ongoing liquidation.
|
703
|
+
'36104': PermissionDenied, // Account is not enabled for options trading.
|
704
|
+
'36105': PermissionDenied, // Please enable the account for option contract.
|
705
|
+
'36106': PermissionDenied, // Funds cannot be transferred in or out, as account is suspended.
|
706
|
+
'36107': PermissionDenied, // Funds cannot be transferred out within 30 minutes after option exercising or settlement.
|
707
|
+
'36108': InsufficientFunds, // Funds cannot be transferred in or out, as equity of the account is less than zero.
|
708
|
+
'36109': PermissionDenied, // Funds cannot be transferred in or out during option exercising or settlement.
|
709
|
+
'36201': PermissionDenied, // New order function is blocked.
|
710
|
+
'36202': PermissionDenied, // Account does not have permission to short option.
|
711
|
+
'36203': InvalidOrder, // Invalid format for client_oid.
|
712
|
+
'36204': ExchangeError, // Invalid format for request_id.
|
713
|
+
'36205': BadRequest, // Instrument id does not match underlying index.
|
714
|
+
'36206': BadRequest, // Order_id and client_oid can not be used at the same time.
|
715
|
+
'36207': InvalidOrder, // Either order price or fartouch price must be present.
|
716
|
+
'36208': InvalidOrder, // Either order price or size must be present.
|
717
|
+
'36209': InvalidOrder, // Either order_id or client_oid must be present.
|
718
|
+
'36210': InvalidOrder, // Either order_ids or client_oids must be present.
|
719
|
+
'36211': InvalidOrder, // Exceeding max batch size for order submission.
|
720
|
+
'36212': InvalidOrder, // Exceeding max batch size for oder cancellation.
|
721
|
+
'36213': InvalidOrder, // Exceeding max batch size for order amendment.
|
722
|
+
'36214': ExchangeError, // Instrument does not have valid bid/ask quote.
|
723
|
+
'36216': OrderNotFound, // Order does not exist.
|
724
|
+
'36217': InvalidOrder, // Order submission failed.
|
725
|
+
'36218': InvalidOrder, // Order cancellation failed.
|
726
|
+
'36219': InvalidOrder, // Order amendment failed.
|
727
|
+
'36220': InvalidOrder, // Order is pending cancel.
|
728
|
+
'36221': InvalidOrder, // Order qty is not valid multiple of lot size.
|
729
|
+
'36222': InvalidOrder, // Order price is breaching highest buy limit.
|
730
|
+
'36223': InvalidOrder, // Order price is breaching lowest sell limit.
|
731
|
+
'36224': InvalidOrder, // Exceeding max order size.
|
732
|
+
'36225': InvalidOrder, // Exceeding max open order count for instrument.
|
733
|
+
'36226': InvalidOrder, // Exceeding max open order count for underlying.
|
734
|
+
'36227': InvalidOrder, // Exceeding max open size across all orders for underlying
|
735
|
+
'36228': InvalidOrder, // Exceeding max available qty for instrument.
|
736
|
+
'36229': InvalidOrder, // Exceeding max available qty for underlying.
|
737
|
+
'36230': InvalidOrder, // Exceeding max position limit for underlying.
|
738
|
+
},
|
739
|
+
'broad': {
|
740
|
+
},
|
741
|
+
},
|
742
|
+
'precisionMode': TICK_SIZE,
|
743
|
+
'options': {
|
744
|
+
'fetchOHLCV': {
|
745
|
+
'type': 'Candles', // Candles or HistoryCandles
|
746
|
+
},
|
747
|
+
'createMarketBuyOrderRequiresPrice': true,
|
748
|
+
'fetchMarkets': [ 'spot' ],
|
749
|
+
'defaultType': 'spot', // 'account', 'spot', 'margin', 'futures', 'swap', 'option'
|
750
|
+
'accountsByType': {
|
751
|
+
'spot': '1',
|
752
|
+
'margin': '5',
|
753
|
+
'funding': '6',
|
754
|
+
},
|
755
|
+
'accountsById': {
|
756
|
+
'1': 'spot',
|
757
|
+
'5': 'margin',
|
758
|
+
'6': 'funding',
|
759
|
+
},
|
760
|
+
'auth': {
|
761
|
+
'time': 'public',
|
762
|
+
'currencies': 'private',
|
763
|
+
'instruments': 'public',
|
764
|
+
'rate': 'public',
|
765
|
+
'{instrument_id}/constituents': 'public',
|
766
|
+
},
|
767
|
+
'warnOnFetchCurrenciesWithoutAuthorization': false,
|
768
|
+
},
|
769
|
+
'commonCurrencies': {
|
770
|
+
// OKEX refers to ERC20 version of Aeternity (AEToken)
|
771
|
+
'AE': 'AET', // https://github.com/ccxt/ccxt/issues/4981
|
772
|
+
'BOX': 'DefiBox',
|
773
|
+
'HOT': 'Hydro Protocol',
|
774
|
+
'HSR': 'HC',
|
775
|
+
'MAG': 'Maggie',
|
776
|
+
'SBTC': 'Super Bitcoin',
|
777
|
+
'TRADE': 'Unitrade',
|
778
|
+
'YOYO': 'YOYOW',
|
779
|
+
'WIN': 'WinToken', // https://github.com/ccxt/ccxt/issues/5701
|
780
|
+
},
|
781
|
+
});
|
782
|
+
}
|
783
|
+
|
784
|
+
async fetchTime (params = {}) {
|
785
|
+
const response = await this.generalGetTime (params);
|
786
|
+
//
|
787
|
+
// {
|
788
|
+
// "iso": "2015-01-07T23:47:25.201Z",
|
789
|
+
// "epoch": 1420674445.201
|
790
|
+
// }
|
791
|
+
//
|
792
|
+
return this.parse8601 (this.safeString (response, 'iso'));
|
793
|
+
}
|
794
|
+
|
795
|
+
async fetchMarkets (params = {}) {
|
796
|
+
const types = this.safeValue (this.options, 'fetchMarkets');
|
797
|
+
let result = [];
|
798
|
+
for (let i = 0; i < types.length; i++) {
|
799
|
+
const markets = await this.fetchMarketsByType (types[i], params);
|
800
|
+
result = this.arrayConcat (result, markets);
|
801
|
+
}
|
802
|
+
return result;
|
803
|
+
}
|
804
|
+
|
805
|
+
parseMarkets (markets) {
|
806
|
+
const result = [];
|
807
|
+
for (let i = 0; i < markets.length; i++) {
|
808
|
+
result.push (this.parseMarket (markets[i]));
|
809
|
+
}
|
810
|
+
return result;
|
811
|
+
}
|
812
|
+
|
813
|
+
parseMarket (market) {
|
814
|
+
//
|
815
|
+
// spot markets
|
816
|
+
//
|
817
|
+
// {
|
818
|
+
// base_currency: "EOS",
|
819
|
+
// instrument_id: "EOS-OKB",
|
820
|
+
// min_size: "0.01",
|
821
|
+
// quote_currency: "OKB",
|
822
|
+
// size_increment: "0.000001",
|
823
|
+
// tick_size: "0.0001"
|
824
|
+
// }
|
825
|
+
//
|
826
|
+
// futures markets
|
827
|
+
//
|
828
|
+
// {
|
829
|
+
// instrument_id: "XRP-USD-200320",
|
830
|
+
// underlying_index: "XRP",
|
831
|
+
// quote_currency: "USD",
|
832
|
+
// tick_size: "0.0001",
|
833
|
+
// contract_val: "10",
|
834
|
+
// listing: "2020-03-06",
|
835
|
+
// delivery: "2020-03-20",
|
836
|
+
// trade_increment: "1",
|
837
|
+
// alias: "this_week",
|
838
|
+
// underlying: "XRP-USD",
|
839
|
+
// base_currency: "XRP",
|
840
|
+
// settlement_currency: "XRP",
|
841
|
+
// is_inverse: "true",
|
842
|
+
// contract_val_currency: "USD",
|
843
|
+
// }
|
844
|
+
//
|
845
|
+
// swap markets
|
846
|
+
//
|
847
|
+
// {
|
848
|
+
// instrument_id: "BSV-USD-SWAP",
|
849
|
+
// underlying_index: "BSV",
|
850
|
+
// quote_currency: "USD",
|
851
|
+
// coin: "BSV",
|
852
|
+
// contract_val: "10",
|
853
|
+
// listing: "2018-12-21T07:53:47.000Z",
|
854
|
+
// delivery: "2020-03-14T08:00:00.000Z",
|
855
|
+
// size_increment: "1",
|
856
|
+
// tick_size: "0.01",
|
857
|
+
// base_currency: "BSV",
|
858
|
+
// underlying: "BSV-USD",
|
859
|
+
// settlement_currency: "BSV",
|
860
|
+
// is_inverse: "true",
|
861
|
+
// contract_val_currency: "USD"
|
862
|
+
// }
|
863
|
+
//
|
864
|
+
// options markets
|
865
|
+
//
|
866
|
+
// {
|
867
|
+
// instrument_id: 'BTC-USD-200327-4000-C',
|
868
|
+
// underlying: 'BTC-USD',
|
869
|
+
// settlement_currency: 'BTC',
|
870
|
+
// contract_val: '0.1000',
|
871
|
+
// option_type: 'C',
|
872
|
+
// strike: '4000',
|
873
|
+
// tick_size: '0.0005',
|
874
|
+
// lot_size: '1.0000',
|
875
|
+
// listing: '2019-12-25T08:30:36.302Z',
|
876
|
+
// delivery: '2020-03-27T08:00:00.000Z',
|
877
|
+
// state: '2',
|
878
|
+
// trading_start_time: '2019-12-25T08:30:36.302Z',
|
879
|
+
// timestamp: '2020-03-13T08:05:09.456Z',
|
880
|
+
// }
|
881
|
+
//
|
882
|
+
const id = this.safeString (market, 'instrument_id');
|
883
|
+
let optionType = this.safeValue (market, 'option_type');
|
884
|
+
const contractVal = this.safeNumber (market, 'contract_val');
|
885
|
+
const contract = contractVal !== undefined;
|
886
|
+
const futuresAlias = this.safeString (market, 'alias');
|
887
|
+
let marketType = 'spot';
|
888
|
+
const spot = !contract;
|
889
|
+
const option = (optionType !== undefined);
|
890
|
+
const future = !option && (futuresAlias !== undefined);
|
891
|
+
const swap = contract && !future && !option;
|
892
|
+
let baseId = this.safeString (market, 'base_currency');
|
893
|
+
let quoteId = this.safeString (market, 'quote_currency');
|
894
|
+
const settleId = this.safeString (market, 'settlement_currency');
|
895
|
+
if (option) {
|
896
|
+
const underlying = this.safeString (market, 'underlying');
|
897
|
+
const parts = underlying.split ('-');
|
898
|
+
baseId = this.safeString (parts, 0);
|
899
|
+
quoteId = this.safeString (parts, 1);
|
900
|
+
marketType = 'option';
|
901
|
+
} else if (future) {
|
902
|
+
baseId = this.safeString (market, 'underlying_index');
|
903
|
+
marketType = 'futures';
|
904
|
+
} else if (swap) {
|
905
|
+
marketType = 'swap';
|
906
|
+
}
|
907
|
+
const base = this.safeCurrencyCode (baseId);
|
908
|
+
const quote = this.safeCurrencyCode (quoteId);
|
909
|
+
const settle = this.safeCurrencyCode (settleId);
|
910
|
+
let symbol = base + '/' + quote;
|
911
|
+
let expiryDatetime = this.safeString (market, 'delivery');
|
912
|
+
let expiry = undefined;
|
913
|
+
const strike = this.safeValue (market, 'strike');
|
914
|
+
if (contract) {
|
915
|
+
symbol = symbol + ':' + settle;
|
916
|
+
if (future || option) {
|
917
|
+
if (future) {
|
918
|
+
expiryDatetime += 'T00:00:00Z';
|
919
|
+
}
|
920
|
+
expiry = this.parse8601 (expiryDatetime);
|
921
|
+
symbol = symbol + '-' + this.yymmdd (expiry);
|
922
|
+
if (option) {
|
923
|
+
symbol = symbol + ':' + strike + ':' + optionType;
|
924
|
+
optionType = (optionType === 'C') ? 'call' : 'put';
|
925
|
+
}
|
926
|
+
}
|
927
|
+
}
|
928
|
+
const lotSize = this.safeNumber2 (market, 'lot_size', 'trade_increment');
|
929
|
+
const minPrice = this.safeString (market, 'tick_size');
|
930
|
+
const minAmountString = this.safeString2 (market, 'min_size', 'base_min_size');
|
931
|
+
const minAmount = this.parseNumber (minAmountString);
|
932
|
+
let minCost = undefined;
|
933
|
+
if ((minAmount !== undefined) && (minPrice !== undefined)) {
|
934
|
+
minCost = this.parseNumber (Precise.stringMul (minPrice, minAmountString));
|
935
|
+
}
|
936
|
+
const fees = this.safeValue2 (this.fees, marketType, 'trading', {});
|
937
|
+
const maxLeverageString = this.safeString (market, 'max_leverage', '1');
|
938
|
+
const maxLeverage = this.parseNumber (Precise.stringMax (maxLeverageString, '1'));
|
939
|
+
const precisionPrice = this.parseNumber (minPrice);
|
940
|
+
return this.extend (fees, {
|
941
|
+
'id': id,
|
942
|
+
'symbol': symbol,
|
943
|
+
'base': base,
|
944
|
+
'quote': quote,
|
945
|
+
'settle': settle,
|
946
|
+
'baseId': baseId,
|
947
|
+
'quoteId': quoteId,
|
948
|
+
'settleId': settleId,
|
949
|
+
'type': marketType,
|
950
|
+
'spot': spot,
|
951
|
+
'margin': spot && (Precise.stringGt (maxLeverageString, '1')),
|
952
|
+
'swap': swap,
|
953
|
+
'future': future,
|
954
|
+
'futures': future, // deprecated
|
955
|
+
'option': option,
|
956
|
+
'active': true,
|
957
|
+
'contract': contract,
|
958
|
+
'linear': contract ? (quote === settle) : undefined,
|
959
|
+
'inverse': contract ? (base === settle) : undefined,
|
960
|
+
'contractSize': contractVal,
|
961
|
+
'expiry': expiry,
|
962
|
+
'expiryDatetime': this.iso8601 (expiry),
|
963
|
+
'strike': strike,
|
964
|
+
'optionType': optionType,
|
965
|
+
'precision': {
|
966
|
+
'amount': this.safeNumber (market, 'size_increment', lotSize),
|
967
|
+
'price': precisionPrice,
|
968
|
+
},
|
969
|
+
'limits': {
|
970
|
+
'leverage': {
|
971
|
+
'min': this.parseNumber ('1'),
|
972
|
+
'max': this.parseNumber (maxLeverage),
|
973
|
+
},
|
974
|
+
'amount': {
|
975
|
+
'min': minAmount,
|
976
|
+
'max': undefined,
|
977
|
+
},
|
978
|
+
'price': {
|
979
|
+
'min': precisionPrice,
|
980
|
+
'max': undefined,
|
981
|
+
},
|
982
|
+
'cost': {
|
983
|
+
'min': minCost,
|
984
|
+
'max': undefined,
|
985
|
+
},
|
986
|
+
},
|
987
|
+
'info': market,
|
988
|
+
});
|
989
|
+
}
|
990
|
+
|
991
|
+
async fetchMarketsByType (type, params = {}) {
|
992
|
+
if (type === 'option') {
|
993
|
+
const underlying = await this.optionGetUnderlying (params);
|
994
|
+
let result = [];
|
995
|
+
for (let i = 0; i < underlying.length; i++) {
|
996
|
+
const response = await this.optionGetInstrumentsUnderlying ({
|
997
|
+
'underlying': underlying[i],
|
998
|
+
});
|
999
|
+
//
|
1000
|
+
// options markets
|
1001
|
+
//
|
1002
|
+
// [
|
1003
|
+
// {
|
1004
|
+
// instrument_id: 'BTC-USD-200327-4000-C',
|
1005
|
+
// underlying: 'BTC-USD',
|
1006
|
+
// settlement_currency: 'BTC',
|
1007
|
+
// contract_val: '0.1000',
|
1008
|
+
// option_type: 'C',
|
1009
|
+
// strike: '4000',
|
1010
|
+
// tick_size: '0.0005',
|
1011
|
+
// lot_size: '1.0000',
|
1012
|
+
// listing: '2019-12-25T08:30:36.302Z',
|
1013
|
+
// delivery: '2020-03-27T08:00:00.000Z',
|
1014
|
+
// state: '2',
|
1015
|
+
// trading_start_time: '2019-12-25T08:30:36.302Z',
|
1016
|
+
// timestamp: '2020-03-13T08:05:09.456Z',
|
1017
|
+
// },
|
1018
|
+
// ]
|
1019
|
+
//
|
1020
|
+
result = this.arrayConcat (result, response);
|
1021
|
+
}
|
1022
|
+
return this.parseMarkets (result);
|
1023
|
+
} else if ((type === 'spot') || (type === 'futures') || (type === 'swap')) {
|
1024
|
+
const method = type + 'GetInstruments';
|
1025
|
+
const response = await this[method] (params);
|
1026
|
+
//
|
1027
|
+
// spot markets
|
1028
|
+
//
|
1029
|
+
// [
|
1030
|
+
// {
|
1031
|
+
// base_currency: "EOS",
|
1032
|
+
// instrument_id: "EOS-OKB",
|
1033
|
+
// min_size: "0.01",
|
1034
|
+
// quote_currency: "OKB",
|
1035
|
+
// size_increment: "0.000001",
|
1036
|
+
// tick_size: "0.0001"
|
1037
|
+
// }
|
1038
|
+
// ]
|
1039
|
+
//
|
1040
|
+
// futures markets
|
1041
|
+
//
|
1042
|
+
// [
|
1043
|
+
// {
|
1044
|
+
// instrument_id: "XRP-USD-200320",
|
1045
|
+
// underlying_index: "XRP",
|
1046
|
+
// quote_currency: "USD",
|
1047
|
+
// tick_size: "0.0001",
|
1048
|
+
// contract_val: "10",
|
1049
|
+
// listing: "2020-03-06",
|
1050
|
+
// delivery: "2020-03-20",
|
1051
|
+
// trade_increment: "1",
|
1052
|
+
// alias: "this_week",
|
1053
|
+
// underlying: "XRP-USD",
|
1054
|
+
// base_currency: "XRP",
|
1055
|
+
// settlement_currency: "XRP",
|
1056
|
+
// is_inverse: "true",
|
1057
|
+
// contract_val_currency: "USD",
|
1058
|
+
// }
|
1059
|
+
// ]
|
1060
|
+
//
|
1061
|
+
// swap markets
|
1062
|
+
//
|
1063
|
+
// [
|
1064
|
+
// {
|
1065
|
+
// instrument_id: "BSV-USD-SWAP",
|
1066
|
+
// underlying_index: "BSV",
|
1067
|
+
// quote_currency: "USD",
|
1068
|
+
// coin: "BSV",
|
1069
|
+
// contract_val: "10",
|
1070
|
+
// listing: "2018-12-21T07:53:47.000Z",
|
1071
|
+
// delivery: "2020-03-14T08:00:00.000Z",
|
1072
|
+
// size_increment: "1",
|
1073
|
+
// tick_size: "0.01",
|
1074
|
+
// base_currency: "BSV",
|
1075
|
+
// underlying: "BSV-USD",
|
1076
|
+
// settlement_currency: "BSV",
|
1077
|
+
// is_inverse: "true",
|
1078
|
+
// contract_val_currency: "USD"
|
1079
|
+
// }
|
1080
|
+
// ]
|
1081
|
+
//
|
1082
|
+
return this.parseMarkets (response);
|
1083
|
+
} else {
|
1084
|
+
throw new NotSupported (this.id + ' fetchMarketsByType() does not support market type ' + type);
|
1085
|
+
}
|
1086
|
+
}
|
1087
|
+
|
1088
|
+
async fetchCurrencies (params = {}) {
|
1089
|
+
// despite that their docs say these endpoints are public:
|
1090
|
+
// https://www.okex.com/api/account/v3/withdrawal/fee
|
1091
|
+
// https://www.okex.com/api/account/v3/currencies
|
1092
|
+
// it will still reply with { "code":30001, "message": "OK-ACCESS-KEY header is required" }
|
1093
|
+
// if you attempt to access it without authentication
|
1094
|
+
if (!this.checkRequiredCredentials (false)) {
|
1095
|
+
if (this.options['warnOnFetchCurrenciesWithoutAuthorization']) {
|
1096
|
+
throw new ExchangeError (this.id + ' fetchCurrencies() is a private API endpoint that requires authentication with API keys. Set the API keys on the exchange instance or exchange.options["warnOnFetchCurrenciesWithoutAuthorization"] = false to suppress this warning message.');
|
1097
|
+
}
|
1098
|
+
return undefined;
|
1099
|
+
} else {
|
1100
|
+
const response = await this.accountGetCurrencies (params);
|
1101
|
+
//
|
1102
|
+
// [
|
1103
|
+
// {
|
1104
|
+
// name: '',
|
1105
|
+
// currency: 'BTC',
|
1106
|
+
// can_withdraw: '1',
|
1107
|
+
// can_deposit: '1',
|
1108
|
+
// min_withdrawal: '0.0100000000000000'
|
1109
|
+
// },
|
1110
|
+
// ]
|
1111
|
+
//
|
1112
|
+
const result = {};
|
1113
|
+
for (let i = 0; i < response.length; i++) {
|
1114
|
+
const currency = response[i];
|
1115
|
+
const id = this.safeString (currency, 'currency');
|
1116
|
+
const code = this.safeCurrencyCode (id);
|
1117
|
+
const precision = 0.00000001; // default precision, todo: fix "magic constants"
|
1118
|
+
const name = this.safeString (currency, 'name');
|
1119
|
+
const canDeposit = this.safeInteger (currency, 'can_deposit');
|
1120
|
+
const canWithdraw = this.safeInteger (currency, 'can_withdraw');
|
1121
|
+
const depositEnabled = (canDeposit === 1);
|
1122
|
+
const withdrawEnabled = (canWithdraw === 1);
|
1123
|
+
const active = (canDeposit && canWithdraw) ? true : false;
|
1124
|
+
result[code] = {
|
1125
|
+
'id': id,
|
1126
|
+
'code': code,
|
1127
|
+
'info': currency,
|
1128
|
+
'type': undefined,
|
1129
|
+
'name': name,
|
1130
|
+
'active': active,
|
1131
|
+
'deposit': depositEnabled,
|
1132
|
+
'withdraw': withdrawEnabled,
|
1133
|
+
'fee': undefined, // todo: redesign
|
1134
|
+
'precision': precision,
|
1135
|
+
'limits': {
|
1136
|
+
'amount': { 'min': undefined, 'max': undefined },
|
1137
|
+
'withdraw': {
|
1138
|
+
'min': this.safeNumber (currency, 'min_withdrawal'),
|
1139
|
+
'max': undefined,
|
1140
|
+
},
|
1141
|
+
},
|
1142
|
+
};
|
1143
|
+
}
|
1144
|
+
return result;
|
1145
|
+
}
|
1146
|
+
}
|
1147
|
+
|
1148
|
+
async fetchOrderBook (symbol, limit = undefined, params = {}) {
|
1149
|
+
await this.loadMarkets ();
|
1150
|
+
const market = this.market (symbol);
|
1151
|
+
let method = market['type'] + 'GetInstrumentsInstrumentId';
|
1152
|
+
method += (market['type'] === 'swap') ? 'Depth' : 'Book';
|
1153
|
+
const request = {
|
1154
|
+
'instrument_id': market['id'],
|
1155
|
+
};
|
1156
|
+
if (limit !== undefined) {
|
1157
|
+
request['size'] = limit; // max 200
|
1158
|
+
}
|
1159
|
+
const response = await this[method] (this.extend (request, params));
|
1160
|
+
//
|
1161
|
+
// spot
|
1162
|
+
//
|
1163
|
+
// { asks: [ ["0.02685268", "0.242571", "1"],
|
1164
|
+
// ["0.02685493", "0.164085", "1"],
|
1165
|
+
// ...
|
1166
|
+
// ["0.02779", "1.039", "1"],
|
1167
|
+
// ["0.027813", "0.0876", "1"] ],
|
1168
|
+
// bids: [ ["0.02684052", "10.371849", "1"],
|
1169
|
+
// ["0.02684051", "3.707", "4"],
|
1170
|
+
// ...
|
1171
|
+
// ["0.02634963", "0.132934", "1"],
|
1172
|
+
// ["0.02634962", "0.264838", "2"] ],
|
1173
|
+
// timestamp: "2018-12-17T20:24:16.159Z" }
|
1174
|
+
//
|
1175
|
+
// swap
|
1176
|
+
//
|
1177
|
+
// {
|
1178
|
+
// "asks":[
|
1179
|
+
// ["916.21","94","0","1"]
|
1180
|
+
// ],
|
1181
|
+
// "bids":[
|
1182
|
+
// ["916.1","15","0","1"]
|
1183
|
+
// ],
|
1184
|
+
// "time":"2021-04-16T02:04:48.282Z"
|
1185
|
+
// }
|
1186
|
+
//
|
1187
|
+
const timestamp = this.parse8601 (this.safeString2 (response, 'timestamp', 'time'));
|
1188
|
+
return this.parseOrderBook (response, symbol, timestamp);
|
1189
|
+
}
|
1190
|
+
|
1191
|
+
parseTicker (ticker, market = undefined) {
|
1192
|
+
//
|
1193
|
+
// { best_ask: "0.02665472",
|
1194
|
+
// best_bid: "0.02665221",
|
1195
|
+
// instrument_id: "ETH-BTC",
|
1196
|
+
// product_id: "ETH-BTC",
|
1197
|
+
// last: "0.02665472",
|
1198
|
+
// ask: "0.02665472", // missing in the docs
|
1199
|
+
// bid: "0.02665221", // not mentioned in the docs
|
1200
|
+
// open_24h: "0.02645482",
|
1201
|
+
// high_24h: "0.02714633",
|
1202
|
+
// low_24h: "0.02614109",
|
1203
|
+
// base_volume_24h: "572298.901923",
|
1204
|
+
// timestamp: "2018-12-17T21:20:07.856Z",
|
1205
|
+
// quote_volume_24h: "15094.86831261" }
|
1206
|
+
//
|
1207
|
+
const timestamp = this.parse8601 (this.safeString (ticker, 'timestamp'));
|
1208
|
+
const marketId = this.safeString (ticker, 'instrument_id');
|
1209
|
+
market = this.safeMarket (marketId, market, '-');
|
1210
|
+
const symbol = market['symbol'];
|
1211
|
+
const last = this.safeString (ticker, 'last');
|
1212
|
+
const open = this.safeString (ticker, 'open_24h');
|
1213
|
+
return this.safeTicker ({
|
1214
|
+
'symbol': symbol,
|
1215
|
+
'timestamp': timestamp,
|
1216
|
+
'datetime': this.iso8601 (timestamp),
|
1217
|
+
'high': this.safeString (ticker, 'high_24h'),
|
1218
|
+
'low': this.safeString (ticker, 'low_24h'),
|
1219
|
+
'bid': this.safeString (ticker, 'best_bid'),
|
1220
|
+
'bidVolume': this.safeString (ticker, 'best_bid_size'),
|
1221
|
+
'ask': this.safeString (ticker, 'best_ask'),
|
1222
|
+
'askVolume': this.safeString (ticker, 'best_ask_size'),
|
1223
|
+
'vwap': undefined,
|
1224
|
+
'open': open,
|
1225
|
+
'close': last,
|
1226
|
+
'last': last,
|
1227
|
+
'previousClose': undefined,
|
1228
|
+
'change': undefined,
|
1229
|
+
'percentage': undefined,
|
1230
|
+
'average': undefined,
|
1231
|
+
'baseVolume': this.safeString (ticker, 'base_volume_24h'),
|
1232
|
+
'quoteVolume': this.safeString (ticker, 'quote_volume_24h'),
|
1233
|
+
'info': ticker,
|
1234
|
+
}, market, false);
|
1235
|
+
}
|
1236
|
+
|
1237
|
+
async fetchTicker (symbol, params = {}) {
|
1238
|
+
await this.loadMarkets ();
|
1239
|
+
const market = this.market (symbol);
|
1240
|
+
const method = market['type'] + 'GetInstrumentsInstrumentIdTicker';
|
1241
|
+
const request = {
|
1242
|
+
'instrument_id': market['id'],
|
1243
|
+
};
|
1244
|
+
const response = await this[method] (this.extend (request, params));
|
1245
|
+
//
|
1246
|
+
// { best_ask: "0.02665472",
|
1247
|
+
// best_bid: "0.02665221",
|
1248
|
+
// instrument_id: "ETH-BTC",
|
1249
|
+
// product_id: "ETH-BTC",
|
1250
|
+
// last: "0.02665472",
|
1251
|
+
// ask: "0.02665472",
|
1252
|
+
// bid: "0.02665221",
|
1253
|
+
// open_24h: "0.02645482",
|
1254
|
+
// high_24h: "0.02714633",
|
1255
|
+
// low_24h: "0.02614109",
|
1256
|
+
// base_volume_24h: "572298.901923",
|
1257
|
+
// timestamp: "2018-12-17T21:20:07.856Z",
|
1258
|
+
// quote_volume_24h: "15094.86831261" }
|
1259
|
+
//
|
1260
|
+
return this.parseTicker (response);
|
1261
|
+
}
|
1262
|
+
|
1263
|
+
async fetchTickersByType (type, symbols = undefined, params = {}) {
|
1264
|
+
await this.loadMarkets ();
|
1265
|
+
const method = type + 'GetInstrumentsTicker';
|
1266
|
+
const response = await this[method] (params);
|
1267
|
+
const result = {};
|
1268
|
+
for (let i = 0; i < response.length; i++) {
|
1269
|
+
const ticker = this.parseTicker (response[i]);
|
1270
|
+
const symbol = ticker['symbol'];
|
1271
|
+
result[symbol] = ticker;
|
1272
|
+
}
|
1273
|
+
return this.filterByArray (result, 'symbol', symbols);
|
1274
|
+
}
|
1275
|
+
|
1276
|
+
async fetchTickers (symbols = undefined, params = {}) {
|
1277
|
+
const defaultType = this.safeString2 (this.options, 'fetchTickers', 'defaultType');
|
1278
|
+
const type = this.safeString (params, 'type', defaultType);
|
1279
|
+
return await this.fetchTickersByType (type, symbols, this.omit (params, 'type'));
|
1280
|
+
}
|
1281
|
+
|
1282
|
+
parseTrade (trade, market = undefined) {
|
1283
|
+
//
|
1284
|
+
// fetchTrades (public)
|
1285
|
+
//
|
1286
|
+
// spot trades
|
1287
|
+
//
|
1288
|
+
// {
|
1289
|
+
// time: "2018-12-17T23:31:08.268Z",
|
1290
|
+
// timestamp: "2018-12-17T23:31:08.268Z",
|
1291
|
+
// trade_id: "409687906",
|
1292
|
+
// price: "0.02677805",
|
1293
|
+
// size: "0.923467",
|
1294
|
+
// side: "sell"
|
1295
|
+
// }
|
1296
|
+
//
|
1297
|
+
// futures trades, swap trades
|
1298
|
+
//
|
1299
|
+
// {
|
1300
|
+
// trade_id: "1989230840021013",
|
1301
|
+
// side: "buy",
|
1302
|
+
// price: "92.42",
|
1303
|
+
// qty: "184", // missing in swap markets
|
1304
|
+
// size: "5", // missing in futures markets
|
1305
|
+
// timestamp: "2018-12-17T23:26:04.613Z"
|
1306
|
+
// }
|
1307
|
+
//
|
1308
|
+
// fetchOrderTrades (private)
|
1309
|
+
//
|
1310
|
+
// spot trades, margin trades
|
1311
|
+
//
|
1312
|
+
// {
|
1313
|
+
// "created_at":"2019-03-15T02:52:56.000Z",
|
1314
|
+
// "exec_type":"T", // whether the order is taker or maker
|
1315
|
+
// "fee":"0.00000082",
|
1316
|
+
// "instrument_id":"BTC-USDT",
|
1317
|
+
// "ledger_id":"3963052721",
|
1318
|
+
// "liquidity":"T", // whether the order is taker or maker
|
1319
|
+
// "order_id":"2482659399697408",
|
1320
|
+
// "price":"3888.6",
|
1321
|
+
// "product_id":"BTC-USDT",
|
1322
|
+
// "side":"buy",
|
1323
|
+
// "size":"0.00055306",
|
1324
|
+
// "timestamp":"2019-03-15T02:52:56.000Z"
|
1325
|
+
// },
|
1326
|
+
//
|
1327
|
+
// futures trades, swap trades
|
1328
|
+
//
|
1329
|
+
// {
|
1330
|
+
// "trade_id":"197429674631450625",
|
1331
|
+
// "instrument_id":"EOS-USD-SWAP",
|
1332
|
+
// "order_id":"6a-7-54d663a28-0",
|
1333
|
+
// "price":"3.633",
|
1334
|
+
// "order_qty":"1.0000",
|
1335
|
+
// "fee":"-0.000551",
|
1336
|
+
// "created_at":"2019-03-21T04:41:58.0Z", // missing in swap trades
|
1337
|
+
// "timestamp":"2019-03-25T05:56:31.287Z", // missing in futures trades
|
1338
|
+
// "exec_type":"M", // whether the order is taker or maker
|
1339
|
+
// "side":"short", // "buy" in futures trades
|
1340
|
+
// }
|
1341
|
+
//
|
1342
|
+
let symbol = undefined;
|
1343
|
+
const marketId = this.safeString (trade, 'instrument_id');
|
1344
|
+
let base = undefined;
|
1345
|
+
let quote = undefined;
|
1346
|
+
if (marketId in this.markets_by_id) {
|
1347
|
+
market = this.markets_by_id[marketId];
|
1348
|
+
symbol = market['symbol'];
|
1349
|
+
base = market['base'];
|
1350
|
+
quote = market['quote'];
|
1351
|
+
} else if (marketId !== undefined) {
|
1352
|
+
const parts = marketId.split ('-');
|
1353
|
+
const numParts = parts.length;
|
1354
|
+
if (numParts === 2) {
|
1355
|
+
const [ baseId, quoteId ] = parts;
|
1356
|
+
base = this.safeCurrencyCode (baseId);
|
1357
|
+
quote = this.safeCurrencyCode (quoteId);
|
1358
|
+
symbol = base + '/' + quote;
|
1359
|
+
} else {
|
1360
|
+
symbol = marketId;
|
1361
|
+
}
|
1362
|
+
}
|
1363
|
+
if ((symbol === undefined) && (market !== undefined)) {
|
1364
|
+
symbol = market['symbol'];
|
1365
|
+
base = market['base'];
|
1366
|
+
quote = market['quote'];
|
1367
|
+
}
|
1368
|
+
const timestamp = this.parse8601 (this.safeString2 (trade, 'timestamp', 'created_at'));
|
1369
|
+
const priceString = this.safeString (trade, 'price');
|
1370
|
+
let amountString = this.safeString2 (trade, 'size', 'qty');
|
1371
|
+
amountString = this.safeString (trade, 'order_qty', amountString);
|
1372
|
+
let takerOrMaker = this.safeString2 (trade, 'exec_type', 'liquidity');
|
1373
|
+
if (takerOrMaker === 'M') {
|
1374
|
+
takerOrMaker = 'maker';
|
1375
|
+
} else if (takerOrMaker === 'T') {
|
1376
|
+
takerOrMaker = 'taker';
|
1377
|
+
}
|
1378
|
+
const side = this.safeString (trade, 'side');
|
1379
|
+
const feeCostString = this.safeString (trade, 'fee');
|
1380
|
+
let fee = undefined;
|
1381
|
+
if (feeCostString !== undefined) {
|
1382
|
+
const feeCurrency = (side === 'buy') ? base : quote;
|
1383
|
+
fee = {
|
1384
|
+
// fee is either a positive number (invitation rebate)
|
1385
|
+
// or a negative number (transaction fee deduction)
|
1386
|
+
// therefore we need to invert the fee
|
1387
|
+
// more about it https://github.com/ccxt/ccxt/issues/5909
|
1388
|
+
'cost': Precise.stringNeg (feeCostString),
|
1389
|
+
'currency': feeCurrency,
|
1390
|
+
};
|
1391
|
+
}
|
1392
|
+
const orderId = this.safeString (trade, 'order_id');
|
1393
|
+
return this.safeTrade ({
|
1394
|
+
'info': trade,
|
1395
|
+
'timestamp': timestamp,
|
1396
|
+
'datetime': this.iso8601 (timestamp),
|
1397
|
+
'symbol': symbol,
|
1398
|
+
'id': this.safeString2 (trade, 'trade_id', 'ledger_id'),
|
1399
|
+
'order': orderId,
|
1400
|
+
'type': undefined,
|
1401
|
+
'takerOrMaker': takerOrMaker,
|
1402
|
+
'side': side,
|
1403
|
+
'price': priceString,
|
1404
|
+
'amount': amountString,
|
1405
|
+
'cost': undefined,
|
1406
|
+
'fee': fee,
|
1407
|
+
}, market);
|
1408
|
+
}
|
1409
|
+
|
1410
|
+
async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) {
|
1411
|
+
await this.loadMarkets ();
|
1412
|
+
const market = this.market (symbol);
|
1413
|
+
const method = market['type'] + 'GetInstrumentsInstrumentIdTrades';
|
1414
|
+
if ((limit === undefined) || (limit > 100)) {
|
1415
|
+
limit = 100; // maximum = default = 100
|
1416
|
+
}
|
1417
|
+
const request = {
|
1418
|
+
'instrument_id': market['id'],
|
1419
|
+
'limit': limit,
|
1420
|
+
// from: 'id',
|
1421
|
+
// to: 'id',
|
1422
|
+
};
|
1423
|
+
const response = await this[method] (this.extend (request, params));
|
1424
|
+
//
|
1425
|
+
// spot markets
|
1426
|
+
//
|
1427
|
+
// [
|
1428
|
+
// {
|
1429
|
+
// time: "2018-12-17T23:31:08.268Z",
|
1430
|
+
// timestamp: "2018-12-17T23:31:08.268Z",
|
1431
|
+
// trade_id: "409687906",
|
1432
|
+
// price: "0.02677805",
|
1433
|
+
// size: "0.923467",
|
1434
|
+
// side: "sell"
|
1435
|
+
// }
|
1436
|
+
// ]
|
1437
|
+
//
|
1438
|
+
// futures markets, swap markets
|
1439
|
+
//
|
1440
|
+
// [
|
1441
|
+
// {
|
1442
|
+
// trade_id: "1989230840021013",
|
1443
|
+
// side: "buy",
|
1444
|
+
// price: "92.42",
|
1445
|
+
// qty: "184", // missing in swap markets
|
1446
|
+
// size: "5", // missing in futures markets
|
1447
|
+
// timestamp: "2018-12-17T23:26:04.613Z"
|
1448
|
+
// }
|
1449
|
+
// ]
|
1450
|
+
//
|
1451
|
+
return this.parseTrades (response, market, since, limit);
|
1452
|
+
}
|
1453
|
+
|
1454
|
+
parseOHLCV (ohlcv, market = undefined) {
|
1455
|
+
//
|
1456
|
+
// spot markets
|
1457
|
+
//
|
1458
|
+
// {
|
1459
|
+
// close: "0.02684545",
|
1460
|
+
// high: "0.02685084",
|
1461
|
+
// low: "0.02683312",
|
1462
|
+
// open: "0.02683894",
|
1463
|
+
// time: "2018-12-17T20:28:00.000Z",
|
1464
|
+
// volume: "101.457222"
|
1465
|
+
// }
|
1466
|
+
//
|
1467
|
+
// futures markets
|
1468
|
+
//
|
1469
|
+
// [
|
1470
|
+
// 1545072720000,
|
1471
|
+
// 0.3159,
|
1472
|
+
// 0.3161,
|
1473
|
+
// 0.3144,
|
1474
|
+
// 0.3149,
|
1475
|
+
// 22886,
|
1476
|
+
// 725179.26172331,
|
1477
|
+
// ]
|
1478
|
+
//
|
1479
|
+
if (Array.isArray (ohlcv)) {
|
1480
|
+
const numElements = ohlcv.length;
|
1481
|
+
const volumeIndex = (numElements > 6) ? 6 : 5;
|
1482
|
+
let timestamp = this.safeValue (ohlcv, 0);
|
1483
|
+
if (typeof timestamp === 'string') {
|
1484
|
+
timestamp = this.parse8601 (timestamp);
|
1485
|
+
}
|
1486
|
+
return [
|
1487
|
+
timestamp, // timestamp
|
1488
|
+
this.safeNumber (ohlcv, 1), // Open
|
1489
|
+
this.safeNumber (ohlcv, 2), // High
|
1490
|
+
this.safeNumber (ohlcv, 3), // Low
|
1491
|
+
this.safeNumber (ohlcv, 4), // Close
|
1492
|
+
// this.safeNumber (ohlcv, 5), // Quote Volume
|
1493
|
+
// this.safeNumber (ohlcv, 6), // Base Volume
|
1494
|
+
this.safeNumber (ohlcv, volumeIndex), // Volume, okex will return base volume in the 7th element for future markets
|
1495
|
+
];
|
1496
|
+
} else {
|
1497
|
+
return [
|
1498
|
+
this.parse8601 (this.safeString (ohlcv, 'time')),
|
1499
|
+
this.safeNumber (ohlcv, 'open'), // Open
|
1500
|
+
this.safeNumber (ohlcv, 'high'), // High
|
1501
|
+
this.safeNumber (ohlcv, 'low'), // Low
|
1502
|
+
this.safeNumber (ohlcv, 'close'), // Close
|
1503
|
+
this.safeNumber (ohlcv, 'volume'), // Base Volume
|
1504
|
+
];
|
1505
|
+
}
|
1506
|
+
}
|
1507
|
+
|
1508
|
+
async fetchOHLCV (symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
|
1509
|
+
await this.loadMarkets ();
|
1510
|
+
const market = this.market (symbol);
|
1511
|
+
const duration = this.parseTimeframe (timeframe);
|
1512
|
+
const request = {
|
1513
|
+
'instrument_id': market['id'],
|
1514
|
+
'granularity': this.timeframes[timeframe],
|
1515
|
+
};
|
1516
|
+
const options = this.safeValue (this.options, 'fetchOHLCV', {});
|
1517
|
+
const defaultType = this.safeString (options, 'type', 'Candles'); // Candles or HistoryCandles
|
1518
|
+
const type = this.safeString (params, 'type', defaultType);
|
1519
|
+
params = this.omit (params, 'type');
|
1520
|
+
const method = market['type'] + 'GetInstrumentsInstrumentId' + type;
|
1521
|
+
if (type === 'Candles') {
|
1522
|
+
if (since !== undefined) {
|
1523
|
+
if (limit !== undefined) {
|
1524
|
+
request['end'] = this.iso8601 (this.sum (since, limit * duration * 1000));
|
1525
|
+
}
|
1526
|
+
request['start'] = this.iso8601 (since);
|
1527
|
+
} else {
|
1528
|
+
if (limit !== undefined) {
|
1529
|
+
const now = this.milliseconds ();
|
1530
|
+
request['start'] = this.iso8601 (now - limit * duration * 1000);
|
1531
|
+
request['end'] = this.iso8601 (now);
|
1532
|
+
}
|
1533
|
+
}
|
1534
|
+
} else if (type === 'HistoryCandles') {
|
1535
|
+
if (market['option']) {
|
1536
|
+
throw new NotSupported (this.id + ' fetchOHLCV() does not have ' + type + ' for ' + market['type'] + ' markets');
|
1537
|
+
}
|
1538
|
+
if (since !== undefined) {
|
1539
|
+
if (limit === undefined) {
|
1540
|
+
limit = 300; // default
|
1541
|
+
}
|
1542
|
+
request['start'] = this.iso8601 (this.sum (since, limit * duration * 1000));
|
1543
|
+
request['end'] = this.iso8601 (since);
|
1544
|
+
} else {
|
1545
|
+
if (limit !== undefined) {
|
1546
|
+
const now = this.milliseconds ();
|
1547
|
+
request['end'] = this.iso8601 (now - limit * duration * 1000);
|
1548
|
+
request['start'] = this.iso8601 (now);
|
1549
|
+
}
|
1550
|
+
}
|
1551
|
+
}
|
1552
|
+
const response = await this[method] (this.extend (request, params));
|
1553
|
+
//
|
1554
|
+
// spot markets
|
1555
|
+
//
|
1556
|
+
// [
|
1557
|
+
// {
|
1558
|
+
// close: "0.02683401",
|
1559
|
+
// high: "0.02683401",
|
1560
|
+
// low: "0.02683401",
|
1561
|
+
// open: "0.02683401",
|
1562
|
+
// time: "2018-12-17T23:47:00.000Z",
|
1563
|
+
// volume: "0"
|
1564
|
+
// },
|
1565
|
+
// {
|
1566
|
+
// close: "0.02684545",
|
1567
|
+
// high: "0.02685084",
|
1568
|
+
// low: "0.02683312",
|
1569
|
+
// open: "0.02683894",
|
1570
|
+
// time: "2018-12-17T20:28:00.000Z",
|
1571
|
+
// volume: "101.457222"
|
1572
|
+
// }
|
1573
|
+
// ]
|
1574
|
+
//
|
1575
|
+
// futures
|
1576
|
+
//
|
1577
|
+
// [
|
1578
|
+
// [
|
1579
|
+
// 1545090660000,
|
1580
|
+
// 0.3171,
|
1581
|
+
// 0.3174,
|
1582
|
+
// 0.3171,
|
1583
|
+
// 0.3173,
|
1584
|
+
// 1648,
|
1585
|
+
// 51930.38579450868
|
1586
|
+
// ],
|
1587
|
+
// [
|
1588
|
+
// 1545072720000,
|
1589
|
+
// 0.3159,
|
1590
|
+
// 0.3161,
|
1591
|
+
// 0.3144,
|
1592
|
+
// 0.3149,
|
1593
|
+
// 22886,
|
1594
|
+
// 725179.26172331
|
1595
|
+
// ]
|
1596
|
+
// ]
|
1597
|
+
//
|
1598
|
+
return this.parseOHLCVs (response, market, timeframe, since, limit);
|
1599
|
+
}
|
1600
|
+
|
1601
|
+
parseAccountBalance (response) {
|
1602
|
+
//
|
1603
|
+
// account
|
1604
|
+
//
|
1605
|
+
// [
|
1606
|
+
// {
|
1607
|
+
// balance: 0,
|
1608
|
+
// available: 0,
|
1609
|
+
// currency: "BTC",
|
1610
|
+
// hold: 0
|
1611
|
+
// },
|
1612
|
+
// {
|
1613
|
+
// balance: 0,
|
1614
|
+
// available: 0,
|
1615
|
+
// currency: "ETH",
|
1616
|
+
// hold: 0
|
1617
|
+
// }
|
1618
|
+
// ]
|
1619
|
+
//
|
1620
|
+
// spot
|
1621
|
+
//
|
1622
|
+
// [
|
1623
|
+
// {
|
1624
|
+
// frozen: "0",
|
1625
|
+
// hold: "0",
|
1626
|
+
// id: "2149632",
|
1627
|
+
// currency: "BTC",
|
1628
|
+
// balance: "0.0000000497717339",
|
1629
|
+
// available: "0.0000000497717339",
|
1630
|
+
// holds: "0"
|
1631
|
+
// },
|
1632
|
+
// {
|
1633
|
+
// frozen: "0",
|
1634
|
+
// hold: "0",
|
1635
|
+
// id: "2149632",
|
1636
|
+
// currency: "ICN",
|
1637
|
+
// balance: "0.00000000925",
|
1638
|
+
// available: "0.00000000925",
|
1639
|
+
// holds: "0"
|
1640
|
+
// }
|
1641
|
+
// ]
|
1642
|
+
//
|
1643
|
+
const result = {
|
1644
|
+
'info': response,
|
1645
|
+
'timestamp': undefined,
|
1646
|
+
'datetime': undefined,
|
1647
|
+
};
|
1648
|
+
for (let i = 0; i < response.length; i++) {
|
1649
|
+
const balance = response[i];
|
1650
|
+
const currencyId = this.safeString (balance, 'currency');
|
1651
|
+
const code = this.safeCurrencyCode (currencyId);
|
1652
|
+
const account = this.account ();
|
1653
|
+
account['total'] = this.safeString (balance, 'balance');
|
1654
|
+
account['used'] = this.safeString (balance, 'hold');
|
1655
|
+
account['free'] = this.safeString (balance, 'available');
|
1656
|
+
result[code] = account;
|
1657
|
+
}
|
1658
|
+
return this.safeBalance (result);
|
1659
|
+
}
|
1660
|
+
|
1661
|
+
parseMarginBalance (response) {
|
1662
|
+
//
|
1663
|
+
// [
|
1664
|
+
// {
|
1665
|
+
// "currency:BTC": {
|
1666
|
+
// "available":"0",
|
1667
|
+
// "balance":"0",
|
1668
|
+
// "borrowed":"0",
|
1669
|
+
// "can_withdraw":"0",
|
1670
|
+
// "frozen":"0",
|
1671
|
+
// "hold":"0",
|
1672
|
+
// "holds":"0",
|
1673
|
+
// "lending_fee":"0"
|
1674
|
+
// },
|
1675
|
+
// "currency:USDT": {
|
1676
|
+
// "available":"100",
|
1677
|
+
// "balance":"100",
|
1678
|
+
// "borrowed":"0",
|
1679
|
+
// "can_withdraw":"100",
|
1680
|
+
// "frozen":"0",
|
1681
|
+
// "hold":"0",
|
1682
|
+
// "holds":"0",
|
1683
|
+
// "lending_fee":"0"
|
1684
|
+
// },
|
1685
|
+
// "instrument_id":"BTC-USDT",
|
1686
|
+
// "liquidation_price":"0",
|
1687
|
+
// "product_id":"BTC-USDT",
|
1688
|
+
// "risk_rate":""
|
1689
|
+
// },
|
1690
|
+
// ]
|
1691
|
+
//
|
1692
|
+
const result = {
|
1693
|
+
'info': response,
|
1694
|
+
'timestamp': undefined,
|
1695
|
+
'datetime': undefined,
|
1696
|
+
};
|
1697
|
+
for (let i = 0; i < response.length; i++) {
|
1698
|
+
const balance = response[i];
|
1699
|
+
const marketId = this.safeString (balance, 'instrument_id');
|
1700
|
+
const market = this.safeValue (this.markets_by_id, marketId);
|
1701
|
+
let symbol = undefined;
|
1702
|
+
if (market === undefined) {
|
1703
|
+
const [ baseId, quoteId ] = marketId.split ('-');
|
1704
|
+
const base = this.safeCurrencyCode (baseId);
|
1705
|
+
const quote = this.safeCurrencyCode (quoteId);
|
1706
|
+
symbol = base + '/' + quote;
|
1707
|
+
} else {
|
1708
|
+
symbol = market['symbol'];
|
1709
|
+
}
|
1710
|
+
const omittedBalance = this.omit (balance, [
|
1711
|
+
'instrument_id',
|
1712
|
+
'liquidation_price',
|
1713
|
+
'product_id',
|
1714
|
+
'risk_rate',
|
1715
|
+
'margin_ratio',
|
1716
|
+
'maint_margin_ratio',
|
1717
|
+
'tiers',
|
1718
|
+
]);
|
1719
|
+
const keys = Object.keys (omittedBalance);
|
1720
|
+
const accounts = {};
|
1721
|
+
for (let k = 0; k < keys.length; k++) {
|
1722
|
+
const key = keys[k];
|
1723
|
+
const marketBalance = balance[key];
|
1724
|
+
if (key.indexOf (':') >= 0) {
|
1725
|
+
const parts = key.split (':');
|
1726
|
+
const currencyId = parts[1];
|
1727
|
+
const code = this.safeCurrencyCode (currencyId);
|
1728
|
+
const account = this.account ();
|
1729
|
+
account['total'] = this.safeString (marketBalance, 'balance');
|
1730
|
+
account['used'] = this.safeString (marketBalance, 'hold');
|
1731
|
+
account['free'] = this.safeString (marketBalance, 'available');
|
1732
|
+
accounts[code] = account;
|
1733
|
+
} else {
|
1734
|
+
throw new NotSupported (this.id + ' margin balance response format has changed!');
|
1735
|
+
}
|
1736
|
+
}
|
1737
|
+
result[symbol] = this.safeBalance (accounts);
|
1738
|
+
}
|
1739
|
+
return result;
|
1740
|
+
}
|
1741
|
+
|
1742
|
+
parseFuturesBalance (response) {
|
1743
|
+
//
|
1744
|
+
// {
|
1745
|
+
// "info":{
|
1746
|
+
// "eos":{
|
1747
|
+
// "auto_margin":"0",
|
1748
|
+
// "contracts": [
|
1749
|
+
// {
|
1750
|
+
// "available_qty":"40.37069445",
|
1751
|
+
// "fixed_balance":"0",
|
1752
|
+
// "instrument_id":"EOS-USD-190329",
|
1753
|
+
// "margin_for_unfilled":"0",
|
1754
|
+
// "margin_frozen":"0",
|
1755
|
+
// "realized_pnl":"0",
|
1756
|
+
// "unrealized_pnl":"0"
|
1757
|
+
// },
|
1758
|
+
// {
|
1759
|
+
// "available_qty":"40.37069445",
|
1760
|
+
// "fixed_balance":"14.54895721",
|
1761
|
+
// "instrument_id":"EOS-USD-190628",
|
1762
|
+
// "margin_for_unfilled":"0",
|
1763
|
+
// "margin_frozen":"10.64042157",
|
1764
|
+
// "realized_pnl":"-3.90853564",
|
1765
|
+
// "unrealized_pnl":"-0.259"
|
1766
|
+
// },
|
1767
|
+
// ],
|
1768
|
+
// "equity":"50.75220665",
|
1769
|
+
// "margin_mode":"fixed",
|
1770
|
+
// "total_avail_balance":"40.37069445"
|
1771
|
+
// },
|
1772
|
+
// }
|
1773
|
+
// }
|
1774
|
+
//
|
1775
|
+
// their root field name is "info", so our info will contain their info
|
1776
|
+
const result = {
|
1777
|
+
'info': response,
|
1778
|
+
'timestamp': undefined,
|
1779
|
+
'datetime': undefined,
|
1780
|
+
};
|
1781
|
+
const info = this.safeValue (response, 'info', {});
|
1782
|
+
const ids = Object.keys (info);
|
1783
|
+
for (let i = 0; i < ids.length; i++) {
|
1784
|
+
const id = ids[i];
|
1785
|
+
const code = this.safeCurrencyCode (id);
|
1786
|
+
const balance = this.safeValue (info, id, {});
|
1787
|
+
const account = this.account ();
|
1788
|
+
const totalAvailBalance = this.safeString (balance, 'total_avail_balance');
|
1789
|
+
if (this.safeString (balance, 'margin_mode') === 'fixed') {
|
1790
|
+
const contracts = this.safeValue (balance, 'contracts', []);
|
1791
|
+
let free = totalAvailBalance;
|
1792
|
+
for (let i = 0; i < contracts.length; i++) {
|
1793
|
+
const contract = contracts[i];
|
1794
|
+
const fixedBalance = this.safeString (contract, 'fixed_balance');
|
1795
|
+
const realizedPnl = this.safeString (contract, 'realized_pnl');
|
1796
|
+
const marginFrozen = this.safeString (contract, 'margin_frozen');
|
1797
|
+
const marginForUnfilled = this.safeString (contract, 'margin_for_unfilled');
|
1798
|
+
const margin = Precise.stringSub (Precise.stringSub (Precise.stringAdd (fixedBalance, realizedPnl), marginFrozen), marginForUnfilled);
|
1799
|
+
free = Precise.stringAdd (free, margin);
|
1800
|
+
}
|
1801
|
+
account['free'] = free;
|
1802
|
+
} else {
|
1803
|
+
const realizedPnl = this.safeString (balance, 'realized_pnl');
|
1804
|
+
const unrealizedPnl = this.safeString (balance, 'unrealized_pnl');
|
1805
|
+
const marginFrozen = this.safeString (balance, 'margin_frozen');
|
1806
|
+
const marginForUnfilled = this.safeString (balance, 'margin_for_unfilled');
|
1807
|
+
const positive = Precise.stringAdd (Precise.stringAdd (totalAvailBalance, realizedPnl), unrealizedPnl);
|
1808
|
+
account['free'] = Precise.stringSub (Precise.stringSub (positive, marginFrozen), marginForUnfilled);
|
1809
|
+
}
|
1810
|
+
// it may be incorrect to use total, free and used for swap accounts
|
1811
|
+
account['total'] = this.safeString (balance, 'equity');
|
1812
|
+
result[code] = account;
|
1813
|
+
}
|
1814
|
+
return this.safeBalance (result);
|
1815
|
+
}
|
1816
|
+
|
1817
|
+
parseSwapBalance (response) {
|
1818
|
+
//
|
1819
|
+
// {
|
1820
|
+
// "info": [
|
1821
|
+
// {
|
1822
|
+
// "equity":"3.0139",
|
1823
|
+
// "fixed_balance":"0.0000",
|
1824
|
+
// "instrument_id":"EOS-USD-SWAP",
|
1825
|
+
// "margin":"0.5523",
|
1826
|
+
// "margin_frozen":"0.0000",
|
1827
|
+
// "margin_mode":"crossed",
|
1828
|
+
// "margin_ratio":"1.0913",
|
1829
|
+
// "realized_pnl":"-0.0006",
|
1830
|
+
// "timestamp":"2019-03-25T03:46:10.336Z",
|
1831
|
+
// "total_avail_balance":"3.0000",
|
1832
|
+
// "unrealized_pnl":"0.0145"
|
1833
|
+
// }
|
1834
|
+
// ]
|
1835
|
+
// }
|
1836
|
+
//
|
1837
|
+
// their root field name is "info", so our info will contain their info
|
1838
|
+
const result = { 'info': response };
|
1839
|
+
let timestamp = undefined;
|
1840
|
+
const info = this.safeValue (response, 'info', []);
|
1841
|
+
for (let i = 0; i < info.length; i++) {
|
1842
|
+
const balance = info[i];
|
1843
|
+
const marketId = this.safeString (balance, 'instrument_id');
|
1844
|
+
let symbol = marketId;
|
1845
|
+
if (marketId in this.markets_by_id) {
|
1846
|
+
symbol = this.markets_by_id[marketId]['symbol'];
|
1847
|
+
}
|
1848
|
+
const balanceTimestamp = this.parse8601 (this.safeString (balance, 'timestamp'));
|
1849
|
+
timestamp = (timestamp === undefined) ? balanceTimestamp : Math.max (timestamp, balanceTimestamp);
|
1850
|
+
const account = this.account ();
|
1851
|
+
// it may be incorrect to use total, free and used for swap accounts
|
1852
|
+
account['total'] = this.safeString (balance, 'equity');
|
1853
|
+
account['free'] = this.safeString (balance, 'total_avail_balance');
|
1854
|
+
result[symbol] = account;
|
1855
|
+
}
|
1856
|
+
result['timestamp'] = timestamp;
|
1857
|
+
result['datetime'] = this.iso8601 (timestamp);
|
1858
|
+
return this.safeBalance (result);
|
1859
|
+
}
|
1860
|
+
|
1861
|
+
async fetchBalance (params = {}) {
|
1862
|
+
const defaultType = this.safeString2 (this.options, 'fetchBalance', 'defaultType');
|
1863
|
+
const type = this.safeString (params, 'type', defaultType);
|
1864
|
+
if (type === undefined) {
|
1865
|
+
throw new ArgumentsRequired (this.id + " fetchBalance() requires a type parameter (one of 'account', 'spot', 'margin', 'futures', 'swap')");
|
1866
|
+
}
|
1867
|
+
await this.loadMarkets ();
|
1868
|
+
const suffix = (type === 'account') ? 'Wallet' : 'Accounts';
|
1869
|
+
const method = type + 'Get' + suffix;
|
1870
|
+
const query = this.omit (params, 'type');
|
1871
|
+
const response = await this[method] (query);
|
1872
|
+
//
|
1873
|
+
// account
|
1874
|
+
//
|
1875
|
+
// [
|
1876
|
+
// {
|
1877
|
+
// balance: 0,
|
1878
|
+
// available: 0,
|
1879
|
+
// currency: "BTC",
|
1880
|
+
// hold: 0
|
1881
|
+
// },
|
1882
|
+
// {
|
1883
|
+
// balance: 0,
|
1884
|
+
// available: 0,
|
1885
|
+
// currency: "ETH",
|
1886
|
+
// hold: 0
|
1887
|
+
// }
|
1888
|
+
// ]
|
1889
|
+
//
|
1890
|
+
// spot
|
1891
|
+
//
|
1892
|
+
// [
|
1893
|
+
// {
|
1894
|
+
// frozen: "0",
|
1895
|
+
// hold: "0",
|
1896
|
+
// id: "2149632",
|
1897
|
+
// currency: "BTC",
|
1898
|
+
// balance: "0.0000000497717339",
|
1899
|
+
// available: "0.0000000497717339",
|
1900
|
+
// holds: "0"
|
1901
|
+
// },
|
1902
|
+
// {
|
1903
|
+
// frozen: "0",
|
1904
|
+
// hold: "0",
|
1905
|
+
// id: "2149632",
|
1906
|
+
// currency: "ICN",
|
1907
|
+
// balance: "0.00000000925",
|
1908
|
+
// available: "0.00000000925",
|
1909
|
+
// holds: "0"
|
1910
|
+
// }
|
1911
|
+
// ]
|
1912
|
+
//
|
1913
|
+
// margin
|
1914
|
+
//
|
1915
|
+
// [
|
1916
|
+
// {
|
1917
|
+
// "currency:BTC": {
|
1918
|
+
// "available":"0",
|
1919
|
+
// "balance":"0",
|
1920
|
+
// "borrowed":"0",
|
1921
|
+
// "can_withdraw":"0",
|
1922
|
+
// "frozen":"0",
|
1923
|
+
// "hold":"0",
|
1924
|
+
// "holds":"0",
|
1925
|
+
// "lending_fee":"0"
|
1926
|
+
// },
|
1927
|
+
// "currency:USDT": {
|
1928
|
+
// "available":"100",
|
1929
|
+
// "balance":"100",
|
1930
|
+
// "borrowed":"0",
|
1931
|
+
// "can_withdraw":"100",
|
1932
|
+
// "frozen":"0",
|
1933
|
+
// "hold":"0",
|
1934
|
+
// "holds":"0",
|
1935
|
+
// "lending_fee":"0"
|
1936
|
+
// },
|
1937
|
+
// "instrument_id":"BTC-USDT",
|
1938
|
+
// "liquidation_price":"0",
|
1939
|
+
// "product_id":"BTC-USDT",
|
1940
|
+
// "risk_rate":""
|
1941
|
+
// },
|
1942
|
+
// ]
|
1943
|
+
//
|
1944
|
+
// futures
|
1945
|
+
//
|
1946
|
+
// {
|
1947
|
+
// "info":{
|
1948
|
+
// "eos":{
|
1949
|
+
// "auto_margin":"0",
|
1950
|
+
// "contracts": [
|
1951
|
+
// {
|
1952
|
+
// "available_qty":"40.37069445",
|
1953
|
+
// "fixed_balance":"0",
|
1954
|
+
// "instrument_id":"EOS-USD-190329",
|
1955
|
+
// "margin_for_unfilled":"0",
|
1956
|
+
// "margin_frozen":"0",
|
1957
|
+
// "realized_pnl":"0",
|
1958
|
+
// "unrealized_pnl":"0"
|
1959
|
+
// },
|
1960
|
+
// {
|
1961
|
+
// "available_qty":"40.37069445",
|
1962
|
+
// "fixed_balance":"14.54895721",
|
1963
|
+
// "instrument_id":"EOS-USD-190628",
|
1964
|
+
// "margin_for_unfilled":"0",
|
1965
|
+
// "margin_frozen":"10.64042157",
|
1966
|
+
// "realized_pnl":"-3.90853564",
|
1967
|
+
// "unrealized_pnl":"-0.259"
|
1968
|
+
// },
|
1969
|
+
// ],
|
1970
|
+
// "equity":"50.75220665",
|
1971
|
+
// "margin_mode":"fixed",
|
1972
|
+
// "total_avail_balance":"40.37069445"
|
1973
|
+
// },
|
1974
|
+
// }
|
1975
|
+
// }
|
1976
|
+
//
|
1977
|
+
// swap
|
1978
|
+
//
|
1979
|
+
// {
|
1980
|
+
// "info": [
|
1981
|
+
// {
|
1982
|
+
// "equity":"3.0139",
|
1983
|
+
// "fixed_balance":"0.0000",
|
1984
|
+
// "instrument_id":"EOS-USD-SWAP",
|
1985
|
+
// "margin":"0.5523",
|
1986
|
+
// "margin_frozen":"0.0000",
|
1987
|
+
// "margin_mode":"crossed",
|
1988
|
+
// "margin_ratio":"1.0913",
|
1989
|
+
// "realized_pnl":"-0.0006",
|
1990
|
+
// "timestamp":"2019-03-25T03:46:10.336Z",
|
1991
|
+
// "total_avail_balance":"3.0000",
|
1992
|
+
// "unrealized_pnl":"0.0145"
|
1993
|
+
// }
|
1994
|
+
// ]
|
1995
|
+
// }
|
1996
|
+
//
|
1997
|
+
return this.parseBalanceByType (type, response);
|
1998
|
+
}
|
1999
|
+
|
2000
|
+
parseBalanceByType (type, response) {
|
2001
|
+
if ((type === 'account') || (type === 'spot')) {
|
2002
|
+
return this.parseAccountBalance (response);
|
2003
|
+
} else if (type === 'margin') {
|
2004
|
+
return this.parseMarginBalance (response);
|
2005
|
+
} else if (type === 'futures') {
|
2006
|
+
return this.parseFuturesBalance (response);
|
2007
|
+
} else if (type === 'swap') {
|
2008
|
+
return this.parseSwapBalance (response);
|
2009
|
+
}
|
2010
|
+
throw new NotSupported (this.id + " fetchBalance does not support the '" + type + "' type (the type must be one of 'account', 'spot', 'margin', 'futures', 'swap')");
|
2011
|
+
}
|
2012
|
+
|
2013
|
+
async createOrder (symbol, type, side, amount, price = undefined, params = {}) {
|
2014
|
+
await this.loadMarkets ();
|
2015
|
+
const market = this.market (symbol);
|
2016
|
+
let request = {
|
2017
|
+
'instrument_id': market['id'],
|
2018
|
+
// 'client_oid': 'abcdef1234567890', // [a-z0-9]{1,32}
|
2019
|
+
// 'order_type': '0', // 0 = Normal limit order, 1 = Post only, 2 = Fill Or Kill, 3 = Immediatel Or Cancel, 4 = Market for futures only
|
2020
|
+
};
|
2021
|
+
const clientOrderId = this.safeString2 (params, 'client_oid', 'clientOrderId');
|
2022
|
+
if (clientOrderId !== undefined) {
|
2023
|
+
request['client_oid'] = clientOrderId;
|
2024
|
+
params = this.omit (params, [ 'client_oid', 'clientOrderId' ]);
|
2025
|
+
}
|
2026
|
+
let method = undefined;
|
2027
|
+
if (market['futures'] || market['swap']) {
|
2028
|
+
const size = market['futures'] ? this.numberToString (amount) : this.amountToPrecision (symbol, amount);
|
2029
|
+
request = this.extend (request, {
|
2030
|
+
'type': type, // 1:open long 2:open short 3:close long 4:close short for futures
|
2031
|
+
'size': size,
|
2032
|
+
// 'match_price': '0', // Order at best counter party price? (0:no 1:yes). The default is 0. If it is set as 1, the price parameter will be ignored. When posting orders at best bid price, order_type can only be 0 (regular order).
|
2033
|
+
});
|
2034
|
+
const orderType = this.safeString (params, 'order_type');
|
2035
|
+
// order_type === '4' means a market order
|
2036
|
+
const isMarketOrder = (type === 'market') || (orderType === '4');
|
2037
|
+
if (isMarketOrder) {
|
2038
|
+
request['order_type'] = '4';
|
2039
|
+
} else {
|
2040
|
+
request['price'] = this.priceToPrecision (symbol, price);
|
2041
|
+
}
|
2042
|
+
if (market['futures']) {
|
2043
|
+
request['leverage'] = '10'; // or '20'
|
2044
|
+
}
|
2045
|
+
method = market['type'] + 'PostOrder';
|
2046
|
+
} else {
|
2047
|
+
const marginTrading = this.safeString (params, 'margin_trading', '1'); // 1 = spot, 2 = margin
|
2048
|
+
request = this.extend (request, {
|
2049
|
+
'side': side,
|
2050
|
+
'type': type, // limit/market
|
2051
|
+
'margin_trading': marginTrading, // 1 = spot, 2 = margin
|
2052
|
+
});
|
2053
|
+
if (type === 'limit') {
|
2054
|
+
request['price'] = this.priceToPrecision (symbol, price);
|
2055
|
+
request['size'] = this.amountToPrecision (symbol, amount);
|
2056
|
+
} else if (type === 'market') {
|
2057
|
+
// for market buy it requires the amount of quote currency to spend
|
2058
|
+
if (side === 'buy') {
|
2059
|
+
let notional = this.safeNumber (params, 'notional');
|
2060
|
+
const createMarketBuyOrderRequiresPrice = this.safeValue (this.options, 'createMarketBuyOrderRequiresPrice', true);
|
2061
|
+
if (createMarketBuyOrderRequiresPrice) {
|
2062
|
+
if (price !== undefined) {
|
2063
|
+
if (notional === undefined) {
|
2064
|
+
notional = amount * price;
|
2065
|
+
}
|
2066
|
+
} else if (notional === undefined) {
|
2067
|
+
throw new InvalidOrder (this.id + " createOrder() requires the price argument with market buy orders to calculate total order cost (amount to spend), where cost = amount * price. Supply a price argument to createOrder() call if you want the cost to be calculated for you from price and amount, or, alternatively, add .options['createMarketBuyOrderRequiresPrice'] = false and supply the total cost value in the 'amount' argument or in the 'notional' extra parameter (the exchange-specific behaviour)");
|
2068
|
+
}
|
2069
|
+
} else {
|
2070
|
+
notional = (notional === undefined) ? amount : notional;
|
2071
|
+
}
|
2072
|
+
const precision = market['precision']['price'];
|
2073
|
+
request['notional'] = this.decimalToPrecision (notional, TRUNCATE, precision, this.precisionMode);
|
2074
|
+
} else {
|
2075
|
+
request['size'] = this.amountToPrecision (symbol, amount);
|
2076
|
+
}
|
2077
|
+
}
|
2078
|
+
method = (marginTrading === '2') ? 'marginPostOrders' : 'spotPostOrders';
|
2079
|
+
}
|
2080
|
+
const response = await this[method] (this.extend (request, params));
|
2081
|
+
//
|
2082
|
+
// {
|
2083
|
+
// "client_oid":"oktspot79",
|
2084
|
+
// "error_code":"",
|
2085
|
+
// "error_message":"",
|
2086
|
+
// "order_id":"2510789768709120",
|
2087
|
+
// "result":true
|
2088
|
+
// }
|
2089
|
+
//
|
2090
|
+
const order = this.parseOrder (response, market);
|
2091
|
+
return this.extend (order, {
|
2092
|
+
'type': type,
|
2093
|
+
'side': side,
|
2094
|
+
});
|
2095
|
+
}
|
2096
|
+
|
2097
|
+
async cancelOrder (id, symbol = undefined, params = {}) {
|
2098
|
+
if (symbol === undefined) {
|
2099
|
+
throw new ArgumentsRequired (this.id + ' cancelOrder() requires a symbol argument');
|
2100
|
+
}
|
2101
|
+
await this.loadMarkets ();
|
2102
|
+
const market = this.market (symbol);
|
2103
|
+
let type = undefined;
|
2104
|
+
if (market['futures'] || market['swap']) {
|
2105
|
+
type = market['type'];
|
2106
|
+
} else {
|
2107
|
+
const defaultType = this.safeString2 (this.options, 'cancelOrder', 'defaultType', market['type']);
|
2108
|
+
type = this.safeString (params, 'type', defaultType);
|
2109
|
+
}
|
2110
|
+
if (type === undefined) {
|
2111
|
+
throw new ArgumentsRequired (this.id + " cancelOrder() requires a type parameter (one of 'spot', 'margin', 'futures', 'swap').");
|
2112
|
+
}
|
2113
|
+
let method = type + 'PostCancelOrder';
|
2114
|
+
const request = {
|
2115
|
+
'instrument_id': market['id'],
|
2116
|
+
};
|
2117
|
+
if (market['futures'] || market['swap']) {
|
2118
|
+
method += 'InstrumentId';
|
2119
|
+
} else {
|
2120
|
+
method += 's';
|
2121
|
+
}
|
2122
|
+
const clientOrderId = this.safeString2 (params, 'client_oid', 'clientOrderId');
|
2123
|
+
if (clientOrderId !== undefined) {
|
2124
|
+
method += 'ClientOid';
|
2125
|
+
request['client_oid'] = clientOrderId;
|
2126
|
+
} else {
|
2127
|
+
method += 'OrderId';
|
2128
|
+
request['order_id'] = id;
|
2129
|
+
}
|
2130
|
+
const query = this.omit (params, [ 'type', 'client_oid', 'clientOrderId' ]);
|
2131
|
+
const response = await this[method] (this.extend (request, query));
|
2132
|
+
const result = ('result' in response) ? response : this.safeValue (response, market['id'], {});
|
2133
|
+
//
|
2134
|
+
// spot, margin
|
2135
|
+
//
|
2136
|
+
// {
|
2137
|
+
// "btc-usdt": [
|
2138
|
+
// {
|
2139
|
+
// "result":true,
|
2140
|
+
// "client_oid":"a123",
|
2141
|
+
// "order_id": "2510832677225473"
|
2142
|
+
// }
|
2143
|
+
// ]
|
2144
|
+
// }
|
2145
|
+
//
|
2146
|
+
// futures, swap
|
2147
|
+
//
|
2148
|
+
// {
|
2149
|
+
// "result": true,
|
2150
|
+
// "client_oid": "oktfuture10", // missing if requested by order_id
|
2151
|
+
// "order_id": "2517535534836736",
|
2152
|
+
// "instrument_id": "EOS-USD-190628"
|
2153
|
+
// }
|
2154
|
+
//
|
2155
|
+
return this.parseOrder (result, market);
|
2156
|
+
}
|
2157
|
+
|
2158
|
+
parseOrderStatus (status) {
|
2159
|
+
const statuses = {
|
2160
|
+
'-2': 'failed',
|
2161
|
+
'-1': 'canceled',
|
2162
|
+
'0': 'open',
|
2163
|
+
'1': 'open',
|
2164
|
+
'2': 'closed',
|
2165
|
+
'3': 'open',
|
2166
|
+
'4': 'canceled',
|
2167
|
+
};
|
2168
|
+
return this.safeString (statuses, status, status);
|
2169
|
+
}
|
2170
|
+
|
2171
|
+
parseOrderSide (side) {
|
2172
|
+
const sides = {
|
2173
|
+
'1': 'buy', // open long
|
2174
|
+
'2': 'sell', // open short
|
2175
|
+
'3': 'sell', // close long
|
2176
|
+
'4': 'buy', // close short
|
2177
|
+
};
|
2178
|
+
return this.safeString (sides, side, side);
|
2179
|
+
}
|
2180
|
+
|
2181
|
+
parseOrder (order, market = undefined) {
|
2182
|
+
//
|
2183
|
+
// createOrder
|
2184
|
+
//
|
2185
|
+
// {
|
2186
|
+
// "client_oid":"oktspot79",
|
2187
|
+
// "error_code":"",
|
2188
|
+
// "error_message":"",
|
2189
|
+
// "order_id":"2510789768709120",
|
2190
|
+
// "result":true
|
2191
|
+
// }
|
2192
|
+
//
|
2193
|
+
// cancelOrder
|
2194
|
+
//
|
2195
|
+
// {
|
2196
|
+
// "result": true,
|
2197
|
+
// "client_oid": "oktfuture10", // missing if requested by order_id
|
2198
|
+
// "order_id": "2517535534836736",
|
2199
|
+
// // instrument_id is missing for spot/margin orders
|
2200
|
+
// // available in futures and swap orders only
|
2201
|
+
// "instrument_id": "EOS-USD-190628",
|
2202
|
+
// }
|
2203
|
+
//
|
2204
|
+
// fetchOrder, fetchOrdersByState, fetchOpenOrders, fetchClosedOrders
|
2205
|
+
//
|
2206
|
+
// // spot and margin orders
|
2207
|
+
//
|
2208
|
+
// {
|
2209
|
+
// "client_oid":"oktspot76",
|
2210
|
+
// "created_at":"2019-03-18T07:26:49.000Z",
|
2211
|
+
// "filled_notional":"3.9734",
|
2212
|
+
// "filled_size":"0.001", // filled_qty in futures and swap orders
|
2213
|
+
// "funds":"", // this is most likely the same as notional
|
2214
|
+
// "instrument_id":"BTC-USDT",
|
2215
|
+
// "notional":"",
|
2216
|
+
// "order_id":"2500723297813504",
|
2217
|
+
// "order_type":"0",
|
2218
|
+
// "price":"4013",
|
2219
|
+
// "product_id":"BTC-USDT", // missing in futures and swap orders
|
2220
|
+
// "side":"buy",
|
2221
|
+
// "size":"0.001",
|
2222
|
+
// "status":"filled",
|
2223
|
+
// "state": "2",
|
2224
|
+
// "timestamp":"2019-03-18T07:26:49.000Z",
|
2225
|
+
// "type":"limit"
|
2226
|
+
// }
|
2227
|
+
//
|
2228
|
+
// // futures and swap orders
|
2229
|
+
//
|
2230
|
+
// {
|
2231
|
+
// "instrument_id":"EOS-USD-190628",
|
2232
|
+
// "size":"10",
|
2233
|
+
// "timestamp":"2019-03-20T10:04:55.000Z",
|
2234
|
+
// "filled_qty":"10", // filled_size in spot and margin orders
|
2235
|
+
// "fee":"-0.00841043",
|
2236
|
+
// "order_id":"2512669605501952",
|
2237
|
+
// "price":"3.668",
|
2238
|
+
// "price_avg":"3.567", // missing in spot and margin orders
|
2239
|
+
// "status":"2",
|
2240
|
+
// "state": "2",
|
2241
|
+
// "type":"4",
|
2242
|
+
// "contract_val":"10",
|
2243
|
+
// "leverage":"10", // missing in swap, spot and margin orders
|
2244
|
+
// "client_oid":"",
|
2245
|
+
// "pnl":"1.09510794", // missing in swap, spo and margin orders
|
2246
|
+
// "order_type":"0"
|
2247
|
+
// }
|
2248
|
+
//
|
2249
|
+
const id = this.safeString (order, 'order_id');
|
2250
|
+
const timestamp = this.parse8601 (this.safeString (order, 'timestamp'));
|
2251
|
+
let side = this.safeString (order, 'side');
|
2252
|
+
const type = this.safeString (order, 'type');
|
2253
|
+
if ((side !== 'buy') && (side !== 'sell')) {
|
2254
|
+
side = this.parseOrderSide (type);
|
2255
|
+
}
|
2256
|
+
const marketId = this.safeString (order, 'instrument_id');
|
2257
|
+
market = this.safeMarket (marketId, market);
|
2258
|
+
let amount = this.safeString (order, 'size');
|
2259
|
+
const filled = this.safeString2 (order, 'filled_size', 'filled_qty');
|
2260
|
+
let remaining = undefined;
|
2261
|
+
if (amount !== undefined) {
|
2262
|
+
if (filled !== undefined) {
|
2263
|
+
amount = Precise.stringMax (amount, filled);
|
2264
|
+
remaining = Precise.stringMax ('0', Precise.stringSub (amount, filled));
|
2265
|
+
}
|
2266
|
+
}
|
2267
|
+
if (type === 'market') {
|
2268
|
+
remaining = '0';
|
2269
|
+
}
|
2270
|
+
let cost = this.safeString2 (order, 'filled_notional', 'funds');
|
2271
|
+
const price = this.safeString (order, 'price');
|
2272
|
+
let average = this.safeString (order, 'price_avg');
|
2273
|
+
if (cost === undefined) {
|
2274
|
+
if (filled !== undefined && average !== undefined) {
|
2275
|
+
cost = Precise.stringMul (average, filled);
|
2276
|
+
}
|
2277
|
+
} else {
|
2278
|
+
if ((average === undefined) && (filled !== undefined) && Precise.stringGt (filled, '0')) {
|
2279
|
+
average = Precise.stringDiv (cost, filled);
|
2280
|
+
}
|
2281
|
+
}
|
2282
|
+
const status = this.parseOrderStatus (this.safeString (order, 'state'));
|
2283
|
+
const feeCost = this.safeNumber (order, 'fee');
|
2284
|
+
let fee = undefined;
|
2285
|
+
if (feeCost !== undefined) {
|
2286
|
+
const feeCurrency = undefined;
|
2287
|
+
fee = {
|
2288
|
+
'cost': feeCost,
|
2289
|
+
'currency': feeCurrency,
|
2290
|
+
};
|
2291
|
+
}
|
2292
|
+
let clientOrderId = this.safeString (order, 'client_oid');
|
2293
|
+
if ((clientOrderId !== undefined) && (clientOrderId.length < 1)) {
|
2294
|
+
clientOrderId = undefined; // fix empty clientOrderId string
|
2295
|
+
}
|
2296
|
+
const stopPrice = this.safeNumber (order, 'trigger_price');
|
2297
|
+
return this.safeOrder ({
|
2298
|
+
'info': order,
|
2299
|
+
'id': id,
|
2300
|
+
'clientOrderId': clientOrderId,
|
2301
|
+
'timestamp': timestamp,
|
2302
|
+
'datetime': this.iso8601 (timestamp),
|
2303
|
+
'lastTradeTimestamp': undefined,
|
2304
|
+
'symbol': market['symbol'],
|
2305
|
+
'type': type,
|
2306
|
+
'timeInForce': undefined,
|
2307
|
+
'postOnly': undefined,
|
2308
|
+
'side': side,
|
2309
|
+
'price': price,
|
2310
|
+
'stopPrice': stopPrice,
|
2311
|
+
'average': average,
|
2312
|
+
'cost': cost,
|
2313
|
+
'amount': amount,
|
2314
|
+
'filled': filled,
|
2315
|
+
'remaining': remaining,
|
2316
|
+
'status': status,
|
2317
|
+
'fee': fee,
|
2318
|
+
'trades': undefined,
|
2319
|
+
}, market);
|
2320
|
+
}
|
2321
|
+
|
2322
|
+
async fetchOrder (id, symbol = undefined, params = {}) {
|
2323
|
+
if (symbol === undefined) {
|
2324
|
+
throw new ArgumentsRequired (this.id + ' fetchOrder() requires a symbol argument');
|
2325
|
+
}
|
2326
|
+
await this.loadMarkets ();
|
2327
|
+
const market = this.market (symbol);
|
2328
|
+
const defaultType = this.safeString2 (this.options, 'fetchOrder', 'defaultType', market['type']);
|
2329
|
+
const type = this.safeString (params, 'type', defaultType);
|
2330
|
+
if (type === undefined) {
|
2331
|
+
throw new ArgumentsRequired (this.id + " fetchOrder() requires a type parameter (one of 'spot', 'margin', 'futures', 'swap').");
|
2332
|
+
}
|
2333
|
+
const instrumentId = (market['futures'] || market['swap']) ? 'InstrumentId' : '';
|
2334
|
+
let method = type + 'GetOrders' + instrumentId;
|
2335
|
+
const request = {
|
2336
|
+
'instrument_id': market['id'],
|
2337
|
+
// 'client_oid': 'abcdef12345', // optional, [a-z0-9]{1,32}
|
2338
|
+
// 'order_id': id,
|
2339
|
+
};
|
2340
|
+
const clientOid = this.safeString (params, 'client_oid');
|
2341
|
+
if (clientOid !== undefined) {
|
2342
|
+
method += 'ClientOid';
|
2343
|
+
request['client_oid'] = clientOid;
|
2344
|
+
} else {
|
2345
|
+
method += 'OrderId';
|
2346
|
+
request['order_id'] = id;
|
2347
|
+
}
|
2348
|
+
const query = this.omit (params, 'type');
|
2349
|
+
const response = await this[method] (this.extend (request, query));
|
2350
|
+
//
|
2351
|
+
// spot, margin
|
2352
|
+
//
|
2353
|
+
// {
|
2354
|
+
// "client_oid":"oktspot70",
|
2355
|
+
// "created_at":"2019-03-15T02:52:56.000Z",
|
2356
|
+
// "filled_notional":"3.8886",
|
2357
|
+
// "filled_size":"0.001",
|
2358
|
+
// "funds":"",
|
2359
|
+
// "instrument_id":"BTC-USDT",
|
2360
|
+
// "notional":"",
|
2361
|
+
// "order_id":"2482659399697408",
|
2362
|
+
// "order_type":"0",
|
2363
|
+
// "price":"3927.3",
|
2364
|
+
// "product_id":"BTC-USDT",
|
2365
|
+
// "side":"buy",
|
2366
|
+
// "size":"0.001",
|
2367
|
+
// "status":"filled",
|
2368
|
+
// "state": "2",
|
2369
|
+
// "timestamp":"2019-03-15T02:52:56.000Z",
|
2370
|
+
// "type":"limit"
|
2371
|
+
// }
|
2372
|
+
//
|
2373
|
+
// futures, swap
|
2374
|
+
//
|
2375
|
+
// {
|
2376
|
+
// "instrument_id":"EOS-USD-190628",
|
2377
|
+
// "size":"10",
|
2378
|
+
// "timestamp":"2019-03-20T02:46:38.000Z",
|
2379
|
+
// "filled_qty":"10",
|
2380
|
+
// "fee":"-0.0080819",
|
2381
|
+
// "order_id":"2510946213248000",
|
2382
|
+
// "price":"3.712",
|
2383
|
+
// "price_avg":"3.712",
|
2384
|
+
// "status":"2",
|
2385
|
+
// "state": "2",
|
2386
|
+
// "type":"2",
|
2387
|
+
// "contract_val":"10",
|
2388
|
+
// "leverage":"10",
|
2389
|
+
// "client_oid":"", // missing in swap orders
|
2390
|
+
// "pnl":"0", // missing in swap orders
|
2391
|
+
// "order_type":"0"
|
2392
|
+
// }
|
2393
|
+
//
|
2394
|
+
return this.parseOrder (response);
|
2395
|
+
}
|
2396
|
+
|
2397
|
+
async fetchOrdersByState (state, symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
2398
|
+
if (symbol === undefined) {
|
2399
|
+
throw new ArgumentsRequired (this.id + ' fetchOrdersByState() requires a symbol argument');
|
2400
|
+
}
|
2401
|
+
await this.loadMarkets ();
|
2402
|
+
const market = this.market (symbol);
|
2403
|
+
let type = undefined;
|
2404
|
+
if (market['futures'] || market['swap']) {
|
2405
|
+
type = market['type'];
|
2406
|
+
} else {
|
2407
|
+
const defaultType = this.safeString2 (this.options, 'fetchOrder', 'defaultType', market['type']);
|
2408
|
+
type = this.safeString (params, 'type', defaultType);
|
2409
|
+
}
|
2410
|
+
if (type === undefined) {
|
2411
|
+
throw new ArgumentsRequired (this.id + " fetchOrdersByState() requires a type parameter (one of 'spot', 'margin', 'futures', 'swap').");
|
2412
|
+
}
|
2413
|
+
const request = {
|
2414
|
+
'instrument_id': market['id'],
|
2415
|
+
// '-2': failed,
|
2416
|
+
// '-1': cancelled,
|
2417
|
+
// '0': open ,
|
2418
|
+
// '1': partially filled,
|
2419
|
+
// '2': fully filled,
|
2420
|
+
// '3': submitting,
|
2421
|
+
// '4': cancelling,
|
2422
|
+
// '6': incomplete(open+partially filled),
|
2423
|
+
// '7': complete(cancelled+fully filled),
|
2424
|
+
'state': state,
|
2425
|
+
};
|
2426
|
+
let method = type + 'GetOrders';
|
2427
|
+
if (market['futures'] || market['swap']) {
|
2428
|
+
method += 'InstrumentId';
|
2429
|
+
}
|
2430
|
+
const query = this.omit (params, 'type');
|
2431
|
+
const response = await this[method] (this.extend (request, query));
|
2432
|
+
//
|
2433
|
+
// spot, margin
|
2434
|
+
//
|
2435
|
+
// [
|
2436
|
+
// // in fact, this documented API response does not correspond
|
2437
|
+
// // to their actual API response for spot markets
|
2438
|
+
// // OKEX v3 API returns a plain array of orders (see below)
|
2439
|
+
// [
|
2440
|
+
// {
|
2441
|
+
// "client_oid":"oktspot76",
|
2442
|
+
// "created_at":"2019-03-18T07:26:49.000Z",
|
2443
|
+
// "filled_notional":"3.9734",
|
2444
|
+
// "filled_size":"0.001",
|
2445
|
+
// "funds":"",
|
2446
|
+
// "instrument_id":"BTC-USDT",
|
2447
|
+
// "notional":"",
|
2448
|
+
// "order_id":"2500723297813504",
|
2449
|
+
// "order_type":"0",
|
2450
|
+
// "price":"4013",
|
2451
|
+
// "product_id":"BTC-USDT",
|
2452
|
+
// "side":"buy",
|
2453
|
+
// "size":"0.001",
|
2454
|
+
// "status":"filled",
|
2455
|
+
// "state": "2",
|
2456
|
+
// "timestamp":"2019-03-18T07:26:49.000Z",
|
2457
|
+
// "type":"limit"
|
2458
|
+
// },
|
2459
|
+
// ],
|
2460
|
+
// {
|
2461
|
+
// "before":"2500723297813504",
|
2462
|
+
// "after":"2500650881647616"
|
2463
|
+
// }
|
2464
|
+
// ]
|
2465
|
+
//
|
2466
|
+
// futures, swap
|
2467
|
+
//
|
2468
|
+
// {
|
2469
|
+
// "result":true, // missing in swap orders
|
2470
|
+
// "order_info": [
|
2471
|
+
// {
|
2472
|
+
// "instrument_id":"EOS-USD-190628",
|
2473
|
+
// "size":"10",
|
2474
|
+
// "timestamp":"2019-03-20T10:04:55.000Z",
|
2475
|
+
// "filled_qty":"10",
|
2476
|
+
// "fee":"-0.00841043",
|
2477
|
+
// "order_id":"2512669605501952",
|
2478
|
+
// "price":"3.668",
|
2479
|
+
// "price_avg":"3.567",
|
2480
|
+
// "status":"2",
|
2481
|
+
// "state": "2",
|
2482
|
+
// "type":"4",
|
2483
|
+
// "contract_val":"10",
|
2484
|
+
// "leverage":"10", // missing in swap orders
|
2485
|
+
// "client_oid":"",
|
2486
|
+
// "pnl":"1.09510794", // missing in swap orders
|
2487
|
+
// "order_type":"0"
|
2488
|
+
// },
|
2489
|
+
// ]
|
2490
|
+
// }
|
2491
|
+
//
|
2492
|
+
let orders = undefined;
|
2493
|
+
if (market['swap'] || market['futures']) {
|
2494
|
+
orders = this.safeValue (response, 'order_info', []);
|
2495
|
+
} else {
|
2496
|
+
orders = response;
|
2497
|
+
const responseLength = response.length;
|
2498
|
+
if (responseLength < 1) {
|
2499
|
+
return [];
|
2500
|
+
}
|
2501
|
+
// in fact, this documented API response does not correspond
|
2502
|
+
// to their actual API response for spot markets
|
2503
|
+
// OKEX v3 API returns a plain array of orders
|
2504
|
+
if (responseLength > 1) {
|
2505
|
+
const before = this.safeValue (response[1], 'before');
|
2506
|
+
if (before !== undefined) {
|
2507
|
+
orders = response[0];
|
2508
|
+
}
|
2509
|
+
}
|
2510
|
+
}
|
2511
|
+
return this.parseOrders (orders, market, since, limit);
|
2512
|
+
}
|
2513
|
+
|
2514
|
+
async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
2515
|
+
// '-2': failed,
|
2516
|
+
// '-1': cancelled,
|
2517
|
+
// '0': open ,
|
2518
|
+
// '1': partially filled,
|
2519
|
+
// '2': fully filled,
|
2520
|
+
// '3': submitting,
|
2521
|
+
// '4': cancelling,
|
2522
|
+
// '6': incomplete(open+partially filled),
|
2523
|
+
// '7': complete(cancelled+fully filled),
|
2524
|
+
return await this.fetchOrdersByState ('6', symbol, since, limit, params);
|
2525
|
+
}
|
2526
|
+
|
2527
|
+
async fetchClosedOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
2528
|
+
// '-2': failed,
|
2529
|
+
// '-1': cancelled,
|
2530
|
+
// '0': open ,
|
2531
|
+
// '1': partially filled,
|
2532
|
+
// '2': fully filled,
|
2533
|
+
// '3': submitting,
|
2534
|
+
// '4': cancelling,
|
2535
|
+
// '6': incomplete(open+partially filled),
|
2536
|
+
// '7': complete(cancelled+fully filled),
|
2537
|
+
return await this.fetchOrdersByState ('7', symbol, since, limit, params);
|
2538
|
+
}
|
2539
|
+
|
2540
|
+
parseDepositAddress (depositAddress, currency = undefined) {
|
2541
|
+
//
|
2542
|
+
// {
|
2543
|
+
// address: '0x696abb81974a8793352cbd33aadcf78eda3cfdfa',
|
2544
|
+
// currency: 'eth'
|
2545
|
+
// tag: 'abcde12345', // will be missing if the token does not require a deposit tag
|
2546
|
+
// payment_id: 'abcde12345', // will not be returned if the token does not require a payment_id
|
2547
|
+
// // can_deposit: 1, // 0 or 1, documented but missing
|
2548
|
+
// // can_withdraw: 1, // 0 or 1, documented but missing
|
2549
|
+
// }
|
2550
|
+
//
|
2551
|
+
const address = this.safeString (depositAddress, 'address');
|
2552
|
+
let tag = this.safeString2 (depositAddress, 'tag', 'payment_id');
|
2553
|
+
tag = this.safeString2 (depositAddress, 'memo', 'Memo', tag);
|
2554
|
+
const currencyId = this.safeString (depositAddress, 'currency');
|
2555
|
+
const code = this.safeCurrencyCode (currencyId);
|
2556
|
+
this.checkAddress (address);
|
2557
|
+
return {
|
2558
|
+
'currency': code,
|
2559
|
+
'address': address,
|
2560
|
+
'tag': tag,
|
2561
|
+
'info': depositAddress,
|
2562
|
+
};
|
2563
|
+
}
|
2564
|
+
|
2565
|
+
async fetchDepositAddress (code, params = {}) {
|
2566
|
+
await this.loadMarkets ();
|
2567
|
+
const parts = code.split ('-');
|
2568
|
+
const currency = this.currency (parts[0]);
|
2569
|
+
const request = {
|
2570
|
+
'currency': currency['id'],
|
2571
|
+
};
|
2572
|
+
const response = await this.accountGetDepositAddress (this.extend (request, params));
|
2573
|
+
//
|
2574
|
+
// [
|
2575
|
+
// {
|
2576
|
+
// address: '0x696abb81974a8793352cbd33aadcf78eda3cfdfa',
|
2577
|
+
// currency: 'eth'
|
2578
|
+
// }
|
2579
|
+
// ]
|
2580
|
+
//
|
2581
|
+
const addressesByCode = this.parseDepositAddresses (response);
|
2582
|
+
const address = this.safeValue (addressesByCode, code);
|
2583
|
+
if (address === undefined) {
|
2584
|
+
throw new InvalidAddress (this.id + ' fetchDepositAddress() cannot return nonexistent addresses, you should create withdrawal addresses with the exchange website first');
|
2585
|
+
}
|
2586
|
+
return address;
|
2587
|
+
}
|
2588
|
+
|
2589
|
+
async transfer (code, amount, fromAccount, toAccount, params = {}) {
|
2590
|
+
await this.loadMarkets ();
|
2591
|
+
const currency = this.currency (code);
|
2592
|
+
const accountsByType = this.safeValue (this.options, 'accountsByType', {});
|
2593
|
+
const fromId = this.safeString (accountsByType, fromAccount, fromAccount);
|
2594
|
+
const toId = this.safeString (accountsByType, toAccount, toAccount);
|
2595
|
+
const request = {
|
2596
|
+
'amount': this.currencyToPrecision (code, amount),
|
2597
|
+
'currency': currency['id'],
|
2598
|
+
'from': fromId, // 1 spot, 5 margin, 6 funding
|
2599
|
+
'to': toId, // 1 spot, 5 margin, 6 funding
|
2600
|
+
'type': '0', // 0 Transfer between accounts in the main account/sub_account, 1 main account to sub_account, 2 sub_account to main account
|
2601
|
+
};
|
2602
|
+
if (fromId === 'main') {
|
2603
|
+
request['type'] = '1';
|
2604
|
+
request['sub_account'] = toId;
|
2605
|
+
request['to'] = '0';
|
2606
|
+
} else if (toId === 'main') {
|
2607
|
+
request['type'] = '2';
|
2608
|
+
request['sub_account'] = fromId;
|
2609
|
+
request['from'] = '0';
|
2610
|
+
request['to'] = '6';
|
2611
|
+
} else if (fromId === '5' || toId === '5') {
|
2612
|
+
let marketId = this.safeString2 (params, 'instrument_id', 'to_instrument_id');
|
2613
|
+
if (marketId === undefined) {
|
2614
|
+
const symbol = this.safeString (params, 'symbol');
|
2615
|
+
if (symbol === undefined) {
|
2616
|
+
throw new ArgumentsRequired (this.id + ' transfer() requires an exchange-specific instrument_id parameter or a unified symbol parameter');
|
2617
|
+
} else {
|
2618
|
+
params = this.omit (params, 'symbol');
|
2619
|
+
const market = this.market (symbol);
|
2620
|
+
marketId = market['id'];
|
2621
|
+
}
|
2622
|
+
if (fromId === '5') {
|
2623
|
+
request['instrument_id'] = marketId;
|
2624
|
+
}
|
2625
|
+
if (toId === '5') {
|
2626
|
+
request['to_instrument_id'] = marketId;
|
2627
|
+
}
|
2628
|
+
}
|
2629
|
+
}
|
2630
|
+
const response = await this.accountPostTransfer (this.extend (request, params));
|
2631
|
+
//
|
2632
|
+
// {
|
2633
|
+
// "transfer_id": "754147",
|
2634
|
+
// "currency": "ETC",
|
2635
|
+
// "from": "6",
|
2636
|
+
// "amount": "0.1",
|
2637
|
+
// "to": "1",
|
2638
|
+
// "result": true
|
2639
|
+
// }
|
2640
|
+
//
|
2641
|
+
return this.parseTransfer (response, currency);
|
2642
|
+
}
|
2643
|
+
|
2644
|
+
parseTransfer (transfer, currency = undefined) {
|
2645
|
+
//
|
2646
|
+
// {
|
2647
|
+
// "transfer_id": "754147",
|
2648
|
+
// "currency": "ETC",
|
2649
|
+
// "from": "6",
|
2650
|
+
// "amount": "0.1",
|
2651
|
+
// "to": "1",
|
2652
|
+
// "result": true
|
2653
|
+
// }
|
2654
|
+
//
|
2655
|
+
const accountsById = this.safeValue (this.options, 'accountsById', {});
|
2656
|
+
return {
|
2657
|
+
'info': transfer,
|
2658
|
+
'id': this.safeString (transfer, 'transfer_id'),
|
2659
|
+
'timestamp': undefined,
|
2660
|
+
'datetime': undefined,
|
2661
|
+
'currency': this.safeCurrencyCode (this.safeString (transfer, 'currency'), currency),
|
2662
|
+
'amount': this.safeNumber (transfer, 'amount'),
|
2663
|
+
'fromAccount': this.safeString (accountsById, this.safeString (transfer, 'from')),
|
2664
|
+
'toAccount': this.safeString (accountsById, this.safeString (transfer, 'to')),
|
2665
|
+
'status': this.parseTransferStatus (this.safeString (transfer, 'result')),
|
2666
|
+
};
|
2667
|
+
}
|
2668
|
+
|
2669
|
+
parseTransferStatus (status) {
|
2670
|
+
const statuses = {
|
2671
|
+
'true': 'ok',
|
2672
|
+
};
|
2673
|
+
return this.safeString (statuses, status, 'failed');
|
2674
|
+
}
|
2675
|
+
|
2676
|
+
async withdraw (code, amount, address, tag = undefined, params = {}) {
|
2677
|
+
[ tag, params ] = this.handleWithdrawTagAndParams (tag, params);
|
2678
|
+
this.checkAddress (address);
|
2679
|
+
await this.loadMarkets ();
|
2680
|
+
const currency = this.currency (code);
|
2681
|
+
if (tag) {
|
2682
|
+
address = address + ':' + tag;
|
2683
|
+
}
|
2684
|
+
const fee = this.safeString (params, 'fee');
|
2685
|
+
if (fee === undefined) {
|
2686
|
+
throw new ArgumentsRequired (this.id + " withdraw() requires a 'fee' string parameter, network transaction fee must be ≥ 0. Withdrawals to OKCoin or OKEx are fee-free, please set '0'. Withdrawing to external digital asset address requires network transaction fee.");
|
2687
|
+
}
|
2688
|
+
const request = {
|
2689
|
+
'currency': currency['id'],
|
2690
|
+
'to_address': address,
|
2691
|
+
'destination': '4', // 2 = OKCoin International, 3 = OKEx 4 = others
|
2692
|
+
'amount': this.numberToString (amount),
|
2693
|
+
'fee': fee, // String. Network transaction fee ≥ 0. Withdrawals to OKCoin or OKEx are fee-free, please set as 0. Withdrawal to external digital asset address requires network transaction fee.
|
2694
|
+
};
|
2695
|
+
if ('password' in params) {
|
2696
|
+
request['trade_pwd'] = params['password'];
|
2697
|
+
} else if ('trade_pwd' in params) {
|
2698
|
+
request['trade_pwd'] = params['trade_pwd'];
|
2699
|
+
} else if (this.password) {
|
2700
|
+
request['trade_pwd'] = this.password;
|
2701
|
+
}
|
2702
|
+
const query = this.omit (params, [ 'fee', 'password', 'trade_pwd' ]);
|
2703
|
+
if (!('trade_pwd' in request)) {
|
2704
|
+
throw new ExchangeError (this.id + ' withdraw() requires this.password set on the exchange instance or a password / trade_pwd parameter');
|
2705
|
+
}
|
2706
|
+
const response = await this.accountPostWithdrawal (this.extend (request, query));
|
2707
|
+
//
|
2708
|
+
// {
|
2709
|
+
// "amount":"0.1",
|
2710
|
+
// "withdrawal_id":"67485",
|
2711
|
+
// "currency":"btc",
|
2712
|
+
// "result":true
|
2713
|
+
// }
|
2714
|
+
//
|
2715
|
+
return this.parseTransaction (response, currency);
|
2716
|
+
}
|
2717
|
+
|
2718
|
+
async fetchDeposits (code = undefined, since = undefined, limit = undefined, params = {}) {
|
2719
|
+
await this.loadMarkets ();
|
2720
|
+
const request = {};
|
2721
|
+
let method = 'accountGetDepositHistory';
|
2722
|
+
let currency = undefined;
|
2723
|
+
if (code !== undefined) {
|
2724
|
+
currency = this.currency (code);
|
2725
|
+
request['currency'] = currency['id'];
|
2726
|
+
method += 'Currency';
|
2727
|
+
}
|
2728
|
+
const response = await this[method] (this.extend (request, params));
|
2729
|
+
return this.parseTransactions (response, currency, since, limit, params);
|
2730
|
+
}
|
2731
|
+
|
2732
|
+
async fetchWithdrawals (code = undefined, since = undefined, limit = undefined, params = {}) {
|
2733
|
+
await this.loadMarkets ();
|
2734
|
+
const request = {};
|
2735
|
+
let method = 'accountGetWithdrawalHistory';
|
2736
|
+
let currency = undefined;
|
2737
|
+
if (code !== undefined) {
|
2738
|
+
currency = this.currency (code);
|
2739
|
+
request['currency'] = currency['id'];
|
2740
|
+
method += 'Currency';
|
2741
|
+
}
|
2742
|
+
const response = await this[method] (this.extend (request, params));
|
2743
|
+
return this.parseTransactions (response, currency, since, limit, params);
|
2744
|
+
}
|
2745
|
+
|
2746
|
+
parseTransactionStatus (status) {
|
2747
|
+
//
|
2748
|
+
// deposit statuses
|
2749
|
+
//
|
2750
|
+
// {
|
2751
|
+
// '0': 'waiting for confirmation',
|
2752
|
+
// '1': 'confirmation account',
|
2753
|
+
// '2': 'recharge success'
|
2754
|
+
// }
|
2755
|
+
//
|
2756
|
+
// withdrawal statues
|
2757
|
+
//
|
2758
|
+
// {
|
2759
|
+
// '-3': 'pending cancel',
|
2760
|
+
// '-2': 'cancelled',
|
2761
|
+
// '-1': 'failed',
|
2762
|
+
// '0': 'pending',
|
2763
|
+
// '1': 'sending',
|
2764
|
+
// '2': 'sent',
|
2765
|
+
// '3': 'email confirmation',
|
2766
|
+
// '4': 'manual confirmation',
|
2767
|
+
// '5': 'awaiting identity confirmation'
|
2768
|
+
// }
|
2769
|
+
//
|
2770
|
+
const statuses = {
|
2771
|
+
'-3': 'pending',
|
2772
|
+
'-2': 'canceled',
|
2773
|
+
'-1': 'failed',
|
2774
|
+
'0': 'pending',
|
2775
|
+
'1': 'pending',
|
2776
|
+
'2': 'ok',
|
2777
|
+
'3': 'pending',
|
2778
|
+
'4': 'pending',
|
2779
|
+
'5': 'pending',
|
2780
|
+
};
|
2781
|
+
return this.safeString (statuses, status, status);
|
2782
|
+
}
|
2783
|
+
|
2784
|
+
parseTransaction (transaction, currency = undefined) {
|
2785
|
+
//
|
2786
|
+
// withdraw
|
2787
|
+
//
|
2788
|
+
// {
|
2789
|
+
// "amount":"0.1",
|
2790
|
+
// "withdrawal_id":"67485",
|
2791
|
+
// "currency":"btc",
|
2792
|
+
// "result":true
|
2793
|
+
// }
|
2794
|
+
//
|
2795
|
+
// fetchWithdrawals
|
2796
|
+
//
|
2797
|
+
// {
|
2798
|
+
// amount: "4.72100000",
|
2799
|
+
// withdrawal_id: "1729116",
|
2800
|
+
// fee: "0.01000000eth",
|
2801
|
+
// txid: "0xf653125bbf090bcfe4b5e8e7b8f586a9d87aa7de94598702758c0802b…",
|
2802
|
+
// currency: "ETH",
|
2803
|
+
// from: "7147338839",
|
2804
|
+
// to: "0x26a3CB49578F07000575405a57888681249c35Fd",
|
2805
|
+
// timestamp: "2018-08-17T07:03:42.000Z",
|
2806
|
+
// status: "2"
|
2807
|
+
// }
|
2808
|
+
//
|
2809
|
+
// fetchDeposits
|
2810
|
+
//
|
2811
|
+
// {
|
2812
|
+
// "amount": "4.19511659",
|
2813
|
+
// "txid": "14c9a8c925647cdb7e5b2937ea9aefe2b29b2c273150ad3f44b3b8a4635ed437",
|
2814
|
+
// "currency": "XMR",
|
2815
|
+
// "from": "",
|
2816
|
+
// "to": "48PjH3ksv1fiXniKvKvyH5UtFs5WhfS2Vf7U3TwzdRJtCc7HJWvCQe56dRahyhQyTAViXZ8Nzk4gQg6o4BJBMUoxNy8y8g7",
|
2817
|
+
// "tag": "1234567",
|
2818
|
+
// "deposit_id": 11571659, <-- we can use this
|
2819
|
+
// "timestamp": "2019-10-01T14:54:19.000Z",
|
2820
|
+
// "status": "2"
|
2821
|
+
// }
|
2822
|
+
//
|
2823
|
+
let type = undefined;
|
2824
|
+
let id = undefined;
|
2825
|
+
let address = undefined;
|
2826
|
+
const withdrawalId = this.safeString (transaction, 'withdrawal_id');
|
2827
|
+
const addressFrom = this.safeString (transaction, 'from');
|
2828
|
+
const addressTo = this.safeString (transaction, 'to');
|
2829
|
+
const tagTo = this.safeString (transaction, 'tag');
|
2830
|
+
if (withdrawalId !== undefined) {
|
2831
|
+
type = 'withdrawal';
|
2832
|
+
id = withdrawalId;
|
2833
|
+
address = addressTo;
|
2834
|
+
} else {
|
2835
|
+
// the payment_id will appear on new deposits but appears to be removed from the response after 2 months
|
2836
|
+
id = this.safeString2 (transaction, 'payment_id', 'deposit_id');
|
2837
|
+
type = 'deposit';
|
2838
|
+
address = addressTo;
|
2839
|
+
}
|
2840
|
+
const currencyId = this.safeString (transaction, 'currency');
|
2841
|
+
const code = this.safeCurrencyCode (currencyId);
|
2842
|
+
const amount = this.safeNumber (transaction, 'amount');
|
2843
|
+
const status = this.parseTransactionStatus (this.safeString (transaction, 'status'));
|
2844
|
+
const txid = this.safeString (transaction, 'txid');
|
2845
|
+
const timestamp = this.parse8601 (this.safeString (transaction, 'timestamp'));
|
2846
|
+
let feeCost = undefined;
|
2847
|
+
if (type === 'deposit') {
|
2848
|
+
feeCost = 0;
|
2849
|
+
} else {
|
2850
|
+
if (currencyId !== undefined) {
|
2851
|
+
const feeWithCurrencyId = this.safeString (transaction, 'fee');
|
2852
|
+
if (feeWithCurrencyId !== undefined) {
|
2853
|
+
// https://github.com/ccxt/ccxt/pull/5748
|
2854
|
+
const lowercaseCurrencyId = currencyId.toLowerCase ();
|
2855
|
+
const feeWithoutCurrencyId = feeWithCurrencyId.replace (lowercaseCurrencyId, '');
|
2856
|
+
feeCost = parseFloat (feeWithoutCurrencyId);
|
2857
|
+
}
|
2858
|
+
}
|
2859
|
+
}
|
2860
|
+
// todo parse tags
|
2861
|
+
return {
|
2862
|
+
'info': transaction,
|
2863
|
+
'id': id,
|
2864
|
+
'currency': code,
|
2865
|
+
'amount': amount,
|
2866
|
+
'network': undefined,
|
2867
|
+
'addressFrom': addressFrom,
|
2868
|
+
'addressTo': addressTo,
|
2869
|
+
'address': address,
|
2870
|
+
'tagFrom': undefined,
|
2871
|
+
'tagTo': tagTo,
|
2872
|
+
'tag': tagTo,
|
2873
|
+
'status': status,
|
2874
|
+
'type': type,
|
2875
|
+
'updated': undefined,
|
2876
|
+
'txid': txid,
|
2877
|
+
'timestamp': timestamp,
|
2878
|
+
'datetime': this.iso8601 (timestamp),
|
2879
|
+
'fee': {
|
2880
|
+
'currency': code,
|
2881
|
+
'cost': feeCost,
|
2882
|
+
},
|
2883
|
+
};
|
2884
|
+
}
|
2885
|
+
|
2886
|
+
parseMyTrade (pair, market = undefined) {
|
2887
|
+
// check that trading symbols match in both entries
|
2888
|
+
const userTrade = this.safeValue (pair, 1);
|
2889
|
+
const otherTrade = this.safeValue (pair, 0);
|
2890
|
+
const firstMarketId = this.safeString (otherTrade, 'instrument_id');
|
2891
|
+
const secondMarketId = this.safeString (userTrade, 'instrument_id');
|
2892
|
+
if (firstMarketId !== secondMarketId) {
|
2893
|
+
throw new NotSupported (this.id + ' parseMyTrade() received unrecognized response format, differing instrument_ids in one fill, the exchange API might have changed, paste your verbose output: https://github.com/ccxt/ccxt/wiki/FAQ#what-is-required-to-get-help');
|
2894
|
+
}
|
2895
|
+
const marketId = firstMarketId;
|
2896
|
+
market = this.safeMarket (marketId, market);
|
2897
|
+
const symbol = market['symbol'];
|
2898
|
+
const quoteId = market['quoteId'];
|
2899
|
+
let side = undefined;
|
2900
|
+
let amountString = undefined;
|
2901
|
+
let costString = undefined;
|
2902
|
+
const receivedCurrencyId = this.safeString (userTrade, 'currency');
|
2903
|
+
let feeCurrencyId = undefined;
|
2904
|
+
if (receivedCurrencyId === quoteId) {
|
2905
|
+
side = this.safeString (otherTrade, 'side');
|
2906
|
+
amountString = this.safeString (otherTrade, 'size');
|
2907
|
+
costString = this.safeString (userTrade, 'size');
|
2908
|
+
feeCurrencyId = this.safeString (otherTrade, 'currency');
|
2909
|
+
} else {
|
2910
|
+
side = this.safeString (userTrade, 'side');
|
2911
|
+
amountString = this.safeString (userTrade, 'size');
|
2912
|
+
costString = this.safeString (otherTrade, 'size');
|
2913
|
+
feeCurrencyId = this.safeString (userTrade, 'currency');
|
2914
|
+
}
|
2915
|
+
const id = this.safeString (userTrade, 'trade_id');
|
2916
|
+
const priceString = this.safeString (userTrade, 'price');
|
2917
|
+
const feeCostFirstString = this.safeString (otherTrade, 'fee');
|
2918
|
+
const feeCostSecondString = this.safeString (userTrade, 'fee');
|
2919
|
+
const feeCurrencyCodeFirst = this.safeCurrencyCode (this.safeString (otherTrade, 'currency'));
|
2920
|
+
const feeCurrencyCodeSecond = this.safeCurrencyCode (this.safeString (userTrade, 'currency'));
|
2921
|
+
let fee = undefined;
|
2922
|
+
let fees = undefined;
|
2923
|
+
// fee is either a positive number (invitation rebate)
|
2924
|
+
// or a negative number (transaction fee deduction)
|
2925
|
+
// therefore we need to invert the fee
|
2926
|
+
// more about it https://github.com/ccxt/ccxt/issues/5909
|
2927
|
+
if ((feeCostFirstString !== undefined) && !Precise.stringEquals (feeCostFirstString, '0')) {
|
2928
|
+
if ((feeCostSecondString !== undefined) && !Precise.stringEquals (feeCostSecondString, '0')) {
|
2929
|
+
fees = [
|
2930
|
+
{
|
2931
|
+
'cost': Precise.stringNeg (feeCostFirstString),
|
2932
|
+
'currency': feeCurrencyCodeFirst,
|
2933
|
+
},
|
2934
|
+
{
|
2935
|
+
'cost': Precise.stringNeg (feeCostSecondString),
|
2936
|
+
'currency': feeCurrencyCodeSecond,
|
2937
|
+
},
|
2938
|
+
];
|
2939
|
+
} else {
|
2940
|
+
fee = {
|
2941
|
+
'cost': Precise.stringNeg (feeCostFirstString),
|
2942
|
+
'currency': feeCurrencyCodeFirst,
|
2943
|
+
};
|
2944
|
+
}
|
2945
|
+
} else if ((feeCostSecondString !== undefined) && !Precise.stringEquals (feeCostSecondString, '0')) {
|
2946
|
+
fee = {
|
2947
|
+
'cost': Precise.stringNeg (feeCostSecondString),
|
2948
|
+
'currency': feeCurrencyCodeSecond,
|
2949
|
+
};
|
2950
|
+
} else {
|
2951
|
+
fee = {
|
2952
|
+
'cost': '0',
|
2953
|
+
'currency': this.safeCurrencyCode (feeCurrencyId),
|
2954
|
+
};
|
2955
|
+
}
|
2956
|
+
//
|
2957
|
+
// simplified structures to show the underlying semantics
|
2958
|
+
//
|
2959
|
+
// // market/limit sell
|
2960
|
+
//
|
2961
|
+
// {
|
2962
|
+
// "currency":"USDT",
|
2963
|
+
// "fee":"-0.04647925", // ←--- fee in received quote currency
|
2964
|
+
// "price":"129.13", // ←------ price
|
2965
|
+
// "size":"30.98616393", // ←-- cost
|
2966
|
+
// },
|
2967
|
+
// {
|
2968
|
+
// "currency":"ETH",
|
2969
|
+
// "fee":"0",
|
2970
|
+
// "price":"129.13",
|
2971
|
+
// "size":"0.23996099", // ←--- amount
|
2972
|
+
// },
|
2973
|
+
//
|
2974
|
+
// // market/limit buy
|
2975
|
+
//
|
2976
|
+
// {
|
2977
|
+
// "currency":"ETH",
|
2978
|
+
// "fee":"-0.00036049", // ←--- fee in received base currency
|
2979
|
+
// "price":"129.16", // ←------ price
|
2980
|
+
// "size":"0.240322", // ←----- amount
|
2981
|
+
// },
|
2982
|
+
// {
|
2983
|
+
// "currency":"USDT",
|
2984
|
+
// "fee":"0",
|
2985
|
+
// "price":"129.16",
|
2986
|
+
// "size":"31.03998952", // ←-- cost
|
2987
|
+
// }
|
2988
|
+
//
|
2989
|
+
const timestamp = this.parse8601 (this.safeString2 (userTrade, 'timestamp', 'created_at'));
|
2990
|
+
let takerOrMaker = this.safeString2 (userTrade, 'exec_type', 'liquidity');
|
2991
|
+
if (takerOrMaker === 'M') {
|
2992
|
+
takerOrMaker = 'maker';
|
2993
|
+
} else if (takerOrMaker === 'T') {
|
2994
|
+
takerOrMaker = 'taker';
|
2995
|
+
}
|
2996
|
+
const orderId = this.safeString (userTrade, 'order_id');
|
2997
|
+
return this.safeTrade ({
|
2998
|
+
'info': pair,
|
2999
|
+
'timestamp': timestamp,
|
3000
|
+
'datetime': this.iso8601 (timestamp),
|
3001
|
+
'symbol': symbol,
|
3002
|
+
'id': id,
|
3003
|
+
'order': orderId,
|
3004
|
+
'type': undefined,
|
3005
|
+
'takerOrMaker': takerOrMaker,
|
3006
|
+
'side': side,
|
3007
|
+
'price': priceString,
|
3008
|
+
'amount': amountString,
|
3009
|
+
'cost': costString,
|
3010
|
+
'fee': fee,
|
3011
|
+
'fees': fees,
|
3012
|
+
}, market);
|
3013
|
+
}
|
3014
|
+
|
3015
|
+
parseMyTrades (trades, market = undefined, since = undefined, limit = undefined, params = {}) {
|
3016
|
+
const grouped = this.groupBy (trades, 'trade_id');
|
3017
|
+
const tradeIds = Object.keys (grouped);
|
3018
|
+
const result = [];
|
3019
|
+
for (let i = 0; i < tradeIds.length; i++) {
|
3020
|
+
const tradeId = tradeIds[i];
|
3021
|
+
const pair = grouped[tradeId];
|
3022
|
+
// make sure it has exactly 2 trades, no more, no less
|
3023
|
+
const numTradesInPair = pair.length;
|
3024
|
+
if (numTradesInPair === 2) {
|
3025
|
+
const trade = this.parseMyTrade (pair);
|
3026
|
+
result.push (trade);
|
3027
|
+
}
|
3028
|
+
}
|
3029
|
+
market = this.safeMarket (undefined, market);
|
3030
|
+
return this.filterBySymbolSinceLimit (result, market['symbol'], since, limit);
|
3031
|
+
}
|
3032
|
+
|
3033
|
+
async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
3034
|
+
// okex actually returns ledger entries instead of fills here, so each fill in the order
|
3035
|
+
// is represented by two trades with opposite buy/sell sides, not one :\
|
3036
|
+
// this aspect renders the 'fills' endpoint unusable for fetchOrderTrades
|
3037
|
+
// until either OKEX fixes the API or we workaround this on our side somehow
|
3038
|
+
if (symbol === undefined) {
|
3039
|
+
throw new ArgumentsRequired (this.id + ' fetchMyTrades() requires a symbol argument');
|
3040
|
+
}
|
3041
|
+
await this.loadMarkets ();
|
3042
|
+
const market = this.market (symbol);
|
3043
|
+
if ((limit !== undefined) && (limit > 100)) {
|
3044
|
+
limit = 100;
|
3045
|
+
}
|
3046
|
+
const request = {
|
3047
|
+
'instrument_id': market['id'],
|
3048
|
+
// 'order_id': id, // string
|
3049
|
+
// 'after': '1', // pagination of data to return records earlier than the requested ledger_id
|
3050
|
+
// 'before': '1', // P=pagination of data to return records newer than the requested ledger_id
|
3051
|
+
// 'limit': limit, // optional, number of results per request, default = maximum = 100
|
3052
|
+
};
|
3053
|
+
const defaultType = this.safeString2 (this.options, 'fetchMyTrades', 'defaultType');
|
3054
|
+
const type = this.safeString (params, 'type', defaultType);
|
3055
|
+
const query = this.omit (params, 'type');
|
3056
|
+
const method = type + 'GetFills';
|
3057
|
+
const response = await this[method] (this.extend (request, query));
|
3058
|
+
//
|
3059
|
+
// [
|
3060
|
+
// // sell
|
3061
|
+
// {
|
3062
|
+
// "created_at":"2020-03-29T11:55:25.000Z",
|
3063
|
+
// "currency":"USDT",
|
3064
|
+
// "exec_type":"T",
|
3065
|
+
// "fee":"-0.04647925",
|
3066
|
+
// "instrument_id":"ETH-USDT",
|
3067
|
+
// "ledger_id":"10562924353",
|
3068
|
+
// "liquidity":"T",
|
3069
|
+
// "order_id":"4636470489136128",
|
3070
|
+
// "price":"129.13",
|
3071
|
+
// "product_id":"ETH-USDT",
|
3072
|
+
// "side":"buy",
|
3073
|
+
// "size":"30.98616393",
|
3074
|
+
// "timestamp":"2020-03-29T11:55:25.000Z",
|
3075
|
+
// "trade_id":"18551601"
|
3076
|
+
// },
|
3077
|
+
// {
|
3078
|
+
// "created_at":"2020-03-29T11:55:25.000Z",
|
3079
|
+
// "currency":"ETH",
|
3080
|
+
// "exec_type":"T",
|
3081
|
+
// "fee":"0",
|
3082
|
+
// "instrument_id":"ETH-USDT",
|
3083
|
+
// "ledger_id":"10562924352",
|
3084
|
+
// "liquidity":"T",
|
3085
|
+
// "order_id":"4636470489136128",
|
3086
|
+
// "price":"129.13",
|
3087
|
+
// "product_id":"ETH-USDT",
|
3088
|
+
// "side":"sell",
|
3089
|
+
// "size":"0.23996099",
|
3090
|
+
// "timestamp":"2020-03-29T11:55:25.000Z",
|
3091
|
+
// "trade_id":"18551601"
|
3092
|
+
// },
|
3093
|
+
// // buy
|
3094
|
+
// {
|
3095
|
+
// "created_at":"2020-03-29T11:55:16.000Z",
|
3096
|
+
// "currency":"ETH",
|
3097
|
+
// "exec_type":"T",
|
3098
|
+
// "fee":"-0.00036049",
|
3099
|
+
// "instrument_id":"ETH-USDT",
|
3100
|
+
// "ledger_id":"10562922669",
|
3101
|
+
// "liquidity":"T",
|
3102
|
+
// "order_id": "4636469894136832",
|
3103
|
+
// "price":"129.16",
|
3104
|
+
// "product_id":"ETH-USDT",
|
3105
|
+
// "side":"buy",
|
3106
|
+
// "size":"0.240322",
|
3107
|
+
// "timestamp":"2020-03-29T11:55:16.000Z",
|
3108
|
+
// "trade_id":"18551600"
|
3109
|
+
// },
|
3110
|
+
// {
|
3111
|
+
// "created_at":"2020-03-29T11:55:16.000Z",
|
3112
|
+
// "currency":"USDT",
|
3113
|
+
// "exec_type":"T",
|
3114
|
+
// "fee":"0",
|
3115
|
+
// "instrument_id":"ETH-USDT",
|
3116
|
+
// "ledger_id":"10562922668",
|
3117
|
+
// "liquidity":"T",
|
3118
|
+
// "order_id":"4636469894136832",
|
3119
|
+
// "price":"129.16",
|
3120
|
+
// "product_id":"ETH-USDT",
|
3121
|
+
// "side":"sell",
|
3122
|
+
// "size":"31.03998952",
|
3123
|
+
// "timestamp":"2020-03-29T11:55:16.000Z",
|
3124
|
+
// "trade_id":"18551600"
|
3125
|
+
// }
|
3126
|
+
// ]
|
3127
|
+
//
|
3128
|
+
return this.parseMyTrades (response, market, since, limit, params);
|
3129
|
+
}
|
3130
|
+
|
3131
|
+
async fetchOrderTrades (id, symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
3132
|
+
const request = {
|
3133
|
+
// 'instrument_id': market['id'],
|
3134
|
+
'order_id': id,
|
3135
|
+
// 'after': '1', // return the page after the specified page number
|
3136
|
+
// 'before': '1', // return the page before the specified page number
|
3137
|
+
// 'limit': limit, // optional, number of results per request, default = maximum = 100
|
3138
|
+
};
|
3139
|
+
return await this.fetchMyTrades (symbol, since, limit, this.extend (request, params));
|
3140
|
+
}
|
3141
|
+
|
3142
|
+
async fetchPosition (symbol, params = {}) {
|
3143
|
+
await this.loadMarkets ();
|
3144
|
+
const market = this.market (symbol);
|
3145
|
+
let method = undefined;
|
3146
|
+
const request = {
|
3147
|
+
'instrument_id': market['id'],
|
3148
|
+
// 'order_id': id, // string
|
3149
|
+
// 'after': '1', // pagination of data to return records earlier than the requested ledger_id
|
3150
|
+
// 'before': '1', // P=pagination of data to return records newer than the requested ledger_id
|
3151
|
+
// 'limit': limit, // optional, number of results per request, default = maximum = 100
|
3152
|
+
};
|
3153
|
+
const type = market['type'];
|
3154
|
+
if ((type === 'futures') || (type === 'swap')) {
|
3155
|
+
method = type + 'GetInstrumentIdPosition';
|
3156
|
+
} else if (type === 'option') {
|
3157
|
+
const underlying = this.safeString (params, 'underlying');
|
3158
|
+
if (underlying === undefined) {
|
3159
|
+
throw new ArgumentsRequired (this.id + ' fetchPosition() requires an underlying parameter for ' + type + ' market ' + symbol);
|
3160
|
+
}
|
3161
|
+
method = type + 'GetUnderlyingPosition';
|
3162
|
+
} else {
|
3163
|
+
throw new NotSupported (this.id + ' fetchPosition() does not support ' + type + ' market ' + symbol + ', supported market types are futures, swap or option');
|
3164
|
+
}
|
3165
|
+
const response = await this[method] (this.extend (request, params));
|
3166
|
+
//
|
3167
|
+
// futures
|
3168
|
+
//
|
3169
|
+
// crossed margin mode
|
3170
|
+
//
|
3171
|
+
// {
|
3172
|
+
// "result": true,
|
3173
|
+
// "holding": [
|
3174
|
+
// {
|
3175
|
+
// "long_qty": "2",
|
3176
|
+
// "long_avail_qty": "2",
|
3177
|
+
// "long_avg_cost": "8260",
|
3178
|
+
// "long_settlement_price": "8260",
|
3179
|
+
// "realised_pnl": "0.00020928",
|
3180
|
+
// "short_qty": "2",
|
3181
|
+
// "short_avail_qty": "2",
|
3182
|
+
// "short_avg_cost": "8259.99",
|
3183
|
+
// "short_settlement_price": "8259.99",
|
3184
|
+
// "liquidation_price": "113.81",
|
3185
|
+
// "instrument_id": "BTC-USD-191227",
|
3186
|
+
// "leverage": "10",
|
3187
|
+
// "created_at": "2019-09-25T07:58:42.129Z",
|
3188
|
+
// "updated_at": "2019-10-08T14:02:51.029Z",
|
3189
|
+
// "margin_mode": "crossed",
|
3190
|
+
// "short_margin": "0.00242197",
|
3191
|
+
// "short_pnl": "6.63E-6",
|
3192
|
+
// "short_pnl_ratio": "0.002477997",
|
3193
|
+
// "short_unrealised_pnl": "6.63E-6",
|
3194
|
+
// "long_margin": "0.00242197",
|
3195
|
+
// "long_pnl": "-6.65E-6",
|
3196
|
+
// "long_pnl_ratio": "-0.002478",
|
3197
|
+
// "long_unrealised_pnl": "-6.65E-6",
|
3198
|
+
// "long_settled_pnl": "0",
|
3199
|
+
// "short_settled_pnl": "0",
|
3200
|
+
// "last": "8257.57"
|
3201
|
+
// }
|
3202
|
+
// ],
|
3203
|
+
// "margin_mode": "crossed"
|
3204
|
+
// }
|
3205
|
+
//
|
3206
|
+
// fixed margin mode
|
3207
|
+
//
|
3208
|
+
// {
|
3209
|
+
// "result": true,
|
3210
|
+
// "holding": [
|
3211
|
+
// {
|
3212
|
+
// "long_qty": "4",
|
3213
|
+
// "long_avail_qty": "4",
|
3214
|
+
// "long_margin": "0.00323844",
|
3215
|
+
// "long_liqui_price": "7762.09",
|
3216
|
+
// "long_pnl_ratio": "0.06052306",
|
3217
|
+
// "long_avg_cost": "8234.43",
|
3218
|
+
// "long_settlement_price": "8234.43",
|
3219
|
+
// "realised_pnl": "-0.00000296",
|
3220
|
+
// "short_qty": "2",
|
3221
|
+
// "short_avail_qty": "2",
|
3222
|
+
// "short_margin": "0.00241105",
|
3223
|
+
// "short_liqui_price": "9166.74",
|
3224
|
+
// "short_pnl_ratio": "0.03318052",
|
3225
|
+
// "short_avg_cost": "8295.13",
|
3226
|
+
// "short_settlement_price": "8295.13",
|
3227
|
+
// "instrument_id": "BTC-USD-191227",
|
3228
|
+
// "long_leverage": "15",
|
3229
|
+
// "short_leverage": "10",
|
3230
|
+
// "created_at": "2019-09-25T07:58:42.129Z",
|
3231
|
+
// "updated_at": "2019-10-08T13:12:09.438Z",
|
3232
|
+
// "margin_mode": "fixed",
|
3233
|
+
// "short_margin_ratio": "0.10292507",
|
3234
|
+
// "short_maint_margin_ratio": "0.005",
|
3235
|
+
// "short_pnl": "7.853E-5",
|
3236
|
+
// "short_unrealised_pnl": "7.853E-5",
|
3237
|
+
// "long_margin_ratio": "0.07103743",
|
3238
|
+
// "long_maint_margin_ratio": "0.005",
|
3239
|
+
// "long_pnl": "1.9841E-4",
|
3240
|
+
// "long_unrealised_pnl": "1.9841E-4",
|
3241
|
+
// "long_settled_pnl": "0",
|
3242
|
+
// "short_settled_pnl": "0",
|
3243
|
+
// "last": "8266.99"
|
3244
|
+
// }
|
3245
|
+
// ],
|
3246
|
+
// "margin_mode": "fixed"
|
3247
|
+
// }
|
3248
|
+
//
|
3249
|
+
// swap
|
3250
|
+
//
|
3251
|
+
// crossed margin mode
|
3252
|
+
//
|
3253
|
+
// {
|
3254
|
+
// "margin_mode": "crossed",
|
3255
|
+
// "timestamp": "2019-09-27T03:49:02.018Z",
|
3256
|
+
// "holding": [
|
3257
|
+
// {
|
3258
|
+
// "avail_position": "3",
|
3259
|
+
// "avg_cost": "59.49",
|
3260
|
+
// "instrument_id": "LTC-USD-SWAP",
|
3261
|
+
// "last": "55.98",
|
3262
|
+
// "leverage": "10.00",
|
3263
|
+
// "liquidation_price": "4.37",
|
3264
|
+
// "maint_margin_ratio": "0.0100",
|
3265
|
+
// "margin": "0.0536",
|
3266
|
+
// "position": "3",
|
3267
|
+
// "realized_pnl": "0.0000",
|
3268
|
+
// "unrealized_pnl": "0",
|
3269
|
+
// "settled_pnl": "-0.0330",
|
3270
|
+
// "settlement_price": "55.84",
|
3271
|
+
// "side": "long",
|
3272
|
+
// "timestamp": "2019-09-27T03:49:02.018Z"
|
3273
|
+
// },
|
3274
|
+
// ]
|
3275
|
+
// }
|
3276
|
+
//
|
3277
|
+
// fixed margin mode
|
3278
|
+
//
|
3279
|
+
// {
|
3280
|
+
// "margin_mode": "fixed",
|
3281
|
+
// "timestamp": "2019-09-27T03:47:37.230Z",
|
3282
|
+
// "holding": [
|
3283
|
+
// {
|
3284
|
+
// "avail_position": "20",
|
3285
|
+
// "avg_cost": "8025.0",
|
3286
|
+
// "instrument_id": "BTC-USD-SWAP",
|
3287
|
+
// "last": "8113.1",
|
3288
|
+
// "leverage": "15.00",
|
3289
|
+
// "liquidation_price": "7002.6",
|
3290
|
+
// "maint_margin_ratio": "0.0050",
|
3291
|
+
// "margin": "0.0454",
|
3292
|
+
// "position": "20",
|
3293
|
+
// "realized_pnl": "-0.0001",
|
3294
|
+
// "unrealized_pnl": "0",
|
3295
|
+
// "settled_pnl": "0.0076",
|
3296
|
+
// "settlement_price": "8279.2",
|
3297
|
+
// "side": "long",
|
3298
|
+
// "timestamp": "2019-09-27T03:47:37.230Z"
|
3299
|
+
// }
|
3300
|
+
// ]
|
3301
|
+
// }
|
3302
|
+
//
|
3303
|
+
// option
|
3304
|
+
//
|
3305
|
+
// {
|
3306
|
+
// "holding":[
|
3307
|
+
// {
|
3308
|
+
// "instrument_id":"BTC-USD-190927-12500-C",
|
3309
|
+
// "position":"20",
|
3310
|
+
// "avg_cost":"3.26",
|
3311
|
+
// "avail_position":"20",
|
3312
|
+
// "settlement_price":"0.017",
|
3313
|
+
// "total_pnl":"50",
|
3314
|
+
// "pnl_ratio":"0.3",
|
3315
|
+
// "realized_pnl":"40",
|
3316
|
+
// "unrealized_pnl":"10",
|
3317
|
+
// "pos_margin":"100",
|
3318
|
+
// "option_value":"70",
|
3319
|
+
// "created_at":"2019-08-30T03:09:20.315Z",
|
3320
|
+
// "updated_at":"2019-08-30T03:40:18.318Z"
|
3321
|
+
// },
|
3322
|
+
// {
|
3323
|
+
// "instrument_id":"BTC-USD-190927-12500-P",
|
3324
|
+
// "position":"20",
|
3325
|
+
// "avg_cost":"3.26",
|
3326
|
+
// "avail_position":"20",
|
3327
|
+
// "settlement_price":"0.019",
|
3328
|
+
// "total_pnl":"50",
|
3329
|
+
// "pnl_ratio":"0.3",
|
3330
|
+
// "realized_pnl":"40",
|
3331
|
+
// "unrealized_pnl":"10",
|
3332
|
+
// "pos_margin":"100",
|
3333
|
+
// "option_value":"70",
|
3334
|
+
// "created_at":"2019-08-30T03:09:20.315Z",
|
3335
|
+
// "updated_at":"2019-08-30T03:40:18.318Z"
|
3336
|
+
// }
|
3337
|
+
// ]
|
3338
|
+
// }
|
3339
|
+
//
|
3340
|
+
// todo unify parsePosition/parsePositions
|
3341
|
+
return response;
|
3342
|
+
}
|
3343
|
+
|
3344
|
+
async fetchPositions (symbols = undefined, params = {}) {
|
3345
|
+
await this.loadMarkets ();
|
3346
|
+
let method = undefined;
|
3347
|
+
const defaultType = this.safeString2 (this.options, 'fetchPositions', 'defaultType');
|
3348
|
+
const type = this.safeString (params, 'type', defaultType);
|
3349
|
+
if ((type === 'futures') || (type === 'swap')) {
|
3350
|
+
method = type + 'GetPosition';
|
3351
|
+
} else if (type === 'option') {
|
3352
|
+
const underlying = this.safeString (params, 'underlying');
|
3353
|
+
if (underlying === undefined) {
|
3354
|
+
throw new ArgumentsRequired (this.id + ' fetchPositions() requires an underlying parameter for ' + type + ' markets');
|
3355
|
+
}
|
3356
|
+
method = type + 'GetUnderlyingPosition';
|
3357
|
+
} else {
|
3358
|
+
throw new NotSupported (this.id + ' fetchPositions() does not support ' + type + ' markets, supported market types are futures, swap or option');
|
3359
|
+
}
|
3360
|
+
params = this.omit (params, 'type');
|
3361
|
+
const response = await this[method] (params);
|
3362
|
+
//
|
3363
|
+
// futures
|
3364
|
+
//
|
3365
|
+
// ...
|
3366
|
+
//
|
3367
|
+
//
|
3368
|
+
// swap
|
3369
|
+
//
|
3370
|
+
// ...
|
3371
|
+
//
|
3372
|
+
// option
|
3373
|
+
//
|
3374
|
+
// {
|
3375
|
+
// "holding":[
|
3376
|
+
// {
|
3377
|
+
// "instrument_id":"BTC-USD-190927-12500-C",
|
3378
|
+
// "position":"20",
|
3379
|
+
// "avg_cost":"3.26",
|
3380
|
+
// "avail_position":"20",
|
3381
|
+
// "settlement_price":"0.017",
|
3382
|
+
// "total_pnl":"50",
|
3383
|
+
// "pnl_ratio":"0.3",
|
3384
|
+
// "realized_pnl":"40",
|
3385
|
+
// "unrealized_pnl":"10",
|
3386
|
+
// "pos_margin":"100",
|
3387
|
+
// "option_value":"70",
|
3388
|
+
// "created_at":"2019-08-30T03:09:20.315Z",
|
3389
|
+
// "updated_at":"2019-08-30T03:40:18.318Z"
|
3390
|
+
// },
|
3391
|
+
// {
|
3392
|
+
// "instrument_id":"BTC-USD-190927-12500-P",
|
3393
|
+
// "position":"20",
|
3394
|
+
// "avg_cost":"3.26",
|
3395
|
+
// "avail_position":"20",
|
3396
|
+
// "settlement_price":"0.019",
|
3397
|
+
// "total_pnl":"50",
|
3398
|
+
// "pnl_ratio":"0.3",
|
3399
|
+
// "realized_pnl":"40",
|
3400
|
+
// "unrealized_pnl":"10",
|
3401
|
+
// "pos_margin":"100",
|
3402
|
+
// "option_value":"70",
|
3403
|
+
// "created_at":"2019-08-30T03:09:20.315Z",
|
3404
|
+
// "updated_at":"2019-08-30T03:40:18.318Z"
|
3405
|
+
// }
|
3406
|
+
// ]
|
3407
|
+
// }
|
3408
|
+
//
|
3409
|
+
// todo unify parsePosition/parsePositions
|
3410
|
+
return response;
|
3411
|
+
}
|
3412
|
+
|
3413
|
+
async fetchLedger (code = undefined, since = undefined, limit = undefined, params = {}) {
|
3414
|
+
await this.loadMarkets ();
|
3415
|
+
const defaultType = this.safeString2 (this.options, 'fetchLedger', 'defaultType');
|
3416
|
+
const type = this.safeString (params, 'type', defaultType);
|
3417
|
+
const query = this.omit (params, 'type');
|
3418
|
+
const suffix = (type === 'account') ? '' : 'Accounts';
|
3419
|
+
let argument = '';
|
3420
|
+
const request = {
|
3421
|
+
// 'from': 'id',
|
3422
|
+
// 'to': 'id',
|
3423
|
+
};
|
3424
|
+
if (limit !== undefined) {
|
3425
|
+
request['limit'] = limit;
|
3426
|
+
}
|
3427
|
+
let currency = undefined;
|
3428
|
+
if (type === 'spot') {
|
3429
|
+
if (code === undefined) {
|
3430
|
+
throw new ArgumentsRequired (this.id + " fetchLedger() requires a currency code argument for '" + type + "' markets");
|
3431
|
+
}
|
3432
|
+
argument = 'Currency';
|
3433
|
+
currency = this.currency (code);
|
3434
|
+
request['currency'] = currency['id'];
|
3435
|
+
} else if (type === 'futures') {
|
3436
|
+
if (code === undefined) {
|
3437
|
+
throw new ArgumentsRequired (this.id + " fetchLedger() requires an underlying symbol for '" + type + "' markets");
|
3438
|
+
}
|
3439
|
+
argument = 'Underlying';
|
3440
|
+
const market = this.market (code); // we intentionally put a market inside here for the margin and swap ledgers
|
3441
|
+
const marketInfo = this.safeValue (market, 'info', {});
|
3442
|
+
const settlementCurrencyId = this.safeString (marketInfo, 'settlement_currency');
|
3443
|
+
const settlementCurrencyCode = this.safeCurrencyCode (settlementCurrencyId);
|
3444
|
+
currency = this.currency (settlementCurrencyCode);
|
3445
|
+
const underlyingId = this.safeString (marketInfo, 'underlying');
|
3446
|
+
request['underlying'] = underlyingId;
|
3447
|
+
} else if ((type === 'margin') || (type === 'swap')) {
|
3448
|
+
if (code === undefined) {
|
3449
|
+
throw new ArgumentsRequired (this.id + " fetchLedger() requires a code argument (a market symbol) for '" + type + "' markets");
|
3450
|
+
}
|
3451
|
+
argument = 'InstrumentId';
|
3452
|
+
const market = this.market (code); // we intentionally put a market inside here for the margin and swap ledgers
|
3453
|
+
currency = this.currency (market['base']);
|
3454
|
+
request['instrument_id'] = market['id'];
|
3455
|
+
//
|
3456
|
+
// if (type === 'margin') {
|
3457
|
+
// //
|
3458
|
+
// // 3. Borrow
|
3459
|
+
// // 4. Repayment
|
3460
|
+
// // 5. Interest
|
3461
|
+
// // 7. Buy
|
3462
|
+
// // 8. Sell
|
3463
|
+
// // 9. From capital account
|
3464
|
+
// // 10. From C2C
|
3465
|
+
// // 11. From Futures
|
3466
|
+
// // 12. From Spot
|
3467
|
+
// // 13. From ETT
|
3468
|
+
// // 14. To capital account
|
3469
|
+
// // 15. To C2C
|
3470
|
+
// // 16. To Spot
|
3471
|
+
// // 17. To Futures
|
3472
|
+
// // 18. To ETT
|
3473
|
+
// // 19. Mandatory Repayment
|
3474
|
+
// // 20. From Piggybank
|
3475
|
+
// // 21. To Piggybank
|
3476
|
+
// // 22. From Perpetual
|
3477
|
+
// // 23. To Perpetual
|
3478
|
+
// // 24. Liquidation Fee
|
3479
|
+
// // 54. Clawback
|
3480
|
+
// // 59. Airdrop Return.
|
3481
|
+
// //
|
3482
|
+
// request['type'] = 'number'; // All types will be returned if this filed is left blank
|
3483
|
+
// }
|
3484
|
+
//
|
3485
|
+
} else if (type === 'account') {
|
3486
|
+
if (code !== undefined) {
|
3487
|
+
currency = this.currency (code);
|
3488
|
+
request['currency'] = currency['id'];
|
3489
|
+
}
|
3490
|
+
//
|
3491
|
+
// //
|
3492
|
+
// // 1. deposit
|
3493
|
+
// // 2. withdrawal
|
3494
|
+
// // 13. cancel withdrawal
|
3495
|
+
// // 18. into futures account
|
3496
|
+
// // 19. out of futures account
|
3497
|
+
// // 20. into sub account
|
3498
|
+
// // 21. out of sub account
|
3499
|
+
// // 28. claim
|
3500
|
+
// // 29. into ETT account
|
3501
|
+
// // 30. out of ETT account
|
3502
|
+
// // 31. into C2C account
|
3503
|
+
// // 32. out of C2C account
|
3504
|
+
// // 33. into margin account
|
3505
|
+
// // 34. out of margin account
|
3506
|
+
// // 37. into spot account
|
3507
|
+
// // 38. out of spot account
|
3508
|
+
// //
|
3509
|
+
// request['type'] = 'number';
|
3510
|
+
//
|
3511
|
+
} else {
|
3512
|
+
throw new NotSupported (this.id + " fetchLedger does not support the '" + type + "' type (the type must be one of 'account', 'spot', 'margin', 'futures', 'swap')");
|
3513
|
+
}
|
3514
|
+
const method = type + 'Get' + suffix + argument + 'Ledger';
|
3515
|
+
const response = await this[method] (this.extend (request, query));
|
3516
|
+
//
|
3517
|
+
// transfer funds transfer in/out
|
3518
|
+
// trade funds moved as a result of a trade, spot and margin accounts only
|
3519
|
+
// rebate fee rebate as per fee schedule, spot and margin accounts only
|
3520
|
+
// match open long/open short/close long/close short (futures) or a change in the amount because of trades (swap)
|
3521
|
+
// fee fee, futures only
|
3522
|
+
// settlement settlement/clawback/settle long/settle short
|
3523
|
+
// liquidation force close long/force close short/deliver close long/deliver close short
|
3524
|
+
// funding funding fee, swap only
|
3525
|
+
// margin a change in the amount after adjusting margin, swap only
|
3526
|
+
//
|
3527
|
+
// account
|
3528
|
+
//
|
3529
|
+
// [
|
3530
|
+
// {
|
3531
|
+
// "amount":0.00051843,
|
3532
|
+
// "balance":0.00100941,
|
3533
|
+
// "currency":"BTC",
|
3534
|
+
// "fee":0,
|
3535
|
+
// "ledger_id":8987285,
|
3536
|
+
// "timestamp":"2018-10-12T11:01:14.000Z",
|
3537
|
+
// "typename":"Get from activity"
|
3538
|
+
// }
|
3539
|
+
// ]
|
3540
|
+
//
|
3541
|
+
// spot
|
3542
|
+
//
|
3543
|
+
// [
|
3544
|
+
// {
|
3545
|
+
// "timestamp":"2019-03-18T07:08:25.000Z",
|
3546
|
+
// "ledger_id":"3995334780",
|
3547
|
+
// "created_at":"2019-03-18T07:08:25.000Z",
|
3548
|
+
// "currency":"BTC",
|
3549
|
+
// "amount":"0.0009985",
|
3550
|
+
// "balance":"0.0029955",
|
3551
|
+
// "type":"trade",
|
3552
|
+
// "details":{
|
3553
|
+
// "instrument_id":"BTC-USDT",
|
3554
|
+
// "order_id":"2500650881647616",
|
3555
|
+
// "product_id":"BTC-USDT"
|
3556
|
+
// }
|
3557
|
+
// }
|
3558
|
+
// ]
|
3559
|
+
//
|
3560
|
+
// margin
|
3561
|
+
//
|
3562
|
+
// [
|
3563
|
+
// [
|
3564
|
+
// {
|
3565
|
+
// "created_at":"2019-03-20T03:45:05.000Z",
|
3566
|
+
// "ledger_id":"78918186",
|
3567
|
+
// "timestamp":"2019-03-20T03:45:05.000Z",
|
3568
|
+
// "currency":"EOS",
|
3569
|
+
// "amount":"0", // ?
|
3570
|
+
// "balance":"0.59957711",
|
3571
|
+
// "type":"transfer",
|
3572
|
+
// "details":{
|
3573
|
+
// "instrument_id":"EOS-USDT",
|
3574
|
+
// "order_id":"787057",
|
3575
|
+
// "product_id":"EOS-USDT"
|
3576
|
+
// }
|
3577
|
+
// }
|
3578
|
+
// ],
|
3579
|
+
// {
|
3580
|
+
// "before":"78965766",
|
3581
|
+
// "after":"78918186"
|
3582
|
+
// }
|
3583
|
+
// ]
|
3584
|
+
//
|
3585
|
+
// futures
|
3586
|
+
//
|
3587
|
+
// [
|
3588
|
+
// {
|
3589
|
+
// "ledger_id":"2508090544914461",
|
3590
|
+
// "timestamp":"2019-03-19T14:40:24.000Z",
|
3591
|
+
// "amount":"-0.00529521",
|
3592
|
+
// "balance":"0",
|
3593
|
+
// "currency":"EOS",
|
3594
|
+
// "type":"fee",
|
3595
|
+
// "details":{
|
3596
|
+
// "order_id":"2506982456445952",
|
3597
|
+
// "instrument_id":"EOS-USD-190628"
|
3598
|
+
// }
|
3599
|
+
// }
|
3600
|
+
// ]
|
3601
|
+
//
|
3602
|
+
// swap
|
3603
|
+
//
|
3604
|
+
// [
|
3605
|
+
// {
|
3606
|
+
// "amount":"0.004742",
|
3607
|
+
// "fee":"-0.000551",
|
3608
|
+
// "type":"match",
|
3609
|
+
// "instrument_id":"EOS-USD-SWAP",
|
3610
|
+
// "ledger_id":"197429674941902848",
|
3611
|
+
// "timestamp":"2019-03-25T05:56:31.286Z"
|
3612
|
+
// },
|
3613
|
+
// ]
|
3614
|
+
//
|
3615
|
+
const responseLength = response.length;
|
3616
|
+
if (responseLength < 1) {
|
3617
|
+
return [];
|
3618
|
+
}
|
3619
|
+
const isArray = Array.isArray (response[0]);
|
3620
|
+
const isMargin = (type === 'margin');
|
3621
|
+
const entries = (isMargin && isArray) ? response[0] : response;
|
3622
|
+
if (type === 'swap') {
|
3623
|
+
const ledgerEntries = this.parseLedger (entries);
|
3624
|
+
return this.filterBySymbolSinceLimit (ledgerEntries, code, since, limit);
|
3625
|
+
}
|
3626
|
+
return this.parseLedger (entries, currency, since, limit);
|
3627
|
+
}
|
3628
|
+
|
3629
|
+
parseLedgerEntryType (type) {
|
3630
|
+
const types = {
|
3631
|
+
'transfer': 'transfer', // // funds transfer in/out
|
3632
|
+
'trade': 'trade', // funds moved as a result of a trade, spot and margin accounts only
|
3633
|
+
'rebate': 'rebate', // fee rebate as per fee schedule, spot and margin accounts only
|
3634
|
+
'match': 'trade', // open long/open short/close long/close short (futures) or a change in the amount because of trades (swap)
|
3635
|
+
'fee': 'fee', // fee, futures only
|
3636
|
+
'settlement': 'trade', // settlement/clawback/settle long/settle short
|
3637
|
+
'liquidation': 'trade', // force close long/force close short/deliver close long/deliver close short
|
3638
|
+
'funding': 'fee', // funding fee, swap only
|
3639
|
+
'margin': 'margin', // a change in the amount after adjusting margin, swap only
|
3640
|
+
};
|
3641
|
+
return this.safeString (types, type, type);
|
3642
|
+
}
|
3643
|
+
|
3644
|
+
parseLedgerEntry (item, currency = undefined) {
|
3645
|
+
//
|
3646
|
+
//
|
3647
|
+
// account
|
3648
|
+
//
|
3649
|
+
// {
|
3650
|
+
// "amount":0.00051843,
|
3651
|
+
// "balance":0.00100941,
|
3652
|
+
// "currency":"BTC",
|
3653
|
+
// "fee":0,
|
3654
|
+
// "ledger_id":8987285,
|
3655
|
+
// "timestamp":"2018-10-12T11:01:14.000Z",
|
3656
|
+
// "typename":"Get from activity"
|
3657
|
+
// }
|
3658
|
+
//
|
3659
|
+
// spot
|
3660
|
+
//
|
3661
|
+
// {
|
3662
|
+
// "timestamp":"2019-03-18T07:08:25.000Z",
|
3663
|
+
// "ledger_id":"3995334780",
|
3664
|
+
// "created_at":"2019-03-18T07:08:25.000Z",
|
3665
|
+
// "currency":"BTC",
|
3666
|
+
// "amount":"0.0009985",
|
3667
|
+
// "balance":"0.0029955",
|
3668
|
+
// "type":"trade",
|
3669
|
+
// "details":{
|
3670
|
+
// "instrument_id":"BTC-USDT",
|
3671
|
+
// "order_id":"2500650881647616",
|
3672
|
+
// "product_id":"BTC-USDT"
|
3673
|
+
// }
|
3674
|
+
// }
|
3675
|
+
//
|
3676
|
+
// margin
|
3677
|
+
//
|
3678
|
+
// {
|
3679
|
+
// "created_at":"2019-03-20T03:45:05.000Z",
|
3680
|
+
// "ledger_id":"78918186",
|
3681
|
+
// "timestamp":"2019-03-20T03:45:05.000Z",
|
3682
|
+
// "currency":"EOS",
|
3683
|
+
// "amount":"0", // ?
|
3684
|
+
// "balance":"0.59957711",
|
3685
|
+
// "type":"transfer",
|
3686
|
+
// "details":{
|
3687
|
+
// "instrument_id":"EOS-USDT",
|
3688
|
+
// "order_id":"787057",
|
3689
|
+
// "product_id":"EOS-USDT"
|
3690
|
+
// }
|
3691
|
+
// }
|
3692
|
+
//
|
3693
|
+
// futures
|
3694
|
+
//
|
3695
|
+
// {
|
3696
|
+
// "ledger_id":"2508090544914461",
|
3697
|
+
// "timestamp":"2019-03-19T14:40:24.000Z",
|
3698
|
+
// "amount":"-0.00529521",
|
3699
|
+
// "balance":"0",
|
3700
|
+
// "currency":"EOS",
|
3701
|
+
// "type":"fee",
|
3702
|
+
// "details":{
|
3703
|
+
// "order_id":"2506982456445952",
|
3704
|
+
// "instrument_id":"EOS-USD-190628"
|
3705
|
+
// }
|
3706
|
+
// }
|
3707
|
+
//
|
3708
|
+
// swap
|
3709
|
+
//
|
3710
|
+
// {
|
3711
|
+
// "amount":"0.004742",
|
3712
|
+
// "fee":"-0.000551",
|
3713
|
+
// "type":"match",
|
3714
|
+
// "instrument_id":"EOS-USD-SWAP",
|
3715
|
+
// "ledger_id":"197429674941902848",
|
3716
|
+
// "timestamp":"2019-03-25T05:56:31.286Z"
|
3717
|
+
// },
|
3718
|
+
//
|
3719
|
+
const id = this.safeString (item, 'ledger_id');
|
3720
|
+
const account = undefined;
|
3721
|
+
const details = this.safeValue (item, 'details', {});
|
3722
|
+
const referenceId = this.safeString (details, 'order_id');
|
3723
|
+
const referenceAccount = undefined;
|
3724
|
+
const type = this.parseLedgerEntryType (this.safeString (item, 'type'));
|
3725
|
+
const code = this.safeCurrencyCode (this.safeString (item, 'currency'), currency);
|
3726
|
+
const amount = this.safeNumber (item, 'amount');
|
3727
|
+
const timestamp = this.parse8601 (this.safeString (item, 'timestamp'));
|
3728
|
+
const fee = {
|
3729
|
+
'cost': this.safeNumber (item, 'fee'),
|
3730
|
+
'currency': code,
|
3731
|
+
};
|
3732
|
+
const before = undefined;
|
3733
|
+
const after = this.safeNumber (item, 'balance');
|
3734
|
+
const status = 'ok';
|
3735
|
+
const marketId = this.safeString (item, 'instrument_id');
|
3736
|
+
let symbol = undefined;
|
3737
|
+
if (marketId in this.markets_by_id) {
|
3738
|
+
const market = this.markets_by_id[marketId];
|
3739
|
+
symbol = market['symbol'];
|
3740
|
+
}
|
3741
|
+
return {
|
3742
|
+
'info': item,
|
3743
|
+
'id': id,
|
3744
|
+
'account': account,
|
3745
|
+
'referenceId': referenceId,
|
3746
|
+
'referenceAccount': referenceAccount,
|
3747
|
+
'type': type,
|
3748
|
+
'currency': code,
|
3749
|
+
'symbol': symbol,
|
3750
|
+
'amount': amount,
|
3751
|
+
'before': before, // balance before
|
3752
|
+
'after': after, // balance after
|
3753
|
+
'status': status,
|
3754
|
+
'timestamp': timestamp,
|
3755
|
+
'datetime': this.iso8601 (timestamp),
|
3756
|
+
'fee': fee,
|
3757
|
+
};
|
3758
|
+
}
|
3759
|
+
|
3760
|
+
sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
|
3761
|
+
const isArray = Array.isArray (params);
|
3762
|
+
let request = '/api/' + api + '/' + this.version + '/';
|
3763
|
+
request += isArray ? path : this.implodeParams (path, params);
|
3764
|
+
const query = isArray ? params : this.omit (params, this.extractParams (path));
|
3765
|
+
let url = this.implodeHostname (this.urls['api']['rest']) + request;
|
3766
|
+
const type = this.getPathAuthenticationType (path);
|
3767
|
+
if ((type === 'public') || (type === 'information')) {
|
3768
|
+
if (Object.keys (query).length) {
|
3769
|
+
url += '?' + this.urlencode (query);
|
3770
|
+
}
|
3771
|
+
} else if (type === 'private') {
|
3772
|
+
this.checkRequiredCredentials ();
|
3773
|
+
const timestamp = this.iso8601 (this.milliseconds ());
|
3774
|
+
headers = {
|
3775
|
+
'OK-ACCESS-KEY': this.apiKey,
|
3776
|
+
'OK-ACCESS-PASSPHRASE': this.password,
|
3777
|
+
'OK-ACCESS-TIMESTAMP': timestamp,
|
3778
|
+
// 'OK-FROM': '',
|
3779
|
+
// 'OK-TO': '',
|
3780
|
+
// 'OK-LIMIT': '',
|
3781
|
+
};
|
3782
|
+
let auth = timestamp + method + request;
|
3783
|
+
if (method === 'GET') {
|
3784
|
+
if (Object.keys (query).length) {
|
3785
|
+
const urlencodedQuery = '?' + this.urlencode (query);
|
3786
|
+
url += urlencodedQuery;
|
3787
|
+
auth += urlencodedQuery;
|
3788
|
+
}
|
3789
|
+
} else {
|
3790
|
+
if (isArray || Object.keys (query).length) {
|
3791
|
+
body = this.json (query);
|
3792
|
+
auth += body;
|
3793
|
+
}
|
3794
|
+
headers['Content-Type'] = 'application/json';
|
3795
|
+
}
|
3796
|
+
const signature = this.hmac (this.encode (auth), this.encode (this.secret), 'sha256', 'base64');
|
3797
|
+
headers['OK-ACCESS-SIGN'] = signature;
|
3798
|
+
}
|
3799
|
+
return { 'url': url, 'method': method, 'body': body, 'headers': headers };
|
3800
|
+
}
|
3801
|
+
|
3802
|
+
getPathAuthenticationType (path) {
|
3803
|
+
// https://github.com/ccxt/ccxt/issues/6651
|
3804
|
+
// a special case to handle the optionGetUnderlying interefering with
|
3805
|
+
// other endpoints containing this keyword
|
3806
|
+
if (path === 'underlying') {
|
3807
|
+
return 'public';
|
3808
|
+
}
|
3809
|
+
const auth = this.safeValue (this.options, 'auth', {});
|
3810
|
+
const key = this.findBroadlyMatchedKey (auth, path);
|
3811
|
+
return this.safeString (auth, key, 'private');
|
3812
|
+
}
|
3813
|
+
|
3814
|
+
handleErrors (code, reason, url, method, headers, body, response, requestHeaders, requestBody) {
|
3815
|
+
if (!response) {
|
3816
|
+
return; // fallback to default error handler
|
3817
|
+
}
|
3818
|
+
const feedback = this.id + ' ' + body;
|
3819
|
+
if (code === 503) {
|
3820
|
+
// {"message":"name resolution failed"}
|
3821
|
+
throw new ExchangeNotAvailable (feedback);
|
3822
|
+
}
|
3823
|
+
//
|
3824
|
+
// {"error_message":"Order does not exist","result":"true","error_code":"35029","order_id":"-1"}
|
3825
|
+
//
|
3826
|
+
const message = this.safeString (response, 'message');
|
3827
|
+
const errorCode = this.safeString2 (response, 'code', 'error_code');
|
3828
|
+
const nonEmptyMessage = ((message !== undefined) && (message !== ''));
|
3829
|
+
const nonZeroErrorCode = (errorCode !== undefined) && (errorCode !== '0');
|
3830
|
+
if (nonEmptyMessage) {
|
3831
|
+
this.throwExactlyMatchedException (this.exceptions['exact'], message, feedback);
|
3832
|
+
this.throwBroadlyMatchedException (this.exceptions['broad'], message, feedback);
|
3833
|
+
}
|
3834
|
+
if (nonZeroErrorCode) {
|
3835
|
+
this.throwExactlyMatchedException (this.exceptions['exact'], errorCode, feedback);
|
3836
|
+
}
|
3837
|
+
if (nonZeroErrorCode || nonEmptyMessage) {
|
3838
|
+
throw new ExchangeError (feedback); // unknown message
|
3839
|
+
}
|
3840
|
+
}
|
3841
|
+
};
|