Skip to content

Commit eae7e24

Browse files
author
scottmw89
committed
buffer vuln fix,
candle method simple limitOrder method simple marketOrder method
1 parent 9f02c92 commit eae7e24

1 file changed

Lines changed: 45 additions & 14 deletions

File tree

ProbitRest.js

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,51 @@ const EventEmitter = require('./EventEmitter.js');
22
const SuperAgent = require('superagent');
33

44
class ProbitRest extends EventEmitter {
5+
56
constructor(key, secret) {
67
super();
78

89
this.exchangeUrl = 'https://api.probit.com/api/exchange/v1';
910
this._updateToken(key, secret);
1011
}
1112

12-
async market() {
13-
return await this._request('GET', '/market');
13+
async balance() {
14+
return await this._requestAuthenticated('GET', '/balance');
15+
}
16+
17+
async cancelOrder(marketId, orderId) {
18+
return await this._requestAuthenticated('POST', '/cancel_order', {
19+
"market_id" : marketId.toString(),
20+
"order_id" : orderId.toString()
21+
});
22+
}
23+
24+
async candle(marketId, startTime, endTime, interval, limit=200) {
25+
startTime = new Date(startTime).toISOString();
26+
endTime = new Date(endTime).toISOString();
27+
limit = limit.toString();
28+
29+
return await this._request('GET', `/candle?nocache=${Date.now()}&market_ids=${marketId}&start_time=${startTime}&end_time=${endTime}&interval=${interval}&sort=desc&limit=${limit}`);
1430
}
1531

1632
async currency() {
1733
return await this._request('GET', '/currency');
1834
}
1935

36+
async market() {
37+
return await this._request('GET', '/market');
38+
}
39+
2040
async time() {
2141
return await this._request('GET', '/time');
2242
}
2343

2444
async ticker(tickers) {
25-
return await this._request('GET', '/ticker?market_ids=' + tickers.join(','));
45+
return await this._request('GET', `/ticker?market_ids=${tickers.join(',')}`);
2646
}
2747

2848
async orderBook(marketId) {
29-
return await this._request('GET', '/order_book?market_id=' + marketId);
49+
return await this._request('GET', `/order_book?market_id=${marketId}`);
3050
}
3151

3252
async trade(marketId, startTime, endTime, limit) {
@@ -47,17 +67,32 @@ class ProbitRest extends EventEmitter {
4767
async newMarketOrder(marketId, quantity, side, timeInForce) {
4868
return await this._requestAuthenticated("POST", "/new_order", {
4969
"market_id" : marketId,
50-
"quantity" : quantity.toString(),
70+
"quantity" : Math.abs(quantity).toString(),
5171
"side" : side,
5272
"time_in_force" : timeInForce,
5373
"type" : "market"
5474
});
5575
}
5676

57-
async cancelOrder(marketId, orderId) {
58-
return await this._requestAuthenticated('POST', '/cancel_order', {
59-
"market_id" : marketId.toString(),
60-
"order_id" : orderId.toString()
77+
async limitOrder(marketId, quantity, price, timeInForce='gtc', orderId="") {
78+
return await this._requestAuthenticated("POST", "/new_order", {
79+
"market_id" : marketId,
80+
"type" : "limit",
81+
"side" : quantity < 0 ? "sell" : "buy",
82+
"time_in_force" : timeInForce,
83+
"limit_price" : price.toString(),
84+
"quantity" : Math.abs(quantity).toString()
85+
});
86+
}
87+
88+
async marketOrder(marketId, quantity, timeInForce='ioc') {
89+
//return await this.newMarketOrder(marketId, quantity, side = quantity < 0 ? "sell" : "buy", timeInForce);
90+
return await this._requestAuthenticated("POST", "/new_order", {
91+
"market_id" : marketId,
92+
"type" : "market",
93+
"side" : quantity < 0 ? "sell" : "buy",
94+
"time_in_force" : timeInForce,
95+
"quantity" : Math.abs(quantity).toString()
6196
});
6297
}
6398

@@ -75,10 +110,6 @@ class ProbitRest extends EventEmitter {
75110
return await this._requestAuthenticated('GET', `/trade_history?market_id=${marketId}&start_time=${startTime}&end_time=${endTime}&limit=${limit}`);
76111
}
77112

78-
async balance() {
79-
return await this._requestAuthenticated('GET', '/balance');
80-
}
81-
82113
async order(marketId, orderId) {
83114
return await this._requestAuthenticated('GET', `/order?market_id=${marketId}&order_id=${orderId}`);
84115
}
@@ -113,7 +144,7 @@ class ProbitRest extends EventEmitter {
113144
}
114145

115146
_updateToken(key, secret) {
116-
let auth = "Basic " + new Buffer(`${key}:${secret}`).toString('base64');
147+
let auth = "Basic " + new Buffer.from(`${key}:${secret}`).toString('base64');
117148
let body = JSON.stringify({ grant_type: 'client_credentials' });
118149
let url = 'https://accounts.probit.com/token';
119150

0 commit comments

Comments
 (0)