-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoingi.js
312 lines (295 loc) · 11.1 KB
/
coingi.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
"use strict";
// ---------------------------------------------------------------------------
const Exchange = require ('./base/Exchange')
const { ExchangeError } = require ('./base/errors')
// ---------------------------------------------------------------------------
module.exports = class coingi extends Exchange {
describe () {
return this.deepExtend (super.describe (), {
'id': 'coingi',
'name': 'Coingi',
'rateLimit': 1000,
'countries': [ 'PA', 'BG', 'CN', 'US' ], // Panama, Bulgaria, China, US
'hasFetchTickers': true,
'hasCORS': false,
'urls': {
'logo': 'https://user-images.githubusercontent.com/1294454/28619707-5c9232a8-7212-11e7-86d6-98fe5d15cc6e.jpg',
'api': {
'www': 'https://coingi.com',
'current': 'https://api.coingi.com',
'user': 'https://api.coingi.com',
},
'www': 'https://coingi.com',
'doc': 'http://docs.coingi.apiary.io/',
},
'api': {
'www': {
'get': [
'',
],
},
'current': {
'get': [
'order-book/{pair}/{askCount}/{bidCount}/{depth}',
'transactions/{pair}/{maxCount}',
'24hour-rolling-aggregation',
],
},
'user': {
'post': [
'balance',
'add-order',
'cancel-order',
'orders',
'transactions',
'create-crypto-withdrawal',
],
},
},
'fees': {
'trading': {
'tierBased': false,
'percentage': true,
'taker': 0.2 / 100,
'maker': 0.2 / 100,
},
'funding': {
'tierBased': false,
'percentage': false,
'withdraw': {
'BTC': 0.001,
'LTC': 0.01,
'DOGE': 2,
'PPC': 0.02,
'VTC': 0.2,
'NMC': 2,
'DASH': 0.002,
'USD': 10,
'EUR': 10,
},
'deposit': {
'BTC': 0,
'LTC': 0,
'DOGE': 0,
'PPC': 0,
'VTC': 0,
'NMC': 0,
'DASH': 0,
'USD': 5,
'EUR': 1,
},
},
},
});
}
async fetchMarkets () {
this.parseJsonResponse = false;
let response = await this.wwwGet ();
this.parseJsonResponse = true;
let parts = response.split ('do=currencyPairSelector-selectCurrencyPair" class="active">');
let currencyParts = parts[1].split ('<div class="currency-pair-label">');
let result = [];
for (let i = 1; i < currencyParts.length; i++) {
let currencyPart = currencyParts[i];
let idParts = currencyPart.split ('</div>');
let id = idParts[0];
let symbol = id;
id = id.replace ('/', '-');
id = id.toLowerCase ();
let [ base, quote ] = symbol.split ('/');
let precision = {
'amount': 8,
'price': 8,
};
let lot = Math.pow (10, -precision['amount']);
result.push ({
'id': id,
'symbol': symbol,
'base': base,
'quote': quote,
'info': id,
'lot': lot,
'active': true,
'precision': precision,
'limits': {
'amount': {
'min': lot,
'max': Math.pow (10, precision['amount']),
},
'price': {
'min': Math.pow (10, -precision['price']),
'max': undefined,
},
'cost': {
'min': 0,
'max': undefined,
},
},
});
}
return result;
}
async fetchBalance (params = {}) {
await this.loadMarkets ();
let lowercaseCurrencies = [];
let currencies = Object.keys (this.currencies);
for (let i = 0; i < currencies.length; i++) {
let currency = currencies[i];
lowercaseCurrencies.push (currency.toLowerCase ());
}
let balances = await this.userPostBalance ({
'currencies': lowercaseCurrencies.join (',')
});
let result = { 'info': balances };
for (let b = 0; b < balances.length; b++) {
let balance = balances[b];
let currency = balance['currency']['name'];
currency = currency.toUpperCase ();
let account = {
'free': balance['available'],
'used': balance['blocked'] + balance['inOrders'] + balance['withdrawing'],
'total': 0.0,
};
account['total'] = this.sum (account['free'], account['used']);
result[currency] = account;
}
return this.parseBalance (result);
}
async fetchOrderBook (symbol, params = {}) {
await this.loadMarkets ();
let market = this.market (symbol);
let orderbook = await this.currentGetOrderBookPairAskCountBidCountDepth (this.extend ({
'pair': market['id'],
'askCount': 512, // maximum returned number of asks 1-512
'bidCount': 512, // maximum returned number of bids 1-512
'depth': 32, // maximum number of depth range steps 1-32
}, params));
return this.parseOrderBook (orderbook, undefined, 'bids', 'asks', 'price', 'baseAmount');
}
parseTicker (ticker, market = undefined) {
let timestamp = this.milliseconds ();
let symbol = undefined;
if (market)
symbol = market['symbol'];
return {
'symbol': symbol,
'timestamp': timestamp,
'datetime': this.iso8601 (timestamp),
'high': ticker['high'],
'low': ticker['low'],
'bid': ticker['highestBid'],
'ask': ticker['lowestAsk'],
'vwap': undefined,
'open': undefined,
'close': undefined,
'first': undefined,
'last': undefined,
'change': undefined,
'percentage': undefined,
'average': undefined,
'baseVolume': ticker['baseVolume'],
'quoteVolume': ticker['counterVolume'],
'info': ticker,
};
return ticker;
}
async fetchTickers (symbols = undefined, params = {}) {
await this.loadMarkets ();
let response = await this.currentGet24hourRollingAggregation (params);
let result = {};
for (let t = 0; t < response.length; t++) {
let ticker = response[t];
let base = ticker['currencyPair']['base'].toUpperCase ();
let quote = ticker['currencyPair']['counter'].toUpperCase ();
let symbol = base + '/' + quote;
let market = undefined;
if (symbol in this.markets) {
market = this.markets[symbol];
}
result[symbol] = this.parseTicker (ticker, market);
}
return result;
}
async fetchTicker (symbol, params = {}) {
await this.loadMarkets ();
let tickers = await this.fetchTickers (undefined, params);
if (symbol in tickers)
return tickers[symbol];
throw new ExchangeError (this.id + ' return did not contain ' + symbol);
}
parseTrade (trade, market = undefined) {
if (!market)
market = this.markets_by_id[trade['currencyPair']];
return {
'id': trade['id'],
'info': trade,
'timestamp': trade['timestamp'],
'datetime': this.iso8601 (trade['timestamp']),
'symbol': market['symbol'],
'type': undefined,
'side': undefined, // type
'price': trade['price'],
'amount': trade['amount'],
};
}
async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) {
await this.loadMarkets ();
let market = this.market (symbol);
let response = await this.currentGetTransactionsPairMaxCount (this.extend ({
'pair': market['id'],
'maxCount': 128,
}, params));
return this.parseTrades (response, market, since, limit);
}
async createOrder (symbol, type, side, amount, price = undefined, params = {}) {
await this.loadMarkets ();
let order = {
'currencyPair': this.marketId (symbol),
'volume': amount,
'price': price,
'orderType': (side == 'buy') ? 0 : 1,
};
let response = await this.userPostAddOrder (this.extend (order, params));
return {
'info': response,
'id': response['result'],
};
}
async cancelOrder (id, symbol = undefined, params = {}) {
await this.loadMarkets ();
return await this.userPostCancelOrder ({ 'orderId': id });
}
sign (path, api = 'current', method = 'GET', params = {}, headers = undefined, body = undefined) {
let url = this.urls['api'][api];
if (api != 'www') {
url += '/' + api + '/' + this.implodeParams (path, params);
}
let query = this.omit (params, this.extractParams (path));
if (api == 'current') {
if (Object.keys (query).length)
url += '?' + this.urlencode (query);
} else if (api == 'user') {
this.checkRequiredCredentials ();
let nonce = this.nonce ();
let request = this.extend ({
'token': this.apiKey,
'nonce': nonce,
}, query);
let auth = nonce.toString () + '$' + this.apiKey;
request['signature'] = this.hmac (this.encode (auth), this.encode (this.secret));
body = this.json (request);
headers = {
'Content-Type': 'application/json',
};
}
return { 'url': url, 'method': method, 'body': body, 'headers': headers };
}
async request (path, api = 'current', method = 'GET', params = {}, headers = undefined, body = undefined) {
let response = await this.fetch2 (path, api, method, params, headers, body);
if (typeof response !== 'string') {
if ('errors' in response)
throw new ExchangeError (this.id + ' ' + this.json (response));
}
return response;
}
}