NFA Accounts: Pending to Filled

Posted By: AndrewAMD

NFA Accounts: Pending to Filled - 10/21/17 03:23

jcl, I have a broker plugin question regarding NFA accounts.

Zorro distinguishes between “orders” and “trades”. On NFA accounts, there technically are no trades, only orders and positions.

In the plugin, I get a BrokerBuy call. If the order is placed (instantly in pending mode), I return a trade ID from a counter. And normally, the order will eventually get filled, but not exactly at the most recently quoted price. As in: it might be a series of partial fills at different prices whose average will be close to but not equal to the most recently quoted price.

Is there a way to designate the order as: “pending, please confirm actual transaction later”? If not, I’d be interested in a new function such as “BrokerFill”, to verify fill status.
Posted By: jcl

Re: NFA Accounts: Pending to Filled - 10/21/17 12:00

It normally would be the BrokerTrade function. You can use it for returning the fill price. But for some reason it currently works for non-NFA accounts only. I've noted to make it work also for NFA accounts in the next version.
Posted By: AndrewAMD

Re: NFA Accounts: Pending to Filled - 10/21/17 12:30

Good!

For context, I will note the different fill cases that are enumerated.

In FIXML:
Code:
enum FixmlOrdStatus_enum_t
{
	os_New = '0',
	os_PartiallyFilled = '1',
	os_Filled = '2',
	os_DoneForDay = '3',
	os_Canceled = '4',
	os_PendingCancel = '6',
	os_Stopped = '7',
	os_Rejected = '8',
	os_Suspended = '9',
	os_PendingNew = 'A',
	os_Calculated = 'B',
	os_Expired = 'C',
	os_AcceptedForBidding = 'D',
	os_PendingReplace = 'E',
};


In Sierra Chart's DTC protocol:
Code:
enum OrderStatusEnum : int32_t
	{ ORDER_STATUS_UNSPECIFIED = 0
	, ORDER_STATUS_ORDER_SENT = 1
	, ORDER_STATUS_PENDING_OPEN = 2
	, ORDER_STATUS_PENDING_CHILD = 3
	, ORDER_STATUS_OPEN = 4
	, ORDER_STATUS_PENDING_CANCEL_REPLACE = 5
	, ORDER_STATUS_PENDING_CANCEL = 6
	, ORDER_STATUS_FILLED = 7
	, ORDER_STATUS_CANCELED = 8
	, ORDER_STATUS_REJECTED = 9
	, ORDER_STATUS_PARTIALLY_FILLED = 10
	};


I do not think **all** of these should be accounted for, just enough of them.

Thanks!
Andrew
Posted By: AndrewAMD

Re: NFA Accounts: Pending to Filled - 10/22/17 13:01

Originally Posted By: jcl
It normally would be the BrokerTrade function. You can use it for returning the fill price. But for some reason it currently works for non-NFA accounts only. I've noted to make it work also for NFA accounts in the next version.
jcl, this solution would appear to confirm fill status for orders to open a position.

Does it also confirm fill status for orders to close a position? This would also be useful.
Posted By: jcl

Re: NFA Accounts: Pending to Filled - 10/23/17 11:05

For closing an order on an NFA account, the fill price is passed in the BrokerBuy function. If the position is not yet closed, return zero. Zorro will then repeat the close order until the fill price is known.
Posted By: AndrewAMD

Re: NFA Accounts: Pending to Filled - 10/23/17 11:48

How would my plugin know the difference between multiple identical close orders vs a series of close order follow-ups?

Suppose instead that I return a negative ID number at BrokerBuy so that Zorro can follow up with the negative number at BrokerTrade. Can this be implemented?
Posted By: Zheka

Re: NFA Accounts: Pending to Filled - 10/23/17 14:29

Hi, Andrew,
Originally Posted By: AndrewAMD
In the plugin, I get a BrokerBuy call. If the order is placed (instantly in pending mode), I return a trade ID from a counter. And normally, the order will eventually get filled, but not exactly at the most recently quoted price. As in: it might be a series of partial fills at different prices whose average will be close to but not equal to the most recently quoted price.

It would be useful to get the actual OrderId at the broker, rather then an artificial internal trade counter.
Same for actual order fill prices (rather then the quoted ask/bid at the time of placing an order).
Posted By: AndrewAMD

Re: NFA Accounts: Pending to Filled - 10/23/17 14:54

Zheka, of course! I would always do this if my broker had a compatible value.

Sadly, this is not always the case. Ally Invest gives me an order ID - it’s a string with two letters, a dash, and then a series of numbers.
Posted By: jcl

Re: NFA Accounts: Pending to Filled - 10/23/17 15:08

>>How would my plugin know the difference between multiple identical close orders<<

The difference is not needed, since on NFA accounts it does not matter which order is closed. Only the close amount matters. When positions are not closed immediately, you need anyway a bookkeeping of the positions in your plugin. When a position closes, then return 1 and pass the fill price on the next close order of the same amount. If the close order has a different amount, just ignore it. Unlike open orders, close orders are repeated until the right amount is closed.
Posted By: Zheka

Re: NFA Accounts: Pending to Filled - 10/23/17 16:58

Quote:
Sadly, this is not always the case. Ally Invest gives me an order ID - it’s a string with two letters, a dash, and then a series of numbers.
In case of SierraChart, it is quite safe to assume that OrderIDs reported via DTC would conform to the same convention.
Most SC broker integrations are based on FIX.
Posted By: AndrewAMD

Re: NFA Accounts: Pending to Filled - 10/23/17 17:00

Originally Posted By: Zheka
In case of SierraChart, it is quite safe to assume that OrderIDs reported via DTC would conform to the same convention.
Most SC broker integrations are based on FIX.
Agreed
Posted By: AndrewAMD

Re: NFA Accounts: Pending to Filled - 11/08/17 14:52

Originally Posted By: jcl
For closing an order on an NFA account, the fill price is passed in the BrokerBuy function. If the position is not yet closed, return zero. Zorro will then repeat the close order until the fill price is known.

Originally Posted By: jcl
The difference is not needed, since on NFA accounts it does not matter which order is closed. Only the close amount matters. When positions are not closed immediately, you need anyway a bookkeeping of the positions in your plugin. When a position closes, then return 1 and pass the fill price on the next close order of the same amount. If the close order has a different amount, just ignore it. Unlike open orders, close orders are repeated until the right amount is closed.
jcl, this is very useful information. Perhaps this should be added to the manual?
Posted By: jcl

Re: NFA Accounts: Pending to Filled - 11/09/17 08:50

Yes, I will add it.
© 2024 lite-C Forums