Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Represents information about an order, placed with the exchange
- // We receive order updates from the trading rig with data in this form.
- //
- export interface IExchangeOrder
- {
- symbol : string;
- side : OrderSide;
- quantity : number;
- price : number;
- status : OrderStatus;
- time : number;
- }
- //
- // Represents a single "quote" in an order book
- // Qotes with side.Bid are placed in the order book's
- // bid array, side.Ask in the ask array.
- // Together the price and quantity represent
- // the size of the order, in financial terms.
- export interface IOrderBookEntry
- {
- symbol:InstrumentSymbol;
- side:MarketSide;
- price:number;
- quantity:number;
- }
- //
- // Market data providers generally expose real-time
- // feeds, following the pattern where the client
- // first request an initial snapshot of the current state
- // of the order book, and then subscribes to a websocket, or other
- // "push" feed, which updates the client with IExchangeOrder
- // objets, which are meant to replace any existing IExchangeOrder
- // already in the client's order book. By this mechanism, the order
- // book is updated.
- //
- export interface IOrderBookFeed
- {
- loadInitialData(url:string);
- openUpdateFeed(url:string);
- processUpdate();
- }
- //
- // An order book manages two collections of IOderBookEntrys.
- // One for the bid, and one for the ask (offer). Entries
- // in each book are always price sorted. Bids are stored in descending order.
- // Asks are stored in ascending order. This causes the order book to reflect
- // The real market structure where the highest bid approaches the price of the lowest ask.
- // All other market participants are "away" from the market, with either a lower bid, or
- // a higher ask. The distance between the lowest ask and the highest bid is called the "spread".
- export interface IOrderBook
- {
- exchange:ExchangeName;
- symbol:InstrumentSymbol;
- bids:Array<IOrderBookEntry>;
- asks:Array<IOrderBookEntry>;
- feed:IOrderBookFeed;
- insideBid:IOrderBookEntry;
- insideAsk:IOrderBookEntry;
- spread:number;
- mid:number;
- clear();
- sort();
- getEntries(side:MarketSide) : Array<IOrderBookEntry>;
- getEntry(side:MarketSide, depth:number);
- addEntry(side:MarketSide, price:number, quantity:number);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement