Node.JS trading bot for Bitkub.com using TradingView webhook.
This application is based on bitkub-official-api-docs
- Buy or Sell Bitcoin when received webhook from TradingView.
- Records transactions to the self-managed database.
- Notify trading transactions with LINE (need to register).
- ✅ Replace moment.js with date-fns.
- ⏰ Add other instant messaging (e.g. Slack) for notify action.
- ⏰ Add stop-limit order feature (waiting for Bitkub to release this API, see more).
- ⏰ Add trailing stop order feature (after stop-limit order API is released).
- ⏰ Design a web dashboard to visualize profit and loss.
- Buying or selling signals will be triggered from TradingView, we should set up at TradingView side.
- Buy BTC using 90% off THB on your available balance at market price when the condition is met.
- Sell 100% BTC of your available balance at market price when the condition is met.
- TradingView Pro plan or above for server-side webhook.
- Setup trigger condition and webhook URL.
Example TradingView payload
side = sell, tf = 4h, exchange = {{exchange}}, ticker = {{ticker}}, open = {{open}}, close = {{close}}, high = {{high}}, low = {{low}}, volume = {{volume}}, timestamp = {{time}}
git clone https://github.com/nanmcpe/bitkub-optimize
npm install
We allow incoming traffic from trusted sources only. Here is a list of IP addresses that we need to receive POST requests. For more information, please see About webhooks.
52.89.214.238
34.212.75.30
54.218.53.128
52.32.178.7
TradingView only accepts URLs with port numbers 80 and 443.
# ufw allow from 52.89.214.238 to any port 443
# ufw allow from 34.212.75.30 to any port 443
# ufw allow from 54.218.53.128 to any port 443
# ufw allow from 52.32.178.7 to any port 443
NODE_ENV=Development
API_KEY=<YOUR-API-KEY>
API_SECRET=<YOUR-API-SECRET>
DB_SQL_HOST=<YOUR-DATABASE-HOST>
DB_SQL_PORT=3306
DB_SQL_DB=<YOUR-DATABASE-NAME>
DB_SQL_USER=<YOUR-DATABASE-USER>
DB_SQL_PASS=<YOUR-DATABASE-PASS>
SERVER_PORT=3000
BITKUB_ROOT_URL=https://api.bitkub.com
LINE_TOKEN=<YOUR-LINE-TOKEN>
BUY_RATIO=0.9
SELL_RATIO=1
$ mysql -u <user> -p bitkub < database.sql
docker build -t <YOUR-IMAGE-HOST>/bitkub-optimize:<version>
docker push <YOUR-IMAGE-HOST>/bitkub-optimize:<version>
docker-compose pull
node app.js
or docker-compose up -d
location / {
proxy_pass http://172.50.0.2:3000/; # IP of docker container
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr; # Add this header to get real remote IP
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_cache_bypass $http_upgrade;
}
If you use Certbot to renew the SSL certificate, you need to change from HTTP challenge
to DNS challenge
because we only whitelist from TradingView so the Certbot task will fail
- BTC: 3NkbtCeykMvAX32rAd14h3pBstHZ47RaNb
- ETH: 0xc0430624d2e04a2d5e393554904ebefca39b48ca