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/deribit.js
ADDED
@@ -0,0 +1,2148 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
// ---------------------------------------------------------------------------
|
4
|
+
|
5
|
+
const Exchange = require ('./base/Exchange');
|
6
|
+
const { TICK_SIZE } = require ('./base/functions/number');
|
7
|
+
const { AuthenticationError, ExchangeError, ArgumentsRequired, PermissionDenied, InvalidOrder, OrderNotFound, DDoSProtection, NotSupported, ExchangeNotAvailable, InsufficientFunds, BadRequest, InvalidAddress, OnMaintenance } = require ('./base/errors');
|
8
|
+
const Precise = require ('./base/Precise');
|
9
|
+
// ---------------------------------------------------------------------------
|
10
|
+
|
11
|
+
module.exports = class deribit extends Exchange {
|
12
|
+
describe () {
|
13
|
+
return this.deepExtend (super.describe (), {
|
14
|
+
'id': 'deribit',
|
15
|
+
'name': 'Deribit',
|
16
|
+
'countries': [ 'NL' ], // Netherlands
|
17
|
+
'version': 'v2',
|
18
|
+
'userAgent': undefined,
|
19
|
+
// 20 requests per second for non-matching-engine endpoints, 1000ms / 20 = 50ms between requests
|
20
|
+
// 5 requests per second for matching-engine endpoints, cost = (1000ms / rateLimit) / 5 = 4
|
21
|
+
'rateLimit': 50,
|
22
|
+
'has': {
|
23
|
+
'CORS': true,
|
24
|
+
'spot': false,
|
25
|
+
'margin': false,
|
26
|
+
'swap': undefined,
|
27
|
+
'future': undefined,
|
28
|
+
'option': undefined,
|
29
|
+
'cancelAllOrders': true,
|
30
|
+
'cancelOrder': true,
|
31
|
+
'createDepositAddress': true,
|
32
|
+
'createOrder': true,
|
33
|
+
'createStopLimitOrder': true,
|
34
|
+
'createStopMarketOrder': true,
|
35
|
+
'createStopOrder': true,
|
36
|
+
'editOrder': true,
|
37
|
+
'fetchBalance': true,
|
38
|
+
'fetchBorrowRate': false,
|
39
|
+
'fetchBorrowRateHistories': false,
|
40
|
+
'fetchBorrowRateHistory': false,
|
41
|
+
'fetchBorrowRates': false,
|
42
|
+
'fetchBorrowRatesPerSymbol': false,
|
43
|
+
'fetchClosedOrders': true,
|
44
|
+
'fetchDepositAddress': true,
|
45
|
+
'fetchDeposits': true,
|
46
|
+
'fetchHistoricalVolatility': true,
|
47
|
+
'fetchIndexOHLCV': false,
|
48
|
+
'fetchLeverageTiers': false,
|
49
|
+
'fetchMarkets': true,
|
50
|
+
'fetchMarkOHLCV': false,
|
51
|
+
'fetchMyTrades': true,
|
52
|
+
'fetchOHLCV': true,
|
53
|
+
'fetchOpenOrders': true,
|
54
|
+
'fetchOrder': true,
|
55
|
+
'fetchOrderBook': true,
|
56
|
+
'fetchOrders': undefined,
|
57
|
+
'fetchOrderTrades': true,
|
58
|
+
'fetchPosition': true,
|
59
|
+
'fetchPositions': true,
|
60
|
+
'fetchPremiumIndexOHLCV': false,
|
61
|
+
'fetchStatus': true,
|
62
|
+
'fetchTicker': true,
|
63
|
+
'fetchTickers': true,
|
64
|
+
'fetchTime': true,
|
65
|
+
'fetchTrades': true,
|
66
|
+
'fetchTradingFee': false,
|
67
|
+
'fetchTradingFees': true,
|
68
|
+
'fetchTransactions': undefined,
|
69
|
+
'fetchWithdrawals': true,
|
70
|
+
'withdraw': true,
|
71
|
+
},
|
72
|
+
'timeframes': {
|
73
|
+
'1m': '1',
|
74
|
+
'3m': '3',
|
75
|
+
'5m': '5',
|
76
|
+
'10m': '10',
|
77
|
+
'15m': '15',
|
78
|
+
'30m': '30',
|
79
|
+
'1h': '60',
|
80
|
+
'2h': '120',
|
81
|
+
'3h': '180',
|
82
|
+
'6h': '360',
|
83
|
+
'12h': '720',
|
84
|
+
'1d': '1D',
|
85
|
+
},
|
86
|
+
'urls': {
|
87
|
+
'test': 'https://test.deribit.com',
|
88
|
+
'logo': 'https://user-images.githubusercontent.com/1294454/41933112-9e2dd65a-798b-11e8-8440-5bab2959fcb8.jpg',
|
89
|
+
'api': 'https://www.deribit.com',
|
90
|
+
'www': 'https://www.deribit.com',
|
91
|
+
'doc': [
|
92
|
+
'https://docs.deribit.com/v2',
|
93
|
+
'https://github.com/deribit',
|
94
|
+
],
|
95
|
+
'fees': 'https://www.deribit.com/pages/information/fees',
|
96
|
+
'referral': {
|
97
|
+
'url': 'https://www.deribit.com/reg-1189.4038',
|
98
|
+
'discount': 0.1,
|
99
|
+
},
|
100
|
+
},
|
101
|
+
'api': {
|
102
|
+
'public': {
|
103
|
+
'get': {
|
104
|
+
// Authentication
|
105
|
+
'auth': 1,
|
106
|
+
'exchange_token': 1,
|
107
|
+
'fork_token': 1,
|
108
|
+
// Session management
|
109
|
+
'set_heartbeat': 1,
|
110
|
+
'disable_heartbeat': 1,
|
111
|
+
// Supporting
|
112
|
+
'get_time': 1,
|
113
|
+
'hello': 1,
|
114
|
+
'test': 1,
|
115
|
+
// Subscription management
|
116
|
+
'subscribe': 1,
|
117
|
+
'unsubscribe': 1,
|
118
|
+
'unsubscribe_all': 1,
|
119
|
+
// Account management
|
120
|
+
'get_announcements': 1,
|
121
|
+
// Market data
|
122
|
+
'get_book_summary_by_currency': 1,
|
123
|
+
'get_book_summary_by_instrument': 1,
|
124
|
+
'get_contract_size': 1,
|
125
|
+
'get_currencies': 1,
|
126
|
+
'get_delivery_prices': 1,
|
127
|
+
'get_funding_chart_data': 1,
|
128
|
+
'get_funding_rate_history': 1,
|
129
|
+
'get_funding_rate_value': 1,
|
130
|
+
'get_historical_volatility': 1,
|
131
|
+
'get_index': 1,
|
132
|
+
'get_index_price': 1,
|
133
|
+
'get_index_price_names': 1,
|
134
|
+
'get_instrument': 1,
|
135
|
+
'get_instruments': 1,
|
136
|
+
'get_last_settlements_by_currency': 1,
|
137
|
+
'get_last_settlements_by_instrument': 1,
|
138
|
+
'get_last_trades_by_currency': 1,
|
139
|
+
'get_last_trades_by_currency_and_time': 1,
|
140
|
+
'get_last_trades_by_instrument': 1,
|
141
|
+
'get_last_trades_by_instrument_and_time': 1,
|
142
|
+
'get_mark_price_history': 1,
|
143
|
+
'get_order_book': 1,
|
144
|
+
'get_trade_volumes': 1,
|
145
|
+
'get_tradingview_chart_data': 1,
|
146
|
+
'get_volatility_index_data': 1,
|
147
|
+
'ticker': 1,
|
148
|
+
},
|
149
|
+
},
|
150
|
+
'private': {
|
151
|
+
'get': {
|
152
|
+
// Authentication
|
153
|
+
'logout': 1,
|
154
|
+
// Session management
|
155
|
+
'enable_cancel_on_disconnect': 1,
|
156
|
+
'disable_cancel_on_disconnect': 1,
|
157
|
+
'get_cancel_on_disconnect': 1,
|
158
|
+
// Subscription management
|
159
|
+
'subscribe': 1,
|
160
|
+
'unsubscribe': 1,
|
161
|
+
'unsubscribe_all': 1,
|
162
|
+
// Account management
|
163
|
+
'change_api_key_name': 1,
|
164
|
+
'change_scope_in_api_key': 1,
|
165
|
+
'change_subaccount_name': 1,
|
166
|
+
'create_api_key': 1,
|
167
|
+
'create_subaccount': 1,
|
168
|
+
'disable_api_key': 1,
|
169
|
+
'disable_tfa_for_subaccount': 1,
|
170
|
+
'enable_affiliate_program': 1,
|
171
|
+
'enable_api_key': 1,
|
172
|
+
'get_access_log': 1,
|
173
|
+
'get_account_summary': 1,
|
174
|
+
'get_affiliate_program_info': 1,
|
175
|
+
'get_email_language': 1,
|
176
|
+
'get_new_announcements': 1,
|
177
|
+
'get_portfolio_margins': 1,
|
178
|
+
'get_position': 1,
|
179
|
+
'get_positions': 1,
|
180
|
+
'get_subaccounts': 1,
|
181
|
+
'get_subaccounts_details': 1,
|
182
|
+
'get_transaction_log': 1,
|
183
|
+
'list_api_keys': 1,
|
184
|
+
'remove_api_key': 1,
|
185
|
+
'remove_subaccount': 1,
|
186
|
+
'reset_api_key': 1,
|
187
|
+
'set_announcement_as_read': 1,
|
188
|
+
'set_api_key_as_default': 1,
|
189
|
+
'set_email_for_subaccount': 1,
|
190
|
+
'set_email_language': 1,
|
191
|
+
'set_password_for_subaccount': 1,
|
192
|
+
'toggle_notifications_from_subaccount': 1,
|
193
|
+
'toggle_subaccount_login': 1,
|
194
|
+
// Block Trade
|
195
|
+
'execute_block_trade': 4,
|
196
|
+
'get_block_trade': 1,
|
197
|
+
'get_last_block_trades_by_currency': 1,
|
198
|
+
'invalidate_block_trade_signature': 1,
|
199
|
+
'verify_block_trade': 4,
|
200
|
+
// Trading
|
201
|
+
'buy': 4,
|
202
|
+
'sell': 4,
|
203
|
+
'edit': 4,
|
204
|
+
'edit_by_label': 4,
|
205
|
+
'cancel': 4,
|
206
|
+
'cancel_all': 4,
|
207
|
+
'cancel_all_by_currency': 4,
|
208
|
+
'cancel_all_by_instrument': 4,
|
209
|
+
'cancel_by_label': 4,
|
210
|
+
'close_position': 4,
|
211
|
+
'get_margins': 1,
|
212
|
+
'get_mmp_config': 1,
|
213
|
+
'get_open_orders_by_currency': 1,
|
214
|
+
'get_open_orders_by_instrument': 1,
|
215
|
+
'get_order_history_by_currency': 1,
|
216
|
+
'get_order_history_by_instrument': 1,
|
217
|
+
'get_order_margin_by_ids': 1,
|
218
|
+
'get_order_state': 1,
|
219
|
+
'get_stop_order_history': 1, // deprecated
|
220
|
+
'get_trigger_order_history': 1,
|
221
|
+
'get_user_trades_by_currency': 1,
|
222
|
+
'get_user_trades_by_currency_and_time': 1,
|
223
|
+
'get_user_trades_by_instrument': 1,
|
224
|
+
'get_user_trades_by_instrument_and_time': 1,
|
225
|
+
'get_user_trades_by_order': 1,
|
226
|
+
'reset_mmp': 1,
|
227
|
+
'set_mmp_config': 1,
|
228
|
+
'get_settlement_history_by_instrument': 1,
|
229
|
+
'get_settlement_history_by_currency': 1,
|
230
|
+
// Wallet
|
231
|
+
'cancel_transfer_by_id': 1,
|
232
|
+
'cancel_withdrawal': 1,
|
233
|
+
'create_deposit_address': 1,
|
234
|
+
'get_current_deposit_address': 1,
|
235
|
+
'get_deposits': 1,
|
236
|
+
'get_transfers': 1,
|
237
|
+
'get_withdrawals': 1,
|
238
|
+
'submit_transfer_to_subaccount': 1,
|
239
|
+
'submit_transfer_to_user': 1,
|
240
|
+
'withdraw': 1,
|
241
|
+
},
|
242
|
+
},
|
243
|
+
},
|
244
|
+
'exceptions': {
|
245
|
+
// 0 or absent Success, No error.
|
246
|
+
'9999': PermissionDenied, // 'api_not_enabled' User didn't enable API for the Account.
|
247
|
+
'10000': AuthenticationError, // 'authorization_required' Authorization issue, invalid or absent signature etc.
|
248
|
+
'10001': ExchangeError, // 'error' Some general failure, no public information available.
|
249
|
+
'10002': InvalidOrder, // 'qty_too_low' Order quantity is too low.
|
250
|
+
'10003': InvalidOrder, // 'order_overlap' Rejection, order overlap is found and self-trading is not enabled.
|
251
|
+
'10004': OrderNotFound, // 'order_not_found' Attempt to operate with order that can't be found by specified id.
|
252
|
+
'10005': InvalidOrder, // 'price_too_low <Limit>' Price is too low, <Limit> defines current limit for the operation.
|
253
|
+
'10006': InvalidOrder, // 'price_too_low4idx <Limit>' Price is too low for current index, <Limit> defines current bottom limit for the operation.
|
254
|
+
'10007': InvalidOrder, // 'price_too_high <Limit>' Price is too high, <Limit> defines current up limit for the operation.
|
255
|
+
'10008': InvalidOrder, // 'price_too_high4idx <Limit>' Price is too high for current index, <Limit> defines current up limit for the operation.
|
256
|
+
'10009': InsufficientFunds, // 'not_enough_funds' Account has not enough funds for the operation.
|
257
|
+
'10010': OrderNotFound, // 'already_closed' Attempt of doing something with closed order.
|
258
|
+
'10011': InvalidOrder, // 'price_not_allowed' This price is not allowed for some reason.
|
259
|
+
'10012': InvalidOrder, // 'book_closed' Operation for instrument which order book had been closed.
|
260
|
+
'10013': PermissionDenied, // 'pme_max_total_open_orders <Limit>' Total limit of open orders has been exceeded, it is applicable for PME users.
|
261
|
+
'10014': PermissionDenied, // 'pme_max_future_open_orders <Limit>' Limit of count of futures' open orders has been exceeded, it is applicable for PME users.
|
262
|
+
'10015': PermissionDenied, // 'pme_max_option_open_orders <Limit>' Limit of count of options' open orders has been exceeded, it is applicable for PME users.
|
263
|
+
'10016': PermissionDenied, // 'pme_max_future_open_orders_size <Limit>' Limit of size for futures has been exceeded, it is applicable for PME users.
|
264
|
+
'10017': PermissionDenied, // 'pme_max_option_open_orders_size <Limit>' Limit of size for options has been exceeded, it is applicable for PME users.
|
265
|
+
'10018': PermissionDenied, // 'non_pme_max_future_position_size <Limit>' Limit of size for futures has been exceeded, it is applicable for non-PME users.
|
266
|
+
'10019': PermissionDenied, // 'locked_by_admin' Trading is temporary locked by admin.
|
267
|
+
'10020': ExchangeError, // 'invalid_or_unsupported_instrument' Instrument name is not valid.
|
268
|
+
'10021': InvalidOrder, // 'invalid_amount' Amount is not valid.
|
269
|
+
'10022': InvalidOrder, // 'invalid_quantity' quantity was not recognized as a valid number (for API v1).
|
270
|
+
'10023': InvalidOrder, // 'invalid_price' price was not recognized as a valid number.
|
271
|
+
'10024': InvalidOrder, // 'invalid_max_show' max_show parameter was not recognized as a valid number.
|
272
|
+
'10025': InvalidOrder, // 'invalid_order_id' Order id is missing or its format was not recognized as valid.
|
273
|
+
'10026': InvalidOrder, // 'price_precision_exceeded' Extra precision of the price is not supported.
|
274
|
+
'10027': InvalidOrder, // 'non_integer_contract_amount' Futures contract amount was not recognized as integer.
|
275
|
+
'10028': DDoSProtection, // 'too_many_requests' Allowed request rate has been exceeded.
|
276
|
+
'10029': OrderNotFound, // 'not_owner_of_order' Attempt to operate with not own order.
|
277
|
+
'10030': ExchangeError, // 'must_be_websocket_request' REST request where Websocket is expected.
|
278
|
+
'10031': ExchangeError, // 'invalid_args_for_instrument' Some of arguments are not recognized as valid.
|
279
|
+
'10032': InvalidOrder, // 'whole_cost_too_low' Total cost is too low.
|
280
|
+
'10033': NotSupported, // 'not_implemented' Method is not implemented yet.
|
281
|
+
'10034': InvalidOrder, // 'stop_price_too_high' Stop price is too high.
|
282
|
+
'10035': InvalidOrder, // 'stop_price_too_low' Stop price is too low.
|
283
|
+
'10036': InvalidOrder, // 'invalid_max_show_amount' Max Show Amount is not valid.
|
284
|
+
'10040': ExchangeNotAvailable, // 'retry' Request can't be processed right now and should be retried.
|
285
|
+
'10041': OnMaintenance, // 'settlement_in_progress' Settlement is in progress. Every day at settlement time for several seconds, the system calculates user profits and updates balances. That time trading is paused for several seconds till the calculation is completed.
|
286
|
+
'10043': InvalidOrder, // 'price_wrong_tick' Price has to be rounded to a certain tick size.
|
287
|
+
'10044': InvalidOrder, // 'stop_price_wrong_tick' Stop Price has to be rounded to a certain tick size.
|
288
|
+
'10045': InvalidOrder, // 'can_not_cancel_liquidation_order' Liquidation order can't be canceled.
|
289
|
+
'10046': InvalidOrder, // 'can_not_edit_liquidation_order' Liquidation order can't be edited.
|
290
|
+
'10047': DDoSProtection, // 'matching_engine_queue_full' Reached limit of pending Matching Engine requests for user.
|
291
|
+
'10048': ExchangeError, // 'not_on_this_server' The requested operation is not available on this server.
|
292
|
+
'11008': InvalidOrder, // 'already_filled' This request is not allowed in regards to the filled order.
|
293
|
+
'11029': BadRequest, // 'invalid_arguments' Some invalid input has been detected.
|
294
|
+
'11030': ExchangeError, // 'other_reject <Reason>' Some rejects which are not considered as very often, more info may be specified in <Reason>.
|
295
|
+
'11031': ExchangeError, // 'other_error <Error>' Some errors which are not considered as very often, more info may be specified in <Error>.
|
296
|
+
'11035': DDoSProtection, // 'no_more_stops <Limit>' Allowed amount of stop orders has been exceeded.
|
297
|
+
'11036': InvalidOrder, // 'invalid_stoppx_for_index_or_last' Invalid StopPx (too high or too low) as to current index or market.
|
298
|
+
'11037': BadRequest, // 'outdated_instrument_for_IV_order' Instrument already not available for trading.
|
299
|
+
'11038': InvalidOrder, // 'no_adv_for_futures' Advanced orders are not available for futures.
|
300
|
+
'11039': InvalidOrder, // 'no_adv_postonly' Advanced post-only orders are not supported yet.
|
301
|
+
'11041': InvalidOrder, // 'not_adv_order' Advanced order properties can't be set if the order is not advanced.
|
302
|
+
'11042': PermissionDenied, // 'permission_denied' Permission for the operation has been denied.
|
303
|
+
'11043': BadRequest, // 'bad_argument' Bad argument has been passed.
|
304
|
+
'11044': InvalidOrder, // 'not_open_order' Attempt to do open order operations with the not open order.
|
305
|
+
'11045': BadRequest, // 'invalid_event' Event name has not been recognized.
|
306
|
+
'11046': BadRequest, // 'outdated_instrument' At several minutes to instrument expiration, corresponding advanced implied volatility orders are not allowed.
|
307
|
+
'11047': BadRequest, // 'unsupported_arg_combination' The specified combination of arguments is not supported.
|
308
|
+
'11048': ExchangeError, // 'wrong_max_show_for_option' Wrong Max Show for options.
|
309
|
+
'11049': BadRequest, // 'bad_arguments' Several bad arguments have been passed.
|
310
|
+
'11050': BadRequest, // 'bad_request' Request has not been parsed properly.
|
311
|
+
'11051': OnMaintenance, // 'system_maintenance' System is under maintenance.
|
312
|
+
'11052': ExchangeError, // 'subscribe_error_unsubscribed' Subscription error. However, subscription may fail without this error, please check list of subscribed channels returned, as some channels can be not subscribed due to wrong input or lack of permissions.
|
313
|
+
'11053': ExchangeError, // 'transfer_not_found' Specified transfer is not found.
|
314
|
+
'11090': InvalidAddress, // 'invalid_addr' Invalid address.
|
315
|
+
'11091': InvalidAddress, // 'invalid_transfer_address' Invalid addres for the transfer.
|
316
|
+
'11092': InvalidAddress, // 'address_already_exist' The address already exists.
|
317
|
+
'11093': DDoSProtection, // 'max_addr_count_exceeded' Limit of allowed addresses has been reached.
|
318
|
+
'11094': ExchangeError, // 'internal_server_error' Some unhandled error on server. Please report to admin. The details of the request will help to locate the problem.
|
319
|
+
'11095': ExchangeError, // 'disabled_deposit_address_creation' Deposit address creation has been disabled by admin.
|
320
|
+
'11096': ExchangeError, // 'address_belongs_to_user' Withdrawal instead of transfer.
|
321
|
+
'12000': AuthenticationError, // 'bad_tfa' Wrong TFA code
|
322
|
+
'12001': DDoSProtection, // 'too_many_subaccounts' Limit of subbacounts is reached.
|
323
|
+
'12002': ExchangeError, // 'wrong_subaccount_name' The input is not allowed as name of subaccount.
|
324
|
+
'12998': AuthenticationError, // 'tfa_over_limit' The number of failed TFA attempts is limited.
|
325
|
+
'12003': AuthenticationError, // 'login_over_limit' The number of failed login attempts is limited.
|
326
|
+
'12004': AuthenticationError, // 'registration_over_limit' The number of registration requests is limited.
|
327
|
+
'12005': AuthenticationError, // 'country_is_banned' The country is banned (possibly via IP check).
|
328
|
+
'12100': ExchangeError, // 'transfer_not_allowed' Transfer is not allowed. Possible wrong direction or other mistake.
|
329
|
+
'12999': AuthenticationError, // 'tfa_used' TFA code is correct but it is already used. Please, use next code.
|
330
|
+
'13000': AuthenticationError, // 'invalid_login' Login name is invalid (not allowed or it contains wrong characters).
|
331
|
+
'13001': AuthenticationError, // 'account_not_activated' Account must be activated.
|
332
|
+
'13002': PermissionDenied, // 'account_blocked' Account is blocked by admin.
|
333
|
+
'13003': AuthenticationError, // 'tfa_required' This action requires TFA authentication.
|
334
|
+
'13004': AuthenticationError, // 'invalid_credentials' Invalid credentials has been used.
|
335
|
+
'13005': AuthenticationError, // 'pwd_match_error' Password confirmation error.
|
336
|
+
'13006': AuthenticationError, // 'security_error' Invalid Security Code.
|
337
|
+
'13007': AuthenticationError, // 'user_not_found' User's security code has been changed or wrong.
|
338
|
+
'13008': ExchangeError, // 'request_failed' Request failed because of invalid input or internal failure.
|
339
|
+
'13009': AuthenticationError, // 'unauthorized' Wrong or expired authorization token or bad signature. For example, please check scope of the token, 'connection' scope can't be reused for other connections.
|
340
|
+
'13010': BadRequest, // 'value_required' Invalid input, missing value.
|
341
|
+
'13011': BadRequest, // 'value_too_short' Input is too short.
|
342
|
+
'13012': PermissionDenied, // 'unavailable_in_subaccount' Subaccount restrictions.
|
343
|
+
'13013': BadRequest, // 'invalid_phone_number' Unsupported or invalid phone number.
|
344
|
+
'13014': BadRequest, // 'cannot_send_sms' SMS sending failed -- phone number is wrong.
|
345
|
+
'13015': BadRequest, // 'invalid_sms_code' Invalid SMS code.
|
346
|
+
'13016': BadRequest, // 'invalid_input' Invalid input.
|
347
|
+
'13017': ExchangeError, // 'subscription_failed' Subscription hailed, invalid subscription parameters.
|
348
|
+
'13018': ExchangeError, // 'invalid_content_type' Invalid content type of the request.
|
349
|
+
'13019': ExchangeError, // 'orderbook_closed' Closed, expired order book.
|
350
|
+
'13020': ExchangeError, // 'not_found' Instrument is not found, invalid instrument name.
|
351
|
+
'13021': PermissionDenied, // 'forbidden' Not enough permissions to execute the request, forbidden.
|
352
|
+
'13025': ExchangeError, // 'method_switched_off_by_admin' API method temporarily switched off by administrator.
|
353
|
+
'-32602': BadRequest, // 'Invalid params' see JSON-RPC spec.
|
354
|
+
'-32601': BadRequest, // 'Method not found' see JSON-RPC spec.
|
355
|
+
'-32700': BadRequest, // 'Parse error' see JSON-RPC spec.
|
356
|
+
'-32000': BadRequest, // 'Missing params' see JSON-RPC spec.
|
357
|
+
},
|
358
|
+
'precisionMode': TICK_SIZE,
|
359
|
+
'options': {
|
360
|
+
'code': 'BTC',
|
361
|
+
'fetchBalance': {
|
362
|
+
'code': 'BTC',
|
363
|
+
},
|
364
|
+
'fetchPositions': {
|
365
|
+
'code': 'BTC',
|
366
|
+
},
|
367
|
+
},
|
368
|
+
});
|
369
|
+
}
|
370
|
+
|
371
|
+
async fetchTime (params = {}) {
|
372
|
+
const response = await this.publicGetGetTime (params);
|
373
|
+
//
|
374
|
+
// {
|
375
|
+
// jsonrpc: '2.0',
|
376
|
+
// result: 1583922446019,
|
377
|
+
// usIn: 1583922446019955,
|
378
|
+
// usOut: 1583922446019956,
|
379
|
+
// usDiff: 1,
|
380
|
+
// testnet: false
|
381
|
+
// }
|
382
|
+
//
|
383
|
+
return this.safeInteger (response, 'result');
|
384
|
+
}
|
385
|
+
|
386
|
+
codeFromOptions (methodName, params = {}) {
|
387
|
+
const defaultCode = this.safeValue (this.options, 'code', 'BTC');
|
388
|
+
const options = this.safeValue (this.options, methodName, {});
|
389
|
+
const code = this.safeValue (options, 'code', defaultCode);
|
390
|
+
return this.safeValue (params, 'code', code);
|
391
|
+
}
|
392
|
+
|
393
|
+
async fetchStatus (params = {}) {
|
394
|
+
const response = await this.publicGetStatus (params);
|
395
|
+
//
|
396
|
+
// {
|
397
|
+
// "jsonrpc": "2.0",
|
398
|
+
// "result": {
|
399
|
+
// "locked": "false" // true, partial, false
|
400
|
+
// },
|
401
|
+
// "usIn": 1650641690226788,
|
402
|
+
// "usOut": 1650641690226836,
|
403
|
+
// "usDiff": 48,
|
404
|
+
// "testnet": false
|
405
|
+
// }
|
406
|
+
//
|
407
|
+
const result = this.safeString (response, 'result');
|
408
|
+
const locked = this.safeString (result, 'locked');
|
409
|
+
const updateTime = this.safeIntegerProduct (response, 'usIn', 0.001, this.milliseconds ());
|
410
|
+
return {
|
411
|
+
'status': (locked === 'false') ? 'ok' : 'maintenance',
|
412
|
+
'updated': updateTime,
|
413
|
+
'eta': undefined,
|
414
|
+
'url': undefined,
|
415
|
+
'info': response,
|
416
|
+
};
|
417
|
+
}
|
418
|
+
|
419
|
+
async fetchMarkets (params = {}) {
|
420
|
+
const currenciesResponse = await this.publicGetGetCurrencies (params);
|
421
|
+
//
|
422
|
+
// {
|
423
|
+
// jsonrpc: '2.0',
|
424
|
+
// result: [
|
425
|
+
// {
|
426
|
+
// withdrawal_priorities: [
|
427
|
+
// { value: 0.15, name: 'very_low' },
|
428
|
+
// { value: 1.5, name: 'very_high' },
|
429
|
+
// ],
|
430
|
+
// withdrawal_fee: 0.0005,
|
431
|
+
// min_withdrawal_fee: 0.0005,
|
432
|
+
// min_confirmations: 1,
|
433
|
+
// fee_precision: 4,
|
434
|
+
// currency_long: 'Bitcoin',
|
435
|
+
// currency: 'BTC',
|
436
|
+
// coin_type: 'BITCOIN'
|
437
|
+
// }
|
438
|
+
// ],
|
439
|
+
// usIn: 1583761588590479,
|
440
|
+
// usOut: 1583761588590544,
|
441
|
+
// usDiff: 65,
|
442
|
+
// testnet: false
|
443
|
+
// }
|
444
|
+
//
|
445
|
+
const currenciesResult = this.safeValue (currenciesResponse, 'result', []);
|
446
|
+
const result = [];
|
447
|
+
for (let i = 0; i < currenciesResult.length; i++) {
|
448
|
+
const currencyId = this.safeString (currenciesResult[i], 'currency');
|
449
|
+
const request = {
|
450
|
+
'currency': currencyId,
|
451
|
+
};
|
452
|
+
const instrumentsResponse = await this.publicGetGetInstruments (this.extend (request, params));
|
453
|
+
//
|
454
|
+
// {
|
455
|
+
// "jsonrpc":"2.0",
|
456
|
+
// "result":[
|
457
|
+
// {
|
458
|
+
// "tick_size":0.0005,
|
459
|
+
// "taker_commission":0.0003,
|
460
|
+
// "strike":52000.0,
|
461
|
+
// "settlement_period":"month",
|
462
|
+
// "settlement_currency":"BTC",
|
463
|
+
// "quote_currency":"BTC",
|
464
|
+
// "option_type":"put", // put, call
|
465
|
+
// "min_trade_amount":0.1,
|
466
|
+
// "maker_commission":0.0003,
|
467
|
+
// "kind":"option",
|
468
|
+
// "is_active":true,
|
469
|
+
// "instrument_name":"BTC-24JUN22-52000-P",
|
470
|
+
// "expiration_timestamp":1656057600000,
|
471
|
+
// "creation_timestamp":1648199543000,
|
472
|
+
// "counter_currency":"USD",
|
473
|
+
// "contract_size":1.0,
|
474
|
+
// "block_trade_commission":0.0003,
|
475
|
+
// "base_currency":"BTC"
|
476
|
+
// },
|
477
|
+
// {
|
478
|
+
// "tick_size":0.5,
|
479
|
+
// "taker_commission":0.0005,
|
480
|
+
// "settlement_period":"month", // month, week
|
481
|
+
// "settlement_currency":"BTC",
|
482
|
+
// "quote_currency":"USD",
|
483
|
+
// "min_trade_amount":10.0,
|
484
|
+
// "max_liquidation_commission":0.0075,
|
485
|
+
// "max_leverage":50,
|
486
|
+
// "maker_commission":0.0,
|
487
|
+
// "kind":"future",
|
488
|
+
// "is_active":true,
|
489
|
+
// "instrument_name":"BTC-27MAY22",
|
490
|
+
// "future_type":"reversed",
|
491
|
+
// "expiration_timestamp":1653638400000,
|
492
|
+
// "creation_timestamp":1648195209000,
|
493
|
+
// "counter_currency":"USD",
|
494
|
+
// "contract_size":10.0,
|
495
|
+
// "block_trade_commission":0.0001,
|
496
|
+
// "base_currency":"BTC"
|
497
|
+
// },
|
498
|
+
// {
|
499
|
+
// "tick_size":0.5,
|
500
|
+
// "taker_commission":0.0005,
|
501
|
+
// "settlement_period":"perpetual",
|
502
|
+
// "settlement_currency":"BTC",
|
503
|
+
// "quote_currency":"USD",
|
504
|
+
// "min_trade_amount":10.0,
|
505
|
+
// "max_liquidation_commission":0.0075,
|
506
|
+
// "max_leverage":50,
|
507
|
+
// "maker_commission":0.0,
|
508
|
+
// "kind":"future",
|
509
|
+
// "is_active":true,
|
510
|
+
// "instrument_name":"BTC-PERPETUAL",
|
511
|
+
// "future_type":"reversed",
|
512
|
+
// "expiration_timestamp":32503708800000,
|
513
|
+
// "creation_timestamp":1534242287000,
|
514
|
+
// "counter_currency":"USD",
|
515
|
+
// "contract_size":10.0,
|
516
|
+
// "block_trade_commission":0.0001,
|
517
|
+
// "base_currency":"BTC"
|
518
|
+
// },
|
519
|
+
// ],
|
520
|
+
// "usIn":1648691472831791,
|
521
|
+
// "usOut":1648691472831896,
|
522
|
+
// "usDiff":105,
|
523
|
+
// "testnet":false
|
524
|
+
// }
|
525
|
+
//
|
526
|
+
const instrumentsResult = this.safeValue (instrumentsResponse, 'result', []);
|
527
|
+
for (let k = 0; k < instrumentsResult.length; k++) {
|
528
|
+
const market = instrumentsResult[k];
|
529
|
+
const id = this.safeString (market, 'instrument_name');
|
530
|
+
const baseId = this.safeString (market, 'base_currency');
|
531
|
+
const quoteId = this.safeString (market, 'counter_currency');
|
532
|
+
const settleId = this.safeString (market, 'settlement_currency');
|
533
|
+
const base = this.safeCurrencyCode (baseId);
|
534
|
+
const quote = this.safeCurrencyCode (quoteId);
|
535
|
+
const settle = this.safeCurrencyCode (settleId);
|
536
|
+
const kind = this.safeString (market, 'kind');
|
537
|
+
const settlementPeriod = this.safeValue (market, 'settlement_period');
|
538
|
+
const swap = (settlementPeriod === 'perpetual');
|
539
|
+
const future = !swap && (kind === 'future');
|
540
|
+
const option = (kind === 'option');
|
541
|
+
let symbol = base + '/' + quote + ':' + settle;
|
542
|
+
const expiry = this.safeInteger (market, 'expiration_timestamp');
|
543
|
+
let strike = undefined;
|
544
|
+
let optionType = undefined;
|
545
|
+
let type = 'swap';
|
546
|
+
if (option || future) {
|
547
|
+
symbol = symbol + '-' + this.yymmdd (expiry, '');
|
548
|
+
if (option) {
|
549
|
+
type = 'option';
|
550
|
+
strike = this.safeNumber (market, 'strike');
|
551
|
+
optionType = this.safeString (market, 'option_type');
|
552
|
+
const letter = (optionType === 'call') ? 'C' : 'P';
|
553
|
+
symbol = symbol + ':' + this.numberToString (strike) + ':' + letter;
|
554
|
+
} else {
|
555
|
+
type = 'future';
|
556
|
+
}
|
557
|
+
}
|
558
|
+
const minTradeAmount = this.safeNumber (market, 'min_trade_amount');
|
559
|
+
const tickSize = this.safeNumber (market, 'tick_size');
|
560
|
+
result.push ({
|
561
|
+
'id': id,
|
562
|
+
'symbol': symbol,
|
563
|
+
'base': base,
|
564
|
+
'quote': quote,
|
565
|
+
'settle': settle,
|
566
|
+
'baseId': baseId,
|
567
|
+
'quoteId': quoteId,
|
568
|
+
'settleId': settleId,
|
569
|
+
'type': type,
|
570
|
+
'spot': false,
|
571
|
+
'margin': false,
|
572
|
+
'swap': swap,
|
573
|
+
'future': future,
|
574
|
+
'option': option,
|
575
|
+
'active': this.safeValue (market, 'is_active'),
|
576
|
+
'contract': true,
|
577
|
+
'linear': false,
|
578
|
+
'inverse': true,
|
579
|
+
'taker': this.safeNumber (market, 'taker_commission'),
|
580
|
+
'maker': this.safeNumber (market, 'maker_commission'),
|
581
|
+
'contractSize': this.safeNumber (market, 'contract_size'),
|
582
|
+
'expiry': expiry,
|
583
|
+
'expiryDatetime': this.iso8601 (expiry),
|
584
|
+
'strike': strike,
|
585
|
+
'optionType': optionType,
|
586
|
+
'precision': {
|
587
|
+
'amount': minTradeAmount,
|
588
|
+
'price': tickSize,
|
589
|
+
},
|
590
|
+
'limits': {
|
591
|
+
'leverage': {
|
592
|
+
'min': undefined,
|
593
|
+
'max': undefined,
|
594
|
+
},
|
595
|
+
'amount': {
|
596
|
+
'min': minTradeAmount,
|
597
|
+
'max': undefined,
|
598
|
+
},
|
599
|
+
'price': {
|
600
|
+
'min': tickSize,
|
601
|
+
'max': undefined,
|
602
|
+
},
|
603
|
+
'cost': {
|
604
|
+
'min': undefined,
|
605
|
+
'max': undefined,
|
606
|
+
},
|
607
|
+
},
|
608
|
+
'info': market,
|
609
|
+
});
|
610
|
+
}
|
611
|
+
}
|
612
|
+
return result;
|
613
|
+
}
|
614
|
+
|
615
|
+
parseBalance (response) {
|
616
|
+
const result = {
|
617
|
+
'info': response,
|
618
|
+
};
|
619
|
+
const balance = this.safeValue (response, 'result', {});
|
620
|
+
const currencyId = this.safeString (balance, 'currency');
|
621
|
+
const currencyCode = this.safeCurrencyCode (currencyId);
|
622
|
+
const account = this.account ();
|
623
|
+
account['free'] = this.safeString (balance, 'available_funds');
|
624
|
+
account['used'] = this.safeString (balance, 'maintenance_margin');
|
625
|
+
account['total'] = this.safeString (balance, 'equity');
|
626
|
+
result[currencyCode] = account;
|
627
|
+
return this.safeBalance (result);
|
628
|
+
}
|
629
|
+
|
630
|
+
async fetchBalance (params = {}) {
|
631
|
+
await this.loadMarkets ();
|
632
|
+
const code = this.codeFromOptions ('fetchBalance', params);
|
633
|
+
const currency = this.currency (code);
|
634
|
+
const request = {
|
635
|
+
'currency': currency['id'],
|
636
|
+
};
|
637
|
+
const response = await this.privateGetGetAccountSummary (this.extend (request, params));
|
638
|
+
//
|
639
|
+
// {
|
640
|
+
// jsonrpc: '2.0',
|
641
|
+
// result: {
|
642
|
+
// total_pl: 0,
|
643
|
+
// session_upl: 0,
|
644
|
+
// session_rpl: 0,
|
645
|
+
// session_funding: 0,
|
646
|
+
// portfolio_margining_enabled: false,
|
647
|
+
// options_vega: 0,
|
648
|
+
// options_theta: 0,
|
649
|
+
// options_session_upl: 0,
|
650
|
+
// options_session_rpl: 0,
|
651
|
+
// options_pl: 0,
|
652
|
+
// options_gamma: 0,
|
653
|
+
// options_delta: 0,
|
654
|
+
// margin_balance: 0.00062359,
|
655
|
+
// maintenance_margin: 0,
|
656
|
+
// limits: {
|
657
|
+
// non_matching_engine_burst: 300,
|
658
|
+
// non_matching_engine: 200,
|
659
|
+
// matching_engine_burst: 20,
|
660
|
+
// matching_engine: 2
|
661
|
+
// },
|
662
|
+
// initial_margin: 0,
|
663
|
+
// futures_session_upl: 0,
|
664
|
+
// futures_session_rpl: 0,
|
665
|
+
// futures_pl: 0,
|
666
|
+
// equity: 0.00062359,
|
667
|
+
// deposit_address: '13tUtNsJSZa1F5GeCmwBywVrymHpZispzw',
|
668
|
+
// delta_total: 0,
|
669
|
+
// currency: 'BTC',
|
670
|
+
// balance: 0.00062359,
|
671
|
+
// available_withdrawal_funds: 0.00062359,
|
672
|
+
// available_funds: 0.00062359
|
673
|
+
// },
|
674
|
+
// usIn: 1583775838115975,
|
675
|
+
// usOut: 1583775838116520,
|
676
|
+
// usDiff: 545,
|
677
|
+
// testnet: false
|
678
|
+
// }
|
679
|
+
//
|
680
|
+
return this.parseBalance (response);
|
681
|
+
}
|
682
|
+
|
683
|
+
async createDepositAddress (code, params = {}) {
|
684
|
+
await this.loadMarkets ();
|
685
|
+
const currency = this.currency (code);
|
686
|
+
const request = {
|
687
|
+
'currency': currency['id'],
|
688
|
+
};
|
689
|
+
const response = await this.privateGetCreateDepositAddress (this.extend (request, params));
|
690
|
+
//
|
691
|
+
// {
|
692
|
+
// 'jsonrpc': '2.0',
|
693
|
+
// 'id': 7538,
|
694
|
+
// 'result': {
|
695
|
+
// 'address': '2N8udZGBc1hLRCFsU9kGwMPpmYUwMFTuCwB',
|
696
|
+
// 'creation_timestamp': 1550575165170,
|
697
|
+
// 'currency': 'BTC',
|
698
|
+
// 'type': 'deposit'
|
699
|
+
// }
|
700
|
+
// }
|
701
|
+
//
|
702
|
+
const result = this.safeValue (response, 'result', {});
|
703
|
+
const address = this.safeString (result, 'address');
|
704
|
+
this.checkAddress (address);
|
705
|
+
return {
|
706
|
+
'currency': code,
|
707
|
+
'address': address,
|
708
|
+
'tag': undefined,
|
709
|
+
'info': response,
|
710
|
+
};
|
711
|
+
}
|
712
|
+
|
713
|
+
async fetchDepositAddress (code, params = {}) {
|
714
|
+
await this.loadMarkets ();
|
715
|
+
const currency = this.currency (code);
|
716
|
+
const request = {
|
717
|
+
'currency': currency['id'],
|
718
|
+
};
|
719
|
+
const response = await this.privateGetGetCurrentDepositAddress (this.extend (request, params));
|
720
|
+
//
|
721
|
+
// {
|
722
|
+
// jsonrpc: '2.0',
|
723
|
+
// result: {
|
724
|
+
// type: 'deposit',
|
725
|
+
// status: 'ready',
|
726
|
+
// requires_confirmation: true,
|
727
|
+
// currency: 'BTC',
|
728
|
+
// creation_timestamp: 1514694684651,
|
729
|
+
// address: '13tUtNsJSZa1F5GeCmwBywVrymHpZispzw'
|
730
|
+
// },
|
731
|
+
// usIn: 1583785137274288,
|
732
|
+
// usOut: 1583785137274454,
|
733
|
+
// usDiff: 166,
|
734
|
+
// testnet: false
|
735
|
+
// }
|
736
|
+
//
|
737
|
+
const result = this.safeValue (response, 'result', {});
|
738
|
+
const address = this.safeString (result, 'address');
|
739
|
+
this.checkAddress (address);
|
740
|
+
return {
|
741
|
+
'currency': code,
|
742
|
+
'address': address,
|
743
|
+
'tag': undefined,
|
744
|
+
'network': undefined,
|
745
|
+
'info': response,
|
746
|
+
};
|
747
|
+
}
|
748
|
+
|
749
|
+
parseTicker (ticker, market = undefined) {
|
750
|
+
//
|
751
|
+
// fetchTicker /public/ticker
|
752
|
+
//
|
753
|
+
// {
|
754
|
+
// timestamp: 1583778859480,
|
755
|
+
// stats: { volume: 60627.57263769, low: 7631.5, high: 8311.5 },
|
756
|
+
// state: 'open',
|
757
|
+
// settlement_price: 7903.21,
|
758
|
+
// open_interest: 111543850,
|
759
|
+
// min_price: 7634,
|
760
|
+
// max_price: 7866.51,
|
761
|
+
// mark_price: 7750.02,
|
762
|
+
// last_price: 7750.5,
|
763
|
+
// instrument_name: 'BTC-PERPETUAL',
|
764
|
+
// index_price: 7748.01,
|
765
|
+
// funding_8h: 0.0000026,
|
766
|
+
// current_funding: 0,
|
767
|
+
// best_bid_price: 7750,
|
768
|
+
// best_bid_amount: 19470,
|
769
|
+
// best_ask_price: 7750.5,
|
770
|
+
// best_ask_amount: 343280
|
771
|
+
// }
|
772
|
+
//
|
773
|
+
// fetchTicker /public/get_book_summary_by_instrument
|
774
|
+
// fetchTickers /public/get_book_summary_by_currency
|
775
|
+
//
|
776
|
+
// {
|
777
|
+
// volume: 124.1,
|
778
|
+
// underlying_price: 7856.445926872601,
|
779
|
+
// underlying_index: 'SYN.BTC-10MAR20',
|
780
|
+
// quote_currency: 'USD',
|
781
|
+
// open_interest: 121.8,
|
782
|
+
// mid_price: 0.01975,
|
783
|
+
// mark_price: 0.01984559,
|
784
|
+
// low: 0.0095,
|
785
|
+
// last: 0.0205,
|
786
|
+
// interest_rate: 0,
|
787
|
+
// instrument_name: 'BTC-10MAR20-7750-C',
|
788
|
+
// high: 0.0295,
|
789
|
+
// estimated_delivery_price: 7856.29,
|
790
|
+
// creation_timestamp: 1583783678366,
|
791
|
+
// bid_price: 0.0185,
|
792
|
+
// base_currency: 'BTC',
|
793
|
+
// ask_price: 0.021
|
794
|
+
// },
|
795
|
+
//
|
796
|
+
const timestamp = this.safeInteger2 (ticker, 'timestamp', 'creation_timestamp');
|
797
|
+
const marketId = this.safeString (ticker, 'instrument_name');
|
798
|
+
const symbol = this.safeSymbol (marketId, market);
|
799
|
+
const last = this.safeString2 (ticker, 'last_price', 'last');
|
800
|
+
const stats = this.safeValue (ticker, 'stats', ticker);
|
801
|
+
return this.safeTicker ({
|
802
|
+
'symbol': symbol,
|
803
|
+
'timestamp': timestamp,
|
804
|
+
'datetime': this.iso8601 (timestamp),
|
805
|
+
'high': this.safeString2 (stats, 'high', 'max_price'),
|
806
|
+
'low': this.safeString2 (stats, 'low', 'min_price'),
|
807
|
+
'bid': this.safeString2 (ticker, 'best_bid_price', 'bid_price'),
|
808
|
+
'bidVolume': this.safeString (ticker, 'best_bid_amount'),
|
809
|
+
'ask': this.safeString2 (ticker, 'best_ask_price', 'ask_price'),
|
810
|
+
'askVolume': this.safeString (ticker, 'best_ask_amount'),
|
811
|
+
'vwap': undefined,
|
812
|
+
'open': undefined,
|
813
|
+
'close': last,
|
814
|
+
'last': last,
|
815
|
+
'previousClose': undefined,
|
816
|
+
'change': undefined,
|
817
|
+
'percentage': undefined,
|
818
|
+
'average': undefined,
|
819
|
+
'baseVolume': undefined,
|
820
|
+
'quoteVolume': this.safeString (stats, 'volume'),
|
821
|
+
'info': ticker,
|
822
|
+
}, market, false);
|
823
|
+
}
|
824
|
+
|
825
|
+
async fetchTicker (symbol, params = {}) {
|
826
|
+
await this.loadMarkets ();
|
827
|
+
const market = this.market (symbol);
|
828
|
+
const request = {
|
829
|
+
'instrument_name': market['id'],
|
830
|
+
};
|
831
|
+
const response = await this.publicGetTicker (this.extend (request, params));
|
832
|
+
//
|
833
|
+
// {
|
834
|
+
// jsonrpc: '2.0',
|
835
|
+
// result: {
|
836
|
+
// timestamp: 1583778859480,
|
837
|
+
// stats: { volume: 60627.57263769, low: 7631.5, high: 8311.5 },
|
838
|
+
// state: 'open',
|
839
|
+
// settlement_price: 7903.21,
|
840
|
+
// open_interest: 111543850,
|
841
|
+
// min_price: 7634,
|
842
|
+
// max_price: 7866.51,
|
843
|
+
// mark_price: 7750.02,
|
844
|
+
// last_price: 7750.5,
|
845
|
+
// instrument_name: 'BTC-PERPETUAL',
|
846
|
+
// index_price: 7748.01,
|
847
|
+
// funding_8h: 0.0000026,
|
848
|
+
// current_funding: 0,
|
849
|
+
// best_bid_price: 7750,
|
850
|
+
// best_bid_amount: 19470,
|
851
|
+
// best_ask_price: 7750.5,
|
852
|
+
// best_ask_amount: 343280
|
853
|
+
// },
|
854
|
+
// usIn: 1583778859483941,
|
855
|
+
// usOut: 1583778859484075,
|
856
|
+
// usDiff: 134,
|
857
|
+
// testnet: false
|
858
|
+
// }
|
859
|
+
//
|
860
|
+
const result = this.safeValue (response, 'result');
|
861
|
+
return this.parseTicker (result, market);
|
862
|
+
}
|
863
|
+
|
864
|
+
async fetchTickers (symbols = undefined, params = {}) {
|
865
|
+
await this.loadMarkets ();
|
866
|
+
const code = this.codeFromOptions ('fetchTickers', params);
|
867
|
+
const currency = this.currency (code);
|
868
|
+
const request = {
|
869
|
+
'currency': currency['id'],
|
870
|
+
};
|
871
|
+
const response = await this.publicGetGetBookSummaryByCurrency (this.extend (request, params));
|
872
|
+
//
|
873
|
+
// {
|
874
|
+
// jsonrpc: '2.0',
|
875
|
+
// result: [
|
876
|
+
// {
|
877
|
+
// volume: 124.1,
|
878
|
+
// underlying_price: 7856.445926872601,
|
879
|
+
// underlying_index: 'SYN.BTC-10MAR20',
|
880
|
+
// quote_currency: 'USD',
|
881
|
+
// open_interest: 121.8,
|
882
|
+
// mid_price: 0.01975,
|
883
|
+
// mark_price: 0.01984559,
|
884
|
+
// low: 0.0095,
|
885
|
+
// last: 0.0205,
|
886
|
+
// interest_rate: 0,
|
887
|
+
// instrument_name: 'BTC-10MAR20-7750-C',
|
888
|
+
// high: 0.0295,
|
889
|
+
// estimated_delivery_price: 7856.29,
|
890
|
+
// creation_timestamp: 1583783678366,
|
891
|
+
// bid_price: 0.0185,
|
892
|
+
// base_currency: 'BTC',
|
893
|
+
// ask_price: 0.021
|
894
|
+
// },
|
895
|
+
// ],
|
896
|
+
// usIn: 1583783678361966,
|
897
|
+
// usOut: 1583783678372069,
|
898
|
+
// usDiff: 10103,
|
899
|
+
// testnet: false
|
900
|
+
// }
|
901
|
+
//
|
902
|
+
const result = this.safeValue (response, 'result', []);
|
903
|
+
const tickers = {};
|
904
|
+
for (let i = 0; i < result.length; i++) {
|
905
|
+
const ticker = this.parseTicker (result[i]);
|
906
|
+
const symbol = ticker['symbol'];
|
907
|
+
tickers[symbol] = ticker;
|
908
|
+
}
|
909
|
+
return this.filterByArray (tickers, 'symbol', symbols);
|
910
|
+
}
|
911
|
+
|
912
|
+
async fetchOHLCV (symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
|
913
|
+
await this.loadMarkets ();
|
914
|
+
const market = this.market (symbol);
|
915
|
+
const request = {
|
916
|
+
'instrument_name': market['id'],
|
917
|
+
'resolution': this.timeframes[timeframe],
|
918
|
+
};
|
919
|
+
const duration = this.parseTimeframe (timeframe);
|
920
|
+
const now = this.milliseconds ();
|
921
|
+
if (since === undefined) {
|
922
|
+
if (limit === undefined) {
|
923
|
+
throw new ArgumentsRequired (this.id + ' fetchOHLCV() requires a since argument or a limit argument');
|
924
|
+
} else {
|
925
|
+
request['start_timestamp'] = now - (limit - 1) * duration * 1000;
|
926
|
+
request['end_timestamp'] = now;
|
927
|
+
}
|
928
|
+
} else {
|
929
|
+
request['start_timestamp'] = since;
|
930
|
+
if (limit === undefined) {
|
931
|
+
request['end_timestamp'] = now;
|
932
|
+
} else {
|
933
|
+
request['end_timestamp'] = this.sum (since, limit * duration * 1000);
|
934
|
+
}
|
935
|
+
}
|
936
|
+
const response = await this.publicGetGetTradingviewChartData (this.extend (request, params));
|
937
|
+
//
|
938
|
+
// {
|
939
|
+
// jsonrpc: '2.0',
|
940
|
+
// result: {
|
941
|
+
// volume: [ 3.6680847969999992, 22.682721123, 3.011587939, 0 ],
|
942
|
+
// ticks: [ 1583916960000, 1583917020000, 1583917080000, 1583917140000 ],
|
943
|
+
// status: 'ok',
|
944
|
+
// open: [ 7834, 7839, 7833.5, 7833 ],
|
945
|
+
// low: [ 7834, 7833.5, 7832.5, 7833 ],
|
946
|
+
// high: [ 7839.5, 7839, 7833.5, 7833 ],
|
947
|
+
// cost: [ 28740, 177740, 23590, 0 ],
|
948
|
+
// close: [ 7839.5, 7833.5, 7833, 7833 ]
|
949
|
+
// },
|
950
|
+
// usIn: 1583917166709801,
|
951
|
+
// usOut: 1583917166710175,
|
952
|
+
// usDiff: 374,
|
953
|
+
// testnet: false
|
954
|
+
// }
|
955
|
+
//
|
956
|
+
const result = this.safeValue (response, 'result', {});
|
957
|
+
const ohlcvs = this.convertTradingViewToOHLCV (result, 'ticks', 'open', 'high', 'low', 'close', 'volume', true);
|
958
|
+
return this.parseOHLCVs (ohlcvs, market, timeframe, since, limit);
|
959
|
+
}
|
960
|
+
|
961
|
+
parseTrade (trade, market = undefined) {
|
962
|
+
//
|
963
|
+
// fetchTrades (public)
|
964
|
+
//
|
965
|
+
// {
|
966
|
+
// "trade_seq":132564271,
|
967
|
+
// "trade_id":"195402220",
|
968
|
+
// "timestamp":1639684927932,
|
969
|
+
// "tick_direction":0,
|
970
|
+
// "price":47946.5,
|
971
|
+
// "mark_price":47944.13,
|
972
|
+
// "instrument_name":"BTC-PERPETUAL",
|
973
|
+
// "index_price":47925.45,
|
974
|
+
// "direction":"buy",
|
975
|
+
// "amount":580.0
|
976
|
+
// }
|
977
|
+
//
|
978
|
+
//
|
979
|
+
// fetchMyTrades, fetchOrderTrades (private)
|
980
|
+
//
|
981
|
+
// {
|
982
|
+
// "trade_seq": 3,
|
983
|
+
// "trade_id": "ETH-34066",
|
984
|
+
// "timestamp": 1550219814585,
|
985
|
+
// "tick_direction": 1,
|
986
|
+
// "state": "open",
|
987
|
+
// "self_trade": false,
|
988
|
+
// "reduce_only": false,
|
989
|
+
// "price": 0.04,
|
990
|
+
// "post_only": false,
|
991
|
+
// "order_type": "limit",
|
992
|
+
// "order_id": "ETH-334607",
|
993
|
+
// "matching_id": null,
|
994
|
+
// "liquidity": "M",
|
995
|
+
// "iv": 56.83,
|
996
|
+
// "instrument_name": "ETH-22FEB19-120-C",
|
997
|
+
// "index_price": 121.37,
|
998
|
+
// "fee_currency": "ETH",
|
999
|
+
// "fee": 0.0011,
|
1000
|
+
// "direction": "buy",
|
1001
|
+
// "amount": 11
|
1002
|
+
// }
|
1003
|
+
//
|
1004
|
+
const id = this.safeString (trade, 'trade_id');
|
1005
|
+
const marketId = this.safeString (trade, 'instrument_name');
|
1006
|
+
const symbol = this.safeSymbol (marketId, market);
|
1007
|
+
const timestamp = this.safeInteger (trade, 'timestamp');
|
1008
|
+
const side = this.safeString (trade, 'direction');
|
1009
|
+
const priceString = this.safeString (trade, 'price');
|
1010
|
+
const amountString = this.safeString (trade, 'amount');
|
1011
|
+
const liquidity = this.safeString (trade, 'liquidity');
|
1012
|
+
let takerOrMaker = undefined;
|
1013
|
+
if (liquidity !== undefined) {
|
1014
|
+
// M = maker, T = taker, MT = both
|
1015
|
+
takerOrMaker = (liquidity === 'M') ? 'maker' : 'taker';
|
1016
|
+
}
|
1017
|
+
const feeCostString = this.safeString (trade, 'fee');
|
1018
|
+
let fee = undefined;
|
1019
|
+
if (feeCostString !== undefined) {
|
1020
|
+
const feeCurrencyId = this.safeString (trade, 'fee_currency');
|
1021
|
+
const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId);
|
1022
|
+
fee = {
|
1023
|
+
'cost': feeCostString,
|
1024
|
+
'currency': feeCurrencyCode,
|
1025
|
+
};
|
1026
|
+
}
|
1027
|
+
return this.safeTrade ({
|
1028
|
+
'id': id,
|
1029
|
+
'info': trade,
|
1030
|
+
'timestamp': timestamp,
|
1031
|
+
'datetime': this.iso8601 (timestamp),
|
1032
|
+
'symbol': symbol,
|
1033
|
+
'order': this.safeString (trade, 'order_id'),
|
1034
|
+
'type': this.safeString (trade, 'order_type'),
|
1035
|
+
'side': side,
|
1036
|
+
'takerOrMaker': takerOrMaker,
|
1037
|
+
'price': priceString,
|
1038
|
+
'amount': amountString,
|
1039
|
+
'cost': undefined,
|
1040
|
+
'fee': fee,
|
1041
|
+
}, market);
|
1042
|
+
}
|
1043
|
+
|
1044
|
+
async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) {
|
1045
|
+
await this.loadMarkets ();
|
1046
|
+
const market = this.market (symbol);
|
1047
|
+
const request = {
|
1048
|
+
'instrument_name': market['id'],
|
1049
|
+
'include_old': true,
|
1050
|
+
};
|
1051
|
+
const method = (since === undefined) ? 'publicGetGetLastTradesByInstrument' : 'publicGetGetLastTradesByInstrumentAndTime';
|
1052
|
+
if (since !== undefined) {
|
1053
|
+
request['start_timestamp'] = since;
|
1054
|
+
}
|
1055
|
+
if (limit !== undefined) {
|
1056
|
+
request['count'] = limit; // default 10
|
1057
|
+
}
|
1058
|
+
const response = await this[method] (this.extend (request, params));
|
1059
|
+
//
|
1060
|
+
// {
|
1061
|
+
// "jsonrpc":"2.0",
|
1062
|
+
// "result": {
|
1063
|
+
// "trades": [
|
1064
|
+
// {
|
1065
|
+
// "trade_seq":132564271,
|
1066
|
+
// "trade_id":"195402220",
|
1067
|
+
// "timestamp":1639684927932,
|
1068
|
+
// "tick_direction":0,
|
1069
|
+
// "price":47946.5,
|
1070
|
+
// "mark_price":47944.13,
|
1071
|
+
// "instrument_name":"BTC-PERPETUAL",
|
1072
|
+
// "index_price":47925.45,
|
1073
|
+
// "direction":"buy","amount":580.0
|
1074
|
+
// }
|
1075
|
+
// ],
|
1076
|
+
// "has_more":true
|
1077
|
+
// },
|
1078
|
+
// "usIn":1639684931934671,
|
1079
|
+
// "usOut":1639684931935337,
|
1080
|
+
// "usDiff":666,
|
1081
|
+
// "testnet":false
|
1082
|
+
// }
|
1083
|
+
//
|
1084
|
+
const result = this.safeValue (response, 'result', {});
|
1085
|
+
const trades = this.safeValue (result, 'trades', []);
|
1086
|
+
return this.parseTrades (trades, market, since, limit);
|
1087
|
+
}
|
1088
|
+
|
1089
|
+
async fetchTradingFees (params = {}) {
|
1090
|
+
await this.loadMarkets ();
|
1091
|
+
const code = this.codeFromOptions ('fetchTradingFees', params);
|
1092
|
+
const currency = this.currency (code);
|
1093
|
+
const request = {
|
1094
|
+
'currency': currency['id'],
|
1095
|
+
'extended': true,
|
1096
|
+
};
|
1097
|
+
const response = await this.privateGetGetAccountSummary (this.extend (request, params));
|
1098
|
+
//
|
1099
|
+
// {
|
1100
|
+
// jsonrpc: '2.0',
|
1101
|
+
// result: {
|
1102
|
+
// total_pl: 0,
|
1103
|
+
// session_upl: 0,
|
1104
|
+
// session_rpl: 0,
|
1105
|
+
// session_funding: 0,
|
1106
|
+
// portfolio_margining_enabled: false,
|
1107
|
+
// options_vega: 0,
|
1108
|
+
// options_theta: 0,
|
1109
|
+
// options_session_upl: 0,
|
1110
|
+
// options_session_rpl: 0,
|
1111
|
+
// options_pl: 0,
|
1112
|
+
// options_gamma: 0,
|
1113
|
+
// options_delta: 0,
|
1114
|
+
// margin_balance: 0.00062359,
|
1115
|
+
// maintenance_margin: 0,
|
1116
|
+
// limits: {
|
1117
|
+
// non_matching_engine_burst: 300,
|
1118
|
+
// non_matching_engine: 200,
|
1119
|
+
// matching_engine_burst: 20,
|
1120
|
+
// matching_engine: 2
|
1121
|
+
// },
|
1122
|
+
// initial_margin: 0,
|
1123
|
+
// futures_session_upl: 0,
|
1124
|
+
// futures_session_rpl: 0,
|
1125
|
+
// futures_pl: 0,
|
1126
|
+
// equity: 0.00062359,
|
1127
|
+
// deposit_address: '13tUtNsJSZa1F5GeCmwBywVrymHpZispzw',
|
1128
|
+
// delta_total: 0,
|
1129
|
+
// currency: 'BTC',
|
1130
|
+
// balance: 0.00062359,
|
1131
|
+
// available_withdrawal_funds: 0.00062359,
|
1132
|
+
// available_funds: 0.00062359,
|
1133
|
+
// fees: [
|
1134
|
+
// currency: '',
|
1135
|
+
// instrument_type: 'perpetual',
|
1136
|
+
// fee_type: 'relative',
|
1137
|
+
// maker_fee: 0,
|
1138
|
+
// taker_fee: 0,
|
1139
|
+
// ],
|
1140
|
+
// },
|
1141
|
+
// usIn: 1583775838115975,
|
1142
|
+
// usOut: 1583775838116520,
|
1143
|
+
// usDiff: 545,
|
1144
|
+
// testnet: false
|
1145
|
+
// }
|
1146
|
+
//
|
1147
|
+
const result = this.safeValue (response, 'result', {});
|
1148
|
+
const fees = this.safeValue (result, 'fees', []);
|
1149
|
+
let perpetualFee = {};
|
1150
|
+
let futureFee = {};
|
1151
|
+
let optionFee = {};
|
1152
|
+
for (let i = 0; i < fees.length; i++) {
|
1153
|
+
const fee = fees[i];
|
1154
|
+
const instrumentType = this.safeString (fee, 'instrument_type');
|
1155
|
+
if (instrumentType === 'future') {
|
1156
|
+
futureFee = {
|
1157
|
+
'info': fee,
|
1158
|
+
'maker': this.safeNumber (fee, 'maker_fee'),
|
1159
|
+
'taker': this.safeNumber (fee, 'taker_fee'),
|
1160
|
+
};
|
1161
|
+
} else if (instrumentType === 'perpetual') {
|
1162
|
+
perpetualFee = {
|
1163
|
+
'info': fee,
|
1164
|
+
'maker': this.safeNumber (fee, 'maker_fee'),
|
1165
|
+
'taker': this.safeNumber (fee, 'taker_fee'),
|
1166
|
+
};
|
1167
|
+
} else if (instrumentType === 'option') {
|
1168
|
+
optionFee = {
|
1169
|
+
'info': fee,
|
1170
|
+
'maker': this.safeNumber (fee, 'maker_fee'),
|
1171
|
+
'taker': this.safeNumber (fee, 'taker_fee'),
|
1172
|
+
};
|
1173
|
+
}
|
1174
|
+
}
|
1175
|
+
const parsedFees = {};
|
1176
|
+
for (let i = 0; i < this.symbols.length; i++) {
|
1177
|
+
const symbol = this.symbols[i];
|
1178
|
+
const market = this.market (symbol);
|
1179
|
+
let fee = {
|
1180
|
+
'info': market,
|
1181
|
+
'symbol': symbol,
|
1182
|
+
'percentage': true,
|
1183
|
+
'tierBased': true,
|
1184
|
+
'maker': market['maker'],
|
1185
|
+
'taker': market['taker'],
|
1186
|
+
};
|
1187
|
+
if (market['swap']) {
|
1188
|
+
fee = this.extend (fee, perpetualFee);
|
1189
|
+
} else if (market['future']) {
|
1190
|
+
fee = this.extend (fee, futureFee);
|
1191
|
+
} else if (market['option']) {
|
1192
|
+
fee = this.extend (fee, optionFee);
|
1193
|
+
}
|
1194
|
+
parsedFees[symbol] = fee;
|
1195
|
+
}
|
1196
|
+
return parsedFees;
|
1197
|
+
}
|
1198
|
+
|
1199
|
+
async fetchOrderBook (symbol, limit = undefined, params = {}) {
|
1200
|
+
await this.loadMarkets ();
|
1201
|
+
const market = this.market (symbol);
|
1202
|
+
const request = {
|
1203
|
+
'instrument_name': market['id'],
|
1204
|
+
};
|
1205
|
+
if (limit !== undefined) {
|
1206
|
+
request['depth'] = limit;
|
1207
|
+
}
|
1208
|
+
const response = await this.publicGetGetOrderBook (this.extend (request, params));
|
1209
|
+
//
|
1210
|
+
// {
|
1211
|
+
// jsonrpc: '2.0',
|
1212
|
+
// result: {
|
1213
|
+
// timestamp: 1583781354740,
|
1214
|
+
// stats: { volume: 61249.66735634, low: 7631.5, high: 8311.5 },
|
1215
|
+
// state: 'open',
|
1216
|
+
// settlement_price: 7903.21,
|
1217
|
+
// open_interest: 111536690,
|
1218
|
+
// min_price: 7695.13,
|
1219
|
+
// max_price: 7929.49,
|
1220
|
+
// mark_price: 7813.06,
|
1221
|
+
// last_price: 7814.5,
|
1222
|
+
// instrument_name: 'BTC-PERPETUAL',
|
1223
|
+
// index_price: 7810.12,
|
1224
|
+
// funding_8h: 0.0000031,
|
1225
|
+
// current_funding: 0,
|
1226
|
+
// change_id: 17538025952,
|
1227
|
+
// bids: [
|
1228
|
+
// [7814, 351820],
|
1229
|
+
// [7813.5, 207490],
|
1230
|
+
// [7813, 32160],
|
1231
|
+
// ],
|
1232
|
+
// best_bid_price: 7814,
|
1233
|
+
// best_bid_amount: 351820,
|
1234
|
+
// best_ask_price: 7814.5,
|
1235
|
+
// best_ask_amount: 11880,
|
1236
|
+
// asks: [
|
1237
|
+
// [7814.5, 11880],
|
1238
|
+
// [7815, 18100],
|
1239
|
+
// [7815.5, 2640],
|
1240
|
+
// ],
|
1241
|
+
// },
|
1242
|
+
// usIn: 1583781354745804,
|
1243
|
+
// usOut: 1583781354745932,
|
1244
|
+
// usDiff: 128,
|
1245
|
+
// testnet: false
|
1246
|
+
// }
|
1247
|
+
//
|
1248
|
+
const result = this.safeValue (response, 'result', {});
|
1249
|
+
const timestamp = this.safeInteger (result, 'timestamp');
|
1250
|
+
const nonce = this.safeInteger (result, 'change_id');
|
1251
|
+
const orderbook = this.parseOrderBook (result, symbol, timestamp);
|
1252
|
+
orderbook['nonce'] = nonce;
|
1253
|
+
return orderbook;
|
1254
|
+
}
|
1255
|
+
|
1256
|
+
parseOrderStatus (status) {
|
1257
|
+
const statuses = {
|
1258
|
+
'open': 'open',
|
1259
|
+
'cancelled': 'canceled',
|
1260
|
+
'filled': 'closed',
|
1261
|
+
'rejected': 'rejected',
|
1262
|
+
'untriggered': 'open',
|
1263
|
+
};
|
1264
|
+
return this.safeString (statuses, status, status);
|
1265
|
+
}
|
1266
|
+
|
1267
|
+
parseTimeInForce (timeInForce) {
|
1268
|
+
const timeInForces = {
|
1269
|
+
'good_til_cancelled': 'GTC',
|
1270
|
+
'fill_or_kill': 'FOK',
|
1271
|
+
'immediate_or_cancel': 'IOC',
|
1272
|
+
};
|
1273
|
+
return this.safeString (timeInForces, timeInForce, timeInForce);
|
1274
|
+
}
|
1275
|
+
|
1276
|
+
parseOrder (order, market = undefined) {
|
1277
|
+
//
|
1278
|
+
// createOrder
|
1279
|
+
//
|
1280
|
+
// {
|
1281
|
+
// "time_in_force": "good_til_cancelled",
|
1282
|
+
// "reduce_only": false,
|
1283
|
+
// "profit_loss": 0,
|
1284
|
+
// "price": "market_price",
|
1285
|
+
// "post_only": false,
|
1286
|
+
// "order_type": "market",
|
1287
|
+
// "order_state": "filled",
|
1288
|
+
// "order_id": "ETH-349249",
|
1289
|
+
// "max_show": 40,
|
1290
|
+
// "last_update_timestamp": 1550657341322,
|
1291
|
+
// "label": "market0000234",
|
1292
|
+
// "is_liquidation": false,
|
1293
|
+
// "instrument_name": "ETH-PERPETUAL",
|
1294
|
+
// "filled_amount": 40,
|
1295
|
+
// "direction": "buy",
|
1296
|
+
// "creation_timestamp": 1550657341322,
|
1297
|
+
// "commission": 0.000139,
|
1298
|
+
// "average_price": 143.81,
|
1299
|
+
// "api": true,
|
1300
|
+
// "amount": 40,
|
1301
|
+
// "trades": [], // injected by createOrder
|
1302
|
+
// }
|
1303
|
+
//
|
1304
|
+
const timestamp = this.safeInteger (order, 'creation_timestamp');
|
1305
|
+
const lastUpdate = this.safeInteger (order, 'last_update_timestamp');
|
1306
|
+
const id = this.safeString (order, 'order_id');
|
1307
|
+
let priceString = this.safeString (order, 'price');
|
1308
|
+
if (priceString === 'market_price') {
|
1309
|
+
// for market orders we get a literal 'market_price' string here
|
1310
|
+
priceString = undefined;
|
1311
|
+
}
|
1312
|
+
const averageString = this.safeString (order, 'average_price');
|
1313
|
+
const amountString = this.safeString (order, 'amount');
|
1314
|
+
const filledString = this.safeString (order, 'filled_amount');
|
1315
|
+
let lastTradeTimestamp = undefined;
|
1316
|
+
if (filledString !== undefined) {
|
1317
|
+
const isFilledPositive = Precise.stringGt (filledString, '0');
|
1318
|
+
if (isFilledPositive) {
|
1319
|
+
lastTradeTimestamp = lastUpdate;
|
1320
|
+
}
|
1321
|
+
}
|
1322
|
+
const status = this.parseOrderStatus (this.safeString (order, 'order_state'));
|
1323
|
+
const marketId = this.safeString (order, 'instrument_name');
|
1324
|
+
market = this.safeMarket (marketId, market);
|
1325
|
+
const side = this.safeStringLower (order, 'direction');
|
1326
|
+
let feeCostString = this.safeString (order, 'commission');
|
1327
|
+
let fee = undefined;
|
1328
|
+
if (feeCostString !== undefined) {
|
1329
|
+
feeCostString = Precise.stringAbs (feeCostString);
|
1330
|
+
fee = {
|
1331
|
+
'cost': feeCostString,
|
1332
|
+
'currency': market['base'],
|
1333
|
+
};
|
1334
|
+
}
|
1335
|
+
const type = this.safeString (order, 'order_type');
|
1336
|
+
// injected in createOrder
|
1337
|
+
let trades = this.safeValue (order, 'trades');
|
1338
|
+
if (trades !== undefined) {
|
1339
|
+
trades = this.parseTrades (trades, market);
|
1340
|
+
}
|
1341
|
+
const timeInForce = this.parseTimeInForce (this.safeString (order, 'time_in_force'));
|
1342
|
+
const stopPrice = this.safeValue (order, 'stop_price');
|
1343
|
+
const postOnly = this.safeValue (order, 'post_only');
|
1344
|
+
return this.safeOrder ({
|
1345
|
+
'info': order,
|
1346
|
+
'id': id,
|
1347
|
+
'clientOrderId': undefined,
|
1348
|
+
'timestamp': timestamp,
|
1349
|
+
'datetime': this.iso8601 (timestamp),
|
1350
|
+
'lastTradeTimestamp': lastTradeTimestamp,
|
1351
|
+
'symbol': market['symbol'],
|
1352
|
+
'type': type,
|
1353
|
+
'timeInForce': timeInForce,
|
1354
|
+
'postOnly': postOnly,
|
1355
|
+
'side': side,
|
1356
|
+
'price': priceString,
|
1357
|
+
'stopPrice': stopPrice,
|
1358
|
+
'amount': amountString,
|
1359
|
+
'cost': undefined,
|
1360
|
+
'average': averageString,
|
1361
|
+
'filled': filledString,
|
1362
|
+
'remaining': undefined,
|
1363
|
+
'status': status,
|
1364
|
+
'fee': fee,
|
1365
|
+
'trades': trades,
|
1366
|
+
}, market);
|
1367
|
+
}
|
1368
|
+
|
1369
|
+
async fetchOrder (id, symbol = undefined, params = {}) {
|
1370
|
+
await this.loadMarkets ();
|
1371
|
+
const request = {
|
1372
|
+
'order_id': id,
|
1373
|
+
};
|
1374
|
+
const response = await this.privateGetGetOrderState (this.extend (request, params));
|
1375
|
+
//
|
1376
|
+
// {
|
1377
|
+
// "jsonrpc": "2.0",
|
1378
|
+
// "id": 4316,
|
1379
|
+
// "result": {
|
1380
|
+
// "time_in_force": "good_til_cancelled",
|
1381
|
+
// "reduce_only": false,
|
1382
|
+
// "profit_loss": 0.051134,
|
1383
|
+
// "price": 118.94,
|
1384
|
+
// "post_only": false,
|
1385
|
+
// "order_type": "limit",
|
1386
|
+
// "order_state": "filled",
|
1387
|
+
// "order_id": "ETH-331562",
|
1388
|
+
// "max_show": 37,
|
1389
|
+
// "last_update_timestamp": 1550219810944,
|
1390
|
+
// "label": "",
|
1391
|
+
// "is_liquidation": false,
|
1392
|
+
// "instrument_name": "ETH-PERPETUAL",
|
1393
|
+
// "filled_amount": 37,
|
1394
|
+
// "direction": "sell",
|
1395
|
+
// "creation_timestamp": 1550219749176,
|
1396
|
+
// "commission": 0.000031,
|
1397
|
+
// "average_price": 118.94,
|
1398
|
+
// "api": false,
|
1399
|
+
// "amount": 37
|
1400
|
+
// }
|
1401
|
+
// }
|
1402
|
+
//
|
1403
|
+
const result = this.safeValue (response, 'result');
|
1404
|
+
return this.parseOrder (result);
|
1405
|
+
}
|
1406
|
+
|
1407
|
+
async createOrder (symbol, type, side, amount, price = undefined, params = {}) {
|
1408
|
+
await this.loadMarkets ();
|
1409
|
+
const market = this.market (symbol);
|
1410
|
+
const request = {
|
1411
|
+
'instrument_name': market['id'],
|
1412
|
+
// for perpetual and futures the amount is in USD
|
1413
|
+
// for options it is in corresponding cryptocurrency contracts, e.g., BTC or ETH
|
1414
|
+
'amount': this.amountToPrecision (symbol, amount),
|
1415
|
+
'type': type, // limit, stop_limit, market, stop_market, default is limit
|
1416
|
+
// 'label': 'string', // user-defined label for the order (maximum 64 characters)
|
1417
|
+
// 'price': this.priceToPrecision (symbol, 123.45), // only for limit and stop_limit orders
|
1418
|
+
// 'time_in_force' : 'good_til_cancelled', // fill_or_kill, immediate_or_cancel
|
1419
|
+
// 'max_show': 123.45, // max amount within an order to be shown to other customers, 0 for invisible order
|
1420
|
+
// 'post_only': false, // if the new price would cause the order to be filled immediately (as taker), the price will be changed to be just below the spread.
|
1421
|
+
// 'reject_post_only': false, // if true the order is put to order book unmodified or request is rejected
|
1422
|
+
// 'reduce_only': false, // if true, the order is intended to only reduce a current position
|
1423
|
+
// 'stop_price': false, // stop price, required for stop_limit orders
|
1424
|
+
// 'trigger': 'index_price', // mark_price, last_price, required for stop_limit orders
|
1425
|
+
// 'advanced': 'usd', // 'implv', advanced option order type, options only
|
1426
|
+
};
|
1427
|
+
let priceIsRequired = false;
|
1428
|
+
let stopPriceIsRequired = false;
|
1429
|
+
if (type === 'limit') {
|
1430
|
+
priceIsRequired = true;
|
1431
|
+
} else if (type === 'stop_limit') {
|
1432
|
+
priceIsRequired = true;
|
1433
|
+
stopPriceIsRequired = true;
|
1434
|
+
}
|
1435
|
+
if (priceIsRequired) {
|
1436
|
+
if (price !== undefined) {
|
1437
|
+
request['price'] = this.priceToPrecision (symbol, price);
|
1438
|
+
} else {
|
1439
|
+
throw new ArgumentsRequired (this.id + ' createOrder() requires a price argument for a ' + type + ' order');
|
1440
|
+
}
|
1441
|
+
}
|
1442
|
+
if (stopPriceIsRequired) {
|
1443
|
+
const stopPrice = this.safeNumber2 (params, 'stop_price', 'stopPrice');
|
1444
|
+
if (stopPrice === undefined) {
|
1445
|
+
throw new ArgumentsRequired (this.id + ' createOrder() requires a stop_price or stopPrice param for a ' + type + ' order');
|
1446
|
+
} else {
|
1447
|
+
request['stop_price'] = this.priceToPrecision (symbol, stopPrice);
|
1448
|
+
}
|
1449
|
+
params = this.omit (params, [ 'stop_price', 'stopPrice' ]);
|
1450
|
+
}
|
1451
|
+
const method = 'privateGet' + this.capitalize (side);
|
1452
|
+
const response = await this[method] (this.extend (request, params));
|
1453
|
+
//
|
1454
|
+
// {
|
1455
|
+
// "jsonrpc": "2.0",
|
1456
|
+
// "id": 5275,
|
1457
|
+
// "result": {
|
1458
|
+
// "trades": [
|
1459
|
+
// {
|
1460
|
+
// "trade_seq": 14151,
|
1461
|
+
// "trade_id": "ETH-37435",
|
1462
|
+
// "timestamp": 1550657341322,
|
1463
|
+
// "tick_direction": 2,
|
1464
|
+
// "state": "closed",
|
1465
|
+
// "self_trade": false,
|
1466
|
+
// "price": 143.81,
|
1467
|
+
// "order_type": "market",
|
1468
|
+
// "order_id": "ETH-349249",
|
1469
|
+
// "matching_id": null,
|
1470
|
+
// "liquidity": "T",
|
1471
|
+
// "label": "market0000234",
|
1472
|
+
// "instrument_name": "ETH-PERPETUAL",
|
1473
|
+
// "index_price": 143.73,
|
1474
|
+
// "fee_currency": "ETH",
|
1475
|
+
// "fee": 0.000139,
|
1476
|
+
// "direction": "buy",
|
1477
|
+
// "amount": 40
|
1478
|
+
// }
|
1479
|
+
// ],
|
1480
|
+
// "order": {
|
1481
|
+
// "time_in_force": "good_til_cancelled",
|
1482
|
+
// "reduce_only": false,
|
1483
|
+
// "profit_loss": 0,
|
1484
|
+
// "price": "market_price",
|
1485
|
+
// "post_only": false,
|
1486
|
+
// "order_type": "market",
|
1487
|
+
// "order_state": "filled",
|
1488
|
+
// "order_id": "ETH-349249",
|
1489
|
+
// "max_show": 40,
|
1490
|
+
// "last_update_timestamp": 1550657341322,
|
1491
|
+
// "label": "market0000234",
|
1492
|
+
// "is_liquidation": false,
|
1493
|
+
// "instrument_name": "ETH-PERPETUAL",
|
1494
|
+
// "filled_amount": 40,
|
1495
|
+
// "direction": "buy",
|
1496
|
+
// "creation_timestamp": 1550657341322,
|
1497
|
+
// "commission": 0.000139,
|
1498
|
+
// "average_price": 143.81,
|
1499
|
+
// "api": true,
|
1500
|
+
// "amount": 40
|
1501
|
+
// }
|
1502
|
+
// }
|
1503
|
+
// }
|
1504
|
+
//
|
1505
|
+
const result = this.safeValue (response, 'result', {});
|
1506
|
+
const order = this.safeValue (result, 'order');
|
1507
|
+
const trades = this.safeValue (result, 'trades', []);
|
1508
|
+
order['trades'] = trades;
|
1509
|
+
return this.parseOrder (order, market);
|
1510
|
+
}
|
1511
|
+
|
1512
|
+
async editOrder (id, symbol, type, side, amount = undefined, price = undefined, params = {}) {
|
1513
|
+
if (amount === undefined) {
|
1514
|
+
throw new ArgumentsRequired (this.id + ' editOrder() requires an amount argument');
|
1515
|
+
}
|
1516
|
+
if (price === undefined) {
|
1517
|
+
throw new ArgumentsRequired (this.id + ' editOrder() requires a price argument');
|
1518
|
+
}
|
1519
|
+
await this.loadMarkets ();
|
1520
|
+
const request = {
|
1521
|
+
'order_id': id,
|
1522
|
+
// for perpetual and futures the amount is in USD
|
1523
|
+
// for options it is in corresponding cryptocurrency contracts, e.g., BTC or ETH
|
1524
|
+
'amount': this.amountToPrecision (symbol, amount),
|
1525
|
+
'price': this.priceToPrecision (symbol, price), // required
|
1526
|
+
// 'post_only': false, // if the new price would cause the order to be filled immediately (as taker), the price will be changed to be just below the spread.
|
1527
|
+
// 'reject_post_only': false, // if true the order is put to order book unmodified or request is rejected
|
1528
|
+
// 'reduce_only': false, // if true, the order is intended to only reduce a current position
|
1529
|
+
// 'stop_price': false, // stop price, required for stop_limit orders
|
1530
|
+
// 'advanced': 'usd', // 'implv', advanced option order type, options only
|
1531
|
+
};
|
1532
|
+
const response = await this.privateGetEdit (this.extend (request, params));
|
1533
|
+
const result = this.safeValue (response, 'result', {});
|
1534
|
+
const order = this.safeValue (result, 'order');
|
1535
|
+
const trades = this.safeValue (result, 'trades', []);
|
1536
|
+
order['trades'] = trades;
|
1537
|
+
return this.parseOrder (order);
|
1538
|
+
}
|
1539
|
+
|
1540
|
+
async cancelOrder (id, symbol = undefined, params = {}) {
|
1541
|
+
await this.loadMarkets ();
|
1542
|
+
const request = {
|
1543
|
+
'order_id': id,
|
1544
|
+
};
|
1545
|
+
const response = await this.privateGetCancel (this.extend (request, params));
|
1546
|
+
const result = this.safeValue (response, 'result', {});
|
1547
|
+
return this.parseOrder (result);
|
1548
|
+
}
|
1549
|
+
|
1550
|
+
async cancelAllOrders (symbol = undefined, params = {}) {
|
1551
|
+
await this.loadMarkets ();
|
1552
|
+
const request = {};
|
1553
|
+
let method = undefined;
|
1554
|
+
if (symbol === undefined) {
|
1555
|
+
method = 'privateGetCancelAll';
|
1556
|
+
} else {
|
1557
|
+
method = 'privateGetCancelAllByInstrument';
|
1558
|
+
const market = this.market (symbol);
|
1559
|
+
request['instrument_name'] = market['id'];
|
1560
|
+
}
|
1561
|
+
const response = await this[method] (this.extend (request, params));
|
1562
|
+
return response;
|
1563
|
+
}
|
1564
|
+
|
1565
|
+
async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
1566
|
+
await this.loadMarkets ();
|
1567
|
+
const request = {};
|
1568
|
+
let market = undefined;
|
1569
|
+
let method = undefined;
|
1570
|
+
if (symbol === undefined) {
|
1571
|
+
const code = this.codeFromOptions ('fetchOpenOrders', params);
|
1572
|
+
const currency = this.currency (code);
|
1573
|
+
request['currency'] = currency['id'];
|
1574
|
+
method = 'privateGetGetOpenOrdersByCurrency';
|
1575
|
+
} else {
|
1576
|
+
market = this.market (symbol);
|
1577
|
+
request['instrument_name'] = market['id'];
|
1578
|
+
method = 'privateGetGetOpenOrdersByInstrument';
|
1579
|
+
}
|
1580
|
+
const response = await this[method] (this.extend (request, params));
|
1581
|
+
const result = this.safeValue (response, 'result', []);
|
1582
|
+
return this.parseOrders (result, market, since, limit);
|
1583
|
+
}
|
1584
|
+
|
1585
|
+
async fetchClosedOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
1586
|
+
await this.loadMarkets ();
|
1587
|
+
const request = {};
|
1588
|
+
let market = undefined;
|
1589
|
+
let method = undefined;
|
1590
|
+
if (symbol === undefined) {
|
1591
|
+
const code = this.codeFromOptions ('fetchClosedOrders', params);
|
1592
|
+
const currency = this.currency (code);
|
1593
|
+
request['currency'] = currency['id'];
|
1594
|
+
method = 'privateGetGetOrderHistoryByCurrency';
|
1595
|
+
} else {
|
1596
|
+
market = this.market (symbol);
|
1597
|
+
request['instrument_name'] = market['id'];
|
1598
|
+
method = 'privateGetGetOrderHistoryByInstrument';
|
1599
|
+
}
|
1600
|
+
const response = await this[method] (this.extend (request, params));
|
1601
|
+
const result = this.safeValue (response, 'result', []);
|
1602
|
+
return this.parseOrders (result, market, since, limit);
|
1603
|
+
}
|
1604
|
+
|
1605
|
+
async fetchOrderTrades (id, symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
1606
|
+
await this.loadMarkets ();
|
1607
|
+
const request = {
|
1608
|
+
'order_id': id,
|
1609
|
+
};
|
1610
|
+
const response = await this.privateGetGetUserTradesByOrder (this.extend (request, params));
|
1611
|
+
//
|
1612
|
+
// {
|
1613
|
+
// "jsonrpc": "2.0",
|
1614
|
+
// "id": 9367,
|
1615
|
+
// "result": {
|
1616
|
+
// "trades": [
|
1617
|
+
// {
|
1618
|
+
// "trade_seq": 3,
|
1619
|
+
// "trade_id": "ETH-34066",
|
1620
|
+
// "timestamp": 1550219814585,
|
1621
|
+
// "tick_direction": 1,
|
1622
|
+
// "state": "open",
|
1623
|
+
// "self_trade": false,
|
1624
|
+
// "reduce_only": false,
|
1625
|
+
// "price": 0.04,
|
1626
|
+
// "post_only": false,
|
1627
|
+
// "order_type": "limit",
|
1628
|
+
// "order_id": "ETH-334607",
|
1629
|
+
// "matching_id": null,
|
1630
|
+
// "liquidity": "M",
|
1631
|
+
// "iv": 56.83,
|
1632
|
+
// "instrument_name": "ETH-22FEB19-120-C",
|
1633
|
+
// "index_price": 121.37,
|
1634
|
+
// "fee_currency": "ETH",
|
1635
|
+
// "fee": 0.0011,
|
1636
|
+
// "direction": "buy",
|
1637
|
+
// "amount": 11
|
1638
|
+
// },
|
1639
|
+
// ],
|
1640
|
+
// "has_more": true
|
1641
|
+
// }
|
1642
|
+
// }
|
1643
|
+
//
|
1644
|
+
const result = this.safeValue (response, 'result', {});
|
1645
|
+
return this.parseTrades (result, undefined, since, limit);
|
1646
|
+
}
|
1647
|
+
|
1648
|
+
async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
1649
|
+
await this.loadMarkets ();
|
1650
|
+
const request = {
|
1651
|
+
'include_old': true,
|
1652
|
+
};
|
1653
|
+
let market = undefined;
|
1654
|
+
let method = undefined;
|
1655
|
+
if (symbol === undefined) {
|
1656
|
+
const code = this.codeFromOptions ('fetchMyTrades', params);
|
1657
|
+
const currency = this.currency (code);
|
1658
|
+
request['currency'] = currency['id'];
|
1659
|
+
if (since === undefined) {
|
1660
|
+
method = 'privateGetGetUserTradesByCurrency';
|
1661
|
+
} else {
|
1662
|
+
method = 'privateGetGetUserTradesByCurrencyAndTime';
|
1663
|
+
request['start_timestamp'] = since;
|
1664
|
+
}
|
1665
|
+
} else {
|
1666
|
+
market = this.market (symbol);
|
1667
|
+
request['instrument_name'] = market['id'];
|
1668
|
+
if (since === undefined) {
|
1669
|
+
method = 'privateGetGetUserTradesByInstrument';
|
1670
|
+
} else {
|
1671
|
+
method = 'privateGetGetUserTradesByInstrumentAndTime';
|
1672
|
+
request['start_timestamp'] = since;
|
1673
|
+
}
|
1674
|
+
}
|
1675
|
+
if (limit !== undefined) {
|
1676
|
+
request['count'] = limit; // default 10
|
1677
|
+
}
|
1678
|
+
const response = await this[method] (this.extend (request, params));
|
1679
|
+
//
|
1680
|
+
// {
|
1681
|
+
// "jsonrpc": "2.0",
|
1682
|
+
// "id": 9367,
|
1683
|
+
// "result": {
|
1684
|
+
// "trades": [
|
1685
|
+
// {
|
1686
|
+
// "trade_seq": 3,
|
1687
|
+
// "trade_id": "ETH-34066",
|
1688
|
+
// "timestamp": 1550219814585,
|
1689
|
+
// "tick_direction": 1,
|
1690
|
+
// "state": "open",
|
1691
|
+
// "self_trade": false,
|
1692
|
+
// "reduce_only": false,
|
1693
|
+
// "price": 0.04,
|
1694
|
+
// "post_only": false,
|
1695
|
+
// "order_type": "limit",
|
1696
|
+
// "order_id": "ETH-334607",
|
1697
|
+
// "matching_id": null,
|
1698
|
+
// "liquidity": "M",
|
1699
|
+
// "iv": 56.83,
|
1700
|
+
// "instrument_name": "ETH-22FEB19-120-C",
|
1701
|
+
// "index_price": 121.37,
|
1702
|
+
// "fee_currency": "ETH",
|
1703
|
+
// "fee": 0.0011,
|
1704
|
+
// "direction": "buy",
|
1705
|
+
// "amount": 11
|
1706
|
+
// },
|
1707
|
+
// ],
|
1708
|
+
// "has_more": true
|
1709
|
+
// }
|
1710
|
+
// }
|
1711
|
+
//
|
1712
|
+
const result = this.safeValue (response, 'result', {});
|
1713
|
+
const trades = this.safeValue (result, 'trades', []);
|
1714
|
+
return this.parseTrades (trades, market, since, limit);
|
1715
|
+
}
|
1716
|
+
|
1717
|
+
async fetchDeposits (code = undefined, since = undefined, limit = undefined, params = {}) {
|
1718
|
+
if (code === undefined) {
|
1719
|
+
throw new ArgumentsRequired (this.id + ' fetchDeposits() requires a currency code argument');
|
1720
|
+
}
|
1721
|
+
await this.loadMarkets ();
|
1722
|
+
const currency = this.currency (code);
|
1723
|
+
const request = {
|
1724
|
+
'currency': currency['id'],
|
1725
|
+
};
|
1726
|
+
if (limit !== undefined) {
|
1727
|
+
request['count'] = limit;
|
1728
|
+
}
|
1729
|
+
const response = await this.privateGetGetDeposits (this.extend (request, params));
|
1730
|
+
//
|
1731
|
+
// {
|
1732
|
+
// "jsonrpc": "2.0",
|
1733
|
+
// "id": 5611,
|
1734
|
+
// "result": {
|
1735
|
+
// "count": 1,
|
1736
|
+
// "data": [
|
1737
|
+
// {
|
1738
|
+
// "address": "2N35qDKDY22zmJq9eSyiAerMD4enJ1xx6ax",
|
1739
|
+
// "amount": 5,
|
1740
|
+
// "currency": "BTC",
|
1741
|
+
// "received_timestamp": 1549295017670,
|
1742
|
+
// "state": "completed",
|
1743
|
+
// "transaction_id": "230669110fdaf0a0dbcdc079b6b8b43d5af29cc73683835b9bc6b3406c065fda",
|
1744
|
+
// "updated_timestamp": 1549295130159
|
1745
|
+
// }
|
1746
|
+
// ]
|
1747
|
+
// }
|
1748
|
+
// }
|
1749
|
+
//
|
1750
|
+
const result = this.safeValue (response, 'result', {});
|
1751
|
+
const data = this.safeValue (result, 'data', []);
|
1752
|
+
return this.parseTransactions (data, currency, since, limit, params);
|
1753
|
+
}
|
1754
|
+
|
1755
|
+
async fetchWithdrawals (code = undefined, since = undefined, limit = undefined, params = {}) {
|
1756
|
+
if (code === undefined) {
|
1757
|
+
throw new ArgumentsRequired (this.id + ' fetchWithdrawals() requires a currency code argument');
|
1758
|
+
}
|
1759
|
+
await this.loadMarkets ();
|
1760
|
+
const currency = this.currency (code);
|
1761
|
+
const request = {
|
1762
|
+
'currency': currency['id'],
|
1763
|
+
};
|
1764
|
+
if (limit !== undefined) {
|
1765
|
+
request['count'] = limit;
|
1766
|
+
}
|
1767
|
+
const response = await this.privateGetGetWithdrawals (this.extend (request, params));
|
1768
|
+
//
|
1769
|
+
// {
|
1770
|
+
// "jsonrpc": "2.0",
|
1771
|
+
// "id": 2745,
|
1772
|
+
// "result": {
|
1773
|
+
// "count": 1,
|
1774
|
+
// "data": [
|
1775
|
+
// {
|
1776
|
+
// "address": "2NBqqD5GRJ8wHy1PYyCXTe9ke5226FhavBz",
|
1777
|
+
// "amount": 0.5,
|
1778
|
+
// "confirmed_timestamp": null,
|
1779
|
+
// "created_timestamp": 1550571443070,
|
1780
|
+
// "currency": "BTC",
|
1781
|
+
// "fee": 0.0001,
|
1782
|
+
// "id": 1,
|
1783
|
+
// "priority": 0.15,
|
1784
|
+
// "state": "unconfirmed",
|
1785
|
+
// "transaction_id": null,
|
1786
|
+
// "updated_timestamp": 1550571443070
|
1787
|
+
// }
|
1788
|
+
// ]
|
1789
|
+
// }
|
1790
|
+
// }
|
1791
|
+
//
|
1792
|
+
const result = this.safeValue (response, 'result', {});
|
1793
|
+
const data = this.safeValue (result, 'data', []);
|
1794
|
+
return this.parseTransactions (data, currency, since, limit, params);
|
1795
|
+
}
|
1796
|
+
|
1797
|
+
parseTransactionStatus (status) {
|
1798
|
+
const statuses = {
|
1799
|
+
'completed': 'ok',
|
1800
|
+
'unconfirmed': 'pending',
|
1801
|
+
};
|
1802
|
+
return this.safeString (statuses, status, status);
|
1803
|
+
}
|
1804
|
+
|
1805
|
+
parseTransaction (transaction, currency = undefined) {
|
1806
|
+
//
|
1807
|
+
// fetchWithdrawals
|
1808
|
+
//
|
1809
|
+
// {
|
1810
|
+
// "address": "2NBqqD5GRJ8wHy1PYyCXTe9ke5226FhavBz",
|
1811
|
+
// "amount": 0.5,
|
1812
|
+
// "confirmed_timestamp": null,
|
1813
|
+
// "created_timestamp": 1550571443070,
|
1814
|
+
// "currency": "BTC",
|
1815
|
+
// "fee": 0.0001,
|
1816
|
+
// "id": 1,
|
1817
|
+
// "priority": 0.15,
|
1818
|
+
// "state": "unconfirmed",
|
1819
|
+
// "transaction_id": null,
|
1820
|
+
// "updated_timestamp": 1550571443070
|
1821
|
+
// }
|
1822
|
+
//
|
1823
|
+
// fetchDeposits
|
1824
|
+
//
|
1825
|
+
// {
|
1826
|
+
// "address": "2N35qDKDY22zmJq9eSyiAerMD4enJ1xx6ax",
|
1827
|
+
// "amount": 5,
|
1828
|
+
// "currency": "BTC",
|
1829
|
+
// "received_timestamp": 1549295017670,
|
1830
|
+
// "state": "completed",
|
1831
|
+
// "transaction_id": "230669110fdaf0a0dbcdc079b6b8b43d5af29cc73683835b9bc6b3406c065fda",
|
1832
|
+
// "updated_timestamp": 1549295130159
|
1833
|
+
// }
|
1834
|
+
//
|
1835
|
+
const currencyId = this.safeString (transaction, 'currency');
|
1836
|
+
const code = this.safeCurrencyCode (currencyId, currency);
|
1837
|
+
const timestamp = this.safeInteger2 (transaction, 'created_timestamp', 'received_timestamp');
|
1838
|
+
const updated = this.safeInteger (transaction, 'updated_timestamp');
|
1839
|
+
const status = this.parseTransactionStatus (this.safeString (transaction, 'state'));
|
1840
|
+
const address = this.safeString (transaction, 'address');
|
1841
|
+
const feeCost = this.safeNumber (transaction, 'fee');
|
1842
|
+
let type = 'deposit';
|
1843
|
+
let fee = undefined;
|
1844
|
+
if (feeCost !== undefined) {
|
1845
|
+
type = 'withdrawal';
|
1846
|
+
fee = {
|
1847
|
+
'cost': feeCost,
|
1848
|
+
'currency': code,
|
1849
|
+
};
|
1850
|
+
}
|
1851
|
+
return {
|
1852
|
+
'info': transaction,
|
1853
|
+
'id': this.safeString (transaction, 'id'),
|
1854
|
+
'txid': this.safeString (transaction, 'transaction_id'),
|
1855
|
+
'timestamp': timestamp,
|
1856
|
+
'datetime': this.iso8601 (timestamp),
|
1857
|
+
'address': address,
|
1858
|
+
'addressTo': address,
|
1859
|
+
'addressFrom': undefined,
|
1860
|
+
'tag': undefined,
|
1861
|
+
'tagTo': undefined,
|
1862
|
+
'tagFrom': undefined,
|
1863
|
+
'type': type,
|
1864
|
+
'amount': this.safeNumber (transaction, 'amount'),
|
1865
|
+
'currency': code,
|
1866
|
+
'status': status,
|
1867
|
+
'updated': updated,
|
1868
|
+
'fee': fee,
|
1869
|
+
};
|
1870
|
+
}
|
1871
|
+
|
1872
|
+
parsePosition (position, market = undefined) {
|
1873
|
+
//
|
1874
|
+
// {
|
1875
|
+
// "jsonrpc": "2.0",
|
1876
|
+
// "id": 404,
|
1877
|
+
// "result": {
|
1878
|
+
// "average_price": 0,
|
1879
|
+
// "delta": 0,
|
1880
|
+
// "direction": "buy",
|
1881
|
+
// "estimated_liquidation_price": 0,
|
1882
|
+
// "floating_profit_loss": 0,
|
1883
|
+
// "index_price": 3555.86,
|
1884
|
+
// "initial_margin": 0,
|
1885
|
+
// "instrument_name": "BTC-PERPETUAL",
|
1886
|
+
// "leverage": 100,
|
1887
|
+
// "kind": "future",
|
1888
|
+
// "maintenance_margin": 0,
|
1889
|
+
// "mark_price": 3556.62,
|
1890
|
+
// "open_orders_margin": 0.000165889,
|
1891
|
+
// "realized_profit_loss": 0,
|
1892
|
+
// "settlement_price": 3555.44,
|
1893
|
+
// "size": 0,
|
1894
|
+
// "size_currency": 0,
|
1895
|
+
// "total_profit_loss": 0
|
1896
|
+
// }
|
1897
|
+
// }
|
1898
|
+
//
|
1899
|
+
const contract = this.safeString (position, 'instrument_name');
|
1900
|
+
market = this.safeMarket (contract, market);
|
1901
|
+
const size = this.safeString (position, 'size');
|
1902
|
+
let side = this.safeString (position, 'direction');
|
1903
|
+
side = (side === 'buy') ? 'long' : 'short';
|
1904
|
+
const maintenanceRate = this.safeString (position, 'maintenance_margin');
|
1905
|
+
const markPrice = this.safeString (position, 'mark_price');
|
1906
|
+
const notionalString = Precise.stringMul (markPrice, size);
|
1907
|
+
const unrealisedPnl = this.safeString (position, 'floating_profit_loss');
|
1908
|
+
const initialMarginString = this.safeString (position, 'initial_margin');
|
1909
|
+
const percentage = Precise.stringMul (Precise.stringDiv (unrealisedPnl, initialMarginString), '100');
|
1910
|
+
const currentTime = this.milliseconds ();
|
1911
|
+
return {
|
1912
|
+
'info': position,
|
1913
|
+
'symbol': this.safeString (market, 'symbol'),
|
1914
|
+
'timestamp': currentTime,
|
1915
|
+
'datetime': this.iso8601 (currentTime),
|
1916
|
+
'initialMargin': this.parseNumber (initialMarginString),
|
1917
|
+
'initialMarginPercentage': this.parseNumber (Precise.stringDiv (initialMarginString, notionalString)),
|
1918
|
+
'maintenanceMargin': this.parseNumber (Precise.stringMul (maintenanceRate, notionalString)),
|
1919
|
+
'maintenanceMarginPercentage': this.parseNumber (maintenanceRate),
|
1920
|
+
'entryPrice': this.safeString (position, 'average_price'),
|
1921
|
+
'notional': this.parseNumber (notionalString),
|
1922
|
+
'leverage': this.safeNumber (position, 'leverage'),
|
1923
|
+
'unrealizedPnl': this.parseNumber (unrealisedPnl),
|
1924
|
+
'contracts': this.parseNumber (size), // in USD for perpetuals on deribit
|
1925
|
+
'contractSize': this.safeValue (market, 'contractSize'),
|
1926
|
+
'marginRatio': undefined,
|
1927
|
+
'liquidationPrice': this.safeNumber (position, 'estimated_liquidation_price'),
|
1928
|
+
'markPrice': markPrice,
|
1929
|
+
'collateral': undefined,
|
1930
|
+
'marginType': undefined,
|
1931
|
+
'side': side,
|
1932
|
+
'percentage': this.parseNumber (percentage),
|
1933
|
+
};
|
1934
|
+
}
|
1935
|
+
|
1936
|
+
async fetchPosition (symbol, params = {}) {
|
1937
|
+
await this.loadMarkets ();
|
1938
|
+
const market = this.market (symbol);
|
1939
|
+
const request = {
|
1940
|
+
'instrument_name': market['id'],
|
1941
|
+
};
|
1942
|
+
const response = await this.privateGetGetPosition (this.extend (request, params));
|
1943
|
+
//
|
1944
|
+
// {
|
1945
|
+
// "jsonrpc": "2.0",
|
1946
|
+
// "id": 404,
|
1947
|
+
// "result": {
|
1948
|
+
// "average_price": 0,
|
1949
|
+
// "delta": 0,
|
1950
|
+
// "direction": "buy",
|
1951
|
+
// "estimated_liquidation_price": 0,
|
1952
|
+
// "floating_profit_loss": 0,
|
1953
|
+
// "index_price": 3555.86,
|
1954
|
+
// "initial_margin": 0,
|
1955
|
+
// "instrument_name": "BTC-PERPETUAL",
|
1956
|
+
// "leverage": 100,
|
1957
|
+
// "kind": "future",
|
1958
|
+
// "maintenance_margin": 0,
|
1959
|
+
// "mark_price": 3556.62,
|
1960
|
+
// "open_orders_margin": 0.000165889,
|
1961
|
+
// "realized_profit_loss": 0,
|
1962
|
+
// "settlement_price": 3555.44,
|
1963
|
+
// "size": 0,
|
1964
|
+
// "size_currency": 0,
|
1965
|
+
// "total_profit_loss": 0
|
1966
|
+
// }
|
1967
|
+
// }
|
1968
|
+
//
|
1969
|
+
const result = this.safeValue (response, 'result');
|
1970
|
+
return this.parsePosition (result);
|
1971
|
+
}
|
1972
|
+
|
1973
|
+
parsePositions (positions) {
|
1974
|
+
const result = [];
|
1975
|
+
for (let i = 0; i < positions.length; i++) {
|
1976
|
+
result.push (this.parsePosition (positions[i]));
|
1977
|
+
}
|
1978
|
+
return result;
|
1979
|
+
}
|
1980
|
+
|
1981
|
+
async fetchPositions (symbols = undefined, params = {}) {
|
1982
|
+
await this.loadMarkets ();
|
1983
|
+
let code = undefined;
|
1984
|
+
if (symbols === undefined) {
|
1985
|
+
code = this.codeFromOptions ('fetchPositions', params);
|
1986
|
+
} else if (typeof symbols === 'string') {
|
1987
|
+
code = symbols;
|
1988
|
+
} else {
|
1989
|
+
if (Array.isArray (symbols)) {
|
1990
|
+
const length = symbols.length;
|
1991
|
+
if (length !== 1) {
|
1992
|
+
throw new BadRequest (this.id + ' fetchPositions() symbols argument cannot contain more than 1 symbol');
|
1993
|
+
}
|
1994
|
+
const market = this.market (symbols[0]);
|
1995
|
+
code = market['base'];
|
1996
|
+
}
|
1997
|
+
}
|
1998
|
+
const currency = this.currency (code);
|
1999
|
+
const request = {
|
2000
|
+
'currency': currency['id'],
|
2001
|
+
// "kind" : "future", "option"
|
2002
|
+
};
|
2003
|
+
const response = await this.privateGetGetPositions (this.extend (request, params));
|
2004
|
+
//
|
2005
|
+
// {
|
2006
|
+
// "jsonrpc": "2.0",
|
2007
|
+
// "id": 2236,
|
2008
|
+
// "result": [
|
2009
|
+
// {
|
2010
|
+
// "average_price": 7440.18,
|
2011
|
+
// "delta": 0.006687487,
|
2012
|
+
// "direction": "buy",
|
2013
|
+
// "estimated_liquidation_price": 1.74,
|
2014
|
+
// "floating_profit_loss": 0,
|
2015
|
+
// "index_price": 7466.79,
|
2016
|
+
// "initial_margin": 0.000197283,
|
2017
|
+
// "instrument_name": "BTC-PERPETUAL",
|
2018
|
+
// "kind": "future",
|
2019
|
+
// "leverage": 34,
|
2020
|
+
// "maintenance_margin": 0.000143783,
|
2021
|
+
// "mark_price": 7476.65,
|
2022
|
+
// "open_orders_margin": 0.000197288,
|
2023
|
+
// "realized_funding": -1e-8,
|
2024
|
+
// "realized_profit_loss": -9e-9,
|
2025
|
+
// "settlement_price": 7476.65,
|
2026
|
+
// "size": 50,
|
2027
|
+
// "size_currency": 0.006687487,
|
2028
|
+
// "total_profit_loss": 0.000032781
|
2029
|
+
// },
|
2030
|
+
// ]
|
2031
|
+
// }
|
2032
|
+
//
|
2033
|
+
const result = this.safeValue (response, 'result');
|
2034
|
+
return this.parsePositions (result);
|
2035
|
+
}
|
2036
|
+
|
2037
|
+
async fetchHistoricalVolatility (code, params = {}) {
|
2038
|
+
await this.loadMarkets ();
|
2039
|
+
const currency = this.currency (code);
|
2040
|
+
const request = {
|
2041
|
+
'currency': currency['id'],
|
2042
|
+
};
|
2043
|
+
const response = await this.publicGetGetHistoricalVolatility (this.extend (request, params));
|
2044
|
+
//
|
2045
|
+
// {
|
2046
|
+
// "jsonrpc": "2.0",
|
2047
|
+
// "result": [
|
2048
|
+
// [1640142000000,63.828320460740585],
|
2049
|
+
// [1640142000000,63.828320460740585],
|
2050
|
+
// [1640145600000,64.03821964123213]
|
2051
|
+
// ],
|
2052
|
+
// "usIn": 1641515379467734,
|
2053
|
+
// "usOut": 1641515379468095,
|
2054
|
+
// "usDiff": 361,
|
2055
|
+
// "testnet": false
|
2056
|
+
// }
|
2057
|
+
//
|
2058
|
+
const volatilityResult = this.safeValue (response, 'result', {});
|
2059
|
+
const result = [];
|
2060
|
+
for (let i = 0; i < volatilityResult.length; i++) {
|
2061
|
+
const timestamp = this.safeInteger (volatilityResult[i], 0);
|
2062
|
+
const volatility = this.safeNumber (volatilityResult[i], 1);
|
2063
|
+
result.push ({
|
2064
|
+
'info': response,
|
2065
|
+
'timestamp': timestamp,
|
2066
|
+
'datetime': this.iso8601 (timestamp),
|
2067
|
+
'volatility': volatility,
|
2068
|
+
});
|
2069
|
+
}
|
2070
|
+
return result;
|
2071
|
+
}
|
2072
|
+
|
2073
|
+
async withdraw (code, amount, address, tag = undefined, params = {}) {
|
2074
|
+
[ tag, params ] = this.handleWithdrawTagAndParams (tag, params);
|
2075
|
+
this.checkAddress (address);
|
2076
|
+
await this.loadMarkets ();
|
2077
|
+
const currency = this.currency (code);
|
2078
|
+
const request = {
|
2079
|
+
'currency': currency['id'],
|
2080
|
+
'address': address, // must be in the address book
|
2081
|
+
'amount': amount,
|
2082
|
+
// 'priority': 'high', // low, mid, high, very_high, extreme_high, insane
|
2083
|
+
// 'tfa': '123456', // if enabled
|
2084
|
+
};
|
2085
|
+
if (this.twofa !== undefined) {
|
2086
|
+
request['tfa'] = this.oath ();
|
2087
|
+
}
|
2088
|
+
const response = await this.privateGetWithdraw (this.extend (request, params));
|
2089
|
+
return this.parseTransaction (response, currency);
|
2090
|
+
}
|
2091
|
+
|
2092
|
+
nonce () {
|
2093
|
+
return this.milliseconds ();
|
2094
|
+
}
|
2095
|
+
|
2096
|
+
sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
|
2097
|
+
let request = '/' + 'api/' + this.version + '/' + api + '/' + path;
|
2098
|
+
if (api === 'public') {
|
2099
|
+
if (Object.keys (params).length) {
|
2100
|
+
request += '?' + this.urlencode (params);
|
2101
|
+
}
|
2102
|
+
}
|
2103
|
+
if (api === 'private') {
|
2104
|
+
this.checkRequiredCredentials ();
|
2105
|
+
const nonce = this.nonce ().toString ();
|
2106
|
+
const timestamp = this.milliseconds ().toString ();
|
2107
|
+
const requestBody = '';
|
2108
|
+
if (Object.keys (params).length) {
|
2109
|
+
request += '?' + this.urlencode (params);
|
2110
|
+
}
|
2111
|
+
const requestData = method + "\n" + request + "\n" + requestBody + "\n"; // eslint-disable-line quotes
|
2112
|
+
const auth = timestamp + "\n" + nonce + "\n" + requestData; // eslint-disable-line quotes
|
2113
|
+
const signature = this.hmac (this.encode (auth), this.encode (this.secret), 'sha256');
|
2114
|
+
headers = {
|
2115
|
+
'Authorization': 'deri-hmac-sha256 id=' + this.apiKey + ',ts=' + timestamp + ',sig=' + signature + ',' + 'nonce=' + nonce,
|
2116
|
+
};
|
2117
|
+
}
|
2118
|
+
const url = this.urls['api'] + request;
|
2119
|
+
return { 'url': url, 'method': method, 'body': body, 'headers': headers };
|
2120
|
+
}
|
2121
|
+
|
2122
|
+
handleErrors (httpCode, reason, url, method, headers, body, response, requestHeaders, requestBody) {
|
2123
|
+
if (!response) {
|
2124
|
+
return; // fallback to default error handler
|
2125
|
+
}
|
2126
|
+
//
|
2127
|
+
// {
|
2128
|
+
// jsonrpc: '2.0',
|
2129
|
+
// error: {
|
2130
|
+
// message: 'Invalid params',
|
2131
|
+
// data: { reason: 'invalid currency', param: 'currency' },
|
2132
|
+
// code: -32602
|
2133
|
+
// },
|
2134
|
+
// testnet: false,
|
2135
|
+
// usIn: 1583763842150374,
|
2136
|
+
// usOut: 1583763842150410,
|
2137
|
+
// usDiff: 36
|
2138
|
+
// }
|
2139
|
+
//
|
2140
|
+
const error = this.safeValue (response, 'error');
|
2141
|
+
if (error !== undefined) {
|
2142
|
+
const errorCode = this.safeString (error, 'code');
|
2143
|
+
const feedback = this.id + ' ' + body;
|
2144
|
+
this.throwExactlyMatchedException (this.exceptions, errorCode, feedback);
|
2145
|
+
throw new ExchangeError (feedback); // unknown message
|
2146
|
+
}
|
2147
|
+
}
|
2148
|
+
};
|