-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
54 lines (43 loc) · 1.65 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const config = require("./config/config.json");
const Data = require(`./data`);
var tradingDecision = require("./decisions")
var dbOps = require("./dbs")
// console.log(config.simulation)
if(config.simulation){
var Trader = require(`./trades`)
}
else{
var Trader = require(`./trades`)
}
// console.log(Trader)
async function init(){
mysqlOps = new dbOps.mysqlOps(config)
await mysqlOps.init()
const dataInstance = new Data(config.exchange, config.simulation, mysqlOps);
await dataInstance.initialFetch();
// console.log("data instance : ",Object.getOwnPropertyNames(dataInstance))
// console.log("trading decision : ", tradingDecision)
let tradingAlgo = tradingDecision[config.algorithm];
let algoInstance = new tradingAlgo(config, dataInstance);
await algoInstance.initialFetch()
const algoConf = config.algoConfig[config.algorithm];
if(config.simulation){
// console.log("starting simulation")
var traderObj = new Trader(currency1 = 0, currency2 = 1, conversion = await dataInstance.getPrice())
for(var i = 0; i < dataInstance.queries.nPast.length-algoConf.lastNCandles-1; i++){
// console.log("start")
await algoInstance.update()
var tradeVal = await algoInstance.whatToDo()
// console.log("action : ",tradeVal,"\n\n")
await traderObj.trade(tradeVal)
}
// return;
console.log("ledger details : ")
for(let j = 0; j < traderObj.ledger.length; j++){
console.log(traderObj.ledger[j])
}
mysqlOps.terminate()
}
// tradeObj = await algoInstance.whatToDo()
}
init()