Skip to content
Snippets Groups Projects
Verified Commit fd040baf authored by Mateusz Tyszczak's avatar Mateusz Tyszczak :scroll:
Browse files

Add feed price collector

parent 7b27b48d
No related branches found
No related tags found
1 merge request!25Add missing filters and providers
Pipeline #112335 passed
......@@ -66,7 +66,7 @@
},
"dependencies": {
"@hiveio/beekeeper": "1.27.6-rc4",
"@hiveio/wax": "1.27.6-rc6"
"@hiveio/wax": "1.27.6-rc6-stable.241219120852"
},
"repository": {
"type": "git",
......
......@@ -12,8 +12,8 @@ importers:
specifier: 1.27.6-rc4
version: 1.27.6-rc4
'@hiveio/wax':
specifier: 1.27.6-rc6
version: 1.27.6-rc6
specifier: 1.27.6-rc6-stable.241219120852
version: 1.27.6-rc6-stable.241219120852
devDependencies:
'@eslint/compat':
specifier: ^1.2.2
......@@ -165,8 +165,8 @@ packages:
resolution: {integrity: sha1-mj3k3qAgTdIrc6IxzC5VOprhWZs=, tarball: https://gitlab.syncad.com/api/v4/projects/198/packages/npm/@hiveio/beekeeper/-/@hiveio/beekeeper-1.27.6-rc4.tgz}
engines: {node: '>= 18'}
'@hiveio/wax@1.27.6-rc6':
resolution: {integrity: sha1-zIoajnS/Ct89scl0F/b1jtpk6hs=, tarball: https://gitlab.syncad.com/api/v4/projects/419/packages/npm/@hiveio/wax/-/@hiveio/wax-1.27.6-rc6.tgz}
'@hiveio/wax@1.27.6-rc6-stable.241219120852':
resolution: {integrity: sha1-4uoDcargMqnEY0eoYJCcyCcbHeM=, tarball: https://gitlab.syncad.com/api/v4/projects/419/packages/npm/@hiveio/wax/-/@hiveio/wax-1.27.6-rc6-stable.241219120852.tgz}
engines: {node: '>= 18'}
'@humanfs/core@0.19.1':
......@@ -2646,7 +2646,7 @@ snapshots:
'@hiveio/beekeeper@1.27.6-rc4': {}
'@hiveio/wax@1.27.6-rc6':
'@hiveio/wax@1.27.6-rc6-stable.241219120852':
dependencies:
'@hiveio/beekeeper': 1.27.6-rc4
class-transformer: 0.5.1
......
......@@ -45,7 +45,7 @@ export const DEFAULT_BLOCK_INTERVAL_TIMEOUT_MS = 2000;
export class WorkerBee implements IWorkerBee {
public readonly configuration: IStartConfiguration;
public chain?: TWaxExtended<typeof WaxExtendTypes>;
public chain?: TWaxExtended<WaxExtendTypes>;
private wallet?: IBeekeeperUnlockedWallet;
......
import { price } from "@hiveio/wax";
import { CollectorClassifierBase } from "./collector-classifier-base";
export interface IFeedPriceData {
currentMedianHistory: price;
marketMedianHistory: price;
currentMinHistory: price;
currentMaxHistory: price;
priceHistory: Iterable<price>;
}
export class FeedPriceClassifier extends CollectorClassifierBase {
public type!: IFeedPriceData;
}
......@@ -5,3 +5,4 @@ export { AccountClassifier } from "./account-classifier";
export { RcAccountClassifier } from "./rc-account-classifier";
export { ImpactedAccountClassifier } from "./impacted-account-classifier";
export { OperationClassifier } from "./operation-classifier";
export { FeedPriceClassifier } from "./feed-price-classifier";
import { DynamicGlobalPropertiesClassifier } from "../../classifiers";
import { IFeedPriceData } from "../../classifiers/feed-price-classifier";
import { DataEvaluationContext } from "../../factories/data-evaluation-context";
import { CollectorBase, TAvailableClassifiers } from "../collector-base";
const isDivisibleByInRange = (by: number, start: number, end: number) => {
// Normalize start to the next multiple of *by*
const firstMultiple = Math.ceil(start / by) * by;
return firstMultiple <= end;
};
export class FeedPriceCollector extends CollectorBase {
private cachedFeedHistoryData: IFeedPriceData | undefined;
private previouslyCheckedBlockNumber = 0;
public async fetchData(data: DataEvaluationContext) {
const { headBlockNumber } = await data.get(DynamicGlobalPropertiesClassifier);
// Update feed price history every hour (HIVE_FEED_INTERVAL_BLOCKS) or when there is no cached data
if ( this.cachedFeedHistoryData === undefined
|| isDivisibleByInRange(Number.parseInt(this.worker.chain!.config["HIVE_FEED_INTERVAL_BLOCKS"]), headBlockNumber, this.previouslyCheckedBlockNumber)
) {
const feedHistoryData = await this.worker.chain!.api.database_api.get_feed_history({});
this.cachedFeedHistoryData = {
currentMedianHistory: feedHistoryData.current_median_history,
marketMedianHistory: feedHistoryData.market_median_history,
currentMinHistory: feedHistoryData.current_min_history,
currentMaxHistory: feedHistoryData.current_max_history,
priceHistory: feedHistoryData.price_history
};
}
this.previouslyCheckedBlockNumber = headBlockNumber;
return {
FeedPriceClassifier: this.cachedFeedHistoryData
} satisfies Partial<TAvailableClassifiers>;
};
}
import type { WorkerBee } from "../../../bot";
import {
AccountClassifier, BlockClassifier, BlockHeaderClassifier,
DynamicGlobalPropertiesClassifier, ImpactedAccountClassifier, OperationClassifier, RcAccountClassifier
DynamicGlobalPropertiesClassifier, FeedPriceClassifier, ImpactedAccountClassifier, OperationClassifier, RcAccountClassifier
} from "../../classifiers";
import { IEvaluationContextClass } from "../../classifiers/collector-classifier-base";
import { CollectorBase } from "../../collectors/collector-base";
......@@ -11,6 +11,7 @@ import { OperationCollector } from "../../collectors/common/operation-collector"
import { AccountCollector } from "../../collectors/jsonrpc/account-collector";
import { BlockCollector } from "../../collectors/jsonrpc/block-collector";
import { DynamicGlobalPropertiesCollector } from "../../collectors/jsonrpc/dynamic-global-properties-collector";
import { FeedPriceCollector } from "../../collectors/jsonrpc/feed-price-collector";
import { RcAccountCollector } from "../../collectors/jsonrpc/rc-account-collector";
export const JsonRpcFactoryData: (worker: WorkerBee) => Array<[IEvaluationContextClass, CollectorBase]> = (worker: WorkerBee) => ([
......@@ -20,5 +21,6 @@ export const JsonRpcFactoryData: (worker: WorkerBee) => Array<[IEvaluationContex
[AccountClassifier, new AccountCollector(worker)],
[RcAccountClassifier, new RcAccountCollector(worker)],
[ImpactedAccountClassifier, new ImpactedAccountCollector(worker)],
[OperationClassifier, new OperationCollector(worker)]
[OperationClassifier, new OperationCollector(worker)],
[FeedPriceClassifier, new FeedPriceCollector(worker)]
]);
import { createHiveChain, IHiveChainInterface, IWaxOptionsChain, TWaxExtended } from "@hiveio/wax";
import { createHiveChain, IHiveChainInterface, IWaxOptionsChain, price, TWaxExtended } from "@hiveio/wax";
export const WaxExtendTypes = {};
export type WaxExtendTypes = {
database_api: {
get_feed_history: {
params: {},
result: {
current_median_history: price;
market_median_history: price;
current_min_history: price;
current_max_history: price;
price_history: price[];
}
}
}
};
export const getWax = async(explicitHiveChain?: IHiveChainInterface, options?: Partial<IWaxOptionsChain>): Promise<TWaxExtended<typeof WaxExtendTypes>> => {
export const getWax = async(explicitHiveChain?: IHiveChainInterface, options?: Partial<IWaxOptionsChain>): Promise<TWaxExtended<WaxExtendTypes>> => {
if(explicitHiveChain === undefined)
explicitHiveChain = await createHiveChain(options);
return explicitHiveChain.extend(WaxExtendTypes);
return explicitHiveChain.extend<WaxExtendTypes>();
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment