Skip to content

Commit

Permalink
update nodejs dependencies (#58)
Browse files Browse the repository at this point in the history
* fix Tensorflow installation problem

* update npm install command

* update nodejs dependencies

* revert commit fix bitmex max listeners exceeded warning

* update docker-compose script

* update README.md

* update nodejs dependencies

* update nodejs dependencies

* update nodejs dependencies

* clean up code /modules/pairs/pair_state_execution.js

* clean up code /modules/order/order_calculator.js

* fix error this.logger.error is not a function

* clean up code index.js
  • Loading branch information
minhphuc429 authored and Haehnchen committed Jun 29, 2019
1 parent f729634 commit 2ca0749
Show file tree
Hide file tree
Showing 11 changed files with 782 additions and 756 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
npm-debug.log
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
language: node_js

node_js:
- '9'
- '10'

install:
- npm install

script:
- npm test
- npm test
24 changes: 17 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
FROM node:11
FROM node:10

MAINTAINER Daniel Espendiller <daniel@espendiller.net>

# Install build-essential, sqlite in order
RUN apt-get update && apt-get install -y \
sqlite
sqlite \
&& rm -rf /var/lib/apt/lists/*

# clean image
RUN rm -rf /var/lib/apt/lists/*
WORKDIR /usr/src/app

WORKDIR /src
# Install app dependencies
COPY package.json /usr/src/app/
RUN npm install --production && \
npm cache clean --force

ENTRYPOINT ["node"]
CMD ["index.js", "trade" ]
# Bundle app source
COPY . /usr/src/app

# Apply all patches in app
RUN npm run postinstall

EXPOSE 8080
CMD ["npm", "run", "start"]
18 changes: 7 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ TODOS:
Install packages

```
npm install
➜ npm install --production
➜ npm run postinstall
```

Create instance file for pairs and changes
Expand All @@ -64,10 +65,8 @@ Provide a configuration with your exchange credentials
cp conf.json.dist conf.json
```

Create a new sqlite data base

Create a new sqlite database use bot.sql scheme to create the tables
```
# use bot.sql scheme to create the tables
sqlite3 bot.db < bot.sql
```

Expand All @@ -82,15 +81,12 @@ node index.js trade
For initialize the configuration once

```
docker-compose run --rm --entrypoint "/bin/bash" bot "-c" "cp instance.js.dist instance.js && cp conf.json.dist conf.json && sqlite3 bot.db < bot.sql"
➜ cp instance.js.dist instance.js && cp conf.json.dist conf.json && sqlite3 bot.db < bot.sql
➜ docker-compose build
➜ docker-compose up -d
```

After this you can use `docker-compose` which will give you a running bot via <http://127.0.0.1:8080>

```
docker-compose up
```

#### Setting Up Telegram Bot
First, you'll need to create a bot for Telegram. Just talk to [BotFather](https://telegram.me/botfather) and follow simple steps until it gives you a token for it.
You'll also need to create a Telegram group, the place where you and crypto-trading-bot will communicate. After creating it, add the bot as administrator (make sure to uncheck "All Members Are Admins").
Expand Down Expand Up @@ -282,4 +278,4 @@ Some strategies based on technical indicators for collection some ideas
* https://github.com/freqtrade/freqtrade-strategies/tree/master/user_data/strategies/berlinguyinca
* https://github.com/xFFFFF/Gekko-Strategies
* https://github.com/sthewissen/Mynt/tree/master/src/Mynt.Core/Strategies
* https://github.com/Ekliptor/WolfBot/tree/master/src/Strategies
* https://github.com/Ekliptor/WolfBot/tree/master/src/Strategies
8 changes: 5 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ version: '3.7'

services:
bot:
image: node:11
container_name: crypto-trading-bot
image: node:10
build:
context: .
dockerfile: Dockerfile
volumes:
- .:/src
- .:/usr/src/app
- /usr/src/app/node_modules
ports:
- "8080:8080"
working_dir: /src
command: npm start
11 changes: 6 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ let Backfill = require('./command/backfill.js');
let program = require('commander');

// init
let services = require('./modules/services')
let services = require('./modules/services');

program
.command('trade')
.description('upload a file')
.description('start crypto trading bot')
.option('-i, --instance <file>', 'Instance to start', 'instance.json')
.action(async options => {
await services.boot()
await services.boot();

let cmd = new TradeCommand(options.instance);
cmd.execute();
});

program
.command('backfill')
.description('upload a file')
.description('process historical data collection')
.option('-e, --exchange <exchange>')
.option('-s, --symbol <symbol>')
.option('-p, --period <period>', '1m 5m, 15m, 1h', '15m')
Expand All @@ -32,7 +32,7 @@ program
throw 'Not all options are given'
}

await services.boot()
await services.boot();

let cmd = new Backfill();
await cmd.execute(options.exchange, options.symbol, options.period, options.date);
Expand All @@ -42,6 +42,7 @@ program

program
.command('server')
.description('')
.option('-i, --instance <file>', 'Instance to start', 'instance.json')
.action(function(options) {
let cmd = new ServerCommand(options.instance);
Expand Down
24 changes: 12 additions & 12 deletions modules/order/order_calculator.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
'use strict';

let _ = require('lodash')
let _ = require('lodash');

module.exports = class OrderCalculator {
constructor(instances, tickers, logger, exchangeManager) {
this.instances = instances
this.tickers = tickers
this.logger = {}
this.instances = instances;
this.tickers = tickers;
this.logger = logger;
this.exchangeManager = exchangeManager
}

async calculateOrderSize(exchangeName, symbol) {
let orderSizeCalculated = await this.getSymbolCapital(exchangeName, symbol)
let orderSizeCalculated = await this.getSymbolCapital(exchangeName, symbol);
if (!orderSizeCalculated) {
return
}

// normalize the size to allowed size
let orderSize = this.exchangeManager.get(exchangeName).calculateAmount(orderSizeCalculated, symbol)
let orderSize = this.exchangeManager.get(exchangeName).calculateAmount(orderSizeCalculated, symbol);
if (!orderSize) {
this.logger.error('Can no normalize buy price: ' + JSON.stringify([exchangeName, symbol, orderSize]))
this.logger.error('Can no normalize buy price: ' + JSON.stringify([exchangeName, symbol, orderSize]));

return
}
Expand All @@ -31,7 +31,7 @@ module.exports = class OrderCalculator {
let capital = this.instances.symbols.find(instance =>
instance.exchange === exchange && instance.symbol === symbol &&
(_.get(instance, 'trade.capital', 0) > 0)
)
);

if (capital) {
return capital.trade.capital
Expand All @@ -40,13 +40,13 @@ module.exports = class OrderCalculator {
let capitalCurrency = this.instances.symbols.find(instance =>
instance.exchange === exchange && instance.symbol === symbol &&
(_.get(instance, 'trade.currency_capital', 0) > 0)
)
);

if (capitalCurrency) {
return await this.convertCurrencyToAsset(exchange, symbol, capitalCurrency.trade.currency_capital)
}

return

}

/**
Expand All @@ -60,10 +60,10 @@ module.exports = class OrderCalculator {
async convertCurrencyToAsset(exchangeName, symbol, currencyAmount) {
let ticker = this.tickers.get(exchangeName, symbol);
if (!ticker || !ticker.bid) {
this.logger.error('Invalid ticker for calculate currency capital:' + JSON.stringify([exchangeName, symbol, currencyAmount]))
this.logger.error('Invalid ticker for calculate currency capital:' + JSON.stringify([exchangeName, symbol, currencyAmount]));
return
}

return currencyAmount / ticker.bid
}
}
};
Loading

0 comments on commit 2ca0749

Please sign in to comment.