tardis-dev
Advanced tools
Comparing version 10.0.9 to 10.0.10
@@ -1,3 +0,4 @@ | ||
import { BookSnapshot } from '../types'; | ||
import { BookChange, BookPriceLevel, BookSnapshot } from '../types'; | ||
import { Computable } from './computable'; | ||
declare type OnLevelRemovedCB = (bookChange: BookChange, bestBidBeforeRemoval: BookPriceLevel | undefined, bestBidAfterRemoval: BookPriceLevel | undefined, bestAskBeforeRemoval: BookPriceLevel | undefined, bestAskAfterRemoval: BookPriceLevel | undefined) => void; | ||
declare type BookSnapshotComputableOptions = { | ||
@@ -8,2 +9,3 @@ name?: string; | ||
removeCrossedLevels?: boolean; | ||
onCrossedLevelRemoved?: OnLevelRemovedCB; | ||
}; | ||
@@ -10,0 +12,0 @@ export declare const computeBookSnapshots: (options: BookSnapshotComputableOptions) => () => Computable<BookSnapshot>; |
@@ -19,3 +19,3 @@ "use strict"; | ||
class BookSnapshotComputable { | ||
constructor({ depth, name, interval, removeCrossedLevels }) { | ||
constructor({ depth, name, interval, removeCrossedLevels, onCrossedLevelRemoved }) { | ||
this.sourceDataTypes = ['book_change']; | ||
@@ -31,2 +31,3 @@ this._bookChanged = false; | ||
this._removeCrossedLevels = removeCrossedLevels; | ||
this._onCrossedLevelRemoved = onCrossedLevelRemoved; | ||
// initialize all bids/asks levels to empty ones | ||
@@ -97,4 +98,9 @@ for (let i = 0; i < this._depth; i++) { | ||
} | ||
bestBid = this._orderBook.bestBid(); | ||
bestAsk = this._orderBook.bestAsk(); | ||
const newBestBid = this._orderBook.bestBid(); | ||
const newBestAsk = this._orderBook.bestAsk(); | ||
if (this._onCrossedLevelRemoved !== undefined) { | ||
this._onCrossedLevelRemoved(bookChange, bestBid, newBestBid, bestAsk, newBestAsk); | ||
} | ||
bestBid = newBestBid; | ||
bestAsk = newBestAsk; | ||
bookIsCrossed = bestBid !== undefined && bestAsk !== undefined && bestBid.price >= bestAsk.price; | ||
@@ -101,0 +107,0 @@ } |
{ | ||
"name": "tardis-dev", | ||
"version": "10.0.9", | ||
"version": "10.0.10", | ||
"engines": { | ||
@@ -5,0 +5,0 @@ "node": ">=12" |
@@ -5,4 +5,18 @@ import { OrderBook } from '../orderbook' | ||
type BookSnapshotComputableOptions = { name?: string; depth: number; interval: number; removeCrossedLevels?: boolean } | ||
type OnLevelRemovedCB = ( | ||
bookChange: BookChange, | ||
bestBidBeforeRemoval: BookPriceLevel | undefined, | ||
bestBidAfterRemoval: BookPriceLevel | undefined, | ||
bestAskBeforeRemoval: BookPriceLevel | undefined, | ||
bestAskAfterRemoval: BookPriceLevel | undefined | ||
) => void | ||
type BookSnapshotComputableOptions = { | ||
name?: string | ||
depth: number | ||
interval: number | ||
removeCrossedLevels?: boolean | ||
onCrossedLevelRemoved?: OnLevelRemovedCB | ||
} | ||
export const computeBookSnapshots = (options: BookSnapshotComputableOptions): (() => Computable<BookSnapshot>) => () => | ||
@@ -37,3 +51,4 @@ new BookSnapshotComputable(options) | ||
private readonly _name: string | ||
private readonly _removeCrossedLevels?: boolean | ||
private readonly _removeCrossedLevels: boolean | undefined | ||
private readonly _onCrossedLevelRemoved: OnLevelRemovedCB | undefined | ||
@@ -44,6 +59,7 @@ private _lastUpdateTimestamp: Date = new Date(-1) | ||
constructor({ depth, name, interval, removeCrossedLevels }: BookSnapshotComputableOptions) { | ||
constructor({ depth, name, interval, removeCrossedLevels, onCrossedLevelRemoved }: BookSnapshotComputableOptions) { | ||
this._depth = depth | ||
this._interval = interval | ||
this._removeCrossedLevels = removeCrossedLevels | ||
this._onCrossedLevelRemoved = onCrossedLevelRemoved | ||
@@ -129,5 +145,10 @@ // initialize all bids/asks levels to empty ones | ||
} | ||
const newBestBid = this._orderBook.bestBid() | ||
const newBestAsk = this._orderBook.bestAsk() | ||
if (this._onCrossedLevelRemoved !== undefined) { | ||
this._onCrossedLevelRemoved(bookChange, bestBid, newBestBid, bestAsk, newBestAsk) | ||
} | ||
bestBid = this._orderBook.bestBid() | ||
bestAsk = this._orderBook.bestAsk() | ||
bestBid = newBestBid | ||
bestAsk = newBestAsk | ||
bookIsCrossed = bestBid !== undefined && bestAsk !== undefined && bestBid.price >= bestAsk.price | ||
@@ -134,0 +155,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
660717
11662