Nour/improved rotation (#290)
* improved rotation * fix bugs * only parse slot if necessary * add metrics for ws source * add select by recent slot to utils * fix solana web3.js version --------- Co-authored-by: wphan <william@drift.trade>
This commit is contained in:
@@ -472,3 +472,18 @@ export type SubscriberLookup = {
|
||||
openbook?: OpenbookV2Subscriber;
|
||||
};
|
||||
};
|
||||
|
||||
export const selectMostRecentBySlot = (responses: any[]): any => {
|
||||
const parsedResponses = responses
|
||||
.map((response) => {
|
||||
try {
|
||||
return JSON.parse(response);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.filter((parsed) => parsed && typeof parsed.slot === 'number');
|
||||
return parsedResponses.reduce((mostRecent, current) => {
|
||||
return !mostRecent || current.slot > mostRecent.slot ? current : mostRecent;
|
||||
}, null);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user