Skip to content
This repository was archived by the owner on Feb 22, 2024. It is now read-only.

Commit dee03ce

Browse files
author
bahar-fs
committed
bahar/multiple_active-symbols_and_ticks-history_when_starting_a_bot_loop
1 parent f751729 commit dee03ce

File tree

1 file changed

+44
-36
lines changed

1 file changed

+44
-36
lines changed

src/botPage/common/TicksService.js

Lines changed: 44 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,29 @@ export default class TicksService {
4646
this.tickListeners = new Map();
4747
this.ohlcListeners = new Map();
4848
this.subscriptions = new Map();
49+
this.ticks_history_promise = null;
50+
this.active_symbols_promise = null;
4951
this.observe();
5052
}
5153
requestPipSizes() {
5254
if (this.pipSizes) {
5355
return Promise.resolve(this.pipSizes);
5456
}
5557

56-
return new Promise(resolve => {
57-
this.api.getActiveSymbolsBrief().then(r => {
58-
const { active_symbols: symbols } = r;
59-
this.pipSizes = symbols.reduce((accumulator, currSymbol) => {
60-
// eslint-disable-next-line no-param-reassign
61-
accumulator[currSymbol.symbol] = `${currSymbol.pip}`.length - 2;
62-
return accumulator;
63-
}, {});
64-
resolve(this.pipSizes);
58+
if (!this.active_symbols_promise) {
59+
this.active_symbols_promise = new Promise(resolve => {
60+
this.api.getActiveSymbolsBrief().then(r => {
61+
const { active_symbols: symbols } = r;
62+
this.pipSizes = symbols.reduce((accumulator, currSymbol) => {
63+
// eslint-disable-next-line no-param-reassign
64+
accumulator[currSymbol.symbol] = `${currSymbol.pip}`.length - 2;
65+
return accumulator;
66+
}, {});
67+
resolve(this.pipSizes);
68+
});
6569
});
66-
});
70+
}
71+
return this.active_symbols_promise;
6772
}
6873
request(options) {
6974
const { symbol, granularity } = options;
@@ -208,31 +213,34 @@ export default class TicksService {
208213
requestTicks(options) {
209214
const { symbol, granularity, style } = options;
210215

211-
return new Promise((resolve, reject) => {
212-
doUntilDone(() =>
213-
this.api.getTickHistory(symbol, {
214-
subscribe : 1,
215-
end : 'latest',
216-
count : 1000,
217-
granularity: granularity ? Number(granularity) : undefined,
218-
style,
219-
})
220-
)
221-
.then(r => {
222-
if (style === 'ticks') {
223-
const ticks = historyToTicks(r.history);
224-
225-
this.updateTicksAndCallListeners(symbol, ticks);
226-
resolve(ticks);
227-
} else {
228-
const candles = parseCandles(r.candles);
229-
230-
this.updateCandlesAndCallListeners([symbol, Number(granularity)], candles);
231-
232-
resolve(candles);
233-
}
234-
})
235-
.catch(reject);
236-
});
216+
if (!this.ticks_history_promise) {
217+
this.ticks_history_promise = new Promise((resolve, reject) => {
218+
doUntilDone(() =>
219+
this.api.getTickHistory(symbol, {
220+
subscribe : 1,
221+
end : 'latest',
222+
count : 1000,
223+
granularity: granularity ? Number(granularity) : undefined,
224+
style,
225+
})
226+
)
227+
.then(r => {
228+
if (style === 'ticks') {
229+
const ticks = historyToTicks(r.history);
230+
231+
this.updateTicksAndCallListeners(symbol, ticks);
232+
resolve(ticks);
233+
} else {
234+
const candles = parseCandles(r.candles);
235+
236+
this.updateCandlesAndCallListeners([symbol, Number(granularity)], candles);
237+
238+
resolve(candles);
239+
}
240+
})
241+
.catch(reject);
242+
});
243+
}
244+
return this.ticks_history_promise;
237245
}
238246
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy