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
@@ -0,0 +1,2185 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
// ---------------------------------------------------------------------------
|
4
|
+
|
5
|
+
const Exchange = require ('./base/Exchange');
|
6
|
+
const { ArgumentsRequired, AuthenticationError, InsufficientFunds, InvalidOrder, AccountSuspended, ExchangeError, DuplicateOrderId, OrderNotFound, BadSymbol, ExchangeNotAvailable, BadRequest } = require ('./base/errors');
|
7
|
+
const Precise = require ('./base/Precise');
|
8
|
+
|
9
|
+
// ---------------------------------------------------------------------------
|
10
|
+
|
11
|
+
module.exports = class wavesexchange extends Exchange {
|
12
|
+
describe () {
|
13
|
+
return this.deepExtend (super.describe (), {
|
14
|
+
'id': 'wavesexchange',
|
15
|
+
'name': 'Waves.Exchange',
|
16
|
+
'countries': [ 'CH' ], // Switzerland
|
17
|
+
'certified': true,
|
18
|
+
'pro': false,
|
19
|
+
'has': {
|
20
|
+
'CORS': undefined,
|
21
|
+
'spot': true,
|
22
|
+
'margin': false,
|
23
|
+
'swap': false,
|
24
|
+
'future': false,
|
25
|
+
'option': false,
|
26
|
+
'addMargin': false,
|
27
|
+
'cancelOrder': true,
|
28
|
+
'createMarketOrder': true,
|
29
|
+
'createOrder': true,
|
30
|
+
'createReduceOnlyOrder': false,
|
31
|
+
'fetchBalance': true,
|
32
|
+
'fetchBorrowRate': false,
|
33
|
+
'fetchBorrowRateHistories': false,
|
34
|
+
'fetchBorrowRateHistory': false,
|
35
|
+
'fetchBorrowRates': false,
|
36
|
+
'fetchBorrowRatesPerSymbol': false,
|
37
|
+
'fetchClosedOrders': true,
|
38
|
+
'fetchDepositAddress': true,
|
39
|
+
'fetchFundingHistory': false,
|
40
|
+
'fetchFundingRate': false,
|
41
|
+
'fetchFundingRateHistory': false,
|
42
|
+
'fetchFundingRates': false,
|
43
|
+
'fetchIndexOHLCV': false,
|
44
|
+
'fetchLeverage': false,
|
45
|
+
'fetchLeverageTiers': false,
|
46
|
+
'fetchMarkets': true,
|
47
|
+
'fetchMarkOHLCV': false,
|
48
|
+
'fetchMyTrades': true,
|
49
|
+
'fetchOHLCV': true,
|
50
|
+
'fetchOpenOrders': true,
|
51
|
+
'fetchOrder': true,
|
52
|
+
'fetchOrderBook': true,
|
53
|
+
'fetchOrders': true,
|
54
|
+
'fetchPosition': false,
|
55
|
+
'fetchPositions': false,
|
56
|
+
'fetchPositionsRisk': false,
|
57
|
+
'fetchPremiumIndexOHLCV': false,
|
58
|
+
'fetchTicker': true,
|
59
|
+
'fetchTrades': true,
|
60
|
+
'fetchTransfer': false,
|
61
|
+
'fetchTransfers': false,
|
62
|
+
'reduceMargin': false,
|
63
|
+
'setLeverage': false,
|
64
|
+
'setMarginMode': false,
|
65
|
+
'setPositionMode': false,
|
66
|
+
'signIn': true,
|
67
|
+
'transfer': false,
|
68
|
+
'withdraw': true,
|
69
|
+
},
|
70
|
+
'timeframes': {
|
71
|
+
'1m': '1m',
|
72
|
+
'5m': '5m',
|
73
|
+
'15m': '15m',
|
74
|
+
'30m': '30m',
|
75
|
+
'1h': '1h',
|
76
|
+
'2h': '2h',
|
77
|
+
'3h': '3h',
|
78
|
+
'4h': '4h',
|
79
|
+
'6h': '6h',
|
80
|
+
'12h': '12h',
|
81
|
+
'1d': '1d',
|
82
|
+
'1w': '1w',
|
83
|
+
'1M': '1M',
|
84
|
+
},
|
85
|
+
'urls': {
|
86
|
+
'logo': 'https://user-images.githubusercontent.com/1294454/84547058-5fb27d80-ad0b-11ea-8711-78ac8b3c7f31.jpg',
|
87
|
+
'test': {
|
88
|
+
'matcher': 'https://matcher-testnet.waves.exchange',
|
89
|
+
'node': 'https://nodes-testnet.wavesnodes.com',
|
90
|
+
'public': 'https://api-testnet.wavesplatform.com/v0',
|
91
|
+
'private': 'https://api-testnet.waves.exchange/v1',
|
92
|
+
'forward': 'https://testnet.waves.exchange/api/v1/forward/matcher',
|
93
|
+
'market': 'https://testnet.waves.exchange/api/v1/forward/marketdata/api/v1',
|
94
|
+
},
|
95
|
+
'api': {
|
96
|
+
'matcher': 'https://matcher.waves.exchange',
|
97
|
+
'node': 'https://nodes.waves.exchange',
|
98
|
+
'public': 'https://api.wavesplatform.com/v0',
|
99
|
+
'private': 'https://api.waves.exchange/v1',
|
100
|
+
'forward': 'https://waves.exchange/api/v1/forward/matcher',
|
101
|
+
'market': 'https://waves.exchange/api/v1/forward/marketdata/api/v1',
|
102
|
+
},
|
103
|
+
'doc': 'https://docs.waves.exchange',
|
104
|
+
'www': 'https://waves.exchange',
|
105
|
+
},
|
106
|
+
'api': {
|
107
|
+
'matcher': {
|
108
|
+
'get': [
|
109
|
+
'matcher',
|
110
|
+
'matcher/settings',
|
111
|
+
'matcher/settings/rates',
|
112
|
+
'matcher/balance/reserved/{publicKey}',
|
113
|
+
'matcher/debug/allSnashotOffsets',
|
114
|
+
'matcher/debug/currentOffset',
|
115
|
+
'matcher/debug/lastOffset',
|
116
|
+
'matcher/debug/oldestSnapshotOffset',
|
117
|
+
'matcher/orderbook',
|
118
|
+
'matcher/orderbook/{amountAsset}/{priceAsset}',
|
119
|
+
'matcher/orderbook/{baseId}/{quoteId}/publicKey/{publicKey}',
|
120
|
+
'matcher/orderbook/{baseId}/{quoteId}/{orderId}',
|
121
|
+
'matcher/orderbook/{baseId}/{quoteId}/info',
|
122
|
+
'matcher/orderbook/{baseId}/{quoteId}/status',
|
123
|
+
'matcher/orderbook/{baseId}/{quoteId}/tradeableBalance/{address}',
|
124
|
+
'matcher/orderbook/{publicKey}',
|
125
|
+
'matcher/orderbook/{publicKey}/{orderId}',
|
126
|
+
'matcher/orders/{address}',
|
127
|
+
'matcher/orders/{address}/{orderId}',
|
128
|
+
'matcher/transactions/{orderId}',
|
129
|
+
],
|
130
|
+
'post': [
|
131
|
+
'matcher/orderbook',
|
132
|
+
'matcher/orderbook/market',
|
133
|
+
'matcher/orderbook/cancel',
|
134
|
+
'matcher/orderbook/{baseId}/{quoteId}/cancel',
|
135
|
+
'matcher/orderbook/{amountAsset}/{priceAsset}/calculateFee',
|
136
|
+
'matcher/debug/saveSnapshots',
|
137
|
+
'matcher/orders/{address}/cancel',
|
138
|
+
'matcher/orders/cancel/{orderId}',
|
139
|
+
],
|
140
|
+
'delete': [
|
141
|
+
'matcher/orderbook/{baseId}/{quoteId}',
|
142
|
+
'matcher/settings/rates/{assetId}',
|
143
|
+
],
|
144
|
+
'put': [
|
145
|
+
'matcher/settings/rates/{assetId}',
|
146
|
+
],
|
147
|
+
},
|
148
|
+
'node': {
|
149
|
+
'get': [
|
150
|
+
'addresses',
|
151
|
+
'addresses/balance/{address}',
|
152
|
+
'addresses/balance/{address}/{confirmations}',
|
153
|
+
'addresses/balance/details/{address}',
|
154
|
+
'addresses/data/{address}',
|
155
|
+
'addresses/data/{address}/{key}',
|
156
|
+
'addresses/effectiveBalance/{address}',
|
157
|
+
'addresses/effectiveBalance/{address}/{confirmations}',
|
158
|
+
'addresses/publicKey/{publicKey}',
|
159
|
+
'addresses/scriptInfo/{address}',
|
160
|
+
'addresses/scriptInfo/{address}/meta',
|
161
|
+
'addresses/seed/{address}',
|
162
|
+
'addresses/seq/{from}/{to}',
|
163
|
+
'addresses/validate/{address}',
|
164
|
+
'alias/by-address/{address}',
|
165
|
+
'alias/by-alias/{alias}',
|
166
|
+
'assets/{assetId}/distribution/{height}/{limit}',
|
167
|
+
'assets/balance/{address}',
|
168
|
+
'assets/balance/{address}/{assetId}',
|
169
|
+
'assets/details/{assetId}',
|
170
|
+
'assets/nft/{address}/limit/{limit}',
|
171
|
+
'blockchain/rewards',
|
172
|
+
'blockchain/rewards/height',
|
173
|
+
'blocks/address/{address}/{from}/{to}/',
|
174
|
+
'blocks/at/{height}',
|
175
|
+
'blocks/delay/{signature}/{blockNum}',
|
176
|
+
'blocks/first',
|
177
|
+
'blocks/headers/last',
|
178
|
+
'blocks/headers/seq/{from}/{to}',
|
179
|
+
'blocks/height',
|
180
|
+
'blocks/height/{signature}',
|
181
|
+
'blocks/last',
|
182
|
+
'blocks/seq/{from}/{to}',
|
183
|
+
'blocks/signature/{signature}',
|
184
|
+
'consensus/algo',
|
185
|
+
'consensus/basetarget',
|
186
|
+
'consensus/basetarget/{blockId}',
|
187
|
+
'consensus/{generatingbalance}/address',
|
188
|
+
'consensus/generationsignature',
|
189
|
+
'consensus/generationsignature/{blockId}',
|
190
|
+
'debug/balances/history/{address}',
|
191
|
+
'debug/blocks/{howMany}',
|
192
|
+
'debug/configInfo',
|
193
|
+
'debug/historyInfo',
|
194
|
+
'debug/info',
|
195
|
+
'debug/minerInfo',
|
196
|
+
'debug/portfolios/{address}',
|
197
|
+
'debug/state',
|
198
|
+
'debug/stateChanges/address/{address}',
|
199
|
+
'debug/stateChanges/info/{id}',
|
200
|
+
'debug/stateWaves/{height}',
|
201
|
+
'leasing/active/{address}',
|
202
|
+
'node/state',
|
203
|
+
'node/version',
|
204
|
+
'peers/all',
|
205
|
+
'peers/blacklisted',
|
206
|
+
'peers/connected',
|
207
|
+
'peers/suspended',
|
208
|
+
'transactions/address/{address}/limit/{limit}',
|
209
|
+
'transactions/info/{id}',
|
210
|
+
'transactions/status',
|
211
|
+
'transactions/unconfirmed',
|
212
|
+
'transactions/unconfirmed/info/{id}',
|
213
|
+
'transactions/unconfirmed/size',
|
214
|
+
'utils/seed',
|
215
|
+
'utils/seed/{length}',
|
216
|
+
'utils/time',
|
217
|
+
'wallet/seed',
|
218
|
+
],
|
219
|
+
'post': [
|
220
|
+
'addresses',
|
221
|
+
'addresses/data/{address}',
|
222
|
+
'addresses/sign/{address}',
|
223
|
+
'addresses/signText/{address}',
|
224
|
+
'addresses/verify/{address}',
|
225
|
+
'addresses/verifyText/{address}',
|
226
|
+
'debug/blacklist',
|
227
|
+
'debug/print',
|
228
|
+
'debug/rollback',
|
229
|
+
'debug/validate',
|
230
|
+
'node/stop',
|
231
|
+
'peers/clearblacklist',
|
232
|
+
'peers/connect',
|
233
|
+
'transactions/broadcast',
|
234
|
+
'transactions/calculateFee',
|
235
|
+
'tranasctions/sign',
|
236
|
+
'transactions/sign/{signerAddress}',
|
237
|
+
'tranasctions/status',
|
238
|
+
'utils/hash/fast',
|
239
|
+
'utils/hash/secure',
|
240
|
+
'utils/script/compileCode',
|
241
|
+
'utils/script/compileWithImports',
|
242
|
+
'utils/script/decompile',
|
243
|
+
'utils/script/estimate',
|
244
|
+
'utils/sign/{privateKey}',
|
245
|
+
'utils/transactionsSerialize',
|
246
|
+
],
|
247
|
+
'delete': [
|
248
|
+
'addresses/{address}',
|
249
|
+
'debug/rollback-to/{signature}',
|
250
|
+
],
|
251
|
+
},
|
252
|
+
'public': {
|
253
|
+
'get': [
|
254
|
+
'assets',
|
255
|
+
'pairs',
|
256
|
+
'candles/{baseId}/{quoteId}',
|
257
|
+
'transactions/exchange',
|
258
|
+
],
|
259
|
+
},
|
260
|
+
'private': {
|
261
|
+
'get': [
|
262
|
+
'deposit/addresses/{currency}',
|
263
|
+
'deposit/addresses/{currency}/{platform}',
|
264
|
+
'platforms',
|
265
|
+
'deposit/currencies',
|
266
|
+
'withdraw/currencies',
|
267
|
+
'withdraw/addresses/{currency}/{address}',
|
268
|
+
],
|
269
|
+
'post': [
|
270
|
+
'oauth2/token',
|
271
|
+
],
|
272
|
+
},
|
273
|
+
'forward': {
|
274
|
+
'get': [
|
275
|
+
'matcher/orders/{address}', // can't get the orders endpoint to work with the matcher api
|
276
|
+
'matcher/orders/{address}/{orderId}',
|
277
|
+
],
|
278
|
+
'post': [
|
279
|
+
'matcher/orders/{wavesAddress}/cancel',
|
280
|
+
],
|
281
|
+
},
|
282
|
+
'market': {
|
283
|
+
'get': [
|
284
|
+
'tickers',
|
285
|
+
],
|
286
|
+
},
|
287
|
+
},
|
288
|
+
'currencies': {
|
289
|
+
'WX': { 'id': 'EMAMLxDnv3xiz8RXg8Btj33jcEw3wLczL3JKYYmuubpc', 'numericId': undefined, 'code': 'WX', 'precision': 8 },
|
290
|
+
},
|
291
|
+
'options': {
|
292
|
+
'allowedCandles': 1440,
|
293
|
+
'accessToken': undefined,
|
294
|
+
'createMarketBuyOrderRequiresPrice': true,
|
295
|
+
'matcherPublicKey': undefined,
|
296
|
+
'quotes': undefined,
|
297
|
+
'createOrderDefaultExpiry': 2419200000, // 60 * 60 * 24 * 28 * 1000
|
298
|
+
'wavesAddress': undefined,
|
299
|
+
'withdrawFeeUSDN': 7420,
|
300
|
+
'withdrawFeeWAVES': 100000,
|
301
|
+
'wavesPrecision': 8,
|
302
|
+
'messagePrefix': 'W', // W for production, T for testnet
|
303
|
+
'networks': {
|
304
|
+
'ERC20': 'ETH',
|
305
|
+
'BEP20': 'BSC',
|
306
|
+
},
|
307
|
+
'reverseNetworks': {
|
308
|
+
'ETH': 'ERC20',
|
309
|
+
'BSC': 'BEP20',
|
310
|
+
},
|
311
|
+
},
|
312
|
+
'commonCurrencies': {
|
313
|
+
'EGG': 'Waves Ducks',
|
314
|
+
},
|
315
|
+
'requiresEddsa': true,
|
316
|
+
'exceptions': {
|
317
|
+
'3147270': InsufficientFunds, // https://github.com/wavesplatform/matcher/wiki/List-of-all-errors
|
318
|
+
'112': InsufficientFunds,
|
319
|
+
'4': ExchangeError,
|
320
|
+
'13': ExchangeNotAvailable,
|
321
|
+
'14': ExchangeNotAvailable,
|
322
|
+
'3145733': AccountSuspended,
|
323
|
+
'3148040': DuplicateOrderId,
|
324
|
+
'3148801': AuthenticationError,
|
325
|
+
'9440512': AuthenticationError,
|
326
|
+
'9440771': BadSymbol,
|
327
|
+
'9441026': InvalidOrder,
|
328
|
+
'9441282': InvalidOrder,
|
329
|
+
'9441286': InvalidOrder,
|
330
|
+
'9441295': InvalidOrder,
|
331
|
+
'9441540': InvalidOrder,
|
332
|
+
'9441542': InvalidOrder,
|
333
|
+
'106954752': AuthenticationError,
|
334
|
+
'106954769': AuthenticationError,
|
335
|
+
'106957828': AuthenticationError,
|
336
|
+
'106960131': AuthenticationError,
|
337
|
+
'106981137': AuthenticationError,
|
338
|
+
'9437193': OrderNotFound,
|
339
|
+
'1048577': BadRequest,
|
340
|
+
'1051904': AuthenticationError,
|
341
|
+
},
|
342
|
+
});
|
343
|
+
}
|
344
|
+
|
345
|
+
setSandboxMode (enabled) {
|
346
|
+
this.options['messagePrefix'] = enabled ? 'T' : 'W';
|
347
|
+
return super.setSandboxMode (enabled);
|
348
|
+
}
|
349
|
+
|
350
|
+
async getFeesForAsset (symbol, side, amount, price, params = {}) {
|
351
|
+
await this.loadMarkets ();
|
352
|
+
const market = this.market (symbol);
|
353
|
+
amount = this.amountToPrecision (symbol, amount);
|
354
|
+
price = this.priceToPrecision (symbol, price);
|
355
|
+
const request = this.extend ({
|
356
|
+
'amountAsset': market['baseId'],
|
357
|
+
'priceAsset': market['quoteId'],
|
358
|
+
'orderType': side,
|
359
|
+
'amount': amount,
|
360
|
+
'price': price,
|
361
|
+
}, params);
|
362
|
+
return await this.matcherPostMatcherOrderbookAmountAssetPriceAssetCalculateFee (request);
|
363
|
+
}
|
364
|
+
|
365
|
+
async calculateFee (symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) {
|
366
|
+
const response = await this.getFeesForAsset (symbol, side, amount, price);
|
367
|
+
// {
|
368
|
+
// "base":{
|
369
|
+
// "feeAssetId":"WAVES",
|
370
|
+
// "matcherFee":"1000000"
|
371
|
+
// },
|
372
|
+
// "discount":{
|
373
|
+
// "feeAssetId":"EMAMLxDnv3xiz8RXg8Btj33jcEw3wLczL3JKYYmuubpc",
|
374
|
+
// "matcherFee":"4077612"
|
375
|
+
// }
|
376
|
+
// }
|
377
|
+
const isDiscountFee = this.safeValue (params, 'isDiscountFee', false);
|
378
|
+
let mode = undefined;
|
379
|
+
if (isDiscountFee) {
|
380
|
+
mode = this.safeValue (response, 'discount');
|
381
|
+
} else {
|
382
|
+
mode = this.safeValue (response, 'base');
|
383
|
+
}
|
384
|
+
const matcherFee = this.safeString (mode, 'matcherFee');
|
385
|
+
const feeAssetId = this.safeString (mode, 'feeAssetId');
|
386
|
+
const feeAsset = this.safeCurrencyCode (feeAssetId);
|
387
|
+
const adjustedMatcherFee = this.currencyFromPrecision (feeAsset, matcherFee);
|
388
|
+
const amountAsString = this.numberToString (amount);
|
389
|
+
const priceAsString = this.numberToString (price);
|
390
|
+
const feeCost = this.feeToPrecision (symbol, this.parseNumber (adjustedMatcherFee));
|
391
|
+
const feeRate = Precise.stringDiv (adjustedMatcherFee, Precise.stringMul (amountAsString, priceAsString));
|
392
|
+
return {
|
393
|
+
'type': takerOrMaker,
|
394
|
+
'currency': feeAsset,
|
395
|
+
'rate': this.parseNumber (feeRate),
|
396
|
+
'cost': this.parseNumber (feeCost),
|
397
|
+
};
|
398
|
+
}
|
399
|
+
|
400
|
+
async getQuotes () {
|
401
|
+
let quotes = this.safeValue (this.options, 'quotes');
|
402
|
+
if (quotes) {
|
403
|
+
return quotes;
|
404
|
+
} else {
|
405
|
+
// currencies can have any name because you can create you own token
|
406
|
+
// as a result someone can create a fake token called BTC
|
407
|
+
// we use this mapping to determine the real tokens
|
408
|
+
// https://docs.waves.exchange/en/waves-matcher/matcher-api#asset-pair
|
409
|
+
const response = await this.matcherGetMatcherSettings ();
|
410
|
+
// {
|
411
|
+
// "orderVersions": [
|
412
|
+
// 1,
|
413
|
+
// 2,
|
414
|
+
// 3
|
415
|
+
// ],
|
416
|
+
// "success": true,
|
417
|
+
// "matcherPublicKey": "9cpfKN9suPNvfeUNphzxXMjcnn974eme8ZhWUjaktzU5",
|
418
|
+
// "orderFee": {
|
419
|
+
// "dynamic": {
|
420
|
+
// "baseFee": 300000,
|
421
|
+
// "rates": {
|
422
|
+
// "34N9YcEETLWn93qYQ64EsP1x89tSruJU44RrEMSXXEPJ": 1.22639597,
|
423
|
+
// "62LyMjcr2DtiyF5yVXFhoQ2q414VPPJXjsNYp72SuDCH": 0.00989643,
|
424
|
+
// "HZk1mbfuJpmxU1Fs4AX5MWLVYtctsNcg6e2C6VKqK8zk": 0.0395674,
|
425
|
+
// "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS": 0.00018814,
|
426
|
+
// "4LHHvYGNKJUg5hj65aGD5vgScvCBmLpdRFtjokvCjSL8": 26.19721262,
|
427
|
+
// "474jTeYx2r2Va35794tCScAXWJG9hU2HcgxzMowaZUnu": 0.00752978,
|
428
|
+
// "DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p": 1.84575,
|
429
|
+
// "B3uGHFRpSUuGEDWjqB9LWWxafQj8VTvpMucEyoxzws5H": 0.02330273,
|
430
|
+
// "zMFqXuoyrn5w17PFurTqxB7GsS71fp9dfk6XFwxbPCy": 0.00721412,
|
431
|
+
// "5WvPKSJXzVE2orvbkJ8wsQmmQKqTv9sGBPksV4adViw3": 0.02659103,
|
432
|
+
// "WAVES": 1,
|
433
|
+
// "BrjUWjndUanm5VsJkbUip8VRYy6LWJePtxya3FNv4TQa": 0.03433583
|
434
|
+
// }
|
435
|
+
// }
|
436
|
+
// },
|
437
|
+
// "networkByte": 87,
|
438
|
+
// "matcherVersion": "2.1.3.5",
|
439
|
+
// "status": "SimpleResponse",
|
440
|
+
// "priceAssets": [
|
441
|
+
// "Ft8X1v1LTa1ABafufpaCWyVj8KkaxUWE6xBhW6sNFJck",
|
442
|
+
// "DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p",
|
443
|
+
// "34N9YcEETLWn93qYQ64EsP1x89tSruJU44RrEMSXXEPJ",
|
444
|
+
// "Gtb1WRznfchDnTh37ezoDTJ4wcoKaRsKqKjJjy7nm2zU",
|
445
|
+
// "2mX5DzVKWrAJw8iwdJnV2qtoeVG9h5nTDpTqC1wb1WEN",
|
446
|
+
// "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS",
|
447
|
+
// "WAVES",
|
448
|
+
// "474jTeYx2r2Va35794tCScAXWJG9hU2HcgxzMowaZUnu",
|
449
|
+
// "zMFqXuoyrn5w17PFurTqxB7GsS71fp9dfk6XFwxbPCy",
|
450
|
+
// "62LyMjcr2DtiyF5yVXFhoQ2q414VPPJXjsNYp72SuDCH",
|
451
|
+
// "HZk1mbfuJpmxU1Fs4AX5MWLVYtctsNcg6e2C6VKqK8zk",
|
452
|
+
// "B3uGHFRpSUuGEDWjqB9LWWxafQj8VTvpMucEyoxzws5H",
|
453
|
+
// "5WvPKSJXzVE2orvbkJ8wsQmmQKqTv9sGBPksV4adViw3",
|
454
|
+
// "BrjUWjndUanm5VsJkbUip8VRYy6LWJePtxya3FNv4TQa",
|
455
|
+
// "4LHHvYGNKJUg5hj65aGD5vgScvCBmLpdRFtjokvCjSL8"
|
456
|
+
// ]
|
457
|
+
// }
|
458
|
+
quotes = {};
|
459
|
+
const priceAssets = this.safeValue (response, 'priceAssets');
|
460
|
+
for (let i = 0; i < priceAssets.length; i++) {
|
461
|
+
quotes[priceAssets[i]] = true;
|
462
|
+
}
|
463
|
+
this.options['quotes'] = quotes;
|
464
|
+
return quotes;
|
465
|
+
}
|
466
|
+
}
|
467
|
+
|
468
|
+
async fetchMarkets (params = {}) {
|
469
|
+
const response = await this.marketGetTickers ();
|
470
|
+
//
|
471
|
+
// [
|
472
|
+
// {
|
473
|
+
// "symbol": "WAVES/BTC",
|
474
|
+
// "amountAssetID": "WAVES",
|
475
|
+
// "amountAssetName": "Waves",
|
476
|
+
// "amountAssetDecimals": 8,
|
477
|
+
// "amountAssetTotalSupply": "106908766.00000000",
|
478
|
+
// "amountAssetMaxSupply": "106908766.00000000",
|
479
|
+
// "amountAssetCirculatingSupply": "106908766.00000000",
|
480
|
+
// "priceAssetID": "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS",
|
481
|
+
// "priceAssetName": "WBTC",
|
482
|
+
// "priceAssetDecimals": 8,
|
483
|
+
// "priceAssetTotalSupply": "20999999.96007507",
|
484
|
+
// "priceAssetMaxSupply": "20999999.96007507",
|
485
|
+
// "priceAssetCirculatingSupply": "20999999.66019601",
|
486
|
+
// "24h_open": "0.00032688",
|
487
|
+
// "24h_high": "0.00033508",
|
488
|
+
// "24h_low": "0.00032443",
|
489
|
+
// "24h_close": "0.00032806",
|
490
|
+
// "24h_vwap": "0.00032988",
|
491
|
+
// "24h_volume": "42349.69440104",
|
492
|
+
// "24h_priceVolume": "13.97037207",
|
493
|
+
// "timestamp":1640232379124
|
494
|
+
// }
|
495
|
+
// ...
|
496
|
+
// ]
|
497
|
+
//
|
498
|
+
const result = [];
|
499
|
+
for (let i = 0; i < response.length; i++) {
|
500
|
+
const entry = response[i];
|
501
|
+
const baseId = this.safeString (entry, 'amountAssetID');
|
502
|
+
const quoteId = this.safeString (entry, 'priceAssetID');
|
503
|
+
const id = baseId + '/' + quoteId;
|
504
|
+
const marketId = this.safeString (entry, 'symbol');
|
505
|
+
let [ base, quote ] = marketId.split ('/');
|
506
|
+
base = this.safeCurrencyCode (base);
|
507
|
+
quote = this.safeCurrencyCode (quote);
|
508
|
+
const symbol = base + '/' + quote;
|
509
|
+
result.push ({
|
510
|
+
'id': id,
|
511
|
+
'symbol': symbol,
|
512
|
+
'base': base,
|
513
|
+
'quote': quote,
|
514
|
+
'settle': undefined,
|
515
|
+
'baseId': baseId,
|
516
|
+
'quoteId': quoteId,
|
517
|
+
'settleId': undefined,
|
518
|
+
'type': 'spot',
|
519
|
+
'spot': true,
|
520
|
+
'margin': false,
|
521
|
+
'swap': false,
|
522
|
+
'future': false,
|
523
|
+
'option': false,
|
524
|
+
'active': undefined,
|
525
|
+
'contract': false,
|
526
|
+
'linear': undefined,
|
527
|
+
'inverse': undefined,
|
528
|
+
'contractSize': undefined,
|
529
|
+
'expiry': undefined,
|
530
|
+
'expiryDatetime': undefined,
|
531
|
+
'strike': undefined,
|
532
|
+
'optionType': undefined,
|
533
|
+
'precision': {
|
534
|
+
'amount': this.safeInteger (entry, 'amountAssetDecimals'),
|
535
|
+
'price': this.safeInteger (entry, 'priceAssetDecimals'),
|
536
|
+
},
|
537
|
+
'limits': {
|
538
|
+
'leverage': {
|
539
|
+
'min': undefined,
|
540
|
+
'max': undefined,
|
541
|
+
},
|
542
|
+
'amount': {
|
543
|
+
'min': undefined,
|
544
|
+
'max': undefined,
|
545
|
+
},
|
546
|
+
'price': {
|
547
|
+
'min': undefined,
|
548
|
+
'max': undefined,
|
549
|
+
},
|
550
|
+
'cost': {
|
551
|
+
'min': undefined,
|
552
|
+
'max': undefined,
|
553
|
+
},
|
554
|
+
},
|
555
|
+
'info': entry,
|
556
|
+
});
|
557
|
+
}
|
558
|
+
return result;
|
559
|
+
}
|
560
|
+
|
561
|
+
async fetchOrderBook (symbol, limit = undefined, params = {}) {
|
562
|
+
await this.loadMarkets ();
|
563
|
+
const market = this.market (symbol);
|
564
|
+
const request = this.extend ({
|
565
|
+
'amountAsset': market['baseId'],
|
566
|
+
'priceAsset': market['quoteId'],
|
567
|
+
}, params);
|
568
|
+
const response = await this.matcherGetMatcherOrderbookAmountAssetPriceAsset (request);
|
569
|
+
const timestamp = this.safeInteger (response, 'timestamp');
|
570
|
+
const bids = this.parseOrderBookSide (this.safeValue (response, 'bids'), market, limit);
|
571
|
+
const asks = this.parseOrderBookSide (this.safeValue (response, 'asks'), market, limit);
|
572
|
+
return {
|
573
|
+
'symbol': symbol,
|
574
|
+
'bids': bids,
|
575
|
+
'asks': asks,
|
576
|
+
'timestamp': timestamp,
|
577
|
+
'datetime': this.iso8601 (timestamp),
|
578
|
+
'nonce': undefined,
|
579
|
+
};
|
580
|
+
}
|
581
|
+
|
582
|
+
parseOrderBookSide (bookSide, market = undefined, limit = undefined) {
|
583
|
+
const precision = market['precision'];
|
584
|
+
const wavesPrecision = this.safeInteger (this.options, 'wavesPrecision', 8);
|
585
|
+
const amountPrecision = Math.pow (10, precision['amount']);
|
586
|
+
const difference = precision['amount'] - precision['price'];
|
587
|
+
const pricePrecision = Math.pow (10, wavesPrecision - difference);
|
588
|
+
const result = [];
|
589
|
+
for (let i = 0; i < bookSide.length; i++) {
|
590
|
+
const entry = bookSide[i];
|
591
|
+
const price = this.safeInteger (entry, 'price', 0) / pricePrecision;
|
592
|
+
const amount = this.safeInteger (entry, 'amount', 0) / amountPrecision;
|
593
|
+
if ((limit !== undefined) && (i > limit)) {
|
594
|
+
break;
|
595
|
+
}
|
596
|
+
result.push ([ price, amount ]);
|
597
|
+
}
|
598
|
+
return result;
|
599
|
+
}
|
600
|
+
|
601
|
+
checkRequiredKeys () {
|
602
|
+
if (this.apiKey === undefined) {
|
603
|
+
throw new AuthenticationError (this.id + ' requires apiKey credential');
|
604
|
+
}
|
605
|
+
if (this.secret === undefined) {
|
606
|
+
throw new AuthenticationError (this.id + ' requires secret credential');
|
607
|
+
}
|
608
|
+
let apiKeyBytes = undefined;
|
609
|
+
let secretKeyBytes = undefined;
|
610
|
+
try {
|
611
|
+
apiKeyBytes = this.base58ToBinary (this.apiKey);
|
612
|
+
} catch (e) {
|
613
|
+
throw new AuthenticationError (this.id + ' apiKey must be a base58 encoded public key');
|
614
|
+
}
|
615
|
+
try {
|
616
|
+
secretKeyBytes = this.base58ToBinary (this.secret);
|
617
|
+
} catch (e) {
|
618
|
+
throw new AuthenticationError (this.id + ' secret must be a base58 encoded private key');
|
619
|
+
}
|
620
|
+
const hexApiKeyBytes = this.binaryToBase16 (apiKeyBytes);
|
621
|
+
const hexSecretKeyBytes = this.binaryToBase16 (secretKeyBytes);
|
622
|
+
if (hexApiKeyBytes.length !== 64) {
|
623
|
+
throw new AuthenticationError (this.id + ' apiKey must be a base58 encoded public key');
|
624
|
+
}
|
625
|
+
if (hexSecretKeyBytes.length !== 64) {
|
626
|
+
throw new AuthenticationError (this.id + ' secret must be a base58 encoded private key');
|
627
|
+
}
|
628
|
+
}
|
629
|
+
|
630
|
+
sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
|
631
|
+
const query = this.omit (params, this.extractParams (path));
|
632
|
+
const isCancelOrder = path === 'matcher/orders/{wavesAddress}/cancel';
|
633
|
+
path = this.implodeParams (path, params);
|
634
|
+
let url = this.urls['api'][api] + '/' + path;
|
635
|
+
let queryString = this.urlencodeWithArrayRepeat (query);
|
636
|
+
if ((api === 'private') || (api === 'forward')) {
|
637
|
+
headers = {
|
638
|
+
'Accept': 'application/json',
|
639
|
+
};
|
640
|
+
const accessToken = this.safeString (this.options, 'accessToken');
|
641
|
+
if (accessToken) {
|
642
|
+
headers['Authorization'] = 'Bearer ' + accessToken;
|
643
|
+
}
|
644
|
+
if (method === 'POST') {
|
645
|
+
headers['content-type'] = 'application/json';
|
646
|
+
} else {
|
647
|
+
headers['content-type'] = 'application/x-www-form-urlencoded';
|
648
|
+
}
|
649
|
+
if (isCancelOrder) {
|
650
|
+
body = this.json ([ query['orderId'] ]);
|
651
|
+
queryString = '';
|
652
|
+
}
|
653
|
+
if (queryString.length > 0) {
|
654
|
+
url += '?' + queryString;
|
655
|
+
}
|
656
|
+
} else if (api === 'matcher') {
|
657
|
+
if (method === 'POST') {
|
658
|
+
headers = {
|
659
|
+
'Accept': 'application/json',
|
660
|
+
'Content-Type': 'application/json',
|
661
|
+
};
|
662
|
+
body = this.json (query);
|
663
|
+
} else {
|
664
|
+
headers = query;
|
665
|
+
}
|
666
|
+
} else {
|
667
|
+
if (method === 'POST') {
|
668
|
+
headers = {
|
669
|
+
'content-type': 'application/json',
|
670
|
+
};
|
671
|
+
body = this.json (query);
|
672
|
+
} else {
|
673
|
+
headers = {
|
674
|
+
'content-type': 'application/x-www-form-urlencoded',
|
675
|
+
};
|
676
|
+
if (queryString.length > 0) {
|
677
|
+
url += '?' + queryString;
|
678
|
+
}
|
679
|
+
}
|
680
|
+
}
|
681
|
+
return { 'url': url, 'method': method, 'body': body, 'headers': headers };
|
682
|
+
}
|
683
|
+
|
684
|
+
async signIn (params = {}) {
|
685
|
+
if (!this.safeString (this.options, 'accessToken')) {
|
686
|
+
const prefix = 'ffffff01';
|
687
|
+
const expiresDelta = 60 * 60 * 24 * 7;
|
688
|
+
let seconds = this.sum (this.seconds (), expiresDelta);
|
689
|
+
seconds = seconds.toString ();
|
690
|
+
const clientId = 'waves.exchange';
|
691
|
+
// W for production, T for testnet
|
692
|
+
const defaultMessagePrefix = this.safeString (this.options, 'messagePrefix', 'W');
|
693
|
+
const message = defaultMessagePrefix + ':' + clientId + ':' + seconds;
|
694
|
+
const messageHex = this.binaryToBase16 (this.stringToBinary (this.encode (message)));
|
695
|
+
const payload = prefix + messageHex;
|
696
|
+
const hexKey = this.binaryToBase16 (this.base58ToBinary (this.secret));
|
697
|
+
const signature = this.eddsa (payload, hexKey, 'ed25519');
|
698
|
+
const request = {
|
699
|
+
'grant_type': 'password',
|
700
|
+
'scope': 'general',
|
701
|
+
'username': this.apiKey,
|
702
|
+
'password': seconds + ':' + signature,
|
703
|
+
'client_id': clientId,
|
704
|
+
};
|
705
|
+
const response = await this.privatePostOauth2Token (request);
|
706
|
+
// { access_token: 'eyJhbGciOXJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzaWciOiJiaTZiMVhMQlo0M1Q4QmRTSlVSejJBZGlQdVlpaFZQYVhhVjc4ZGVIOEpTM3M3NUdSeEU1VkZVOE5LRUI0UXViNkFHaUhpVFpuZ3pzcnhXdExUclRvZTgiLCJhIjoiM1A4VnpMU2EyM0VXNUNWY2tIYlY3ZDVCb043NWZGMWhoRkgiLCJuYiI6IlciLCJ1c2VyX25hbWUiOiJBSFhuOG5CQTRTZkxRRjdoTFFpU24xNmt4eWVoaml6QkdXMVRkcm1TWjFnRiIsInNjb3BlIjpbImdlbmVyYWwiXSwibHQiOjYwNDc5OSwicGsiOiJBSFhuOG5CQTRTZkxRRjdoTFFpU24xNmt4eWVoaml6QkdXMVRkcm1TWjFnRiIsImV4cCI6MTU5MTk3NTA1NywiZXhwMCI6MTU5MTk3NTA1NywianRpIjoiN2JhOTUxMTMtOGI2MS00NjEzLTlkZmYtNTEwYTc0NjlkOWI5IiwiY2lkIjoid2F2ZXMuZXhjaGFuZ2UifQ.B-XwexBnUAzbWknVN68RKT0ZP5w6Qk1SKJ8usL3OIwDEzCUUX9PjW-5TQHmiCRcA4oft8lqXEiCwEoNfsblCo_jTpRo518a1vZkIbHQk0-13Dm1K5ewGxfxAwBk0g49odcbKdjl64TN1yM_PO1VtLVuiTeZP-XF-S42Uj-7fcO-r7AulyQLuTE0uo-Qdep8HDCk47rduZwtJOmhFbCCnSgnLYvKWy3CVTeldsR77qxUY-vy8q9McqeP7Id-_MWnsob8vWXpkeJxaEsw1Fke1dxApJaJam09VU8EB3ZJWpkT7V8PdafIrQGeexx3jhKKxo7rRb4hDV8kfpVoCgkvFan',
|
707
|
+
// token_type: 'bearer',
|
708
|
+
// refresh_token: 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzaWciOiJiaTZiMVhMQlo0M1Q4QmRTSlVSejJBZGlQdVlpaFZQYVhhVjc4ZGVIOEpTM3M3NUdSeEU1VkZVOE5LRUI0UXViNkFHaUhpVFpuZ3pzcnhXdExUclRvZTgiLCJhIjoiM1A4VnpMU2EyM0VXNUNWY2tIYlY3ZDVCb043NWZGMWhoRkgiLCJuYiI6IlciLCJ1c2VyX25hbWUiOiJBSFhuOG5CQTRTZkxRRjdoTFFpU24xNmt4eWVoaml6QkdXMVRkcm1TWjFnRiIsInNjb3BlIjpbImdlbmVyYWwiXSwiYXRpIjoiN2JhOTUxMTMtOGI2MS00NjEzLTlkZmYtNTEwYTc0NjlkXWI5IiwibHQiOjYwNDc5OSwicGsiOiJBSFhuOG5CQTRTZkxRRjdoTFFpU24xNmt4eWVoaml6QkdXMVRkcm1TWjFnRiIsImV4cCI6MTU5Mzk2MjI1OCwiZXhwMCI6MTU5MTk3NTA1NywianRpIjoiM2MzZWRlMTktNjI5My00MTNlLWJmMWUtZTRlZDZlYzUzZTgzIiwiY2lkIjoid2F2ZXMuZXhjaGFuZ2UifQ.gD1Qj0jfqayfZpBvNY0t3ccMyK5hdbT7dY-_5L6LxwV0Knan4ndEtvygxlTOczmJUKtnA4T1r5GBFgNMZTvtViKZIbqZNysEg2OY8UxwDaF4VPeGJLg_QXEnn8wBeBQdyMafh9UQdwD2ci7x-saM4tOAGmncAygfTDxy80201gwDhfAkAGerb9kL00oWzSJScldxu--pNLDBUEHZt52MSEel10HGrzvZkkvvSh67vcQo5TOGb5KG6nh65UdJCwr41AVz4fbQPP-N2Nkxqy0TE_bqVzZxExXgvcS8TS0Z82T3ijJa_ct7B9wblpylBnvmyj3VycUzufD6uy8MUGq32D',
|
709
|
+
// expires_in: 604798,
|
710
|
+
// scope: 'general' }
|
711
|
+
this.options['accessToken'] = this.safeString (response, 'access_token');
|
712
|
+
return this.options['accessToken'];
|
713
|
+
}
|
714
|
+
}
|
715
|
+
|
716
|
+
parseTicker (ticker, market = undefined) {
|
717
|
+
//
|
718
|
+
// {
|
719
|
+
// "__type":"pair",
|
720
|
+
// "data":{
|
721
|
+
// "firstPrice":0.00012512,
|
722
|
+
// "lastPrice":0.00012441,
|
723
|
+
// "low":0.00012167,
|
724
|
+
// "high":0.00012768,
|
725
|
+
// "weightedAveragePrice":0.000124710697407246,
|
726
|
+
// "volume":209554.26356614,
|
727
|
+
// "quoteVolume":26.1336583539951,
|
728
|
+
// "volumeWaves":209554.26356614,
|
729
|
+
// "txsCount":6655
|
730
|
+
// },
|
731
|
+
// "amountAsset":"WAVES",
|
732
|
+
// "priceAsset":"8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS"
|
733
|
+
// }
|
734
|
+
//
|
735
|
+
const timestamp = undefined;
|
736
|
+
const baseId = this.safeString (ticker, 'amountAsset');
|
737
|
+
const quoteId = this.safeString (ticker, 'priceAsset');
|
738
|
+
let symbol = undefined;
|
739
|
+
if ((baseId !== undefined) && (quoteId !== undefined)) {
|
740
|
+
const marketId = baseId + '/' + quoteId;
|
741
|
+
if (marketId in this.markets_by_id) {
|
742
|
+
market = this.markets_by_id[marketId];
|
743
|
+
} else {
|
744
|
+
const base = this.safeCurrencyCode (baseId);
|
745
|
+
const quote = this.safeCurrencyCode (quoteId);
|
746
|
+
symbol = base + '/' + quote;
|
747
|
+
}
|
748
|
+
}
|
749
|
+
if ((symbol === undefined) && (market !== undefined)) {
|
750
|
+
symbol = market['symbol'];
|
751
|
+
}
|
752
|
+
const data = this.safeValue (ticker, 'data', {});
|
753
|
+
const last = this.safeString (data, 'lastPrice');
|
754
|
+
const low = this.safeString (data, 'low');
|
755
|
+
const high = this.safeString (data, 'high');
|
756
|
+
const vwap = this.safeString (data, 'weightedAveragePrice');
|
757
|
+
const baseVolume = this.safeString (data, 'volume');
|
758
|
+
const quoteVolume = this.safeString (data, 'quoteVolume');
|
759
|
+
const open = this.safeString (data, 'firstPrice');
|
760
|
+
return this.safeTicker ({
|
761
|
+
'symbol': symbol,
|
762
|
+
'timestamp': timestamp,
|
763
|
+
'datetime': this.iso8601 (timestamp),
|
764
|
+
'high': high,
|
765
|
+
'low': low,
|
766
|
+
'bid': undefined,
|
767
|
+
'bidVolume': undefined,
|
768
|
+
'ask': undefined,
|
769
|
+
'askVolume': undefined,
|
770
|
+
'vwap': vwap,
|
771
|
+
'open': open,
|
772
|
+
'close': last,
|
773
|
+
'last': last,
|
774
|
+
'previousClose': undefined,
|
775
|
+
'change': undefined,
|
776
|
+
'percentage': undefined,
|
777
|
+
'average': undefined,
|
778
|
+
'baseVolume': baseVolume,
|
779
|
+
'quoteVolume': quoteVolume,
|
780
|
+
'info': ticker,
|
781
|
+
}, market, false);
|
782
|
+
}
|
783
|
+
|
784
|
+
async fetchTicker (symbol, params = {}) {
|
785
|
+
await this.loadMarkets ();
|
786
|
+
const market = this.market (symbol);
|
787
|
+
const request = {
|
788
|
+
'pairs': market['id'],
|
789
|
+
};
|
790
|
+
const response = await this.publicGetPairs (this.extend (request, params));
|
791
|
+
//
|
792
|
+
// {
|
793
|
+
// "__type":"list",
|
794
|
+
// "data":[
|
795
|
+
// {
|
796
|
+
// "__type":"pair",
|
797
|
+
// "data":{
|
798
|
+
// "firstPrice":0.00012512,
|
799
|
+
// "lastPrice":0.00012441,
|
800
|
+
// "low":0.00012167,
|
801
|
+
// "high":0.00012768,
|
802
|
+
// "weightedAveragePrice":0.000124710697407246,
|
803
|
+
// "volume":209554.26356614,
|
804
|
+
// "quoteVolume":26.1336583539951,
|
805
|
+
// "volumeWaves":209554.26356614,
|
806
|
+
// "txsCount":6655
|
807
|
+
// },
|
808
|
+
// "amountAsset":"WAVES",
|
809
|
+
// "priceAsset":"8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS"
|
810
|
+
// }
|
811
|
+
// ]
|
812
|
+
// }
|
813
|
+
//
|
814
|
+
const data = this.safeValue (response, 'data', []);
|
815
|
+
const ticker = this.safeValue (data, 0, {});
|
816
|
+
return this.parseTicker (ticker, market);
|
817
|
+
}
|
818
|
+
|
819
|
+
async fetchOHLCV (symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
|
820
|
+
await this.loadMarkets ();
|
821
|
+
const market = this.market (symbol);
|
822
|
+
const request = {
|
823
|
+
'baseId': market['baseId'],
|
824
|
+
'quoteId': market['quoteId'],
|
825
|
+
'interval': this.timeframes[timeframe],
|
826
|
+
};
|
827
|
+
const allowedCandles = this.safeInteger (this.options, 'allowedCandles', 1440);
|
828
|
+
if (limit === undefined) {
|
829
|
+
limit = allowedCandles;
|
830
|
+
}
|
831
|
+
limit = Math.min (allowedCandles, limit);
|
832
|
+
const duration = this.parseTimeframe (timeframe) * 1000;
|
833
|
+
if (since === undefined) {
|
834
|
+
const durationRoundedTimestamp = parseInt (this.milliseconds () / duration) * duration;
|
835
|
+
const delta = (limit - 1) * duration;
|
836
|
+
const timeStart = durationRoundedTimestamp - delta;
|
837
|
+
request['timeStart'] = timeStart.toString ();
|
838
|
+
} else {
|
839
|
+
request['timeStart'] = since.toString ();
|
840
|
+
const timeEnd = this.sum (since, duration * limit);
|
841
|
+
request['timeEnd'] = timeEnd.toString ();
|
842
|
+
}
|
843
|
+
const response = await this.publicGetCandlesBaseIdQuoteId (this.extend (request, params));
|
844
|
+
//
|
845
|
+
// {
|
846
|
+
// "__type": "list",
|
847
|
+
// "data": [
|
848
|
+
// {
|
849
|
+
// "__type": "candle",
|
850
|
+
// "data": {
|
851
|
+
// "time": "2020-06-09T14:47:00.000Z",
|
852
|
+
// "open": 0.0250385,
|
853
|
+
// "close": 0.0250385,
|
854
|
+
// "high": 0.0250385,
|
855
|
+
// "low": 0.0250385,
|
856
|
+
// "volume": 0.01033012,
|
857
|
+
// "quoteVolume": 0.00025865,
|
858
|
+
// "weightedAveragePrice": 0.0250385,
|
859
|
+
// "maxHeight": 2099399,
|
860
|
+
// "txsCount": 5,
|
861
|
+
// "timeClose": "2020-06-09T14:47:59.999Z"
|
862
|
+
// }
|
863
|
+
// }
|
864
|
+
// ]
|
865
|
+
// }
|
866
|
+
//
|
867
|
+
const data = this.safeValue (response, 'data', []);
|
868
|
+
let result = this.parseOHLCVs (data, market, timeframe, since, limit);
|
869
|
+
result = this.filterFutureCandles (result);
|
870
|
+
let lastClose = undefined;
|
871
|
+
const length = result.length;
|
872
|
+
for (let i = 0; i < result.length; i++) {
|
873
|
+
const j = length - i - 1;
|
874
|
+
const entry = result[j];
|
875
|
+
const open = entry[1];
|
876
|
+
if (open === undefined) {
|
877
|
+
entry[1] = lastClose;
|
878
|
+
entry[2] = lastClose;
|
879
|
+
entry[3] = lastClose;
|
880
|
+
entry[4] = lastClose;
|
881
|
+
result[j] = entry;
|
882
|
+
}
|
883
|
+
lastClose = entry[4];
|
884
|
+
}
|
885
|
+
return result;
|
886
|
+
}
|
887
|
+
|
888
|
+
filterFutureCandles (ohlcvs) {
|
889
|
+
const result = [];
|
890
|
+
const timestamp = this.milliseconds ();
|
891
|
+
for (let i = 0; i < ohlcvs.length; i++) {
|
892
|
+
if (ohlcvs[i][0] > timestamp) {
|
893
|
+
// stop when getting data from the future
|
894
|
+
break;
|
895
|
+
}
|
896
|
+
result.push (ohlcvs[i]);
|
897
|
+
}
|
898
|
+
return result;
|
899
|
+
}
|
900
|
+
|
901
|
+
parseOHLCV (ohlcv, market = undefined) {
|
902
|
+
//
|
903
|
+
// {
|
904
|
+
// __type: 'candle',
|
905
|
+
// data: {
|
906
|
+
// time: '2020-06-05T20:46:00.000Z',
|
907
|
+
// open: 240.573975,
|
908
|
+
// close: 240.573975,
|
909
|
+
// high: 240.573975,
|
910
|
+
// low: 240.573975,
|
911
|
+
// volume: 0.01278413,
|
912
|
+
// quoteVolume: 3.075528,
|
913
|
+
// weightedAveragePrice: 240.573975,
|
914
|
+
// maxHeight: 2093895,
|
915
|
+
// txsCount: 5,
|
916
|
+
// timeClose: '2020-06-05T20:46:59.999Z'
|
917
|
+
// }
|
918
|
+
// }
|
919
|
+
//
|
920
|
+
const data = this.safeValue (ohlcv, 'data', {});
|
921
|
+
return [
|
922
|
+
this.parse8601 (this.safeString (data, 'time')),
|
923
|
+
this.safeNumber (data, 'open'),
|
924
|
+
this.safeNumber (data, 'high'),
|
925
|
+
this.safeNumber (data, 'low'),
|
926
|
+
this.safeNumber (data, 'close'),
|
927
|
+
this.safeNumber (data, 'volume', 0),
|
928
|
+
];
|
929
|
+
}
|
930
|
+
|
931
|
+
async fetchDepositAddress (code, params = {}) {
|
932
|
+
await this.signIn ();
|
933
|
+
const networks = this.safeValue (this.options, 'networks', {});
|
934
|
+
const rawNetwork = this.safeStringUpper (params, 'network');
|
935
|
+
const network = this.safeString (networks, rawNetwork, rawNetwork);
|
936
|
+
params = this.omit (params, [ 'network' ]);
|
937
|
+
const supportedCurrencies = await this.privateGetPlatforms ();
|
938
|
+
//
|
939
|
+
// {
|
940
|
+
// "type": "list",
|
941
|
+
// "page_info": {
|
942
|
+
// "has_next_page": false,
|
943
|
+
// "last_cursor": null
|
944
|
+
// },
|
945
|
+
// "items": [
|
946
|
+
// {
|
947
|
+
// "type": "platform",
|
948
|
+
// "id": "ETH",
|
949
|
+
// "name": "Ethereum",
|
950
|
+
// "currencies": [
|
951
|
+
// "BAG",
|
952
|
+
// "BNT",
|
953
|
+
// "CRV",
|
954
|
+
// "EGG",
|
955
|
+
// "ETH",
|
956
|
+
// "EURN",
|
957
|
+
// "FL",
|
958
|
+
// "NSBT",
|
959
|
+
// "USDAP",
|
960
|
+
// "USDC",
|
961
|
+
// "USDFL",
|
962
|
+
// "USDN",
|
963
|
+
// "USDT",
|
964
|
+
// "WAVES"
|
965
|
+
// ]
|
966
|
+
// }
|
967
|
+
// ]
|
968
|
+
// }
|
969
|
+
//
|
970
|
+
const currencies = {};
|
971
|
+
const networksByCurrency = {};
|
972
|
+
const items = this.safeValue (supportedCurrencies, 'items', []);
|
973
|
+
for (let i = 0; i < items.length; i++) {
|
974
|
+
const entry = items[i];
|
975
|
+
const currencyId = this.safeString (entry, 'id');
|
976
|
+
const innerCurrencies = this.safeValue (entry, 'currencies', []);
|
977
|
+
for (let j = 0; j < innerCurrencies.length; j++) {
|
978
|
+
const currencyCode = this.safeString (innerCurrencies, j);
|
979
|
+
currencies[currencyCode] = true;
|
980
|
+
if (!(currencyCode in networksByCurrency)) {
|
981
|
+
networksByCurrency[currencyCode] = {};
|
982
|
+
}
|
983
|
+
networksByCurrency[currencyCode][currencyId] = true;
|
984
|
+
}
|
985
|
+
}
|
986
|
+
if (!(code in currencies)) {
|
987
|
+
const codes = Object.keys (currencies);
|
988
|
+
throw new ExchangeError (this.id + ' fetchDepositAddress() ' + code + ' not supported. Currency code must be one of ' + codes.join (', '));
|
989
|
+
}
|
990
|
+
let response = undefined;
|
991
|
+
if (network === undefined) {
|
992
|
+
const request = {
|
993
|
+
'currency': code,
|
994
|
+
};
|
995
|
+
response = await this.privateGetDepositAddressesCurrency (this.extend (request, params));
|
996
|
+
} else {
|
997
|
+
const supportedNetworks = networksByCurrency[code];
|
998
|
+
if (!(network in supportedNetworks)) {
|
999
|
+
const supportedNetworkKeys = Object.keys (supportedNetworks);
|
1000
|
+
throw new ExchangeError (this.id + ' ' + network + ' network ' + code + ' deposit address not supported. Network must be one of ' + supportedNetworkKeys.join (', '));
|
1001
|
+
}
|
1002
|
+
if (network === 'WAVES') {
|
1003
|
+
const request = {
|
1004
|
+
'publicKey': this.apiKey,
|
1005
|
+
};
|
1006
|
+
const response = await this.nodeGetAddressesPublicKeyPublicKey (this.extend (request, request));
|
1007
|
+
const address = this.safeString (response, 'address');
|
1008
|
+
return {
|
1009
|
+
'address': address,
|
1010
|
+
'code': code,
|
1011
|
+
'network': network,
|
1012
|
+
'tag': undefined,
|
1013
|
+
'info': response,
|
1014
|
+
};
|
1015
|
+
} else {
|
1016
|
+
const request = {
|
1017
|
+
'currency': code,
|
1018
|
+
'platform': network,
|
1019
|
+
};
|
1020
|
+
response = await this.privateGetDepositAddressesCurrencyPlatform (this.extend (request, params));
|
1021
|
+
}
|
1022
|
+
}
|
1023
|
+
//
|
1024
|
+
// {
|
1025
|
+
// "type": "deposit_addresses",
|
1026
|
+
// "currency": {
|
1027
|
+
// "type": "deposit_currency",
|
1028
|
+
// "id": "ERGO",
|
1029
|
+
// "waves_asset_id": "5dJj4Hn9t2Ve3tRpNGirUHy4yBK6qdJRAJYV21yPPuGz",
|
1030
|
+
// "platform_id": "BSC",
|
1031
|
+
// "decimals": 9,
|
1032
|
+
// "status": "active",
|
1033
|
+
// "allowed_amount": {
|
1034
|
+
// "min": 0.001,
|
1035
|
+
// "max": 100000
|
1036
|
+
// },
|
1037
|
+
// "fees": {
|
1038
|
+
// "flat": 0,
|
1039
|
+
// "rate": 0
|
1040
|
+
// }
|
1041
|
+
// },
|
1042
|
+
// "deposit_addresses": [
|
1043
|
+
// "9fRAAQjF8Yqg7qicQCL884zjimsRnuwsSavsM1rUdDaoG8mThku"
|
1044
|
+
// ]
|
1045
|
+
// }
|
1046
|
+
const currency = this.safeValue (response, 'currency');
|
1047
|
+
const networkId = this.safeString (currency, 'platform_id');
|
1048
|
+
const reverseNetworks = this.safeValue (this.options, 'reverseNetworks', {});
|
1049
|
+
const unifiedNetwork = this.safeString (reverseNetworks, networkId, networkId);
|
1050
|
+
const addresses = this.safeValue (response, 'deposit_addresses');
|
1051
|
+
const address = this.safeString (addresses, 0);
|
1052
|
+
return {
|
1053
|
+
'address': address,
|
1054
|
+
'code': code,
|
1055
|
+
'tag': undefined,
|
1056
|
+
'network': unifiedNetwork,
|
1057
|
+
'info': response,
|
1058
|
+
};
|
1059
|
+
}
|
1060
|
+
|
1061
|
+
async getMatcherPublicKey () {
|
1062
|
+
// this method returns a single string
|
1063
|
+
const matcherPublicKey = this.safeString (this.options, 'matcherPublicKey');
|
1064
|
+
if (matcherPublicKey) {
|
1065
|
+
return matcherPublicKey;
|
1066
|
+
} else {
|
1067
|
+
const response = await this.matcherGetMatcher ();
|
1068
|
+
// remove trailing quotes from string response
|
1069
|
+
this.options['matcherPublicKey'] = response.slice (1, response.length - 1);
|
1070
|
+
return this.options['matcherPublicKey'];
|
1071
|
+
}
|
1072
|
+
}
|
1073
|
+
|
1074
|
+
getAssetBytes (currencyId) {
|
1075
|
+
if (currencyId === 'WAVES') {
|
1076
|
+
return this.numberToBE (0, 1);
|
1077
|
+
} else {
|
1078
|
+
return this.binaryConcat (this.numberToBE (1, 1), this.base58ToBinary (currencyId));
|
1079
|
+
}
|
1080
|
+
}
|
1081
|
+
|
1082
|
+
getAssetId (currencyId) {
|
1083
|
+
if (currencyId === 'WAVES') {
|
1084
|
+
return '';
|
1085
|
+
}
|
1086
|
+
return currencyId;
|
1087
|
+
}
|
1088
|
+
|
1089
|
+
priceToPrecision (symbol, price) {
|
1090
|
+
const market = this.markets[symbol];
|
1091
|
+
const wavesPrecision = this.safeInteger (this.options, 'wavesPrecision', 8);
|
1092
|
+
const difference = market['precision']['amount'] - market['precision']['price'];
|
1093
|
+
return parseInt (parseFloat (this.toPrecision (price, wavesPrecision - difference)));
|
1094
|
+
}
|
1095
|
+
|
1096
|
+
amountToPrecision (symbol, amount) {
|
1097
|
+
return parseInt (parseFloat (this.toPrecision (amount, this.markets[symbol]['precision']['amount'])));
|
1098
|
+
}
|
1099
|
+
|
1100
|
+
currencyToPrecision (code, amount) {
|
1101
|
+
return parseInt (parseFloat (this.toPrecision (amount, this.currencies[code]['precision'])));
|
1102
|
+
}
|
1103
|
+
|
1104
|
+
fromPrecision (amount, scale) {
|
1105
|
+
if (amount === undefined) {
|
1106
|
+
return undefined;
|
1107
|
+
}
|
1108
|
+
const precise = new Precise (amount);
|
1109
|
+
precise.decimals = precise.decimals + scale;
|
1110
|
+
precise.reduce ();
|
1111
|
+
return precise.toString ();
|
1112
|
+
}
|
1113
|
+
|
1114
|
+
toPrecision (amount, scale) {
|
1115
|
+
const amountString = amount.toString ();
|
1116
|
+
const precise = new Precise (amountString);
|
1117
|
+
precise.decimals = precise.decimals - scale;
|
1118
|
+
precise.reduce ();
|
1119
|
+
return precise.toString ();
|
1120
|
+
}
|
1121
|
+
|
1122
|
+
currencyFromPrecision (currency, amount) {
|
1123
|
+
const scale = this.currencies[currency]['precision'];
|
1124
|
+
return this.fromPrecision (amount, scale);
|
1125
|
+
}
|
1126
|
+
|
1127
|
+
priceFromPrecision (symbol, price) {
|
1128
|
+
const market = this.markets[symbol];
|
1129
|
+
const wavesPrecision = this.safeInteger (this.options, 'wavesPrecision', 8);
|
1130
|
+
const scale = wavesPrecision - market['precision']['amount'] + market['precision']['price'];
|
1131
|
+
return this.fromPrecision (price, scale);
|
1132
|
+
}
|
1133
|
+
|
1134
|
+
safeGetDynamic (settings) {
|
1135
|
+
const orderFee = this.safeValue (settings, 'orderFee');
|
1136
|
+
if ('dynamic' in orderFee) {
|
1137
|
+
return this.safeValue (orderFee, 'dynamic');
|
1138
|
+
} else {
|
1139
|
+
return this.safeValue (orderFee['composite']['default'], 'dynamic');
|
1140
|
+
}
|
1141
|
+
}
|
1142
|
+
|
1143
|
+
safeGetRates (dynamic) {
|
1144
|
+
const rates = this.safeValue (dynamic, 'rates');
|
1145
|
+
if (rates === undefined) {
|
1146
|
+
return { 'WAVES': 1 };
|
1147
|
+
}
|
1148
|
+
return rates;
|
1149
|
+
}
|
1150
|
+
|
1151
|
+
async createOrder (symbol, type, side, amount, price = undefined, params = {}) {
|
1152
|
+
this.checkRequiredDependencies ();
|
1153
|
+
this.checkRequiredKeys ();
|
1154
|
+
await this.loadMarkets ();
|
1155
|
+
const market = this.market (symbol);
|
1156
|
+
const matcherPublicKey = await this.getMatcherPublicKey ();
|
1157
|
+
const amountAsset = this.getAssetId (market['baseId']);
|
1158
|
+
const priceAsset = this.getAssetId (market['quoteId']);
|
1159
|
+
const isMarketOrder = (type === 'market');
|
1160
|
+
if ((isMarketOrder) && (price === undefined)) {
|
1161
|
+
throw new InvalidOrder (this.id + ' createOrder() requires a price argument for ' + type + ' orders to determine the max price for buy and the min price for sell');
|
1162
|
+
}
|
1163
|
+
const orderType = (side === 'buy') ? 0 : 1;
|
1164
|
+
const timestamp = this.milliseconds ();
|
1165
|
+
const defaultExpiryDelta = this.safeInteger (this.options, 'createOrderDefaultExpiry', 2419200000);
|
1166
|
+
const expiration = this.sum (timestamp, defaultExpiryDelta);
|
1167
|
+
const matcherFees = await this.getFeesForAsset (symbol, side, amount, price);
|
1168
|
+
// {
|
1169
|
+
// "base":{
|
1170
|
+
// "feeAssetId":"WAVES", // varies depending on the trading pair
|
1171
|
+
// "matcherFee":"1000000"
|
1172
|
+
// },
|
1173
|
+
// "discount":{
|
1174
|
+
// "feeAssetId":"EMAMLxDnv3xiz8RXg8Btj33jcEw3wLczL3JKYYmuubpc",
|
1175
|
+
// "matcherFee":"4077612"
|
1176
|
+
// }
|
1177
|
+
// }
|
1178
|
+
const base = this.safeValue (matcherFees, 'base');
|
1179
|
+
const baseFeeAssetId = this.safeString (base, 'feeAssetId');
|
1180
|
+
const baseFeeAsset = this.safeCurrencyCode (baseFeeAssetId);
|
1181
|
+
const baseMatcherFee = this.safeString (base, 'matcherFee');
|
1182
|
+
const discount = this.safeValue (matcherFees, 'discount');
|
1183
|
+
const discountFeeAssetId = this.safeString (discount, 'feeAssetId');
|
1184
|
+
const discountFeeAsset = this.safeCurrencyCode (discountFeeAssetId);
|
1185
|
+
const discountMatcherFee = this.safeString (discount, 'matcherFee');
|
1186
|
+
let matcherFeeAssetId = undefined;
|
1187
|
+
let matcherFee = undefined;
|
1188
|
+
// check first if user supplied asset fee is valid
|
1189
|
+
if (('feeAsset' in params) || ('feeAsset' in this.options)) {
|
1190
|
+
const feeAsset = this.safeString (params, 'feeAsset', this.safeString (this.options, 'feeAsset'));
|
1191
|
+
const feeCurrency = this.currency (feeAsset);
|
1192
|
+
matcherFeeAssetId = this.safeString (feeCurrency, 'id');
|
1193
|
+
}
|
1194
|
+
const balances = await this.fetchBalance ();
|
1195
|
+
if (matcherFeeAssetId !== undefined) {
|
1196
|
+
if (baseFeeAssetId !== matcherFeeAssetId && discountFeeAssetId !== matcherFeeAssetId) {
|
1197
|
+
throw new InvalidOrder (this.id + ' asset fee must be ' + baseFeeAsset + ' or ' + discountFeeAsset);
|
1198
|
+
}
|
1199
|
+
const matcherFeeAsset = this.safeCurrencyCode (matcherFeeAssetId);
|
1200
|
+
const rawMatcherFee = (matcherFeeAssetId === baseFeeAssetId) ? baseMatcherFee : discountMatcherFee;
|
1201
|
+
const floatMatcherFee = parseFloat (this.currencyFromPrecision (matcherFeeAsset, rawMatcherFee));
|
1202
|
+
if ((matcherFeeAsset in balances) && (balances[matcherFeeAsset]['free'] >= floatMatcherFee)) {
|
1203
|
+
matcherFee = parseInt (rawMatcherFee);
|
1204
|
+
} else {
|
1205
|
+
throw new InsufficientFunds (this.id + ' not enough funds of the selected asset fee');
|
1206
|
+
}
|
1207
|
+
}
|
1208
|
+
if (matcherFeeAssetId === undefined) {
|
1209
|
+
// try to the pay the fee using the base first then discount asset
|
1210
|
+
const floatBaseMatcherFee = parseFloat (this.currencyFromPrecision (baseFeeAsset, baseMatcherFee));
|
1211
|
+
if ((baseFeeAsset in balances) && (balances[baseFeeAsset]['free'] >= floatBaseMatcherFee)) {
|
1212
|
+
matcherFeeAssetId = baseFeeAssetId;
|
1213
|
+
matcherFee = parseInt (baseMatcherFee);
|
1214
|
+
} else {
|
1215
|
+
const floatDiscountMatcherFee = parseFloat (this.currencyFromPrecision (discountFeeAsset, discountMatcherFee));
|
1216
|
+
if ((discountFeeAsset in balances) && (balances[discountFeeAsset]['free'] >= floatDiscountMatcherFee)) {
|
1217
|
+
matcherFeeAssetId = discountFeeAssetId;
|
1218
|
+
matcherFee = parseInt (discountMatcherFee);
|
1219
|
+
}
|
1220
|
+
}
|
1221
|
+
}
|
1222
|
+
if (matcherFeeAssetId === undefined) {
|
1223
|
+
throw new InsufficientFunds (this.id + ' not enough funds on none of the eligible asset fees');
|
1224
|
+
}
|
1225
|
+
amount = this.amountToPrecision (symbol, amount);
|
1226
|
+
price = this.priceToPrecision (symbol, price);
|
1227
|
+
const byteArray = [
|
1228
|
+
this.numberToBE (3, 1),
|
1229
|
+
this.base58ToBinary (this.apiKey),
|
1230
|
+
this.base58ToBinary (matcherPublicKey),
|
1231
|
+
this.getAssetBytes (market['baseId']),
|
1232
|
+
this.getAssetBytes (market['quoteId']),
|
1233
|
+
this.numberToBE (orderType, 1),
|
1234
|
+
this.numberToBE (price, 8),
|
1235
|
+
this.numberToBE (amount, 8),
|
1236
|
+
this.numberToBE (timestamp, 8),
|
1237
|
+
this.numberToBE (expiration, 8),
|
1238
|
+
this.numberToBE (matcherFee, 8),
|
1239
|
+
this.getAssetBytes (matcherFeeAssetId),
|
1240
|
+
];
|
1241
|
+
const binary = this.binaryConcatArray (byteArray);
|
1242
|
+
const signature = this.eddsa (this.binaryToBase16 (binary), this.binaryToBase16 (this.base58ToBinary (this.secret)), 'ed25519');
|
1243
|
+
const assetPair = {
|
1244
|
+
'amountAsset': amountAsset,
|
1245
|
+
'priceAsset': priceAsset,
|
1246
|
+
};
|
1247
|
+
const body = {
|
1248
|
+
'senderPublicKey': this.apiKey,
|
1249
|
+
'matcherPublicKey': matcherPublicKey,
|
1250
|
+
'assetPair': assetPair,
|
1251
|
+
'orderType': side,
|
1252
|
+
'price': price,
|
1253
|
+
'amount': amount,
|
1254
|
+
'timestamp': timestamp,
|
1255
|
+
'expiration': expiration,
|
1256
|
+
'matcherFee': parseInt (matcherFee),
|
1257
|
+
'signature': signature,
|
1258
|
+
'version': 3,
|
1259
|
+
};
|
1260
|
+
if (matcherFeeAssetId !== 'WAVES') {
|
1261
|
+
body['matcherFeeAssetId'] = matcherFeeAssetId;
|
1262
|
+
}
|
1263
|
+
//
|
1264
|
+
// {
|
1265
|
+
// "success":true,
|
1266
|
+
// "message":{
|
1267
|
+
// "version":3,
|
1268
|
+
// "id":"GK5ox4RfLJFtqjQsCbDmvCya8ZhFVEUQDtF4yYuAJ6C7",
|
1269
|
+
// "sender":"3P8VzLSa23EW5CVckHbV7d5BoN75fF1hhFH",
|
1270
|
+
// "senderPublicKey":"AHXn8nBA4SfLQF7hLQiSn16kxyehjizBGW1TdrmSZ1gF",
|
1271
|
+
// "matcherPublicKey":"9cpfKN9suPNvfeUNphzxXMjcnn974eme8ZhWUjaktzU5",
|
1272
|
+
// "assetPair":{
|
1273
|
+
// "amountAsset":"C1iWsKGqLwjHUndiQ7iXpdmPum9PeCDFfyXBdJJosDRS",
|
1274
|
+
// "priceAsset":"WAVES"
|
1275
|
+
// },
|
1276
|
+
// "orderType":"buy",
|
1277
|
+
// "amount":110874978,
|
1278
|
+
// "price":514397851,
|
1279
|
+
// "timestamp":1650473255988,
|
1280
|
+
// "expiration":1652892455988,
|
1281
|
+
// "matcherFee":7074571,
|
1282
|
+
// "matcherFeeAssetId":"Atqv59EYzjFGuitKVnMRk6H8FukjoV3ktPorbEys25on",
|
1283
|
+
// "signature":"5Vgs6mbdZJv5Ce9mdobT6fppXr6bKn5WVDbzP6mGG5jMB5jgcA2eSScwctgvY5SwPm9n1bctAAKuXtLcdHjNNie8",
|
1284
|
+
// "proofs":["5Vgs6mbdZJv5Ce9mdobT6fppXr6bKn5WVDbzP6mGG5jMB5jgcA2eSScwctgvY5SwPm9n1bctAAKuXtLcdHjNNie8"]
|
1285
|
+
// },
|
1286
|
+
// "status":"OrderAccepted"
|
1287
|
+
// }
|
1288
|
+
//
|
1289
|
+
if (isMarketOrder) {
|
1290
|
+
const response = await this.matcherPostMatcherOrderbookMarket (body);
|
1291
|
+
const value = this.safeValue (response, 'message');
|
1292
|
+
return this.parseOrder (value, market);
|
1293
|
+
} else {
|
1294
|
+
const response = await this.matcherPostMatcherOrderbook (body);
|
1295
|
+
const value = this.safeValue (response, 'message');
|
1296
|
+
return this.parseOrder (value, market);
|
1297
|
+
}
|
1298
|
+
}
|
1299
|
+
|
1300
|
+
async cancelOrder (id, symbol = undefined, params = {}) {
|
1301
|
+
this.checkRequiredDependencies ();
|
1302
|
+
this.checkRequiredKeys ();
|
1303
|
+
await this.signIn ();
|
1304
|
+
const wavesAddress = await this.getWavesAddress ();
|
1305
|
+
const response = await this.forwardPostMatcherOrdersWavesAddressCancel ({
|
1306
|
+
'wavesAddress': wavesAddress,
|
1307
|
+
'orderId': id,
|
1308
|
+
});
|
1309
|
+
// {
|
1310
|
+
// "success":true,
|
1311
|
+
// "message":[[{"orderId":"EBpJeGM36KKFz5gTJAUKDBm89V8wqxKipSFBdU35AN3c","success":true,"status":"OrderCanceled"}]],
|
1312
|
+
// "status":"BatchCancelCompleted"
|
1313
|
+
// }
|
1314
|
+
const message = this.safeValue (response, 'message');
|
1315
|
+
const firstMessage = this.safeValue (message, 0);
|
1316
|
+
const firstOrder = this.safeValue (firstMessage, 0);
|
1317
|
+
const returnedId = this.safeString (firstOrder, 'orderId');
|
1318
|
+
return {
|
1319
|
+
'info': response,
|
1320
|
+
'id': returnedId,
|
1321
|
+
'clientOrderId': undefined,
|
1322
|
+
'timestamp': undefined,
|
1323
|
+
'datetime': undefined,
|
1324
|
+
'lastTradeTimestamp': undefined,
|
1325
|
+
'symbol': symbol,
|
1326
|
+
'type': undefined,
|
1327
|
+
'side': undefined,
|
1328
|
+
'price': undefined,
|
1329
|
+
'amount': undefined,
|
1330
|
+
'cost': undefined,
|
1331
|
+
'average': undefined,
|
1332
|
+
'filled': undefined,
|
1333
|
+
'remaining': undefined,
|
1334
|
+
'status': undefined,
|
1335
|
+
'fee': undefined,
|
1336
|
+
'trades': undefined,
|
1337
|
+
};
|
1338
|
+
}
|
1339
|
+
|
1340
|
+
async fetchOrder (id, symbol = undefined, params = {}) {
|
1341
|
+
this.checkRequiredDependencies ();
|
1342
|
+
this.checkRequiredKeys ();
|
1343
|
+
await this.loadMarkets ();
|
1344
|
+
let market = undefined;
|
1345
|
+
if (symbol !== undefined) {
|
1346
|
+
market = this.market (symbol);
|
1347
|
+
}
|
1348
|
+
const timestamp = this.milliseconds ();
|
1349
|
+
const byteArray = [
|
1350
|
+
this.base58ToBinary (this.apiKey),
|
1351
|
+
this.numberToBE (timestamp, 8),
|
1352
|
+
];
|
1353
|
+
const binary = this.binaryConcatArray (byteArray);
|
1354
|
+
const hexSecret = this.binaryToBase16 (this.base58ToBinary (this.secret));
|
1355
|
+
const signature = this.eddsa (this.binaryToBase16 (binary), hexSecret, 'ed25519');
|
1356
|
+
const request = {
|
1357
|
+
'Timestamp': timestamp.toString (),
|
1358
|
+
'Signature': signature,
|
1359
|
+
'publicKey': this.apiKey,
|
1360
|
+
'orderId': id,
|
1361
|
+
};
|
1362
|
+
const response = await this.matcherGetMatcherOrderbookPublicKeyOrderId (this.extend (request, params));
|
1363
|
+
return this.parseOrder (response, market);
|
1364
|
+
}
|
1365
|
+
|
1366
|
+
async fetchOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
1367
|
+
this.checkRequiredDependencies ();
|
1368
|
+
this.checkRequiredKeys ();
|
1369
|
+
if (symbol === undefined) {
|
1370
|
+
throw new ArgumentsRequired (this.id + ' fetchOrders() requires symbol argument');
|
1371
|
+
}
|
1372
|
+
await this.loadMarkets ();
|
1373
|
+
const market = this.market (symbol);
|
1374
|
+
const timestamp = this.milliseconds ();
|
1375
|
+
const byteArray = [
|
1376
|
+
this.base58ToBinary (this.apiKey),
|
1377
|
+
this.numberToBE (timestamp, 8),
|
1378
|
+
];
|
1379
|
+
const binary = this.binaryConcatArray (byteArray);
|
1380
|
+
const hexSecret = this.binaryToBase16 (this.base58ToBinary (this.secret));
|
1381
|
+
const signature = this.eddsa (this.binaryToBase16 (binary), hexSecret, 'ed25519');
|
1382
|
+
const request = {
|
1383
|
+
'Accept': 'application/json',
|
1384
|
+
'Timestamp': timestamp.toString (),
|
1385
|
+
'Signature': signature,
|
1386
|
+
'publicKey': this.apiKey,
|
1387
|
+
'baseId': market['baseId'],
|
1388
|
+
'quoteId': market['quoteId'],
|
1389
|
+
};
|
1390
|
+
const response = await this.matcherGetMatcherOrderbookBaseIdQuoteIdPublicKeyPublicKey (this.extend (request, params));
|
1391
|
+
// [ { id: '3KicDeWayY2mdrRoYdCkP3gUAoUZUNT1AA6GAtWuPLfa',
|
1392
|
+
// type: 'sell',
|
1393
|
+
// orderType: 'limit',
|
1394
|
+
// amount: 1,
|
1395
|
+
// fee: 300000,
|
1396
|
+
// price: 100000000,
|
1397
|
+
// timestamp: 1591651254076,
|
1398
|
+
// filled: 0,
|
1399
|
+
// filledFee: 0,
|
1400
|
+
// feeAsset: 'WAVES',
|
1401
|
+
// status: 'Accepted',
|
1402
|
+
// assetPair:
|
1403
|
+
// { amountAsset: null,
|
1404
|
+
// priceAsset: '8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS' },
|
1405
|
+
// avgWeighedPrice: 0 }, ... ]
|
1406
|
+
return this.parseOrders (response, market, since, limit);
|
1407
|
+
}
|
1408
|
+
|
1409
|
+
async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
1410
|
+
await this.loadMarkets ();
|
1411
|
+
await this.signIn ();
|
1412
|
+
let market = undefined;
|
1413
|
+
if (symbol !== undefined) {
|
1414
|
+
market = this.market (symbol);
|
1415
|
+
}
|
1416
|
+
const address = await this.getWavesAddress ();
|
1417
|
+
const request = {
|
1418
|
+
'address': address,
|
1419
|
+
'activeOnly': true,
|
1420
|
+
};
|
1421
|
+
const response = await this.forwardGetMatcherOrdersAddress (request);
|
1422
|
+
return this.parseOrders (response, market, since, limit);
|
1423
|
+
}
|
1424
|
+
|
1425
|
+
async fetchClosedOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
1426
|
+
await this.loadMarkets ();
|
1427
|
+
await this.signIn ();
|
1428
|
+
let market = undefined;
|
1429
|
+
if (symbol !== undefined) {
|
1430
|
+
market = this.market (symbol);
|
1431
|
+
}
|
1432
|
+
const address = await this.getWavesAddress ();
|
1433
|
+
const request = {
|
1434
|
+
'address': address,
|
1435
|
+
'closedOnly': true,
|
1436
|
+
};
|
1437
|
+
const response = await this.forwardGetMatcherOrdersAddress (request);
|
1438
|
+
// [
|
1439
|
+
// {
|
1440
|
+
// "id": "9aXcxvXai73jbAm7tQNnqaQ2PwUjdmWuyjvRTKAHsw4f",
|
1441
|
+
// "type": "buy",
|
1442
|
+
// "orderType": "limit",
|
1443
|
+
// "amount": 23738330,
|
1444
|
+
// "fee": 300000,
|
1445
|
+
// "price": 3828348334,
|
1446
|
+
// "timestamp": 1591926905636,
|
1447
|
+
// "filled": 23738330,
|
1448
|
+
// "filledFee": 300000,
|
1449
|
+
// "feeAsset": "WAVES",
|
1450
|
+
// "status": "Filled",
|
1451
|
+
// "assetPair": {
|
1452
|
+
// "amountAsset": "HZk1mbfuJpmxU1Fs4AX5MWLVYtctsNcg6e2C6VKqK8zk",
|
1453
|
+
// "priceAsset": null
|
1454
|
+
// },
|
1455
|
+
// "avgWeighedPrice": 3828348334
|
1456
|
+
// }, ...
|
1457
|
+
// ]
|
1458
|
+
return this.parseOrders (response, market, since, limit);
|
1459
|
+
}
|
1460
|
+
|
1461
|
+
parseOrderStatus (status) {
|
1462
|
+
const statuses = {
|
1463
|
+
'Cancelled': 'canceled',
|
1464
|
+
'Accepted': 'open',
|
1465
|
+
'Filled': 'closed',
|
1466
|
+
'PartiallyFilled': 'open',
|
1467
|
+
};
|
1468
|
+
return this.safeString (statuses, status, status);
|
1469
|
+
}
|
1470
|
+
|
1471
|
+
getSymbolFromAssetPair (assetPair) {
|
1472
|
+
// a blank string or null can indicate WAVES
|
1473
|
+
const baseId = this.safeString (assetPair, 'amountAsset', 'WAVES');
|
1474
|
+
const quoteId = this.safeString (assetPair, 'priceAsset', 'WAVES');
|
1475
|
+
return this.safeCurrencyCode (baseId) + '/' + this.safeCurrencyCode (quoteId);
|
1476
|
+
}
|
1477
|
+
|
1478
|
+
parseOrder (order, market = undefined) {
|
1479
|
+
//
|
1480
|
+
// createOrder
|
1481
|
+
//
|
1482
|
+
// {
|
1483
|
+
// 'version': 3,
|
1484
|
+
// 'id': 'BshyeHXDfJmTnjTdBYt371jD4yWaT3JTP6KpjpsiZepS',
|
1485
|
+
// 'sender': '3P8VzLSa23EW5CVckHbV7d5BoN75fF1hhFH',
|
1486
|
+
// 'senderPublicKey': 'AHXn8nBA4SfLQF7hLQiSn16kxyehjizBGW1TdrmSZ1gF',
|
1487
|
+
// 'matcherPublicKey': '9cpfKN9suPNvfeUNphzxXMjcnn974eme8ZhWUjaktzU5',
|
1488
|
+
// 'assetPair': {
|
1489
|
+
// 'amountAsset': '474jTeYx2r2Va35794tCScAXWJG9hU2HcgxzMowaZUnu',
|
1490
|
+
// 'priceAsset': 'DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p',
|
1491
|
+
// },
|
1492
|
+
// 'orderType': 'buy',
|
1493
|
+
// 'amount': 10000,
|
1494
|
+
// 'price': 400000000,
|
1495
|
+
// 'timestamp': 1599848586891,
|
1496
|
+
// 'expiration': 1602267786891,
|
1497
|
+
// 'matcherFee': 3008,
|
1498
|
+
// 'matcherFeeAssetId': '474jTeYx2r2Va35794tCScAXWJG9hU2HcgxzMowaZUnu',
|
1499
|
+
// 'signature': '3D2h8ubrhuWkXbVn4qJ3dvjmZQxLoRNfjTqb9uNpnLxUuwm4fGW2qGH6yKFe2SQPrcbgkS3bDVe7SNtMuatEJ7qy',
|
1500
|
+
// 'proofs': [
|
1501
|
+
// '3D2h8ubrhuWkXbVn4qJ3dvjmZQxLoRNfjTqb9uNpnLxUuwm4fGW2qGH6yKFe2SQPrcbgkS3bDVe7SNtMuatEJ7qy',
|
1502
|
+
// ],
|
1503
|
+
// }
|
1504
|
+
//
|
1505
|
+
//
|
1506
|
+
// fetchOrder, fetchOrders, fetchOpenOrders, fetchClosedOrders
|
1507
|
+
//
|
1508
|
+
// {
|
1509
|
+
// id: '81D9uKk2NfmZzfG7uaJsDtxqWFbJXZmjYvrL88h15fk8',
|
1510
|
+
// type: 'buy',
|
1511
|
+
// orderType: 'limit',
|
1512
|
+
// amount: 30000000000,
|
1513
|
+
// filled: 0,
|
1514
|
+
// price: 1000000,
|
1515
|
+
// fee: 300000,
|
1516
|
+
// filledFee: 0,
|
1517
|
+
// feeAsset: 'WAVES',
|
1518
|
+
// timestamp: 1594303779322,
|
1519
|
+
// status: 'Cancelled',
|
1520
|
+
// assetPair: {
|
1521
|
+
// amountAsset: '474jTeYx2r2Va35794tCScAXWJG9hU2HcgxzMowaZUnu',
|
1522
|
+
// priceAsset: 'WAVES'
|
1523
|
+
// },
|
1524
|
+
// avgWeighedPrice: 0,
|
1525
|
+
// version: 3,
|
1526
|
+
// totalExecutedPriceAssets: 0, // in fetchOpenOrder/s
|
1527
|
+
// }
|
1528
|
+
//
|
1529
|
+
const timestamp = this.safeInteger (order, 'timestamp');
|
1530
|
+
const side = this.safeString2 (order, 'type', 'orderType');
|
1531
|
+
let type = 'limit';
|
1532
|
+
if ('type' in order) {
|
1533
|
+
// fetchOrders
|
1534
|
+
type = this.safeString (order, 'orderType', type);
|
1535
|
+
}
|
1536
|
+
const id = this.safeString (order, 'id');
|
1537
|
+
const filledString = this.safeString (order, 'filled');
|
1538
|
+
const priceString = this.safeString (order, 'price');
|
1539
|
+
const amountString = this.safeString (order, 'amount');
|
1540
|
+
const assetPair = this.safeValue (order, 'assetPair');
|
1541
|
+
let symbol = undefined;
|
1542
|
+
if (assetPair !== undefined) {
|
1543
|
+
symbol = this.getSymbolFromAssetPair (assetPair);
|
1544
|
+
} else if (market !== undefined) {
|
1545
|
+
symbol = market['symbol'];
|
1546
|
+
}
|
1547
|
+
const amountCurrency = this.safeCurrencyCode (this.safeString (assetPair, 'amountAsset', 'WAVES'));
|
1548
|
+
const price = this.priceFromPrecision (symbol, priceString);
|
1549
|
+
const amount = this.currencyFromPrecision (amountCurrency, amountString);
|
1550
|
+
const filled = this.currencyFromPrecision (amountCurrency, filledString);
|
1551
|
+
const average = this.priceFromPrecision (symbol, this.safeString (order, 'avgWeighedPrice'));
|
1552
|
+
const status = this.parseOrderStatus (this.safeString (order, 'status'));
|
1553
|
+
let fee = undefined;
|
1554
|
+
if ('type' in order) {
|
1555
|
+
const currency = this.safeCurrencyCode (this.safeString (order, 'feeAsset'));
|
1556
|
+
fee = {
|
1557
|
+
'currency': currency,
|
1558
|
+
'fee': this.parseNumber (this.currencyFromPrecision (currency, this.safeString (order, 'filledFee'))),
|
1559
|
+
};
|
1560
|
+
} else {
|
1561
|
+
const currency = this.safeCurrencyCode (this.safeString (order, 'matcherFeeAssetId', 'WAVES'));
|
1562
|
+
fee = {
|
1563
|
+
'currency': currency,
|
1564
|
+
'fee': this.parseNumber (this.currencyFromPrecision (currency, this.safeString (order, 'matcherFee'))),
|
1565
|
+
};
|
1566
|
+
}
|
1567
|
+
return this.safeOrder ({
|
1568
|
+
'info': order,
|
1569
|
+
'id': id,
|
1570
|
+
'clientOrderId': undefined,
|
1571
|
+
'timestamp': timestamp,
|
1572
|
+
'datetime': this.iso8601 (timestamp),
|
1573
|
+
'lastTradeTimestamp': undefined,
|
1574
|
+
'symbol': symbol,
|
1575
|
+
'type': type,
|
1576
|
+
'timeInForce': undefined,
|
1577
|
+
'postOnly': undefined,
|
1578
|
+
'side': side,
|
1579
|
+
'price': price,
|
1580
|
+
'stopPrice': undefined,
|
1581
|
+
'amount': amount,
|
1582
|
+
'cost': undefined,
|
1583
|
+
'average': average,
|
1584
|
+
'filled': filled,
|
1585
|
+
'remaining': undefined,
|
1586
|
+
'status': status,
|
1587
|
+
'fee': fee,
|
1588
|
+
'trades': undefined,
|
1589
|
+
}, market);
|
1590
|
+
}
|
1591
|
+
|
1592
|
+
async getWavesAddress () {
|
1593
|
+
const cachedAddreess = this.safeString (this.options, 'wavesAddress');
|
1594
|
+
if (cachedAddreess === undefined) {
|
1595
|
+
const request = {
|
1596
|
+
'publicKey': this.apiKey,
|
1597
|
+
};
|
1598
|
+
const response = await this.nodeGetAddressesPublicKeyPublicKey (request);
|
1599
|
+
this.options['wavesAddress'] = this.safeString (response, 'address');
|
1600
|
+
return this.options['wavesAddress'];
|
1601
|
+
} else {
|
1602
|
+
return cachedAddreess;
|
1603
|
+
}
|
1604
|
+
}
|
1605
|
+
|
1606
|
+
async fetchBalance (params = {}) {
|
1607
|
+
// makes a lot of different requests to get all the data
|
1608
|
+
// in particular:
|
1609
|
+
// fetchMarkets, getWavesAddress,
|
1610
|
+
// getTotalBalance (doesn't include waves), getReservedBalance (doesn't include waves)
|
1611
|
+
// getReservedBalance (includes WAVES)
|
1612
|
+
// I couldn't find another way to get all the data
|
1613
|
+
this.checkRequiredDependencies ();
|
1614
|
+
this.checkRequiredKeys ();
|
1615
|
+
await this.loadMarkets ();
|
1616
|
+
const wavesAddress = await this.getWavesAddress ();
|
1617
|
+
const request = {
|
1618
|
+
'address': wavesAddress,
|
1619
|
+
};
|
1620
|
+
const totalBalance = await this.nodeGetAssetsBalanceAddress (request);
|
1621
|
+
// {
|
1622
|
+
// "address": "3P8VzLSa23EW5CVckHbV7d5BoN75fF1hhFH",
|
1623
|
+
// "balances": [
|
1624
|
+
// {
|
1625
|
+
// "assetId": "DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p",
|
1626
|
+
// "balance": 1177200,
|
1627
|
+
// "reissuable": false,
|
1628
|
+
// "minSponsoredAssetFee": 7420,
|
1629
|
+
// "sponsorBalance": 47492147189709,
|
1630
|
+
// "quantity": 999999999775381400,
|
1631
|
+
// "issueTransaction": {
|
1632
|
+
// "senderPublicKey": "BRnVwSVctnV8pge5vRpsJdWnkjWEJspFb6QvrmZvu3Ht",
|
1633
|
+
// "quantity": 1000000000000000000,
|
1634
|
+
// "fee": 100400000,
|
1635
|
+
// "description": "Neutrino USD",
|
1636
|
+
// "type": 3,
|
1637
|
+
// "version": 2,
|
1638
|
+
// "reissuable": false,
|
1639
|
+
// "script": null,
|
1640
|
+
// "sender": "3PC9BfRwJWWiw9AREE2B3eWzCks3CYtg4yo",
|
1641
|
+
// "feeAssetId": null,
|
1642
|
+
// "chainId": 87,
|
1643
|
+
// "proofs": [
|
1644
|
+
// "3HNpbVkgP69NWSeb9hGYauiQDaXrRXh3tXFzNsGwsAAXnFrA29SYGbLtziW9JLpXEq7qW1uytv5Fnm5XTUMB2BxU"
|
1645
|
+
// ],
|
1646
|
+
// "assetId": "DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p",
|
1647
|
+
// "decimals": 6,
|
1648
|
+
// "name": "USD-N",
|
1649
|
+
// "id": "DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p",
|
1650
|
+
// "timestamp": 1574429393962
|
1651
|
+
// }
|
1652
|
+
// }
|
1653
|
+
// ]
|
1654
|
+
// }
|
1655
|
+
const balances = this.safeValue (totalBalance, 'balances');
|
1656
|
+
const result = {};
|
1657
|
+
let timestamp = undefined;
|
1658
|
+
const assetIds = [];
|
1659
|
+
const nonStandardBalances = [];
|
1660
|
+
for (let i = 0; i < balances.length; i++) {
|
1661
|
+
const entry = balances[i];
|
1662
|
+
const entryTimestamp = this.safeInteger (entry, 'timestamp');
|
1663
|
+
timestamp = (timestamp === undefined) ? entryTimestamp : Math.max (timestamp, entryTimestamp);
|
1664
|
+
const issueTransaction = this.safeValue (entry, 'issueTransaction');
|
1665
|
+
const currencyId = this.safeString (entry, 'assetId');
|
1666
|
+
const balance = this.safeString (entry, 'balance');
|
1667
|
+
if (issueTransaction === undefined) {
|
1668
|
+
assetIds.push (currencyId);
|
1669
|
+
nonStandardBalances.push (balance);
|
1670
|
+
continue;
|
1671
|
+
}
|
1672
|
+
const decimals = this.safeInteger (issueTransaction, 'decimals');
|
1673
|
+
let code = undefined;
|
1674
|
+
if (currencyId in this.currencies_by_id) {
|
1675
|
+
code = this.safeCurrencyCode (currencyId);
|
1676
|
+
result[code] = this.account ();
|
1677
|
+
result[code]['total'] = this.fromPrecision (balance, decimals);
|
1678
|
+
}
|
1679
|
+
}
|
1680
|
+
const nonStandardAssets = assetIds.length;
|
1681
|
+
if (nonStandardAssets) {
|
1682
|
+
const request = {
|
1683
|
+
'ids': assetIds,
|
1684
|
+
};
|
1685
|
+
const response = await this.publicGetAssets (request);
|
1686
|
+
const data = this.safeValue (response, 'data');
|
1687
|
+
for (let i = 0; i < data.length; i++) {
|
1688
|
+
const entry = data[i];
|
1689
|
+
const balance = nonStandardBalances[i];
|
1690
|
+
const inner = this.safeValue (entry, 'data');
|
1691
|
+
const decimals = this.safeInteger (inner, 'precision');
|
1692
|
+
const ticker = this.safeString (inner, 'ticker');
|
1693
|
+
const code = this.safeCurrencyCode (ticker);
|
1694
|
+
result[code] = this.account ();
|
1695
|
+
result[code]['total'] = this.fromPrecision (balance, decimals);
|
1696
|
+
}
|
1697
|
+
}
|
1698
|
+
const currentTimestamp = this.milliseconds ();
|
1699
|
+
const byteArray = [
|
1700
|
+
this.base58ToBinary (this.apiKey),
|
1701
|
+
this.numberToBE (currentTimestamp, 8),
|
1702
|
+
];
|
1703
|
+
const binary = this.binaryConcatArray (byteArray);
|
1704
|
+
const hexSecret = this.binaryToBase16 (this.base58ToBinary (this.secret));
|
1705
|
+
const signature = this.eddsa (this.binaryToBase16 (binary), hexSecret, 'ed25519');
|
1706
|
+
const matcherRequest = {
|
1707
|
+
'publicKey': this.apiKey,
|
1708
|
+
'signature': signature,
|
1709
|
+
'timestamp': currentTimestamp.toString (),
|
1710
|
+
};
|
1711
|
+
const reservedBalance = await this.matcherGetMatcherBalanceReservedPublicKey (matcherRequest);
|
1712
|
+
// { WAVES: 200300000 }
|
1713
|
+
const reservedKeys = Object.keys (reservedBalance);
|
1714
|
+
for (let i = 0; i < reservedKeys.length; i++) {
|
1715
|
+
const currencyId = reservedKeys[i];
|
1716
|
+
const code = this.safeCurrencyCode (currencyId);
|
1717
|
+
if (!(code in result)) {
|
1718
|
+
result[code] = this.account ();
|
1719
|
+
}
|
1720
|
+
const amount = this.safeString (reservedBalance, currencyId);
|
1721
|
+
if (code in this.currencies) {
|
1722
|
+
result[code]['used'] = this.currencyFromPrecision (code, amount);
|
1723
|
+
} else {
|
1724
|
+
result[code]['used'] = amount;
|
1725
|
+
}
|
1726
|
+
}
|
1727
|
+
const wavesRequest = {
|
1728
|
+
'address': wavesAddress,
|
1729
|
+
};
|
1730
|
+
const wavesTotal = await this.nodeGetAddressesBalanceAddress (wavesRequest);
|
1731
|
+
// {
|
1732
|
+
// "address": "3P8VzLSa23EW5CVckHbV7d5BoN75fF1hhFH",
|
1733
|
+
// "confirmations": 0,
|
1734
|
+
// "balance": 909085978
|
1735
|
+
// }
|
1736
|
+
result['WAVES'] = this.safeValue (result, 'WAVES', {});
|
1737
|
+
result['WAVES']['total'] = this.currencyFromPrecision ('WAVES', this.safeString (wavesTotal, 'balance'));
|
1738
|
+
const codes = Object.keys (result);
|
1739
|
+
for (let i = 0; i < codes.length; i++) {
|
1740
|
+
const code = codes[i];
|
1741
|
+
if (this.safeValue (result[code], 'used') === undefined) {
|
1742
|
+
result[code]['used'] = '0';
|
1743
|
+
}
|
1744
|
+
}
|
1745
|
+
result['timestamp'] = timestamp;
|
1746
|
+
result['datetime'] = this.iso8601 (timestamp);
|
1747
|
+
return this.safeBalance (result);
|
1748
|
+
}
|
1749
|
+
|
1750
|
+
async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
1751
|
+
await this.loadMarkets ();
|
1752
|
+
const market = this.market (symbol);
|
1753
|
+
const address = await this.getWavesAddress ();
|
1754
|
+
const request = {
|
1755
|
+
'sender': address,
|
1756
|
+
'amountAsset': market['baseId'],
|
1757
|
+
'priceAsset': market['quoteId'],
|
1758
|
+
};
|
1759
|
+
const response = await this.publicGetTransactionsExchange (request);
|
1760
|
+
const data = this.safeValue (response, 'data');
|
1761
|
+
//
|
1762
|
+
// {
|
1763
|
+
// "__type":"list",
|
1764
|
+
// "isLastPage":true,
|
1765
|
+
// "lastCursor":"MzA2MjQ0MzAwMDI5OjpkZXNj",
|
1766
|
+
// "data": [
|
1767
|
+
// {
|
1768
|
+
// "__type":"transaction",
|
1769
|
+
// "data": {
|
1770
|
+
// "id":"GbjPqco2wRP5QSrY5LimFrUyJaM535K9nhK5zaQ7J7Tx",
|
1771
|
+
// "timestamp":"2022-04-06T19:56:31.479Z",
|
1772
|
+
// "height":3062443,
|
1773
|
+
// "type":7,
|
1774
|
+
// "version":2,
|
1775
|
+
// "proofs":[
|
1776
|
+
// "57mYrANw61eiArCTv2eYwzXm71jYC2KpZ5AeM9zHEstuRaYSAWSuSE7njAJYJu8zap6DMCm3nzqc6es3wQFDpRCN"
|
1777
|
+
// ],
|
1778
|
+
// "fee":0.003,
|
1779
|
+
// "applicationStatus":"succeeded",
|
1780
|
+
// "sender":"3PEjHv3JGjcWNpYEEkif2w8NXV4kbhnoGgu",
|
1781
|
+
// "senderPublicKey":"9cpfKN9suPNvfeUNphzxXMjcnn974eme8ZhWUjaktzU5",
|
1782
|
+
// "buyMatcherFee":0,
|
1783
|
+
// "sellMatcherFee":0.00141728,
|
1784
|
+
// "price":215.7431,
|
1785
|
+
// "amount":0.09,
|
1786
|
+
// "order1": {
|
1787
|
+
// "id":"49qiuQj5frdZ6zpTCEpMuKPMAh1EimwXpXWB4BeCw33h",
|
1788
|
+
// "senderPublicKey":"CjUfoH3dsDZsf5UuAjqqzpWHXgvKzBZpVG9YixF7L48K",
|
1789
|
+
// "matcherPublicKey":"9cpfKN9suPNvfeUNphzxXMjcnn974eme8ZhWUjaktzU5",
|
1790
|
+
// "assetPair": {
|
1791
|
+
// "amountAsset":"7TMu26hAs7B2oW6c5sfx45KSZT7GQA3TZNYuCav8Dcqt",
|
1792
|
+
// "priceAsset":"DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p"
|
1793
|
+
// },
|
1794
|
+
// "orderType":"buy",
|
1795
|
+
// "price":215.7431,
|
1796
|
+
// "sender":"3PR9WmaHV5ueVw2Wr9xsiCG3t4ySXzkkGLy",
|
1797
|
+
// "amount":0.36265477,
|
1798
|
+
// "timestamp":"2022-04-06T19:55:06.832Z",
|
1799
|
+
// "expiration":"2022-05-05T19:55:06.832Z",
|
1800
|
+
// "matcherFee":3.000334,
|
1801
|
+
// "signature":"2rBWhdeuRJNpQfXfTFtcR8x8Lpic8FUHPdLML9uxABRUuxe48YRJcZxbncwWAh9LWFCEUZiztv7RZBZfGMWfFxTs",
|
1802
|
+
// "matcherFeeAssetId":"DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p"
|
1803
|
+
// },
|
1804
|
+
// "order2": {
|
1805
|
+
// "id":"AkxiJqCuv6wm8K41TUSgFNwShZMnCbMDT78MqrcWpQ53",
|
1806
|
+
// "senderPublicKey":"72o7qNKyne5hthB1Ww6famE7uHrk5vTVB2ZfUMBEqL3Y",
|
1807
|
+
// "matcherPublicKey":"9cpfKN9suPNvfeUNphzxXMjcnn974eme8ZhWUjaktzU5",
|
1808
|
+
// "assetPair": {
|
1809
|
+
// "amountAsset":"7TMu26hAs7B2oW6c5sfx45KSZT7GQA3TZNYuCav8Dcqt",
|
1810
|
+
// "priceAsset":"DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p"
|
1811
|
+
// },
|
1812
|
+
// "orderType":"sell",
|
1813
|
+
// "price":210,
|
1814
|
+
// "sender":"3P3CzbjGgiqEyUBeKZYfgZtyaZfMG8fjoUD",
|
1815
|
+
// "amount":0.09,
|
1816
|
+
// "timestamp":"2022-04-06T19:56:18.535Z",
|
1817
|
+
// "expiration":"2022-05-04T19:56:18.535Z",
|
1818
|
+
// "matcherFee":0.00141728,
|
1819
|
+
// "signature":"5BZCjYn6QzVkMXBFDBnzcAUBdCZqhq9hQfRXFHfLUQCsbis4zeriw4sUqLa1BZRT2isC6iY4Z4HtekikPqZ461PT",
|
1820
|
+
// "matcherFeeAssetId":"7TMu26hAs7B2oW6c5sfx45KSZT7GQA3TZNYuCav8Dcqt"
|
1821
|
+
// }
|
1822
|
+
// }
|
1823
|
+
// },...
|
1824
|
+
// ]
|
1825
|
+
// }
|
1826
|
+
//
|
1827
|
+
return this.parseTrades (data, market, since, limit);
|
1828
|
+
}
|
1829
|
+
|
1830
|
+
async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) {
|
1831
|
+
await this.loadMarkets ();
|
1832
|
+
const market = this.market (symbol);
|
1833
|
+
const request = {
|
1834
|
+
'amountAsset': market['baseId'],
|
1835
|
+
'priceAsset': market['quoteId'],
|
1836
|
+
};
|
1837
|
+
if (limit !== undefined) {
|
1838
|
+
request['limit'] = limit;
|
1839
|
+
}
|
1840
|
+
if (since !== undefined) {
|
1841
|
+
request['timeStart'] = since;
|
1842
|
+
}
|
1843
|
+
const response = await this.publicGetTransactionsExchange (request);
|
1844
|
+
const data = this.safeValue (response, 'data');
|
1845
|
+
//
|
1846
|
+
// {
|
1847
|
+
// "__type":"list",
|
1848
|
+
// "isLastPage":false,
|
1849
|
+
// "lastCursor":"MzA2MjM2MTAwMDU0OjpkZXNj",
|
1850
|
+
// "data": [
|
1851
|
+
// {
|
1852
|
+
// "__type":"transaction",
|
1853
|
+
// "data": {
|
1854
|
+
// "id":"F42WsvSsyEzvpPLFjVhQKkSNuopooP4zMkjSUs47NeML",
|
1855
|
+
// "timestamp":"2022-04-06T18:39:49.145Z",
|
1856
|
+
// "height":3062361,
|
1857
|
+
// "type":7,
|
1858
|
+
// "version":2,
|
1859
|
+
// "proofs": [
|
1860
|
+
// "39iJv82kFi4pyuBxYeZpP45NXXjbrCXdVsHPAAvj32UMLmTXLjMTfV43PcmZDSAuS93HKSDo1aKJrin8UvkeE9Bs"
|
1861
|
+
// ],
|
1862
|
+
// "fee":0.003,
|
1863
|
+
// "applicationStatus":"succeeded",
|
1864
|
+
// "sender":"3PEjHv3JGjcWNpYEEkif2w8NXV4kbhnoGgu",
|
1865
|
+
// "senderPublicKey":"9cpfKN9suPNvfeUNphzxXMjcnn974eme8ZhWUjaktzU5",
|
1866
|
+
// "buyMatcherFee":0.02314421,
|
1867
|
+
// "sellMatcherFee":0,
|
1868
|
+
// "price":217.3893,
|
1869
|
+
// "amount":0.34523025,
|
1870
|
+
// "order1": {
|
1871
|
+
// "id":"HkM36PHGaeeZdDKT1mYgZXhaU9PRZ54RZiJc2K4YMT3Q",
|
1872
|
+
// "senderPublicKey":"7wYCaDcc6GX1Jx2uS7QgLHBypBKvrezTS1HfiW6Xe4Bk",
|
1873
|
+
// "matcherPublicKey":"9cpfKN9suPNvfeUNphzxXMjcnn974eme8ZhWUjaktzU5",
|
1874
|
+
// "assetPair": {
|
1875
|
+
// "amountAsset":"7TMu26hAs7B2oW6c5sfx45KSZT7GQA3TZNYuCav8Dcqt",
|
1876
|
+
// "priceAsset":"DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p"
|
1877
|
+
// },
|
1878
|
+
// "orderType":"buy",
|
1879
|
+
// "price":225.2693,
|
1880
|
+
// "sender":"3PLPc8f4DGYaF9C9bwJ2uVmHqRv3NCjg5VQ",
|
1881
|
+
// "amount":2.529,
|
1882
|
+
// "timestamp":"2022-04-06T18:39:48.796Z",
|
1883
|
+
// "expiration":"2022-05-05T18:39:48.796Z",
|
1884
|
+
// "matcherFee":0.17584444,
|
1885
|
+
// "signature":"2yQfJoomv86evQDw36fg1uiRkHvPDZtRp3qvxqTBWPvz4JLTHGQtEHJF5NGTvym6U93CtgNprngzmD9ecHBjxf6U",
|
1886
|
+
// "matcherFeeAssetId":"Atqv59EYzjFGuitKVnMRk6H8FukjoV3ktPorbEys25on"
|
1887
|
+
// },
|
1888
|
+
// "order2": {
|
1889
|
+
// "id":"F7HKmeuzwWdk3wKitHLnVx5MuD4wBWPpphQ8kUGx4tT9",
|
1890
|
+
// "senderPublicKey":"CjUfoH3dsDZsf5UuAjqqzpWHXgvKzBZpVG9YixF7L48K",
|
1891
|
+
// "matcherPublicKey":"9cpfKN9suPNvfeUNphzxXMjcnn974eme8ZhWUjaktzU5",
|
1892
|
+
// "assetPair": {
|
1893
|
+
// "amountAsset":"7TMu26hAs7B2oW6c5sfx45KSZT7GQA3TZNYuCav8Dcqt",
|
1894
|
+
// "priceAsset":"DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p"
|
1895
|
+
// },
|
1896
|
+
// "orderType":"sell",
|
1897
|
+
// "price":217.3893,
|
1898
|
+
// "sender":"3PR9WmaHV5ueVw2Wr9xsiCG3t4ySXzkkGLy",
|
1899
|
+
// "amount":0.35767793,
|
1900
|
+
// "timestamp":"2022-04-06T18:32:01.390Z",
|
1901
|
+
// "expiration":"2022-05-05T18:32:01.390Z",
|
1902
|
+
// "matcherFee":0.0139168,
|
1903
|
+
// "signature":"34HgWVLPgeYWkiSvAc5ChVepGTYDQDug2dMTSincs6idEyoM7AtaZuH3mqQ5RJG2fcxxH2QSB723Qq3dgLQwQmKf",
|
1904
|
+
// "matcherFeeAssetId":"7TMu26hAs7B2oW6c5sfx45KSZT7GQA3TZNYuCav8Dcqt"
|
1905
|
+
// }
|
1906
|
+
// }
|
1907
|
+
// }, ...
|
1908
|
+
// ]
|
1909
|
+
// }
|
1910
|
+
//
|
1911
|
+
return this.parseTrades (data, market, since, limit);
|
1912
|
+
}
|
1913
|
+
|
1914
|
+
parseTrade (trade, market = undefined) {
|
1915
|
+
//
|
1916
|
+
// { __type: 'transaction',
|
1917
|
+
// data:
|
1918
|
+
// { id: 'HSdruioHqvYHeyn9hhyoHdRWPB2bFA8ujeCPZMK6992c',
|
1919
|
+
// timestamp: '2020-06-09T19:34:51.897Z',
|
1920
|
+
// height: 2099684,
|
1921
|
+
// type: 7,
|
1922
|
+
// version: 2,
|
1923
|
+
// proofs:
|
1924
|
+
// [ '26teDHERQgwjjHqEn4REcDotNG8M21xjou3X42XuDuCvrRkQo6aPyrswByH3UrkWG8v27ZAaVNzoxDg4teNcLtde' ],
|
1925
|
+
// fee: 0.003,
|
1926
|
+
// sender: '3PEjHv3JGjcWNpYEEkif2w8NXV4kbhnoGgu',
|
1927
|
+
// senderPublicKey: '9cpfKN9suPNvfeUNphzxXMjcnn974eme8ZhWUjaktzU5',
|
1928
|
+
// buyMatcherFee: 0.00299999,
|
1929
|
+
// sellMatcherFee: 0.00299999,
|
1930
|
+
// price: 0.00012003,
|
1931
|
+
// amount: 60.80421562,
|
1932
|
+
// order1:
|
1933
|
+
// { id: 'CBRwP3ar4oMvvpUiGyfxc1syh41488SDi2GkrjuBDegv',
|
1934
|
+
// senderPublicKey: 'DBXSHBz96NFsMu7xh4fi2eT9ZnyxefAHXsMxUayzgC6a',
|
1935
|
+
// matcherPublicKey: '9cpfKN9suPNvfeUNphzxXMjcnn974eme8ZhWUjaktzU5',
|
1936
|
+
// assetPair: [Object],
|
1937
|
+
// orderType: 'buy',
|
1938
|
+
// price: 0.00012003,
|
1939
|
+
// sender: '3PJfFRgVuJ47UY4ckb74EGzEBzkHXtmG1LA',
|
1940
|
+
// amount: 60.80424773,
|
1941
|
+
// timestamp: '2020-06-09T19:34:51.885Z',
|
1942
|
+
// expiration: '2020-06-10T12:31:31.885Z',
|
1943
|
+
// matcherFee: 0.003,
|
1944
|
+
// signature: '4cA3ZAb3XAEEXaFG7caqpto5TRbpR5PkhZpxoNQZ9ZReNvjuJQs5a3THnumv7rcqmVUiVtuHAgk2f67ANcqtKyJ8',
|
1945
|
+
// matcherFeeAssetId: null },
|
1946
|
+
// order2:
|
1947
|
+
// { id: 'CHJSLQ6dfSPs6gu2mAegrMUcRiDEDqaj2GKfvptMjS3M',
|
1948
|
+
// senderPublicKey: '3RUC4NGFZm9H8VJhSSjJyFLdiE42qNiUagDcZPwjgDf8',
|
1949
|
+
// matcherPublicKey: '9cpfKN9suPNvfeUNphzxXMjcnn974eme8ZhWUjaktzU5',
|
1950
|
+
// assetPair: [Object],
|
1951
|
+
// orderType: 'sell',
|
1952
|
+
// price: 0.00012003,
|
1953
|
+
// sender: '3P9vKoQpMZtaSkHKpNh977YY9ZPzTuntLAq',
|
1954
|
+
// amount: 60.80424773,
|
1955
|
+
// timestamp: '2020-06-09T19:34:51.887Z',
|
1956
|
+
// expiration: '2020-06-10T12:31:31.887Z',
|
1957
|
+
// matcherFee: 0.003,
|
1958
|
+
// signature: '3SFyrcqzou2ddZyNisnLYaGhLt5qRjKxH8Nw3s4T5U7CEKGX9DDo8dS27RgThPVGbYF1rYET1FwrWoQ2UFZ6SMTR',
|
1959
|
+
// matcherFeeAssetId: null } } }
|
1960
|
+
//
|
1961
|
+
const data = this.safeValue (trade, 'data');
|
1962
|
+
const datetime = this.safeString (data, 'timestamp');
|
1963
|
+
const timestamp = this.parse8601 (datetime);
|
1964
|
+
const id = this.safeString (data, 'id');
|
1965
|
+
const priceString = this.safeString (data, 'price');
|
1966
|
+
const amountString = this.safeString (data, 'amount');
|
1967
|
+
const order1 = this.safeValue (data, 'order1');
|
1968
|
+
const order2 = this.safeValue (data, 'order2');
|
1969
|
+
let order = undefined;
|
1970
|
+
// order2 arrived after order1
|
1971
|
+
if (this.safeString (order1, 'senderPublicKey') === this.apiKey) {
|
1972
|
+
order = order1;
|
1973
|
+
} else {
|
1974
|
+
order = order2;
|
1975
|
+
}
|
1976
|
+
let symbol = undefined;
|
1977
|
+
const assetPair = this.safeValue (order, 'assetPair');
|
1978
|
+
if (assetPair !== undefined) {
|
1979
|
+
symbol = this.getSymbolFromAssetPair (assetPair);
|
1980
|
+
} else if (market !== undefined) {
|
1981
|
+
symbol = market['symbol'];
|
1982
|
+
}
|
1983
|
+
const side = this.safeString (order, 'orderType');
|
1984
|
+
const orderId = this.safeString (order, 'id');
|
1985
|
+
const fee = {
|
1986
|
+
'cost': this.safeString (order, 'matcherFee'),
|
1987
|
+
'currency': this.safeCurrencyCode (this.safeString (order, 'matcherFeeAssetId', 'WAVES')),
|
1988
|
+
};
|
1989
|
+
return this.safeTrade ({
|
1990
|
+
'info': trade,
|
1991
|
+
'timestamp': timestamp,
|
1992
|
+
'datetime': datetime,
|
1993
|
+
'symbol': symbol,
|
1994
|
+
'id': id,
|
1995
|
+
'order': orderId,
|
1996
|
+
'type': undefined,
|
1997
|
+
'side': side,
|
1998
|
+
'takerOrMaker': undefined,
|
1999
|
+
'price': priceString,
|
2000
|
+
'amount': amountString,
|
2001
|
+
'cost': undefined,
|
2002
|
+
'fee': fee,
|
2003
|
+
}, market);
|
2004
|
+
}
|
2005
|
+
|
2006
|
+
handleErrors (code, reason, url, method, headers, body, response, requestHeaders, requestBody) {
|
2007
|
+
const errorCode = this.safeString (response, 'error');
|
2008
|
+
const success = this.safeValue (response, 'success', true);
|
2009
|
+
const Exception = this.safeValue (this.exceptions, errorCode);
|
2010
|
+
if (Exception !== undefined) {
|
2011
|
+
const message = this.safeString (response, 'message');
|
2012
|
+
throw new Exception (this.id + ' ' + message);
|
2013
|
+
}
|
2014
|
+
const message = this.safeString (response, 'message');
|
2015
|
+
if (message === 'Validation Error') {
|
2016
|
+
throw new BadRequest (this.id + ' ' + body);
|
2017
|
+
}
|
2018
|
+
if (!success) {
|
2019
|
+
throw new ExchangeError (this.id + ' ' + body);
|
2020
|
+
}
|
2021
|
+
}
|
2022
|
+
|
2023
|
+
async withdraw (code, amount, address, tag = undefined, params = {}) {
|
2024
|
+
[ tag, params ] = this.handleWithdrawTagAndParams (tag, params);
|
2025
|
+
// currently only works for BTC and WAVES
|
2026
|
+
if (code !== 'WAVES') {
|
2027
|
+
const supportedCurrencies = await this.privateGetWithdrawCurrencies ();
|
2028
|
+
const currencies = {};
|
2029
|
+
const items = this.safeValue (supportedCurrencies, 'items', []);
|
2030
|
+
for (let i = 0; i < items.length; i++) {
|
2031
|
+
const entry = items[i];
|
2032
|
+
const currencyCode = this.safeString (entry, 'id');
|
2033
|
+
currencies[currencyCode] = true;
|
2034
|
+
}
|
2035
|
+
if (!(code in currencies)) {
|
2036
|
+
const codes = Object.keys (currencies);
|
2037
|
+
throw new ExchangeError (this.id + ' withdraw() ' + code + ' not supported. Currency code must be one of ' + codes.toString ());
|
2038
|
+
}
|
2039
|
+
}
|
2040
|
+
await this.loadMarkets ();
|
2041
|
+
const hexChars = [ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' ];
|
2042
|
+
const set = {};
|
2043
|
+
for (let i = 0; i < hexChars.length; i++) {
|
2044
|
+
const key = hexChars[i];
|
2045
|
+
set[key] = true;
|
2046
|
+
}
|
2047
|
+
let isErc20 = true;
|
2048
|
+
const noPrefix = this.remove0xPrefix (address);
|
2049
|
+
const lower = noPrefix.toLowerCase ();
|
2050
|
+
for (let i = 0; i < lower.length; i++) {
|
2051
|
+
const character = lower[i];
|
2052
|
+
if (!(character in set)) {
|
2053
|
+
isErc20 = false;
|
2054
|
+
break;
|
2055
|
+
}
|
2056
|
+
}
|
2057
|
+
await this.signIn ();
|
2058
|
+
let proxyAddress = undefined;
|
2059
|
+
if (code === 'WAVES' && !isErc20) {
|
2060
|
+
proxyAddress = address;
|
2061
|
+
} else {
|
2062
|
+
const withdrawAddressRequest = {
|
2063
|
+
'address': address,
|
2064
|
+
'currency': code,
|
2065
|
+
};
|
2066
|
+
const withdrawAddress = await this.privateGetWithdrawAddressesCurrencyAddress (withdrawAddressRequest);
|
2067
|
+
const currency = this.safeValue (withdrawAddress, 'currency');
|
2068
|
+
const allowedAmount = this.safeValue (currency, 'allowed_amount');
|
2069
|
+
const minimum = this.safeNumber (allowedAmount, 'min');
|
2070
|
+
if (amount <= minimum) {
|
2071
|
+
throw new BadRequest (this.id + ' ' + code + ' withdraw failed, amount ' + amount.toString () + ' must be greater than the minimum allowed amount of ' + minimum.toString ());
|
2072
|
+
}
|
2073
|
+
// {
|
2074
|
+
// "type": "withdrawal_addresses",
|
2075
|
+
// "currency": {
|
2076
|
+
// "type": "withdrawal_currency",
|
2077
|
+
// "id": "BTC",
|
2078
|
+
// "waves_asset_id": "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS",
|
2079
|
+
// "decimals": 8,
|
2080
|
+
// "status": "active",
|
2081
|
+
// "allowed_amount": {
|
2082
|
+
// "min": 0.001,
|
2083
|
+
// "max": 20
|
2084
|
+
// },
|
2085
|
+
// "fees": {
|
2086
|
+
// "flat": 0.001,
|
2087
|
+
// "rate": 0
|
2088
|
+
// }
|
2089
|
+
// },
|
2090
|
+
// "proxy_addresses": [
|
2091
|
+
// "3P3qqmkiLwNHB7x1FeoE8bvkRtULwGpo9ga"
|
2092
|
+
// ]
|
2093
|
+
// }
|
2094
|
+
const proxyAddresses = this.safeValue (withdrawAddress, 'proxy_addresses', []);
|
2095
|
+
proxyAddress = this.safeString (proxyAddresses, 0);
|
2096
|
+
}
|
2097
|
+
const fee = this.safeInteger (this.options, 'withdrawFeeWAVES', 100000); // 0.001 WAVES
|
2098
|
+
const feeAssetId = 'WAVES';
|
2099
|
+
const type = 4; // transfer
|
2100
|
+
const version = 2;
|
2101
|
+
const amountInteger = this.currencyToPrecision (code, amount);
|
2102
|
+
const currency = this.currency (code);
|
2103
|
+
const timestamp = this.milliseconds ();
|
2104
|
+
const byteArray = [
|
2105
|
+
this.numberToBE (4, 1),
|
2106
|
+
this.numberToBE (2, 1),
|
2107
|
+
this.base58ToBinary (this.apiKey),
|
2108
|
+
this.getAssetBytes (currency['id']),
|
2109
|
+
this.getAssetBytes (feeAssetId),
|
2110
|
+
this.numberToBE (timestamp, 8),
|
2111
|
+
this.numberToBE (amountInteger, 8),
|
2112
|
+
this.numberToBE (fee, 8),
|
2113
|
+
this.base58ToBinary (proxyAddress),
|
2114
|
+
this.numberToBE (0, 2),
|
2115
|
+
];
|
2116
|
+
const binary = this.binaryConcatArray (byteArray);
|
2117
|
+
const hexSecret = this.binaryToBase16 (this.base58ToBinary (this.secret));
|
2118
|
+
const signature = this.eddsa (this.binaryToBase16 (binary), hexSecret, 'ed25519');
|
2119
|
+
const request = {
|
2120
|
+
'senderPublicKey': this.apiKey,
|
2121
|
+
'amount': amountInteger,
|
2122
|
+
'fee': fee,
|
2123
|
+
'type': type,
|
2124
|
+
'version': version,
|
2125
|
+
'attachment': '',
|
2126
|
+
'feeAssetId': this.getAssetId (feeAssetId),
|
2127
|
+
'proofs': [
|
2128
|
+
signature,
|
2129
|
+
],
|
2130
|
+
'assetId': this.getAssetId (currency['id']),
|
2131
|
+
'recipient': proxyAddress,
|
2132
|
+
'timestamp': timestamp,
|
2133
|
+
'signature': signature,
|
2134
|
+
};
|
2135
|
+
const result = await this.nodePostTransactionsBroadcast (request);
|
2136
|
+
//
|
2137
|
+
// {
|
2138
|
+
// "id": "string",
|
2139
|
+
// "signature": "string",
|
2140
|
+
// "fee": 0,
|
2141
|
+
// "timestamp": 1460678400000,
|
2142
|
+
// "recipient": "3P274YB5qseSE9DTTL3bpSjosZrYBPDpJ8k",
|
2143
|
+
// "amount": 0
|
2144
|
+
// }
|
2145
|
+
//
|
2146
|
+
return this.parseTransaction (result, currency);
|
2147
|
+
}
|
2148
|
+
|
2149
|
+
parseTransaction (transaction, currency = undefined) {
|
2150
|
+
//
|
2151
|
+
// withdraw
|
2152
|
+
//
|
2153
|
+
// {
|
2154
|
+
// "id": "string",
|
2155
|
+
// "signature": "string",
|
2156
|
+
// "fee": 0,
|
2157
|
+
// "timestamp": 1460678400000,
|
2158
|
+
// "recipient": "3P274YB5qseSE9DTTL3bpSjosZrYBPDpJ8k",
|
2159
|
+
// "amount": 0
|
2160
|
+
// }
|
2161
|
+
//
|
2162
|
+
currency = this.safeCurrency (undefined, currency);
|
2163
|
+
return {
|
2164
|
+
'id': undefined,
|
2165
|
+
'txid': undefined,
|
2166
|
+
'timestamp': undefined,
|
2167
|
+
'datetime': undefined,
|
2168
|
+
'network': undefined,
|
2169
|
+
'addressFrom': undefined,
|
2170
|
+
'address': undefined,
|
2171
|
+
'addressTo': undefined,
|
2172
|
+
'amount': undefined,
|
2173
|
+
'type': undefined,
|
2174
|
+
'currency': currency['code'],
|
2175
|
+
'status': undefined,
|
2176
|
+
'updated': undefined,
|
2177
|
+
'tagFrom': undefined,
|
2178
|
+
'tag': undefined,
|
2179
|
+
'tagTo': undefined,
|
2180
|
+
'comment': undefined,
|
2181
|
+
'fee': undefined,
|
2182
|
+
'info': transaction,
|
2183
|
+
};
|
2184
|
+
}
|
2185
|
+
};
|