Skip to content

Commit

Permalink
Increase orderbook mid price cache duration to 60 seconds (backport #…
Browse files Browse the repository at this point in the history
…2633) (#2642)

Co-authored-by: Adam Fraser <[email protected]>
  • Loading branch information
mergify[bot] and adamfraser authored Dec 11, 2024
1 parent 2f5a70c commit 8909e2f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ describe('orderbook-mid-prices-cache', () => {
expect(result).toEqual({ 'BTC-USD': '50500' });
});

it('returns the correct median price after 30 seconds', async () => {
it('returns the correct median price after 60 seconds', async () => {
jest.useFakeTimers();
// Mock the getOrderBookMidPrice function for the ticker
const mockPrices: string[] = ['50000', '51000', '49000', '48000', '52000', '53000'];
Expand All @@ -154,7 +154,7 @@ describe('orderbook-mid-prices-cache', () => {
expect(OrderbookLevelsCache.getOrderBookMidPrice).toHaveBeenCalledTimes(2);

// Advance time and fetch more prices
jest.advanceTimersByTime(31000); // Advance time by 31 seconds
jest.advanceTimersByTime(61000); // Advance time by 61 seconds
await fetchAndCacheOrderbookMidPrices(
client,
[defaultTicker, defaultTicker, defaultTicker, defaultTicker],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ local numArgs = #ARGV
-- Get the timestamp from the last argument
local timestamp = tonumber(ARGV[numArgs])

-- Time window (30 seconds)
local thirtySeconds = 30
-- Time window (60 seconds)
local sixtySeconds = 60

-- Validate the timestamp
if not timestamp then
return redis.error_reply("Invalid timestamp")
end

-- Calculate the cutoff time for removing old prices
local cutoffTime = timestamp - thirtySeconds
local cutoffTime = timestamp - sixtySeconds

-- Iterate through each key (market) and corresponding price
for i = 1, numKeys do
Expand All @@ -31,7 +31,7 @@ for i = 1, numKeys do
-- Add the price to the sorted set with the current timestamp as the score
redis.call("ZADD", priceCacheKey, timestamp, price)

-- Remove entries older than the cutoff time (older than 30 seconds)
-- Remove entries older than the cutoff time (older than 60 seconds)
redis.call("ZREMRANGEBYSCORE", priceCacheKey, "-inf", cutoffTime)
end

Expand Down

0 comments on commit 8909e2f

Please sign in to comment.