Skip to content

Latest commit

 

History

History
15 lines (9 loc) · 998 Bytes

README.md

File metadata and controls

15 lines (9 loc) · 998 Bytes

Matching package

A trade matching engine matches up order bids and offers to generate trades. Matching engines allocate trades among competing bids and offers at the same price.

Calculating the cost of closing a trader out

This call will calculate the "cost" to the trader should the be closed out (based on current position). The actual position should be passed, along with a Side. If the trader holds a long position, the call should be:

closeOutPNL := matchingEngine.GetClosePNL(position.Size(), types.Side_Sell)

Internally, the matching engine will iterate over the order book (buy/sell side depending on the second argument). The "cheapest" orders will be used first. This means that, for the buy side, the price levels are traversed backwards (the levels are tracked in descending order). The sell side is stored in ascending order, and is traversed as-is.

This call has no effect on the order status (i.e. it won't change the Remaining field of the orders).