First-class support of Orders, keep separate from Trades

Posted By: AndrewAMD

First-class support of Orders, keep separate from Trades - 07/12/22 20:44

A trading system should have first-class support for placing orders via broker API. With Zorro, orders are second-class to trades in Zorro. This is a major flaw. Most brokers supported by Zorro are nicknamed "NFA brokers", but this really means they take orders and not trades.

I have a three-part proposal. First is the broker plugin API itself:

1) Revamp the Broker API for emphasis on order control. At minimum, a dedicated function for new orders, another to cancel/replace orders, and another for execution reports. Keep it completely separate from "Trade" management.

2) On Live instance launch, Zorro will check the status of all open orders on the API and add them to the list of open orders.

3) Zorro will track order status from birth to death. That is, Zorro will never assume that an order is dead unless it confirms it is in fact dead via execution report. Even if Zorro issues an order cancellation, Zorro should not assume it is cancelled until the order is confirmed dead.

4) The broker plugin can push execution reports to Zorro.

Here's an example execution report from the FIX protocol:
https://www.onixs.biz/fix-dictionary/4.4/msgType_8_8.html

Second, orders should be clearly distinct from ordinary zorro Trades, which have fundamentally different meanings. If necessary, make an ORDER struct. Or at minimum, give TRADE structs an Order flag.

Third would be a new hedge mode (7?) that allows order placement to yield Zorro trades for accounting purposes only. You can call it "reverse pool trades". Example:
Script directly places order: BUY 10 MSFT. Zorro internally opens a long trade for 10. The execution reports will update the fill information.
Script directly places order: SELL 20 MSFT. Zorro internally closes the long trade and opens a new short trade for 10. The execution reports will update the fill information for both the long and short trades on a FIFO basis.
Posted By: jcl

Re: First-class support of Orders, keep separate from Trades - 07/13/22 08:27

Zorro supports orders, but you're right, the emphasis is on trades. There are indeed some functions missing for full order control.

The BrokerBuy, BrokerSell, and BrokerTrade functions can in fact control orders. Zorro switches between orders and trades by the TR_GTC flag. The TRADE struct is for both, the order size is stored in TradeLotsTarget.

We'll implement a clearer distinction and will go through your suggestions and add functions for better controlling orders.






Posted By: MegaTanker

Re: First-class support of Orders, keep separate from Trades - 07/14/22 21:04

Just throwing my support for this in the mix, which should be obvious based on my recent activity grin

I don't know how "deep" of an overhaul is planned, but the existence of crypto exchanges with their 0% maker fees (or even credit) make light market making realistic even for retailers. Being able to directly control orders is essential for that, as well as instant and consistent feedback to Zorro from the plugin about fills, so that the script can determine easily how many lots are open at any given time to compare that to how many *should* be open, to then manage the orders accordingly.

I've had some success trying a very "hacky" approach in the broker plugin that ended up placing 74 trades/day and still was profitable, at least for the ~9 days it ran, which is why I think this is worth pursuing in the first place.
© 2024 lite-C Forums