Multi-Venue Best-Quote and Book Consolidation
Install and import
npm install fintech-algorithmsimport { consolidateVenues } from "fintech-algorithms/market-data-engineering/order-book-feed-engineering/multi-venue-best-quote-and-book-consolidation";Signature
consolidateVenues(quotes)Merges books from several venues into one consolidated view and identifies the best bid and offer across them. Venue clocks differ, so a naive merge can produce a consolidated book that was never simultaneously true.
Parameters
| Name | Type | Notes |
|---|---|---|
quotes | VenueQuote[] | Per-venue quotes with their own timestamps, which is what makes staleness assessable per venue rather than globally. |
Returns
{ best_bid, best_ask, consolidated, contributors, stale_venues, … }
The consolidated top of book with which venue contributed each side, and any venue excluded as stale.
Errors
- When no venue supplies a usable quote — reported as a status rather than thrown
Complexity: time O(venues × levels),
space O(levels).
Worked example
executed Captured by running this function on the input its own test provides. Real output of real code — but not asserted against a published figure.
Input
[
{
"venue": "X1",
"receive_time_ns": 950000,
"eligible": true,
"status": "open",
"bids": [
{
"price_ticks": 10000,
"quantity": 10
},
{
"price_ticks": 9999,
"quantity": 16
},
{
"price_ticks": 9998,
"quantity": 22
}
],
"asks": [
{
"price_ticks": 10003,
"quantity": 9
},
{
"price_ticks": 10004,
"quantity": 15
},
{
"price_ticks": 10005,
"quantity": 21
}
]
},
{
"venue": "X2",
"receive_time_ns": 980000,
"eligible": true,
"status": "open",
"bids": [
{
"price_ticks": 10001,
"quantity": 6
},
{
"price_ticks": 10000,
"quantity": 12
},
{
"price_ticks": 9999,
"quantity": 18
}
],
"asks": [
{
"price_ticks": 10002,
"quantity": 7
},
{
"price_ticks": 10003,
"quantity": 11
},
{
"price_ticks": 10004,
"quantity": 17
}
]
},
{
"venue": "X3",
"receive_time_ns": 850000,
"eligible": true,
"status": "open",
"bids": [
{
"price_ticks": 10001,
"quantity": 20
},
{
"price_ticks": 10000,
"quantity": 20
}
],
"asks": [
{
"price_ticks": 10003,
"quantity": 20
},
{
"price_ticks": 10004,
"quantity": 20
}
]
}
]Showing 3 of 5 elements.
{
"as_of_receive_time_ns": 1000000,
"max_staleness_ns": 100000
}Call
consolidateVenues(quotes)Returns
object with 13 fields: as_of_receive_time_ns, max_staleness_ns, eligible_venue_count, excluded, best_bid_ticks, best_bid_quantity, best_bid_venues, best_ask_ticks, …
{
"as_of_receive_time_ns": 1000000,
"max_staleness_ns": 100000,
"eligible_venue_count": 3,
"excluded": [
{
"venue": "X3",
"reason": "stale"
},
{
"venue": "X4",
"reason": "not-open"
}
],
"best_bid_ticks": 10001,
"best_bid_quantity": 10,
"best_bid_venues": ["X2", "X5"],
"best_ask_ticks": 10002,
"best_ask_quantity": 12,
"best_ask_venues": ["X2", "X5"],
"consolidated_book": {
"bids": [
{
"price_ticks": 10001,
"quantity": 10,
"venues": ["X2", "X5"]
},
{
"price_ticks": 10000,
"quantity": 31,
"venues": ["X1", "X2", "X5"]
},
{
"price_ticks": 9999,
"quantity": 48,
"venues": ["X1", "X2", "X5"]
}
],
"asks": [
{
"price_ticks": 10002,
"quantity": 12,
"venues": ["X2", "X5"]
},
{
"price_ticks": 10003,
"quantity": 30,
"venues": ["X1", "X2", "X5"]
},
{
"price_ticks": 10004,
"quantity": 47,
"venues": ["X1", "X2", "X5"]
}
]
},
"consolidated_levels": [
{
"side": "bid",
"price_ticks": 10001,
"quantity": 10,
"venues": ["X2", "X5"]
},
{
"side": "bid",
"price_ticks": 10000,
"quantity": 31,
"venues": ["X1", "X2", "X5"]
},
{
"side": "bid",
"price_ticks": 9999,
"quantity": 48,
"venues": ["X1", "X2", "X5"]
}
],
"state": "normal"
}Other exports
This module also exports
normalizeEvents, reconstructL2, aggregatePriceLevels, reconstructL3, recoverSequenceStream, reconcileSnapshotIncrementals, calculate. Every module additionally exports run as an alias of its
primary function, and a meta object carrying its catalog id, domain, family,
shape and article URL.
Diagrams
How it works
This page states the contract — how to call it correctly. The article explains the concept: why it works, and where it breaks.
References
- Topic-specific source roles
- Nasdaq TotalView-ITCH 5.0 — Nasdaq
- Nasdaq GLIMPSE 5.0 — Nasdaq
- MoldUDP64 protocol — Nasdaq
- FIX recommended practices for book management — FIX Trading Community
- Cboe Multicast PITCH specification — Cboe Global Markets
- Coinbase Exchange WebSocket channels — Coinbase
- UTP Quote Data Feed — UTP Plan
- UTP odd-lot data service update — UTP Plan / Nasdaq Trader
- UTP Data Feed Services Specification — UTP Plan