-
Notifications
You must be signed in to change notification settings - Fork 23
/
example.js
135 lines (127 loc) · 3.22 KB
/
example.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
'use strict'
// node examples/server-lowdb.js
const Ws = require('ws')
const ws = new Ws('ws://localhost:8899')
ws.on('open', () => {
console.log('open')
ws.send(
JSON.stringify(msg)
)
})
ws.on('message', (data) => {
console.log(data)
})
/* eslint-disable */
const strategy = {
defineIndicators: '(I) => {\n' +
' const indicators = {\n' +
" \temaL: new I.EMA([100, 'high']),\n" +
" \temaS: new I.EMA([10, 'low']),\n" +
' }\n' +
' \n' +
" indicators.emaL.color = '#00ff00'\n" +
" indicators.emaS.color = '#ff0000'\n" +
' \n' +
' return indicators\n' +
'}',
onEnter: '({ HFS, _, HFU }) => async (state = {}, update = {}) => {\n' +
' if (HFS.getNumCandles(state) < 2) { // 2 price points needed\n' +
' return state\n' +
' }\n' +
'\n' +
' const { price, mts } = update\n' +
' const i = HFS.indicators(state)\n' +
' const iv = HFS.indicatorValues(state)\n' +
' const { emaS } = i\n' +
' const l = iv.emaL\n' +
' const s = iv.emaS\n' +
' const amount = 1\n' +
' \n' +
' if (emaS.crossed(l)) {\n' +
' if (s > l) {\n' +
' return HFS.openLongPositionMarket(state, {\n' +
' mtsCreate: mts,\n' +
' amount,\n' +
' price,\n' +
" label: 'enter long',\n" +
' })\n' +
' } else {\n' +
' return HFS.openShortPositionMarket(state, {\n' +
' mtsCreate: mts,\n' +
' amount,\n' +
' price,\n' +
" label: 'enter short',\n" +
' })\n' +
' }\n' +
' }\n' +
'\n' +
' return state\n' +
'}',
onUpdateLong: '({ HFS, HFU }) => async (state = {}, update = {}) => {\n' +
' const { price, mts } = update\n' +
' const i = HFS.indicators(state)\n' +
' const iv = HFS.indicatorValues(state)\n' +
' const { emaS } = i\n' +
' const l = iv.emaL\n' +
' const s = iv.emaS\n' +
' \n' +
' if (emaS.crossed(l) && s < l) {\n' +
' return HFS.closePositionMarket(state, {\n' +
' price,\n' +
' mtsCreate: mts,\n' +
" label: 'close long',\n" +
' })\n' +
' }\n' +
' \n' +
' return state\n' +
'}',
onUpdateShort: '({ HFS, HFU }) => async (state = {}, update = {}) => {\n' +
' const { price, mts } = update\n' +
' const i = HFS.indicators(state)\n' +
' const iv = HFS.indicatorValues(state)\n' +
' const { emaS } = i\n' +
' const l = iv.emaL\n' +
' const s = iv.emaS\n' +
' \n' +
' if (emaS.crossed(l) && s > l) {\n' +
' return HFS.closePositionMarket(state, {\n' +
' price,\n' +
' mtsCreate: mts,\n' +
" label: 'close short',\n" +
' })\n' +
' }\n' +
' \n' +
' return state\n' +
'}',
id: null
}
const msg = [
'exec.str',
[
'bitfinex',
1610029361708,
1610114861708,
'tBTCUSD',
'15m',
true,
false,
true,
strategy,
'1610115118349-tBTCUSD-15m-1610029361708-1610114861708'
]
]
const bugMsg = [
'exec.str',
[
'bitfinex',
1610029109969,
1610114609969,
'tADABTC',
'15m',
true,
false,
true,
strategy,
'1610115118342-tADABTC-15m-1610029109969-1610114609969'
]
]