Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
*.log
nul
.idea
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ The `general` section is for bot wide configurations:

```yaml
general:
fiat: USD
product_ids:
- BTC-USD
- ETH-USD
Expand All @@ -141,6 +142,9 @@ general:
log_level: warning
```

#### Fiat
The `fiat` is the current currency you are using in your account, it can be `USD` or `EUR`.

#### Product IDs

The `product_ids` are a list (array) of all of the product markets on GDAX that you'll be trading in. They are also referred to in this documentation *coins* or *coin markets*.
Expand Down
1 change: 1 addition & 0 deletions config/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@


general:
fiat: USD
product_ids:
- BTC-USD
- ETH-USD
Expand Down
2 changes: 1 addition & 1 deletion lib/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ module.exports = function (input, done, progress) {

switch (input.action) {
case 'initialize':
if (settings.get('general.log')) {
if (settings.get('general.log') === "on") {
log = new Log(settings.get('general.log_level'), fs.createWriteStream(`GDAX-bot-${input.product_id}.log`));
} else {
let dev_null = (process.platform === 'win32') ? 'nul' : '/dev/null'
Expand Down
132 changes: 67 additions & 65 deletions lib/terminal.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const VERSION = require('../package.json').version;



if (settings.get('general.log')) {
if (settings.get('general.log') === "on") {
var log = new Log(settings.get('general.log_level'), fs.createWriteStream('GDAX-terminal.log'));
} else {
let dev_null = (process.platform === 'win32') ? 'nul' : '/dev/null'
Expand All @@ -23,6 +23,14 @@ var product_ids = settings.get('general.product_ids');
var trades = {};
var initial_profit_sn = undefined;
var initial_profit_wf = undefined;
var fiat = settings.get("general.fiat");

let options = {
x: 1,
y: 0,
wrap: false,
attr: theme.account.title,
};

product_ids.forEach((product_id) => {
trades[product_id] = [];
Expand All @@ -45,13 +53,6 @@ const justify_r = (container, text) => {
function account (data) {
log.info(process.pid, 'function account', data);

let options = {
x: 1,
y: 0,
wrap: false,
attr: theme.account.title,
};

b_account.fill({
attr: theme.account.container
});
Expand Down Expand Up @@ -103,63 +104,10 @@ function account (data) {

let calc_x = x_cell_width;


// USD Avail/Total
if ( data.account !== undefined)
{
let usd_indent = 4

options.x = usd_indent;
options.y = 1;
let usd = 'USD: ';
options.attr = theme.account.title;
b_account.put(options, usd);


let usd_avail_label = 'Avail: ';
options.x = options.x + usd.length;
options.attr = theme.account.label;
b_account.put(options, usd_avail_label);

options.x = options.x + usd_avail_label.length;
options.attr = theme.account.standard;
b_account.put(options, data.account.available);

let usd_avail_length = usd.length + usd_avail_label.length + String(data.account.available).length;


options.x = usd_indent + usd.length;
options.y = 2;
let usd_hold_label = ' Hold: ';
options.attr = theme.account.label;
b_account.put(options, usd_hold_label);

options.x = options.x + usd_hold_label.length;
options.attr = theme.account.standard;
b_account.put(options, data.account.hold);

let usd_hold_length = usd.length + usd_hold_label.length + String(data.account.holds).length;


options.x = usd_indent + usd.length;
options.y = 3;
let usd_total_label = 'Total: ';
options.attr = theme.account.label;
b_account.put(options, usd_total_label);

options.x = options.x + usd_total_label.length;
options.attr = theme.account.standard;
b_account.put(options, String(data.account.balance));

let usd_total_length = usd.length + usd_total_label.length + String(data.account.balance).length;


if (usd_indent + Math.max(usd_avail_length, usd_hold_length, usd_total_length) > calc_x)
{
calc_x = usd_indent + Math.max(usd_avail_length, usd_hold_length, usd_total_length);
}
}

// Fiat Currency Avail/Total
if ( data.account !== undefined) {
calc_x = renderFiat(data, calc_x);
}

// Account Calculations
if ( data.calculations !== undefined)
Expand Down Expand Up @@ -273,6 +221,60 @@ function account (data) {
b_account.draw({ delta: settings.get('general.terminal.delta') })
}

function renderFiat(data, calc_x) {

let curr_indent = 4;

options.x = curr_indent;
options.y = 1;
let curr = fiat+': ';
options.attr = theme.account.title;
b_account.put(options, curr);


let curr_avail_label = 'Avail: ';
options.x = options.x + curr.length;
options.attr = theme.account.label;
b_account.put(options, curr_avail_label);

options.x = options.x + curr_avail_label.length;
options.attr = theme.account.standard;
b_account.put(options, data.account.available);

let curr_avail_length = curr.length + curr.length + String(data.account.available).length;


options.x = curr_indent + curr.length;
options.y = 2;
let curr_hold_label = ' Hold: ';
options.attr = theme.account.label;
b_account.put(options, curr_hold_label);

options.x = options.x + curr_hold_label.length;
options.attr = theme.account.standard;
b_account.put(options, data.account.hold);

let curr_hold_length = curr.length + curr_hold_label.length + String(data.account.holds).length;


options.x = curr_indent + curr.length;
options.y = 3;
let curr_total_label = 'Total: ';
options.attr = theme.account.label;
b_account.put(options, curr_total_label);

options.x = options.x + curr_total_label.length;
options.attr = theme.account.standard;
b_account.put(options, String(data.account.balance));

let curr_total_length = curr.length + curr_total_label.length + String(data.account.balance).length;

if (curr_indent + Math.max(curr_avail_length, curr_hold_length, curr_total_length) > calc_x) {
calc_x = curr_indent + Math.max(curr_avail_length, curr_hold_length, curr_total_length);
}

return calc_x;
}


function coin (product_id, data) {
Expand Down
2 changes: 1 addition & 1 deletion lib/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const settings = require('config');

var eventEmitter = new events.EventEmitter();

if (settings.get('general.log')) {
if (settings.get('general.log') === "on") {
var log = new Log(settings.get('general.log_level'), fs.createWriteStream('GDAX-websocket.log'));
} else {
let dev_null = (process.platform === 'win32') ? 'nul' : '/dev/null'
Expand Down
68 changes: 27 additions & 41 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ const sprintf = require('sprintf-js').sprintf;
const terminal = spawn('./lib/terminal.js');
const threads = require('threads');

if (settings.get('general.log')) {
if (settings.get('general.log') === "on") {
var log = new Log(settings.get('general.log_level'), fs.createWriteStream('GDAX.log'));
} else {
let dev_null = (process.platform === 'win32') ? 'nul' : '/dev/null';
var log = new Log(settings.get('general.log_level'), fs.createWriteStream(dev_null));
}

var fiat = settings.get("general.fiat");

var terminal_data = {
account: {
// timestamp: new Date,
Expand All @@ -36,53 +38,37 @@ var terminal_data = {
// },
},
coins: {
'BTC-EUR': {
trending_up: undefined,
should_buy: undefined
},
'ETH-EUR': {
trending_up: undefined,
should_buy: undefined
},
'LTC-EUR': {
trending_up: undefined,
should_buy: undefined
},
'ETH-BTC': {
trending_up: undefined,
should_buy: undefined
},
'LTC-BTC': {
trending_up: undefined,
should_buy: undefined
},
'BTC-USD': {
trending_up: undefined,
should_buy: undefined,
// account: {
// id: "a1b2c3d4",
// balance: "1.100",
// hold: "0.100",
// available: "1.00",
// currency: "BTC"
// },
// calculations: {
// sell_now: '12345.67890123',
// wait_fill: '23456.78901234',
// fees: '23.67890123',
// },
},
'ETH-USD': {
trending_up: undefined,
should_buy: undefined,
// account: {
// id: "a1b2c3d4",
// balance: "1.100",
// hold: "0.100",
// available: "1.00",
// currency: "ETH"
// },
// calculations: {
// sell_now: '12345.67890123',
// wait_fill: '23456.78901234',
// fees: '23.67890123',
// },
},
'LTC-USD': {
trending_up: undefined,
should_buy: undefined,
// account: {
// id: "a1b2c3d4",
// balance: "1.100",
// hold: "0.100",
// available: "1.00",
// currency: "LTC"
// },
// calculations: {
// sell_now: '12345.67890123',
// wait_fill: '23456.78901234',
// fees: '23.67890123',
// },
},
},
};
Expand Down Expand Up @@ -214,13 +200,13 @@ function open_websocket() {


message.data.forEach((account) => {
if (account.currency === 'USD')
if (account.currency === fiat)
{
terminal_data.account.account = account;
}
else if (terminal_data.coins[`${account.currency}-USD`])
else if (terminal_data.coins[`${account.currency}-${fiat}`])
{
terminal_data.coins[`${account.currency}-USD`].account = account;
terminal_data.coins[`${account.currency}-${fiat}`].account = account;
}

account_ids[account.currency] = account.id;
Expand Down Expand Up @@ -347,7 +333,7 @@ function open_websocket() {
fees: sell_now_sum * .003,
}

// orders_cache = [];
orders_cache = [];
getting_orders = false;
}
} else {
Expand Down
Loading