Skip to content

Commit

Permalink
Added getBalances API method (retracted code style changes)
Browse files Browse the repository at this point in the history
  • Loading branch information
neoromantic committed Dec 23, 2017
1 parent 0767810 commit aa6f60b
Showing 1 changed file with 8 additions and 29 deletions.
37 changes: 8 additions & 29 deletions src/Bot.js
@@ -1,17 +1,11 @@
const _ = require('lodash');
const crypto = require('crypto');
const {
URL
} = require('url');
const { URL } = require('url');
const querystring = require('querystring');
const rp = require('request-promise');

class Bot {
constructor({
uri = 'https://bittrex.com',
apikey = '',
apisecret = ''
}) {
constructor({ uri = 'https://bittrex.com', apikey = '', apisecret = '' }) {
this.key = apikey;
this.secret = apisecret;
this.uri = new URL(uri);
Expand All @@ -34,14 +28,11 @@ class Bot {

return rp.get({
uri,
headers: {
apisign: this.sign(uri)
},
headers: { apisign: this.sign(uri) },
json: true,
});
}

// Returns list of account balances
getBalances() {
this.uri.pathname = '/api/v1.1/account/getbalances';
return this.request();
Expand All @@ -58,11 +49,7 @@ class Bot {
}

// Used to place a buy order in a specific market.
buy({
coin,
quantity,
rate
}) {
buy({ coin, quantity, rate }) {
this.uri.pathname = '/api/v1.1/market/buylimit';
const options = {
market: `BTC-${coin}`,
Expand All @@ -73,11 +60,7 @@ class Bot {
}

// Used to place an sell order in a specific market
sell({
coin,
quantity,
rate
}) {
sell({ coin, quantity, rate }) {
this.uri.pathname = '/api/v1.1/market/selllimit';
const options = {
market: `BTC-${coin}`,
Expand All @@ -99,9 +82,7 @@ class Bot {
getMarketSummary(currency = 'eth') {
this.uri.pathname = '/api/v1.1/public/getmarketsummary';
const market = `btc-${currency}`;
return this.request({
market
});
return this.request({ market });
}

getOrderBook(currency = 'ETH', type = 'both') {
Expand Down Expand Up @@ -142,9 +123,7 @@ class Bot {
// Returns closing prices within a specified time frame for a coin pair
async getClosingPrices(currency = 'ETH', period = 5, unit = 'thirtyMin') {
const ticks = await this.getTicks(currency, unit);
const {
result = []
} = ticks;
const { result = [] } = ticks;
return _.takeRight(result, period).map(e => e.C);
}

Expand Down Expand Up @@ -269,4 +248,4 @@ class Bot {
}
}

module.exports = Bot;
module.exports = Bot;

0 comments on commit aa6f60b

Please sign in to comment.