-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IND-442] Don't send cancel messages if orders are fully filled in st…
…ate. (#754)
- Loading branch information
1 parent
b03f25c
commit bfd7cfe
Showing
11 changed files
with
275 additions
and
26 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
indexer/packages/redis/__tests__/caches/state-filled-quantums-cache.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { deleteAllAsync, ttl } from '../../src/helpers/redis'; | ||
import { redis as client } from '../helpers/utils'; | ||
import { orderId } from './constants'; | ||
import { OrderTable } from '@dydxprotocol-indexer/postgres'; | ||
import { | ||
STATE_FILLED_QUANTUMS_TTL_SECONDS, | ||
getCacheKey, | ||
getStateFilledQuantums, | ||
updateStateFilledQuantums, | ||
} from '../../src/caches/state-filled-quantums-cache'; | ||
|
||
describe('stateFilledQuantumsCache', () => { | ||
const orderUuid: string = OrderTable.orderIdToUuid(orderId); | ||
|
||
beforeEach(async () => { | ||
await deleteAllAsync(client); | ||
}); | ||
|
||
afterEach(async () => { | ||
await deleteAllAsync(client); | ||
}); | ||
|
||
describe('updateStateFilledQuantums', () => { | ||
it('updates the state filled amount for an order id', async () => { | ||
const filledQuantums: string = '1000'; | ||
await updateStateFilledQuantums(orderUuid, filledQuantums, client); | ||
|
||
expect(await getStateFilledQuantums(orderUuid, client)).toEqual(filledQuantums); | ||
expect(await ttl(client, getCacheKey(orderUuid))).toEqual(STATE_FILLED_QUANTUMS_TTL_SECONDS); | ||
}); | ||
}); | ||
|
||
describe('getStateFilledQuantums', () => { | ||
it('gets the state filled amount for an order id', async () => { | ||
const filledQuantums: string = '1000'; | ||
await updateStateFilledQuantums(orderUuid, filledQuantums, client); | ||
|
||
expect(await getStateFilledQuantums(orderUuid, client)).toEqual(filledQuantums); | ||
}); | ||
|
||
it('returns undefined if order id does not exist', async () => { | ||
expect(await getStateFilledQuantums(orderUuid, client)).toEqual(undefined); | ||
}); | ||
}); | ||
}); |
52 changes: 52 additions & 0 deletions
52
indexer/packages/redis/src/caches/state-filled-quantums-cache.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { RedisClient } from 'redis'; | ||
|
||
import { getAsync, setexAsync } from '../helpers/redis'; | ||
|
||
export const STATE_FILLED_QUANTUMS_CACHE_KEY_PREFIX: string = 'v4/state_filled_quantums/'; | ||
export const STATE_FILLED_QUANTUMS_TTL_SECONDS: number = 300; // 5 minutes | ||
|
||
/** | ||
* Updates the state-filled quantums for an order id. This is the total filled quantums of the order | ||
* in the state of the network. | ||
* @param orderId | ||
* @param filledQuantums | ||
* @param client | ||
*/ | ||
export async function updateStateFilledQuantums( | ||
orderId: string, | ||
filledQuantums: string, | ||
client: RedisClient, | ||
): Promise<void> { | ||
await setexAsync({ | ||
key: getCacheKey(orderId), | ||
value: filledQuantums, | ||
timeToLiveSeconds: STATE_FILLED_QUANTUMS_TTL_SECONDS, | ||
}, client); | ||
} | ||
|
||
/** | ||
* Gets the state-filled quantums for an order id. This is the total filled quantums of the order | ||
* in the state of the network. | ||
* @param orderId | ||
* @param client | ||
* @returns | ||
*/ | ||
export async function getStateFilledQuantums( | ||
orderId: string, | ||
client: RedisClient, | ||
): Promise<string | undefined> { | ||
const filledQuantums: string | null = await getAsync( | ||
getCacheKey(orderId), | ||
client, | ||
); | ||
|
||
if (filledQuantums === null) { | ||
return undefined; | ||
} | ||
|
||
return filledQuantums; | ||
} | ||
|
||
export function getCacheKey(orderId: string): string { | ||
return `${STATE_FILLED_QUANTUMS_CACHE_KEY_PREFIX}${orderId}`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.