Skip to content

Commit

Permalink
Merge pull request #86 from drift-labs/master
Browse files Browse the repository at this point in the history
market staleness for slot + perp
  • Loading branch information
NourAlharithi authored Feb 6, 2024
2 parents 54e815e + bfd5689 commit 659ad7a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"license": "Apache-2.0",
"dependencies": {
"@coral-xyz/anchor": "^0.29.0",
"@drift-labs/sdk": "2.60.0-beta.4",
"@drift-labs/sdk": "2.60.0-beta.13",
"@opentelemetry/api": "^1.1.0",
"@opentelemetry/auto-instrumentations-node": "^0.31.1",
"@opentelemetry/exporter-prometheus": "^0.31.0",
Expand Down
17 changes: 10 additions & 7 deletions src/dlob-subscriber/DLOBSubscriberIO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ type wsMarketL2Args = {
updateOnChange?: boolean;
};

const MAKRET_STALENESS_THRESHOLD = 10 * 60 * 1000;
const PERP_MAKRET_STALENESS_THRESHOLD = 10 * 60 * 1000;
const SPOT_MAKRET_STALENESS_THRESHOLD = 20 * 60 * 1000;

export type wsMarketInfo = {
marketIndex: number;
Expand Down Expand Up @@ -180,6 +181,10 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
}

// Check if times and slots are too different for market
const MAKRET_STALENESS_THRESHOLD =
marketType === 'perp'
? PERP_MAKRET_STALENESS_THRESHOLD
: SPOT_MAKRET_STALENESS_THRESHOLD;
if (
lastMarketSlotAndTime &&
l2Formatted['marketSlot'] === lastMarketSlotAndTime.slot &&
Expand All @@ -197,12 +202,10 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
console.log(
`Updating market slot for ${l2Args.marketName} with slot ${l2Formatted['marketSlot']}`
);
this.lastMarketSlotMap
.get(l2Args.marketType)
.set(l2Args.marketIndex, {
slot: l2Formatted['marketSlot'],
ts: Date.now(),
});
this.lastMarketSlotMap.get(l2Args.marketType).set(l2Args.marketIndex, {
slot: l2Formatted['marketSlot'],
ts: Date.now(),
});
}

const l2Formatted_depth100 = Object.assign({}, l2Formatted, {
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@
enabled "2.0.x"
kuler "^2.0.0"

"@drift-labs/[email protected].4":
version "2.60.0-beta.4"
resolved "https://registry.yarnpkg.com/@drift-labs/sdk/-/sdk-2.60.0-beta.4.tgz#c77a17195a803fc977e8c7b63d9ec498ae2464ef"
integrity sha512-ulFf20M4KGqxOSqsBX9IImWI0ulejPUTKZiuZGnbq1OmffEM+oB17Mn92PA2dHcXFVNEX4J79H9AT5Z3alf86A==
"@drift-labs/[email protected].13":
version "2.60.0-beta.13"
resolved "https://registry.yarnpkg.com/@drift-labs/sdk/-/sdk-2.60.0-beta.13.tgz#8abb3b0f6bc0341b071f3b769067c9d7e286444f"
integrity sha512-UJuZ72nSN8IUl7t1X/hQmnRtz2x86yTrNEY6lQtYXjCsovgOWGune4TlvF+BNBZ/L83uY4wwWETSWqwEJ5C0iA==
dependencies:
"@coral-xyz/anchor" "0.28.1-beta.2"
"@ellipsis-labs/phoenix-sdk" "^1.4.2"
Expand Down

0 comments on commit 659ad7a

Please sign in to comment.