forked from f3rno/bfx-ws2-api-audit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
105 lines (90 loc) · 2.33 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
98
99
100
101
102
103
104
105
'use strict'
require('dotenv').config()
// process.env.DEBUG = 'bfx:ws2-api-audi*'
// process.env.DEBUG = 'bfx:ws2-api-audit:test_suite'
process.env.DEBUG = '*'
const {
API_KEY_MAKER, API_SECRET_MAKER, API_KEY_TAKER, API_SECRET_TAKER
} = process.env
const DATA_DELAY = 10 * 1000
const INITIAL_MID_PRICE = 13.618 // only used if OB is empty
const INITIAL_LAST_PRICE = 13.618 // only used if ticker not received
const SYMBOL = 'tQTMUSD'
const AMOUNT = 1
const Dataset = require('./lib/dataset')
const { runTestSuites } = require('./lib/test_suite')
const stepOpenWS = require('./lib/steps/open_ws')
const stepCloseWS = require('./lib/steps/close_ws')
const stepAuthWS = require('./lib/steps/auth_ws')
const stepSetupDataset = require('./lib/steps/setup_dataset')
const stepTeardownDataset = require('./lib/steps/teardown_dataset')
const stepDelay = require('./lib/steps/delay')
const getBFX = require('./lib/util/get_bfx')
// TODO: Break this out on the environment
const symbols = [
'tQTMUSD',
/*
'tBTCUSD',
'tETHBTC',
'tETHUSD',
'tIOTUSD',
'tIOTBTC',
'tIOTETH',
'tIFXUSD',
// Virtual
'tBTCEUR',
'tBTCJPY',
'tIOTEUR'
*/
]
const bfxM = getBFX(API_KEY_MAKER, API_SECRET_MAKER)
const bfxT = getBFX(API_KEY_TAKER, API_SECRET_TAKER)
const wsM = bfxM.ws(2)
const wsT = bfxT.ws(2)
const restM = bfxM.rest(2)
const restT = bfxT.rest(2)
const dataM = new Dataset(symbols, wsM, 'maker')
const dataT = new Dataset(symbols, wsT, 'taker')
const orderTestArgs = {
symbol: SYMBOL,
amount: AMOUNT,
initialMid: INITIAL_MID_PRICE,
initialLast: INITIAL_LAST_PRICE,
dataDelay: DATA_DELAY
}
runTestSuites([
require('./lib/tests/limit')(orderTestArgs),
require('./lib/tests/market')(orderTestArgs),
require('./lib/tests/stop')(orderTestArgs),
require('./lib/tests/fok')(orderTestArgs),
require('./lib/tests/stop_limit')(orderTestArgs),
require('./lib/tests/trailing_stop')(orderTestArgs),
/*
require('./lib/tests/virtual_obs')({
...orderTestArgs,
primaryPair: 'tBTCUSD',
virtualPair: 'tBTCJPY'
}),
*/
], {
wsM,
wsT,
dataM,
dataT,
restM,
restT,
symbol: SYMBOL,
amount: AMOUNT,
dataDelay: DATA_DELAY
}, {
before: [
stepOpenWS(),
stepSetupDataset(),
stepAuthWS(),
stepDelay(1 * 1000), // wait for chan 0 data to arrive
],
after: [
stepTeardownDataset(),
stepCloseWS()
]
})