-
Notifications
You must be signed in to change notification settings - Fork 21
/
index.js
97 lines (82 loc) · 2.08 KB
/
index.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
'use strict'
require('bfx-hf-util/lib/catch_uncaught_errors')
const HFDB = require('bfx-hf-models')
const HFDBLowDBAdapter = require('bfx-hf-models-adapter-lowdb')
const { schema: HFDBDummySchema } = require('bfx-hf-ext-plugin-dummy')
const { ALGO_LOG, ALGO_LOG_DIR } = process.env
const APIWSServer = require('./lib/ws_servers/api')
const HttpProxy = require('./lib/bfx_api_proxy')
const getMarketData = require('./lib/get_market_data')
const capture = require('./lib/capture')
const config = require('./config/algo_server.conf.json')
const { RESTv2 } = require('bfx-api-node-rest')
module.exports = async ({
bfxRestURL,
bfxWSURL,
bfxHostedWsUrl,
bfxMetricsWsUrl,
os,
releaseVersion,
isRC,
locale,
uiDBPath,
algoDBPath,
strategyExecutionPath,
dataDir,
wsServerPort = 45000,
httpProxyPort = 45001
}) => {
const apiDB = new HFDB({
schema: HFDBDummySchema,
adapter: HFDBLowDBAdapter({ dbPath: uiDBPath })
})
const algoDB = new HFDB({
schema: HFDBDummySchema,
adapter: HFDBLowDBAdapter({ dbPath: algoDBPath })
})
const strategyExecutionDB = new HFDB({
schema: HFDBDummySchema,
adapter: HFDBLowDBAdapter({ dbPath: strategyExecutionPath })
})
const logAlgoOpts = {
logAlgo: ALGO_LOG ? ALGO_LOG === 'true' : false,
logAlgoDir: ALGO_LOG_DIR || ''
}
const api = new APIWSServer({
algoDB,
db: apiDB,
strategyExecutionDB,
port: wsServerPort,
restURL: bfxRestURL,
wsURL: bfxWSURL,
hostedURL: bfxHostedWsUrl,
metricsServerURL: bfxMetricsWsUrl,
os,
releaseVersion,
isRC,
locale,
algos: config.algos,
logAlgoOpts,
config,
dataDir
})
const proxy = new HttpProxy({
restURL: bfxRestURL || 'https://api-pub.bitfinex.com',
port: httpProxyPort
})
const rest = new RESTv2({
url: bfxRestURL
})
async function tryConnect () {
try {
const marketData = await getMarketData(rest)
api.setMarketData(marketData)
proxy.open()
api.open()
} catch (e) {
capture.exception(e)
setTimeout(tryConnect, 3000)
}
}
await tryConnect()
}