-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnegociecoins.js
347 lines (328 loc) · 12.9 KB
/
negociecoins.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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
'use strict';
// ---------------------------------------------------------------------------
const Exchange = require ('./base/Exchange');
// ---------------------------------------------------------------------------
module.exports = class negociecoins extends Exchange {
describe () {
return this.deepExtend (super.describe (), {
'id': 'negociecoins',
'name': 'NegocieCoins',
'countries': 'BR',
'rateLimit': 1000,
'version': 'v3',
'has': {
'fetchOrder': true,
'fetchOrders': true,
'fetchOpenOrders': true,
'fetchClosedOrders': true,
},
'urls': {
'logo': 'https://user-images.githubusercontent.com/1294454/38008571-25a6246e-3258-11e8-969b-aeb691049245.jpg',
'api': {
'public': 'https://broker.negociecoins.com.br/api/v3',
'private': 'https://broker.negociecoins.com.br/tradeapi/v1',
},
'www': 'https://www.negociecoins.com.br',
'doc': [
'https://www.negociecoins.com.br/documentacao-tradeapi',
'https://www.negociecoins.com.br/documentacao-api',
],
'fees': 'https://www.negociecoins.com.br/comissoes',
},
'api': {
'public': {
'get': [
'{PAR}/ticker',
'{PAR}/orderbook',
'{PAR}/trades',
'{PAR}/trades/{timestamp_inicial}',
'{PAR}/trades/{timestamp_inicial}/{timestamp_final}',
],
},
'private': {
'get': [
'user/balance',
'user/order/{orderId}',
],
'post': [
'user/order',
'user/orders',
],
'delete': [
'user/order/{orderId}',
],
},
},
'markets': {
'B2X/BRL': { 'id': 'b2xbrl', 'symbol': 'B2X/BRL', 'base': 'B2X', 'quote': 'BRL' },
'BCH/BRL': { 'id': 'bchbrl', 'symbol': 'BCH/BRL', 'base': 'BCH', 'quote': 'BRL' },
'BTC/BRL': { 'id': 'btcbrl', 'symbol': 'BTC/BRL', 'base': 'BTC', 'quote': 'BRL' },
'BTG/BRL': { 'id': 'btgbrl', 'symbol': 'BTG/BRL', 'base': 'BTG', 'quote': 'BRL' },
'DASH/BRL': { 'id': 'dashbrl', 'symbol': 'DASH/BRL', 'base': 'DASH', 'quote': 'BRL' },
'LTC/BRL': { 'id': 'ltcbrl', 'symbol': 'LTC/BRL', 'base': 'LTC', 'quote': 'BRL' },
},
'fees': {
'trading': {
'maker': 0.003,
'taker': 0.004,
},
'funding': {
'withdraw': {
'BTC': 0.001,
'BCH': 0.00003,
'BTG': 0.00009,
'LTC': 0.005,
},
},
},
'limits': {
'amount': {
'min': 0.001,
'max': undefined,
},
},
'precision': {
'amount': 8,
'price': 8,
},
});
}
parseTicker (ticker, market = undefined) {
let timestamp = ticker['date'] * 1000;
let symbol = (typeof market !== 'undefined') ? market['symbol'] : undefined;
let last = parseFloat (ticker['last']);
return {
'symbol': symbol,
'timestamp': timestamp,
'datetime': this.iso8601 (timestamp),
'high': parseFloat (ticker['high']),
'low': parseFloat (ticker['low']),
'bid': parseFloat (ticker['buy']),
'bidVolume': undefined,
'ask': parseFloat (ticker['sell']),
'askVolume': undefined,
'vwap': undefined,
'open': undefined,
'close': last,
'last': last,
'previousClose': undefined,
'change': undefined,
'percentage': undefined,
'average': undefined,
'baseVolume': parseFloat (ticker['vol']),
'quoteVolume': undefined,
'info': ticker,
};
}
async fetchTicker (symbol, params = {}) {
await this.loadMarkets ();
let market = this.market (symbol);
let ticker = await this.publicGetPARTicker (this.extend ({
'PAR': market['id'],
}, params));
return this.parseTicker (ticker, market);
}
async fetchOrderBook (symbol, limit = undefined, params = {}) {
await this.loadMarkets ();
let orderbook = await this.publicGetPAROrderbook (this.extend ({
'PAR': this.marketId (symbol),
}, params));
return this.parseOrderBook (orderbook, undefined, 'bid', 'ask', 'price', 'quantity');
}
parseTrade (trade, market = undefined) {
let timestamp = trade['date'] * 1000;
let price = parseFloat (trade['price']);
let amount = parseFloat (trade['amount']);
let symbol = market['symbol'];
let cost = parseFloat (this.costToPrecision (symbol, price * amount));
return {
'timestamp': timestamp,
'datetime': this.iso8601 (timestamp),
'symbol': symbol,
'id': this.safeString (trade, 'tid'),
'order': undefined,
'type': 'limit',
'side': trade['type'].toLowerCase (),
'price': price,
'amount': amount,
'cost': cost,
'fee': undefined,
'info': trade,
};
}
async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) {
await this.loadMarkets ();
let market = this.market (symbol);
if (typeof since === 'undefined')
since = 0;
let request = {
'PAR': market['id'],
'timestamp_inicial': parseInt (since / 1000),
};
let trades = await this.publicGetPARTradesTimestampInicial (this.extend (request, params));
return this.parseTrades (trades, market, since, limit);
}
async fetchBalance (params = {}) {
await this.loadMarkets ();
let balances = await this.privateGetUserBalance (params);
let result = { 'info': balances };
let currencies = Object.keys (balances);
for (let i = 0; i < currencies.length; i++) {
let id = currencies[i];
let balance = balances[id];
let currency = this.commonCurrencyCode (id);
let account = {
'free': parseFloat (balance['total']),
'used': 0.0,
'total': parseFloat (balance['available']),
};
account['used'] = account['total'] - account['free'];
result[currency] = account;
}
return this.parseBalance (result);
}
parseOrder (order, market = undefined) {
let symbol = undefined;
if (!market) {
market = this.safeValue (this.marketsById, order['pair']);
if (market)
symbol = market['symbol'];
}
let timestamp = this.parse8601 (order['created']);
let price = parseFloat (order['price']);
let amount = parseFloat (order['quantity']);
let cost = this.safeFloat (order, 'total');
let remaining = this.safeFloat (order, 'pending_quantity');
let filled = this.safeFloat (order, 'executed_quantity');
let status = order['status'];
// cancelled, filled, partially filled, pending, rejected
if (status === 'filled') {
status = 'closed';
} else if (status === 'cancelled') {
status = 'canceled';
} else {
status = 'open';
}
let trades = undefined;
// if (order['operations'])
// trades = this.parseTrades (order['operations']);
return {
'id': order['id'].toString (),
'datetime': this.iso8601 (timestamp),
'timestamp': timestamp,
'status': status,
'symbol': symbol,
'type': 'limit',
'side': order['type'],
'price': price,
'cost': cost,
'amount': amount,
'filled': filled,
'remaining': remaining,
'trades': trades,
'fee': {
'currency': market['quote'],
'cost': parseFloat (order['fee']),
},
'info': order,
};
}
async createOrder (symbol, type, side, amount, price = undefined, params = {}) {
await this.loadMarkets ();
let market = this.market (symbol);
let response = await this.privatePostUserOrder (this.extend ({
'pair': market['id'],
'price': this.priceToPrecision (symbol, price),
'volume': this.amountToPrecision (symbol, amount),
'type': side,
}, params));
let order = this.parseOrder (response[0], market);
let id = order['id'];
this.orders[id] = order;
return order;
}
async cancelOrder (id, symbol = undefined, params = {}) {
await this.loadMarkets ();
let market = this.markets[symbol];
let response = await this.privateDeleteUserOrderOrderId (this.extend ({
'orderId': id,
}, params));
return this.parseOrder (response[0], market);
}
async fetchOrder (id, symbol = undefined, params = {}) {
await this.loadMarkets ();
let order = await this.privateGetUserOrderOrderId (this.extend ({
'orderId': id,
}, params));
return this.parseOrder (order[0]);
}
async fetchOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
await this.loadMarkets ();
let market = this.market (symbol);
let request = {
'pair': market['id'],
// type: buy, sell
// status: cancelled, filled, partially filled, pending, rejected
// startId
// endId
// startDate yyyy-MM-dd
// endDate: yyyy-MM-dd
};
if (typeof since !== 'undefined')
request['startDate'] = this.ymd (since);
if (typeof limit !== 'undefined')
request['pageSize'] = limit;
let orders = await this.privatePostUserOrders (this.extend (request, params));
return this.parseOrders (orders, market);
}
async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
return await this.fetchOrders (symbol, since, limit, this.extend ({
'status': 'pending',
}, params));
}
async fetchClosedOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
return await this.fetchOrders (symbol, since, limit, this.extend ({
'status': 'filled',
}, params));
}
nonce () {
return this.milliseconds ();
}
sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
let url = this.urls['api'][api] + '/' + this.implodeParams (path, params);
let query = this.omit (params, this.extractParams (path));
let queryString = this.urlencode (query);
if (api === 'public') {
if (queryString.length)
url += '?' + queryString;
} else {
this.checkRequiredCredentials ();
let timestamp = this.seconds ().toString ();
let nonce = this.nonce ().toString ();
let content = '';
if (queryString.length) {
body = this.json (query);
content = this.hash (this.encode (body), 'md5', 'base64');
} else {
body = '';
}
let uri = this.encodeURIComponent (url).toLowerCase ();
let payload = [ this.apiKey, method, uri, timestamp, nonce, content ].join ('');
let secret = this.base64ToBinary (this.secret);
let signature = this.hmac (this.encode (payload), this.encode (secret), 'sha256', 'base64');
signature = this.binaryToString (signature);
let auth = [ this.apiKey, signature, nonce, timestamp ].join (':');
headers = {
'Authorization': 'amx ' + auth,
};
if (method === 'POST') {
headers['Content-Type'] = 'application/json; charset=UTF-8';
headers['Content-Length'] = body.length;
} else if (queryString.length) {
url += '?' + queryString;
body = undefined;
}
}
return { 'url': url, 'method': method, 'body': body, 'headers': headers };
}
};