Skip to content

Commit

Permalink
refactor: apply prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
dargmuesli committed Feb 13, 2021
1 parent 2b92e07 commit 3433772
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 50 deletions.
2 changes: 1 addition & 1 deletion src/backtest.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const colors = require("colors")
const _ = require("lodash")
const moment = require("moment")
const { Client } = require("pg")
const env = require('./env')
const env = require("./env")

//////////////////////////////////////////////////////////////////////////////////

Expand Down
29 changes: 19 additions & 10 deletions src/env.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
// read .env file into proces.env
require('dotenv').config()
require("dotenv").config()

const envalid = require('envalid')
var pjson = require('../package.json');
const envalid = require("envalid")
var pjson = require("../package.json")

module.exports = envalid.cleanEnv(process.env, {
BACKTEST_TEST_PAIR: envalid.str({default: 'BTCUSDT'}),
BACKTEST_TEST_PAIR: envalid.str({ default: "BTCUSDT" }),
BINANCE_API_KEY: envalid.str(),
BINANCE_SECRET_KEY: envalid.str(),
BVA_API_KEY: envalid.str(),
CONNECT_SERVER_TO_BVA: envalid.bool({ default: true }),
DATABASE_CONNECT_VIA_SSL: envalid.bool({ default: false }),
DATABASE_INSERT_PAIR_HISTORY: envalid.bool({ default: true}),
DATABASE_URL: envalid.str({default: 'DATABASE_URL=postgres://postgres:[email protected]:5432/postgres'}),
HOST: envalid.host({ default: 'localhost' }),
SERVER_PORT: envalid.port({ default: 4000, desc: 'The port to start the server on' }),
TRADER_PORT: envalid.port({ default: 8003, desc: 'The port to trader webserver runs' }),
STRATEGY_TIMEFRAME: envalid.str({default:'15m'}),
DATABASE_INSERT_PAIR_HISTORY: envalid.bool({ default: true }),
DATABASE_URL: envalid.str({
default:
"DATABASE_URL=postgres://postgres:[email protected]:5432/postgres",
}),
HOST: envalid.host({ default: "localhost" }),
SERVER_PORT: envalid.port({
default: 4000,
desc: "The port to start the server on",
}),
TRADER_PORT: envalid.port({
default: 8003,
desc: "The port to trader webserver runs",
}),
STRATEGY_TIMEFRAME: envalid.str({ default: "15m" }),
VERSION: envalid.str({ default: pjson.version }),
})
40 changes: 22 additions & 18 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const _ = require("lodash")
const tulind = require("tulind")
const axios = require("axios")
const { Client } = require("pg")
const env = require('./env')
const env = require("./env")

const PORT = env.SERVER_PORT
const INDEX = path.join(__dirname, "index.html")
Expand Down Expand Up @@ -190,25 +190,29 @@ async function trackPairData(pair) {
}
await sleep(wait_time)
// setup candle websocket
const candlesWs = binance_client.ws.candles(pair, timeframe, async (candle) => {
updateLastCandle(pair, candle)
if (candle.isFinal) {
addCandle(pair, candle)
}
const candlesWs = binance_client.ws.candles(
pair,
timeframe,
async (candle) => {
updateLastCandle(pair, candle)
if (candle.isFinal) {
addCandle(pair, candle)
}

try {
await tulind.indicators.stochrsi
.indicator([pairData[pair].candle_closes], [100])
.then((results) => {
pairData[pair].srsi = BigNumber(
results[0][results[0].length - 1] * 100
)
})
} catch (e) {
console.log(pair, "SRSI ERROR!!!")
pairData[pair].srsi = null
try {
await tulind.indicators.stochrsi
.indicator([pairData[pair].candle_closes], [100])
.then((results) => {
pairData[pair].srsi = BigNumber(
results[0][results[0].length - 1] * 100
)
})
} catch (e) {
console.log(pair, "SRSI ERROR!!!")
pairData[pair].srsi = null
}
}
})
)

await sleep(wait_time)

Expand Down
48 changes: 27 additions & 21 deletions src/telegram.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
const TeleBot = require('telebot')
const _ = require('lodash')
const TeleBot = require("telebot")
const _ = require("lodash")

module.exports = function (use_telegram, telegramToken, telChanel, trading_pairs) {
module.exports = function (
use_telegram,
telegramToken,
telChanel,
trading_pairs
) {
if (!use_telegram) {
return true;
return true
}
const telBot = new TeleBot({
const telBot = new TeleBot({
token: telegramToken, // Required. Telegram Bot API token.
polling: { // Optional. Use polling.
polling: {
// Optional. Use polling.
interval: 700, // Optional. How often check updates (in ms).
timeout: 0, // Optional. Update polling timeout (0 - short polling).
limit: 100, // Optional. Limits the number of updates to be retrieved.
Expand All @@ -23,27 +29,27 @@ module.exports = function (use_telegram, telegramToken, telChanel, trading_pairs
// maxConnections: 40 // Optional. Maximum allowed number of simultaneous HTTPS connections to the webhook for update delivery
// },
allowedUpdates: [], // Optional. List the types of updates you want your bot to receive. Specify an empty list to receive all updates.
usePlugins: ['askUser'], // Optional. Use user plugins from pluginFolder.
pluginFolder: '../plugins/', // Optional. Plugin folder location.
pluginConfig: { // Optional. Plugin configuration.
// myPluginName: {
// data: 'my custom value'
// }
}
});
usePlugins: ["askUser"], // Optional. Use user plugins from pluginFolder.
pluginFolder: "../plugins/", // Optional. Plugin folder location.
pluginConfig: {
// Optional. Plugin configuration.
// myPluginName: {
// data: 'my custom value'
// }
},
})

telBot.telChanel = telChanel;
telBot.telChanel = telChanel

// GET CHANEL ID
telBot.on('/info', async (msg) => {
let response = "Open Trades: "+ _.values(trading_pairs).length+"\n"
telBot.on("/info", async (msg) => {
let response = "Open Trades: " + _.values(trading_pairs).length + "\n"
// response += "Chanel ID : "+msg.chat.id+"\n" //IF UNCOMENT SHOW CHANEL ID
// telBot.telChanel = msg.chat.id
return telBot.sendMessage(telChanel, response)
});

telBot.start();
})

return telBot;
telBot.start()

return telBot
}

0 comments on commit 3433772

Please sign in to comment.