-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.ts
62 lines (58 loc) · 1.79 KB
/
index.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
53
54
55
56
57
58
59
60
61
62
// fix for @ledgerhq/hw-transport-u2f 4.28.0
import '@babel/polyfill';
import { Constants as WrapperConstants } from '@finbook/duo-contract-wrapper';
import { Constants as DataConstants } from '@finbook/duo-market-data';
import * as CST from './common/constants';
import ContractService from './services/ContractService';
import MarketDataService from './services/MarketDataService';
import dbUtil from './utils/dbUtil';
import util from './utils/util';
const tool = process.argv[2];
util.logInfo('tool ' + tool);
const option = util.parseOptions(process.argv);
if (!option.provider) {
const infura = require('./keys/infura.json');
option.provider =
(option.live
? WrapperConstants.PROVIDER_INFURA_MAIN
: WrapperConstants.PROVIDER_INFURA_KOVAN) +
'/' +
infura.token;
}
util.logInfo(
`using ${option.live ? 'live' : 'dev'}
running on ${option.server ? 'server' : 'local'}
using source ${option.source}
using provider ${option.provider}`
);
dbUtil.init(tool, option).then(() => {
switch (tool) {
case CST.TRADES:
new MarketDataService().startFetching(tool, option);
break;
case CST.EVENTS:
new MarketDataService().startFetchingEvent(tool, option);
break;
case DataConstants.DB_PRICES:
new MarketDataService().startAggregate(option.period);
break;
case CST.CLEAN_DB:
new MarketDataService().cleanDb();
break;
case CST.START_CUSTODIAN:
new ContractService(tool, option).startCustodian(option);
break;
case CST.COMMIT:
new ContractService(tool, option).commitPrice();
break;
case CST.FETCH_PRICE:
new ContractService(tool, option).fetchPrice();
break;
case CST.ROUND:
new ContractService(tool, option).round(option);
break;
default:
util.logInfo('no such tool ' + tool);
break;
}
});