-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathordermon.js
61 lines (56 loc) · 1.53 KB
/
ordermon.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
// const config = require('./config');
const orderlog = require('./orderlog').OrderLog;
const db = require('./db').Db;
const OrderMonitor = function OrderMonitor() {};
OrderMonitor.prototype.monitor = function monitor(data) {
// loop through all the recent updates
if (data.length > 0) {
const curr = data[data.length - 1];
const {
orderID,
clOrdID,
// clOrdLinkID,
// account,
// symbol,
side,
// simpleOrderQty,
orderQty,
price,
// displayQty,
// stopPx,
// pegOffsetValue,
// pegPriceType,
// currency,
// settlCurrency,
ordType,
// timeInForce,
// execInst,
// contingencyType,
// exDestination,
ordStatus,
// triggered,
// workingIndicator,
// ordRejReason,
// simpleLeavesQty,
// leavesQty,
// simpleCumQty,
// cumQty,
avgPx,
// multiLegReportingType,
// text,
// transactTime,
timestamp,
} = curr;
// console.log(`${timestamp}\t${side}\t${price}\t${orderQty}\t${avgPx}\t${ordType}\t${ordStatus}\t${orderID}\t${clOrdID}`);
if (ordType === 'Stop' && ordStatus === 'Filled') {
// do order log here
db
.setActiveTrade('false')
.then(db.setOrderType('').catch(console.error))
// .then(console.log('----------------------------------------'))
.catch(reply => console.error(`error ending trade${reply}`));
orderlog.stoploss(price);
}
}
};
exports.OrderMonitor = new OrderMonitor();