-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.ts
52 lines (39 loc) · 1.5 KB
/
main.ts
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
import EventAgregator from './sources/event-aggregator';
import Reporter from './sources/reporter';
const eventAggregator = EventAgregator.getInstance();
const reporter = Reporter.getInstance();
let wrapper: App.wrappers.IWrapper;
async function onTickReportSell ( params: App.sources.TTickerSellDataReport ) {
await reporter.report( 'sell', params );
if ( params.terminateConnection ) {
wrapper.terminateConnection( wrapper.getSubscription( params.pair ) );
}
}
function onTickReportAppreciation ( params ) {
reporter.report( 'appreciation', params );
}
function getPairs ( params: App.sources.TStartParams[] ): string[] {
return params.map( ( item ) => {
return item.pair;
});
}
function getParams ( params: App.sources.TStartParams[] ): App.wrappers.TParamsByPair {
let obj = {};
params.forEach( ( item ) => {
obj[ item.pair ] = {
buyPrice: item.buyPrice,
lossTolerance: item.lossTolerance
};
});
return obj;
}
export default function start ( interval: string, params: App.sources.TStartParams[], Wrapper ) {
const pairs = getPairs( params );
const theParams = getParams( params );
wrapper = new Wrapper() as App.wrappers.IWrapper;
eventAggregator.subscribe( 'onTickReportSell', onTickReportSell );
eventAggregator.subscribe( 'onTickReportAppreciation', onTickReportAppreciation );
pairs.forEach( ( pair ) => {
wrapper.placeTrailingStopOrder( pair, interval, theParams );
});
};