Skip to content

Commit ed06bce

Browse files
committed
consolidate trading configuration and provide example
1 parent b3457a4 commit ed06bce

File tree

8 files changed

+122
-28
lines changed

8 files changed

+122
-28
lines changed

README.md

+63
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,69 @@ You should only provide one of them, first wins.
293293
})
294294
```
295295

296+
### Live Strategy
297+
298+
Every strategy stat should be live must be places inside `trade`.
299+
300+
```json
301+
{
302+
"trade": {
303+
"strategies": [
304+
{
305+
"strategy": "dip_catcher",
306+
"interval": "15m",
307+
"options": {
308+
"period": "15m"
309+
}
310+
}
311+
]
312+
}
313+
}
314+
```
315+
316+
Inside logs, visible via browser ui, you can double check the strategies init process after the application started.
317+
318+
```
319+
[info] Starting strategy intervals
320+
[info] "binance_futures" - "ETHUSDT" - "trade" - init strategy "dip_catcher" (15m) in 11.628 minutes
321+
[info] "binance_futures" - "BTCUSDT" - "trade" first strategy run "dip_catcher" now every 15.00 minutes
322+
```
323+
324+
### Full Trade Example
325+
326+
An example `instance.js` which trades can be found inside `instance.js.dist_trade`. Rename it or move the content to you file.
327+
328+
```js
329+
const c = (module.exports = {});
330+
331+
c.symbols = [
332+
{
333+
symbol: 'ETHUSDT',
334+
exchange: 'binance_futures',
335+
periods: ['1m', '15m', '1h'],
336+
trade: {
337+
currency_capital: 10,
338+
strategies: [
339+
{
340+
strategy: 'dip_catcher',
341+
interval: '15m',
342+
options: {
343+
period: '15m'
344+
}
345+
}
346+
]
347+
},
348+
watchdogs: [
349+
{
350+
name: 'risk_reward_ratio',
351+
target_percent: 3.1,
352+
stop_percent: 2.1
353+
}
354+
]
355+
}
356+
];
357+
```
358+
296359
### Margin / Leverage
297360

298361
Per pair you can set used margin before orders are created; depending on exchange

instance.js.dist_trade

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const c = (module.exports = {});
2+
3+
c.symbols = [
4+
{
5+
symbol: 'ETHUSDT',
6+
exchange: 'binance_futures',
7+
periods: ['1m', '15m', '1h'],
8+
trade: {
9+
currency_capital: 10,
10+
strategies: [
11+
{
12+
strategy: 'dip_catcher',
13+
interval: '15m',
14+
options: {
15+
period: '15m'
16+
}
17+
}
18+
]
19+
},
20+
watchdogs: [
21+
{
22+
name: 'risk_reward_ratio',
23+
target_percent: 3.1,
24+
stop_percent: 2.1
25+
}
26+
]
27+
}
28+
];

src/modules/exchange/exchange_manager.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module.exports = class ExchangeManager {
2020
.map(exchange => exchange.getName())
2121
.forEach(exchangeName => {
2222
const pairs = this.instances.symbols.filter(symbol => {
23-
return symbol.exchange === exchangeName && ['watch', 'trade'].includes(symbol.state);
23+
return symbol.exchange === exchangeName;
2424
});
2525

2626
if (pairs.length === 0) {

src/modules/listener/tick_listener.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,15 @@ module.exports = class TickListener {
179179
me.logger.info(`Strategy: "${type.name}" found "${type.items.length}" valid symbols`);
180180

181181
type.items.forEach(symbol => {
182-
symbol.strategies.forEach(strategy => {
182+
// map strategies
183+
let strategies = [];
184+
if (type.name === 'watch') {
185+
strategies = symbol.strategies;
186+
} else if (type.name === 'trade') {
187+
strategies = symbol.trade.strategies;
188+
}
189+
190+
strategies.forEach(strategy => {
183191
let myInterval = '1m';
184192

185193
if (strategy.interval) {

src/modules/pairs/pairs_http.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,17 @@ module.exports = class PairsHttp {
1616
const position = await this.exchangeManager.getPosition(symbol.exchange, symbol.symbol);
1717
const state = await this.pairStateManager.get(symbol.exchange, symbol.symbol);
1818

19+
const strategiesTrade = symbol.trade && symbol.trade.strategies ? symbol.trade.strategies : [];
20+
1921
const item = {
2022
exchange: symbol.exchange,
2123
symbol: symbol.symbol,
2224
watchdogs: symbol.watchdogs,
23-
state: symbol.state,
25+
is_trading: strategiesTrade.length > 0,
2426
has_position: position !== undefined,
2527
capital: `${_.get(symbol, 'trade.capital', 0)} / ${_.get(symbol, 'trade.currency_capital', 0)}`,
2628
strategies: symbol.strategies || [],
29+
strategies_trade: strategiesTrade,
2730
weight: 0
2831
};
2932

src/modules/trade.js

+3-7
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,9 @@ module.exports = class Trade {
5252

5353
const instanceId = crypto.randomBytes(4).toString('hex');
5454

55-
const notifyActivePairs = this.instances.symbols
56-
.filter(symbol => {
57-
return ['watch', 'trade'].includes(symbol.state);
58-
})
59-
.map(symbol => {
60-
return `${symbol.exchange}.${symbol.symbol}`;
61-
});
55+
const notifyActivePairs = this.instances.symbols.map(symbol => {
56+
return `${symbol.exchange}.${symbol.symbol}`;
57+
});
6258

6359
const message = `Start: ${instanceId} - ${os.hostname()} - ${os.platform()} - ${moment().format()} - ${notifyActivePairs.join(
6460
', '

src/utils/instance_util.js

+6-12
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ module.exports = {
3030
let result = {
3131
symbol: pair.name,
3232
periods: ['1m', '15m', '1h'],
33-
exchange: 'ftx',
34-
state: 'watch'
33+
exchange: 'ftx'
3534
};
3635

3736
if (callback) {
@@ -84,8 +83,7 @@ module.exports = {
8483
let result = {
8584
symbol: pair.symbol,
8685
periods: ['1m', '15m', '1h'],
87-
exchange: 'binance',
88-
state: 'watch'
86+
exchange: 'binance'
8987
};
9088

9189
if (callback) {
@@ -181,8 +179,7 @@ module.exports = {
181179
let result = {
182180
symbol: pair.symbol,
183181
periods: ['1m', '15m', '1h'],
184-
exchange: 'bitmex',
185-
state: 'watch'
182+
exchange: 'bitmex'
186183
};
187184

188185
if (callback) {
@@ -217,8 +214,7 @@ module.exports = {
217214
let result = {
218215
symbol: pair.symbol,
219216
periods: ['1m', '15m', '1h'],
220-
exchange: 'binance_futures',
221-
state: 'watch'
217+
exchange: 'binance_futures'
222218
};
223219

224220
if (callback) {
@@ -248,8 +244,7 @@ module.exports = {
248244
let result = {
249245
symbol: pair.pair.toUpperCase(),
250246
periods: ['1m', '15m', '1h'],
251-
exchange: 'bitfinex',
252-
state: 'watch'
247+
exchange: 'bitfinex'
253248
};
254249

255250
if (callback) {
@@ -279,8 +274,7 @@ module.exports = {
279274
let result = {
280275
symbol: pair.name,
281276
periods: ['1m', '15m', '1h'],
282-
exchange: 'bybit',
283-
state: 'watch'
277+
exchange: 'bybit'
284278
};
285279

286280
if (callback) {

templates/pairs.html.twig

+8-6
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
<th scope="col">Symbol</th>
3939
<th scope="col">State</th>
4040
<th scope="col">Capital</th>
41-
<th scope="col">Strategies</th>
41+
<th scope="col">Strategies Watch</th>
42+
<th scope="col">Strategies Trade</th>
4243
<th scope="col">Options</th>
4344
<th scope="col">Process</th>
4445
<th scope="col">Action</th>
@@ -48,11 +49,12 @@
4849
<tbody>
4950
{% for pair in pairs %}
5051
<tr>
51-
<td style="white-space: nowrap"><img src="/img/exchanges/{{ pair.exchange }}.png" title="{{ pair.exchange }}" alt="{{ pair.exchange }}" width="16px" height="16px"></td>
52-
<td style="white-space: nowrap"><a target="blank" href="/tradingview/{{ pair.exchange }}:{{ pair.symbol }}">{{ pair.symbol }}</td>
53-
<td>{{ pair.state }}</td>
54-
<td><strong>{{ pair.capital }}</strong></td>
55-
<td class="text-muted"><span class="span-md">{{ pair.strategies|json_encode }}</span></td>
52+
<td class="no-wrap"><img src="/img/exchanges/{{ pair.exchange }}.png" title="{{ pair.exchange }}" alt="{{ pair.exchange }}" width="16px" height="16px"></td>
53+
<td class="no-wrap"><a target="blank" href="/tradingview/{{ pair.exchange }}:{{ pair.symbol }}">{{ pair.symbol }}</td>
54+
<td class="no-wrap">{{ pair.is_trading ? '<i class="fas fa-cart-plus font-weight-bold"></i>' : '<i class="fas fa-eye text-muted"></i>' }}</td>
55+
<td class="no-wrap"><strong>{{ pair.capital }}</strong></td>
56+
<td class="text-muted"><span class="span-md">{% if pair.strategies.length > 0 %}{{ pair.strategies|json_encode }}{% endif %}</span></td>
57+
<td class="text-muted"><span class="span-md">{% if pair.strategies_trade.length > 0 %}{{ pair.strategies_trade|json_encode }}{% endif %}</span></td>
5658
<td class="text-muted">
5759
<span class="span-md">
5860
{% if pair.watchdogs %}

0 commit comments

Comments
 (0)