Skip to content

Commit

Permalink
Improve OHLC_FILLED refreshness
Browse files Browse the repository at this point in the history
  • Loading branch information
clementpl committed May 10, 2019
1 parent 59e72af commit 69da082
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
15 changes: 9 additions & 6 deletions src/_core/Influx/Influx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ export class Influx {
database: this.conf.stockDatabase,
}
);
// TODO Check => console.log(ret);
return ret;
} catch (error) {
logger.error(error);
Expand Down Expand Up @@ -142,13 +141,13 @@ export class Influx {
}

// public async createContinuousQuery() {
/*
/*
To refill every serie use:
SELECT first(open) as open, max(high) as high, min(low) as low, last(close) as close, sum(volume) as volume
INTO OHLC_FILLED FROM OHLC
GROUP BY time(1m), * fill(linear)
*/
/* try {
/* try {
const query: string = `
SELECT first(open) as open, max(high) as high, min(low) as low, last(close) as close, sum(volume) as volume
INTO ${MEASUREMENT_OHLC_FILLED}
Expand All @@ -168,20 +167,24 @@ export class Influx {
}
}*/

public async refreshOHLCFILLED(tags: { [name: string]: string }, force: boolean = false): Promise<void> {
public async refreshOHLCFILLED(
tags: { [name: string]: string },
force: boolean = false,
date?: string
): Promise<void> {
try {
// Query creator set time in where clause
const query: (time?: string) => string = (time?: string) => `
SELECT first(open) as open, max(high) as high, min(low) as low, last(close) as close, sum(volume) as volume
INTO ${MEASUREMENT_OHLC_FILLED}
FROM ${MEASUREMENT_OHLC}
WHERE ${tagsToString(tags)}
${time ? `AND time > '${time}'` : ''}
${time ? `AND time >= '${time}'` : ''}
GROUP BY time(1m), * fill(linear)
`;
// If for refresh the whole serie
if (force) {
await this.influx.query(query(), { database: this.conf.stockDatabase });
await this.influx.query(query(date), { database: this.conf.stockDatabase });
} else {
const ret = await this.getSeriesGap(MEASUREMENT_OHLC_FILLED);
if (ret.length > 0) {
Expand Down
6 changes: 5 additions & 1 deletion src/_core/Watcher/MarketWatcher/MarketWatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ export class MarketWatcher extends Watcher {
.catch(error => {
throw error;
});
await this.getInflux().refreshOHLCFILLED(tags);
const start = moment()
.subtract(100, 'm')
.utc()
.format();
await this.getInflux().refreshOHLCFILLED(tags, true, start);
} catch (error) {
logger.error(error);
throw new Error(`Error while running market watcher loop ${this.conf.exchange} (${this.symbol})`);
Expand Down

0 comments on commit 69da082

Please sign in to comment.