-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkuna.js
146 lines (135 loc) · 6.24 KB
/
kuna.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
"use strict";
// ---------------------------------------------------------------------------
const acx = require ('./acx.js')
const { ExchangeError, InsufficientFunds } = require ('./base/errors')
// ---------------------------------------------------------------------------
module.exports = class kuna extends acx {
describe () {
return this.deepExtend (super.describe (), {
'id': 'kuna',
'name': 'Kuna',
'countries': 'UA',
'rateLimit': 1000,
'version': 'v2',
'hasCORS': false,
'hasFetchTickers': false,
'hasFetchOHLCV': false,
'urls': {
'logo': 'https://user-images.githubusercontent.com/1294454/31697638-912824fa-b3c1-11e7-8c36-cf9606eb94ac.jpg',
'api': 'https://kuna.io',
'www': 'https://kuna.io',
'doc': 'https://kuna.io/documents/api',
},
'api': {
'public': {
'get': [
'tickers/{market}',
'order_book',
'order_book/{market}',
'trades',
'trades/{market}',
'timestamp',
],
},
'private': {
'get': [
'members/me',
'orders',
'trades/my',
],
'post': [
'orders',
'order/delete',
],
},
},
'markets': {
'BTC/UAH': { 'id': 'btcuah', 'symbol': 'BTC/UAH', 'base': 'BTC', 'quote': 'UAH', 'precision': { 'amount': 6, 'price': 0 }, 'lot': 0.000001, 'limits': { 'amount': { 'min': 0.000001, 'max': undefined }, 'price': { 'min': 1, 'max': undefined }}},
'ETH/UAH': { 'id': 'ethuah', 'symbol': 'ETH/UAH', 'base': 'ETH', 'quote': 'UAH', 'precision': { 'amount': 6, 'price': 0 }, 'lot': 0.000001, 'limits': { 'amount': { 'min': 0.000001, 'max': undefined }, 'price': { 'min': 1, 'max': undefined }}},
'GBG/UAH': { 'id': 'gbguah', 'symbol': 'GBG/UAH', 'base': 'GBG', 'quote': 'UAH', 'precision': { 'amount': 3, 'price': 2 }, 'lot': 0.001, 'limits': { 'amount': { 'min': 0.000001, 'max': undefined }, 'price': { 'min': 0.01, 'max': undefined }}}, // Golos Gold (GBG != GOLOS)
'KUN/BTC': { 'id': 'kunbtc', 'symbol': 'KUN/BTC', 'base': 'KUN', 'quote': 'BTC', 'precision': { 'amount': 6, 'price': 6 }, 'lot': 0.000001, 'limits': { 'amount': { 'min': 0.000001, 'max': undefined }, 'price': { 'min': 0.000001, 'max': undefined }}},
'BCH/BTC': { 'id': 'bchbtc', 'symbol': 'BCH/BTC', 'base': 'BCH', 'quote': 'BTC', 'precision': { 'amount': 6, 'price': 6 }, 'lot': 0.000001, 'limits': { 'amount': { 'min': 0.000001, 'max': undefined }, 'price': { 'min': 0.000001, 'max': undefined }}},
'WAVES/UAH': { 'id': 'wavesuah', 'symbol': 'WAVES/UAH', 'base': 'WAVES', 'quote': 'UAH', 'precision': { 'amount': 6, 'price': 0 }, 'lot': 0.000001, 'limits': { 'amount': { 'min': 0.000001, 'max': undefined }, 'price': { 'min': 1, 'max': undefined }}},
},
'fees': {
'trading': {
'taker': 0.2 / 100,
'maker': 0.2 / 100,
},
},
});
}
handleErrors (code, reason, url, method, headers, body) {
if (code == 400) {
let data = JSON.parse (body);
let error = data['error'];
let errorMessage = error['message'];
if (errorMessage.includes ('cannot lock funds')) {
throw new InsufficientFunds ([ this.id, method, url, code, reason, body ].join (' '));
}
}
}
async fetchOrderBook (symbol, params = {}) {
let market = this.market (symbol);
let orderBook = await this.publicGetOrderBook (this.extend ({
'market': market['id'],
}, params));
return this.parseOrderBook (orderBook, undefined, 'bids', 'asks', 'price', 'volume');
}
parseOrder (order, market) {
let symbol = market['symbol'];
let timestamp = this.parse8601 (order['created_at']);
return {
'id': order['id'],
'timestamp': timestamp,
'datetime': this.iso8601 (timestamp),
'status': 'open',
'symbol': symbol,
'type': order['ord_type'],
'side': order['side'],
'price': parseFloat (order['price']),
'amount': parseFloat (order['volume']),
'filled': parseFloat (order['executed_volume']),
'remaining': parseFloat (order['remaining_volume']),
'trades': undefined,
'fee': undefined,
'info': order,
};
}
async fetchOpenOrders (symbol = undefined, params = {}) {
if (!symbol)
throw new ExchangeError (this.id + ' fetchOpenOrders requires a symbol argument');
let market = this.market (symbol);
let orders = await this.privateGetOrders (this.extend ({
'market': market['id'],
}, params));
// todo emulation of fetchClosedOrders, fetchOrders, fetchOrder
// with order cache + fetchOpenOrders
// as in BTC-e, Liqui, Yobit, DSX, Tidex, WEX
return this.parseOrders (orders, market);
}
parseTrade (trade, market = undefined) {
let timestamp = this.parse8601 (trade['created_at']);
let symbol = undefined;
if (market)
symbol = market['symbol'];
return {
'id': trade['id'],
'timestamp': timestamp,
'datetime': this.iso8601 (timestamp),
'symbol': symbol,
'type': undefined,
'side': undefined,
'price': parseFloat (trade['price']),
'amount': parseFloat (trade['volume']),
'info': trade,
};
}
async fetchTrades (symbol, params = {}) {
let market = this.market (symbol);
let response = await this.publicGetTrades (this.extend ({
'market': market['id'],
}, params));
return this.parseTrades (response, market);
}
}