After Server Disconnect, PendingOrders.Count not correct.
After Server Disconnect, PendingOrders.Count not correct.
07 Nov 2014, 16:49
I use a simple Positions Count in a Cbot that counts Orders and Pending orders like this:
if (Positions.Count(position => position.Label == RobotID) == 2 && PendingOrders.Count(position => position.Label == RobotID) == 0)
If the above is correct it will place a Pending order since this cbot will always have x number of orders and 1 pending order.
Last night after a Disconnect it counted the positions.count correctly, but it did not count that there was already 1 pending order with that RobotID and placed a second pending order. Then both got filled later on. After that everything was fine again.
Is there any reason why it would not be able to count that 1 pending order?
Does a Pending order somehow lose its Label when there is a disconnect? That would be hard to believe, but what else can explain it?
It would would be pretty easy to add some code to check/ delete any duplicate Pending orders, but it would be nicer to know that cbot doesnt do unexplainable things after a disconnect.
Replies
emeeder
07 Nov 2014, 17:49
Ok, Thanks for the clasification.
So something like this would solve the problem?
if (Positions.Count(position => position.Label == RobotID) == 2 && PendingOrders.Count(position => position.Label == RobotID) == 0)
{
if (PendingOrders.Count(position => position.Label == RobotID) == 0)
{
emeeder
07 Nov 2014, 17:52
Sorry, that last post sent by accident
Ok, Thanks for the clarification.
So something like this would solve the problem?
if (Positions.Count(position => position.Label == RobotID) == 2 && PendingOrders.Count(position => position.Label == RobotID) == 0)
{
//put a timer in here
if (PendingOrders.Count(position => position.Label == RobotID) == 0)
{
I assume only placing a timer here would not delay the whole cbot.
Is there a way to add a timer that is only called on after login/relogin to server?
are there other collections that may have a delay as well?
Spotware
10 Nov 2014, 09:38
Is there a way to add a timer that is only called on after login/relogin to server?
No, there is no such way.
are there other collections that may have a delay as well?
Positions and History collections do not have this issue.
Does OnStart() get called after login/relogin to server?
No, OnStart is called only once on cBot start.
So something like this would solve the problem?
if (Positions.Count(position => position.Label == RobotID) == 2 && PendingOrders.Count(position => position.Label == RobotID) == 0)
{//put a timer in here
if (PendingOrders.Count(position => position.Label == RobotID) == 0)
{
Unfortunately no. Positions and PendingOrders collections are updated independently. As a workaround you can place a pending order far away from spot prices. Then if PendingOrders.Count > 0 that will mean that PendingOrders collection is in valid state and you can check it for your other orders.
@Spotware
emeeder
10 Nov 2014, 15:42
Thanks for the replies.
I will just add a pending orders counter that will check to make sure there are no duplicates which may have been created during internet/server outages.
Spotware
07 Nov 2014, 17:11
PendingOrders collection could be empty during several milliseconds after reconnect. If you use a Timer you can catch this moment. This issue will be resolved with next application update. We apologize for any inconvenience.
@Spotware