[#20] AssetDataAggregator erstellt und integriert
This commit is contained in:
parent
721a3a598a
commit
2c13099a2c
@ -119,11 +119,13 @@ export default class AggregatedDataPoint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {TradeEvent} trade
|
* @param {number} time
|
||||||
|
* @param {number} price
|
||||||
|
* @param {number} quantity
|
||||||
*/
|
*/
|
||||||
pushTrade(trade){
|
pushTrade(time, price, quantity){
|
||||||
this.tradeCount ++;
|
this.tradeCount ++;
|
||||||
this.tradeVolume += trade.quantity;
|
this.tradeVolume += quantity;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import OrderBookUpdateEvent from "../../../apiwrapper/event/OrderBookUpdateEvent
|
|||||||
import Ticker24hEvent from "../../../apiwrapper/event/Ticker24hEvent.js";
|
import Ticker24hEvent from "../../../apiwrapper/event/Ticker24hEvent.js";
|
||||||
import OrderBook from "../../../apiwrapper/orderbook/OrderBook.js";
|
import OrderBook from "../../../apiwrapper/orderbook/OrderBook.js";
|
||||||
import OrderBookEntry from "../../../apiwrapper/orderbook/OrderBookEntry.js";
|
import OrderBookEntry from "../../../apiwrapper/orderbook/OrderBookEntry.js";
|
||||||
|
import AssetDataAggregator from "./AssetDataAggregator.js";
|
||||||
import AssetDataCollectionConfig from "./AssetDataCollectionConfig.js";
|
import AssetDataCollectionConfig from "./AssetDataCollectionConfig.js";
|
||||||
import PeakDetector from "./PeakDetector.js";
|
import PeakDetector from "./PeakDetector.js";
|
||||||
import TimedAssetData from "./TimedAssetData.js";
|
import TimedAssetData from "./TimedAssetData.js";
|
||||||
@ -69,6 +70,11 @@ export default class AssetData extends TimedAssetData {
|
|||||||
*/
|
*/
|
||||||
#peakDetector = new PeakDetector();
|
#peakDetector = new PeakDetector();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {AssetDataAggregator}
|
||||||
|
*/
|
||||||
|
assetDataAggregator = new AssetDataAggregator();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {TradingPair} tradingPair
|
* @param {TradingPair} tradingPair
|
||||||
* @param {AssetDataCollectionConfig} collectionConfig
|
* @param {AssetDataCollectionConfig} collectionConfig
|
||||||
@ -98,6 +104,7 @@ export default class AssetData extends TimedAssetData {
|
|||||||
*/
|
*/
|
||||||
updateKline(klineEvent) {
|
updateKline(klineEvent) {
|
||||||
this.push(klineEvent.high, klineEvent.low, klineEvent.open, klineEvent.close);
|
this.push(klineEvent.high, klineEvent.low, klineEvent.open, klineEvent.close);
|
||||||
|
this.assetDataAggregator.pushKLine(klineEvent.timestamp, klineEvent.low, klineEvent.high, klineEvent.open, klineEvent.close);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -108,6 +115,8 @@ export default class AssetData extends TimedAssetData {
|
|||||||
this.pushBestBid(this.#orderBook.getBestBid());
|
this.pushBestBid(this.#orderBook.getBestBid());
|
||||||
this.pushBestAsk(this.#orderBook.getBestAsk());
|
this.pushBestAsk(this.#orderBook.getBestAsk());
|
||||||
this.#peakDetector.push(this.#orderBook.getBestAsk());
|
this.#peakDetector.push(this.#orderBook.getBestAsk());
|
||||||
|
this.assetDataAggregator.pushBestAsk(this.#orderBook.getBestAsk());
|
||||||
|
this.assetDataAggregator.pushBestBid(this.#orderBook.getBestBid());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -187,4 +196,15 @@ export default class AssetData extends TimedAssetData {
|
|||||||
slots[i].removeSubData();
|
slots[i].removeSubData();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {number} time
|
||||||
|
* @param {number} price
|
||||||
|
* @param {number} quantity
|
||||||
|
*/
|
||||||
|
pushTrade(time, price, quantity) {
|
||||||
|
super.pushTrade(time, price, quantity);
|
||||||
|
this.assetDataAggregator.pushTrade(time, price, quantity);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
import TradeEvent from "../../../apiwrapper/event/TradeEvent.js";
|
import OrderBookEntry from "../../../apiwrapper/orderbook/OrderBookEntry.js";
|
||||||
import UnitHelper from "../../util/UnitHelper.js";
|
import UnitHelper from "../../util/UnitHelper.js";
|
||||||
import AggregatedDataPoint from "./AggregatedDataPoint.js";
|
import AggregatedDataPoint from "./AggregatedDataPoint.js";
|
||||||
|
|
||||||
@ -123,8 +123,17 @@ export default class AssetDataAggregator {
|
|||||||
const durationInMs = UnitHelper.formatedDurationToMs(duration);
|
const durationInMs = UnitHelper.formatedDurationToMs(duration);
|
||||||
|
|
||||||
// if seconds data required
|
// if seconds data required
|
||||||
if(duration <= 60000 && start == -1){
|
if(durationInMs <= 60000 && start == -1){
|
||||||
|
const dpCount = Math.round(durationInMs / AssetDataAggregator.#SLOT_1_SEC);
|
||||||
|
if(dpCount <= this.#perSecondDataPoints.length){
|
||||||
|
result = this.#perSecondDataPoints.slice(-1 * dpCount);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const dpCount = Math.round(durationInMs / AssetDataAggregator.#SLOT_1_MIN);
|
||||||
|
const pointOffset = start == -1 ? 0 : Math.round(start / AssetDataAggregator.#SLOT_1_MIN);
|
||||||
|
if(pointOffset + dpCount <= this.#perMinuteDataPoints.length){
|
||||||
|
result = this.#perMinuteDataPoints.slice(-1 * (pointOffset + dpCount), -1 * pointOffset);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@ -137,7 +146,34 @@ export default class AssetDataAggregator {
|
|||||||
*/
|
*/
|
||||||
pushTrade(time, price, quantity) {
|
pushTrade(time, price, quantity) {
|
||||||
this.#updateCurrentDataPoint();
|
this.#updateCurrentDataPoint();
|
||||||
this.#currentDataPoint.pushTrade(/* TODO */);
|
this.#currentDataPoint.pushTrade(time, price, quantity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {number} time
|
||||||
|
* @param {number} low
|
||||||
|
* @param {number} high
|
||||||
|
* @param {number} open
|
||||||
|
* @param {number} close
|
||||||
|
*/
|
||||||
|
pushKLine(time, low, high, open, close){
|
||||||
|
// ingore actual data and just update the point, as data is taken only from orderbook
|
||||||
|
this.#updateCurrentDataPoint();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {OrderBookEntry} ask
|
||||||
|
*/
|
||||||
|
pushBestAsk(ask){
|
||||||
|
this.#updateCurrentDataPoint();
|
||||||
|
this.#currentDataPoint.pushAsk(ask);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {OrderBookEntry} bid
|
||||||
|
*/
|
||||||
|
pushBestBid(bid){
|
||||||
|
this.#updateCurrentDataPoint();
|
||||||
|
this.#currentDataPoint.pushBid(bid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user