-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbot.js
120 lines (94 loc) · 4.38 KB
/
bot.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
const trader = require('./trader');
const {feed} = market = require('./candles_feed/market');
const signal = require('./signals');
// const db = require('./database/index');
let pumpings = {};
function notifyCanBuy({chatId, buyPosition}) {
console.log(`\nBuy ${buyPosition.symbol} at ${buyPosition.close_price} time ${new Date(buyPosition.timestamp)}`);
}
function notifyBuy(param) {
}
function notifyTimeToSell({chatId, buyPrice, sellPoint}) {
console.log(`\nSell ${buyPrice.symbol} at ${sellPoint.sellPrice} win ${sellPoint.tradeGain}`);
}
function notifySell(param) {
}
function tradeCompleted({chatId, buyState, soldPoint}) {
console.log(`\nTrade complete ${buyState.symbol} buy at ${buyState.close_price} sell at ${soldPoint.close_price}`);
}
function notifyBug(ex) {
}
async function onCandleFetched({data, exchangeId, symbol, timeframe}) {
const prices = await db.loadPrices({exchangeId, symbol, timeframe});
// let symbolStatus = await trader.getSymbolStatus({symbol, prices, exchangeId, timeframe});
signal.setIndicators({
exchangeId, symbol, timeframe,
indicators:await signal.strategies.reduce(async (indicators, strategy) => {
indicators[strategy] = await signal[strategy]({prices})
return indicators;
}, {})
})
}
const start = async () => {
try {
// const exchangeId = process.env.EXCHANGE || 'binance';
const exchangeId = 'coinmarketcap';
const timeframe = process.env.TIMEFRAME || '15m';
const symbol = process.env.SYMBOL;
// const symbol = process.env.SYMBOL||'BNB/BTC';
const exchange = await market.init({exchangeId,coinmarketcap:true});
await feed.start({exchange, timeframe, symbol})
// await feed.start({exchange, timeframe, symbol, onCandleFetched})
//xx();
async function xx() {
await market.start({
exchange, limit: null, timeframe, symbol: 'OST/BTC',
onSave: async (err, {data, exchangeId, symbol, timeframe}) => {
if (!err) {
const prices = await db.loadPrices({exchangeId, symbol, timeframe});
let symbolStatus = await trader.getSymbolStatus({symbol, prices, exchangeId, timeframe});
let ema = await signal.ema({prices: prices})
// debugger
console.log(symbol, ema, new Date(prices[prices.length - 1].timestamp))
await xx();
// if (symbolStatus && !pumpings[symbol]) {
// pumpings[symbol] = symbolStatus;
// await notifyCanBuy({chatId, buyPosition: symbolStatus});
// let buyPrice = await trader.buy({symbol, buyPosition: symbolStatus, exchangeId});
// if (buyPrice) {
// await notifyBuy({chatId, buyPrice, symbol, timeframe});
// let sellPoint = await trader.checkSellPoint({
// buyState: symbolStatus,
// exchange,
// symbol,
// timeframe
// });
// await notifyTimeToSell({chatId, buyPrice, sellPoint})
// let soldPoint = await trader.sell({sellPoint, symbol, exchangeId});
// await notifySell({buyPrice, soldPoint})
// pumpings[symbol].tradeCompleted = true;
// await tradeCompleted({chatId, buyState: symbolStatus, soldPoint})
// }
// } else if (!symbolStatus && pumpings[symbol] && pumpings[symbol].tradeCompleted) {
// pumpings[symbol] = null;
// }
}
}
});
}
} catch (ex) {
debugger;
// bot.sendMessage(chatId, ex.toString())
notifyBug(ex)
console.log('End with error', ex)
process.exit(1);
}
};
function displayPumping({chatId, pumpings}) {
debugger
}
const compatibleExchange = (msg) => {
bot.sendMessage(msg.chat.id, market.compatibleExchange())
}
module.exports = {start, compatibleExchange}
start();