Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase orderbook mid price cache duration to 60 seconds #2633

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading