Advertisement
GlobalLiquidity

Untitled

Mar 21st, 2019
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. // Represents information about an order, placed with the exchange
  3. // We receive order updates from the trading rig with data in this form.
  4. //
  5. export interface IExchangeOrder
  6. {
  7.     symbol : string;
  8.     side : OrderSide;
  9.     quantity : number;
  10.     price : number;
  11.     status : OrderStatus;
  12.     time : number;
  13. }
  14.  
  15. //
  16. // Represents a single "quote" in an order book
  17. // Qotes with side.Bid are placed in the order book's
  18. // bid array, side.Ask in the ask array.
  19. // Together the price and quantity represent
  20. // the size of the order, in financial terms.
  21. export interface IOrderBookEntry
  22. {
  23.     symbol:InstrumentSymbol;
  24.     side:MarketSide;
  25.     price:number;
  26.     quantity:number;
  27. }
  28.  
  29. //
  30. // Market data providers generally expose real-time
  31. // feeds, following the pattern where the client
  32. // first request an initial snapshot of the current state
  33. // of the order book, and then subscribes to a websocket, or other
  34. // "push" feed, which updates the client with IExchangeOrder
  35. // objets, which are meant to replace any existing IExchangeOrder
  36. // already in the client's order book. By this mechanism, the order
  37. // book is updated.
  38. //
  39. export interface IOrderBookFeed
  40. {
  41.     loadInitialData(url:string);
  42.     openUpdateFeed(url:string);
  43.     processUpdate();
  44. }
  45.  
  46. //
  47. // An order book manages two collections of IOderBookEntrys.
  48. // One for the bid, and one for the ask (offer). Entries
  49. // in each book are always price sorted. Bids are stored in descending order.
  50. // Asks are stored in ascending order. This causes the order book to reflect
  51. // The real market structure where the highest bid approaches the price of the lowest ask.
  52. // All other market participants are "away" from the market, with either a lower bid, or
  53. // a higher ask. The distance between the lowest ask and the highest bid is called the "spread".
  54. export interface IOrderBook
  55. {
  56.     exchange:ExchangeName;
  57.     symbol:InstrumentSymbol;
  58.  
  59.     bids:Array<IOrderBookEntry>;
  60.     asks:Array<IOrderBookEntry>;
  61.  
  62.     feed:IOrderBookFeed;
  63.  
  64.     insideBid:IOrderBookEntry;
  65.     insideAsk:IOrderBookEntry;
  66.     spread:number;
  67.     mid:number;
  68.  
  69.     clear();
  70.     sort();
  71.  
  72.     getEntries(side:MarketSide) : Array<IOrderBookEntry>;
  73.     getEntry(side:MarketSide, depth:number);
  74.  
  75.     addEntry(side:MarketSide, price:number, quantity:number);
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement