prettify
This commit is contained in:
@@ -18,49 +18,49 @@ type wsMarketL2Args = {
|
|||||||
marketName: string;
|
marketName: string;
|
||||||
depth: number;
|
depth: number;
|
||||||
includeVamm: boolean;
|
includeVamm: boolean;
|
||||||
numVammOrders?: number;
|
numVammOrders?: number;
|
||||||
grouping?: number;
|
grouping?: number;
|
||||||
fallbackL2Generators?: L2OrderBookGenerator[];
|
fallbackL2Generators?: L2OrderBookGenerator[];
|
||||||
updateOnChange?: boolean;
|
updateOnChange?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export class DLOBSubscriberIO extends DLOBSubscriber {
|
export class DLOBSubscriberIO extends DLOBSubscriber {
|
||||||
public marketL2Args: wsMarketL2Args[] = [];
|
public marketL2Args: wsMarketL2Args[] = [];
|
||||||
public lastSeenL2Formatted: Map<MarketType, Map<number, any>>;
|
public lastSeenL2Formatted: Map<MarketType, Map<number, any>>;
|
||||||
io: Server;
|
io: Server;
|
||||||
|
|
||||||
constructor(config: DLOBSubscriptionConfig) {
|
constructor(config: DLOBSubscriptionConfig) {
|
||||||
super(config);
|
super(config);
|
||||||
|
|
||||||
// Set up appropriate maps
|
// Set up appropriate maps
|
||||||
this.lastSeenL2Formatted = new Map();
|
this.lastSeenL2Formatted = new Map();
|
||||||
this.lastSeenL2Formatted.set(MarketType.SPOT, new Map());
|
this.lastSeenL2Formatted.set(MarketType.SPOT, new Map());
|
||||||
this.lastSeenL2Formatted.set(MarketType.PERP, new Map());
|
this.lastSeenL2Formatted.set(MarketType.PERP, new Map());
|
||||||
|
|
||||||
// Add all active markets to the market L2Args
|
// Add all active markets to the market L2Args
|
||||||
for (const market of MainnetPerpMarkets) {
|
for (const market of MainnetPerpMarkets) {
|
||||||
this.marketL2Args.push({
|
this.marketL2Args.push({
|
||||||
marketIndex: market.marketIndex,
|
marketIndex: market.marketIndex,
|
||||||
marketType: MarketType.PERP,
|
marketType: MarketType.PERP,
|
||||||
marketName: market.symbol,
|
marketName: market.symbol,
|
||||||
depth: 2,
|
depth: 2,
|
||||||
includeVamm: true,
|
includeVamm: true,
|
||||||
numVammOrders: 100,
|
numVammOrders: 100,
|
||||||
updateOnChange: true,
|
updateOnChange: true,
|
||||||
fallbackL2Generators: []
|
fallbackL2Generators: [],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
for (const market of MainnetSpotMarkets) {
|
for (const market of MainnetSpotMarkets) {
|
||||||
this.marketL2Args.push({
|
this.marketL2Args.push({
|
||||||
marketIndex: market.marketIndex,
|
marketIndex: market.marketIndex,
|
||||||
marketType: MarketType.SPOT,
|
marketType: MarketType.SPOT,
|
||||||
marketName: market.symbol,
|
marketName: market.symbol,
|
||||||
depth: 2,
|
depth: 2,
|
||||||
includeVamm: false,
|
includeVamm: false,
|
||||||
updateOnChange: true,
|
updateOnChange: true,
|
||||||
fallbackL2Generators: []
|
fallbackL2Generators: [],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override async updateDLOB(): Promise<void> {
|
override async updateDLOB(): Promise<void> {
|
||||||
@@ -73,7 +73,7 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
|
|||||||
|
|
||||||
getL2AndSendMsg(l2Args: wsMarketL2Args): void {
|
getL2AndSendMsg(l2Args: wsMarketL2Args): void {
|
||||||
const grouping = l2Args.grouping;
|
const grouping = l2Args.grouping;
|
||||||
const l2 = this.getL2(l2Args);
|
const l2 = this.getL2(l2Args);
|
||||||
let l2Formatted: any;
|
let l2Formatted: any;
|
||||||
if (grouping) {
|
if (grouping) {
|
||||||
const groupingBN = new BN(grouping);
|
const groupingBN = new BN(grouping);
|
||||||
@@ -82,10 +82,17 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
|
|||||||
l2Formatted = l2WithBNToStrings(l2);
|
l2Formatted = l2WithBNToStrings(l2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (l2Args.updateOnChange && this.lastSeenL2Formatted.get(l2Args.marketType)?.get(l2Args.marketIndex) === JSON.stringify(l2Formatted)) {
|
if (
|
||||||
return;
|
l2Args.updateOnChange &&
|
||||||
}
|
this.lastSeenL2Formatted
|
||||||
this.lastSeenL2Formatted.get(l2Args.marketType)?.set(l2Args.marketIndex, JSON.stringify(l2Formatted));
|
.get(l2Args.marketType)
|
||||||
|
?.get(l2Args.marketIndex) === JSON.stringify(l2Formatted)
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.lastSeenL2Formatted
|
||||||
|
.get(l2Args.marketType)
|
||||||
|
?.set(l2Args.marketIndex, JSON.stringify(l2Formatted));
|
||||||
l2Formatted['marketName'] = l2Args.marketName;
|
l2Formatted['marketName'] = l2Args.marketName;
|
||||||
l2Formatted['marketType'] = l2Args.marketType;
|
l2Formatted['marketType'] = l2Args.marketType;
|
||||||
l2Formatted['marketIndex'] = l2Args.marketIndex;
|
l2Formatted['marketIndex'] = l2Args.marketIndex;
|
||||||
|
|||||||
Reference in New Issue
Block a user