Class PaperTradingGateway
java.lang.Object
com.quantfinlib.trading.PaperTradingGateway
- All Implemented Interfaces:
OrderGateway
Quote-driven paper trading venue: closes the research-to-production loop by
running real strategy + risk-gate code against simulated fills.
- Feed top-of-book quotes with
onQuote(java.lang.String, double, double); market orders fill at the touch, resting limit orders fill when the market crosses them. - Every order passes the optional
PreTradeLimitCheckerfirst — rejected orders never reach the market, exactly like production. - Full account tracking: signed positions with average cost, cash, realized/unrealized P&L, commission, and mark-to-market equity.
snapshot() returns an internally consistent view of the account —
safe to read from a dashboard thread while another thread trades.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordOne internally consistent view of the whole account (single lock acquisition).Nested classes/interfaces inherited from interface com.quantfinlib.trading.OrderGateway
OrderGateway.ExecutionListener -
Constructor Summary
ConstructorsConstructorDescriptionPaperTradingGateway(double initialCash) PaperTradingGateway(double initialCash, double commissionRate, PreTradeLimitChecker limitChecker) -
Method Summary
Modifier and TypeMethodDescriptionvoidbooleancancel(long orderId) Cancels a working order.doublecash()doubleequity()Mark-to-market equity at current mids.voidUpdates the top of book and fills any resting limit orders that now cross.doubleSnapshot of non-zero positions by symbol (for dashboards/monitoring).doubleThe first 1000 rejection messages; the snapshot'srejectionCountkeeps counting past the cap.snapshot()status(long orderId) longsubmitLimit(String symbol, Side side, long quantity, double price) Submits a limit order; returns the order id (status may be REJECTED).longsubmitMarket(String symbol, Side side, long quantity) Submits a market order for immediate execution at the touch.
-
Constructor Details
-
PaperTradingGateway
public PaperTradingGateway(double initialCash) -
PaperTradingGateway
public PaperTradingGateway(double initialCash, double commissionRate, PreTradeLimitChecker limitChecker)
-
-
Method Details
-
onQuote
Updates the top of book and fills any resting limit orders that now cross. -
submitLimit
Description copied from interface:OrderGatewaySubmits a limit order; returns the order id (status may be REJECTED).- Specified by:
submitLimitin interfaceOrderGateway
-
submitMarket
Description copied from interface:OrderGatewaySubmits a market order for immediate execution at the touch.- Specified by:
submitMarketin interfaceOrderGateway
-
cancel
public boolean cancel(long orderId) Description copied from interface:OrderGatewayCancels a working order. Returns false if unknown or already terminal.- Specified by:
cancelin interfaceOrderGateway
-
status
- Specified by:
statusin interfaceOrderGateway
-
addExecutionListener
- Specified by:
addExecutionListenerin interfaceOrderGateway
-
position
-
cash
public double cash() -
realizedPnl
public double realizedPnl() -
equity
public double equity()Mark-to-market equity at current mids. -
rejectionLog
-
positionsSnapshot
-
snapshot
-