#region Variables // User defined variables (add any user defined variables below) private ConnectionStatus dataFeed = ConnectionStatus.Connected; // The next two sections send an email when the connection is lost protected override void OnOrderUpdate(IOrder order) { if (dataFeed != ConnectionStatus.Connected) { SendMail("[email protected]", "[email protected]", "Connection Lost", "Order Connection Lost"); SendMail("[email protected]", "[email protected]", "Connection to Order Server Lost.......Again!", "NT has lost connection to the order server causing a strategy failure. Please logon and shut down NT and restart the PFG connection and your autotrade strategy immediately or suffer crushing losses to your brokerage account."); PlaySound(@"C:\Program Files\NinjaTrader 7\sounds\Alert4.wav"); } } protected override void OnConnectionStatus(ConnectionStatus orderStatus, ConnectionStatus priceStatus) { dataFeed = orderStatus; }
Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
Connection Lost Notification Code (not working)
Collapse
X
-
Connection Lost Notification Code (not working)
To combat the limitation preventing automatic reconnection to the order server during maintenance I have added the following code to my autotrade strategy in order to alert me to this, connection lost, peril:
Code:Tags: None
-
Hello,
Thanks for your note.
Was an order attempted to be send during the downtime? As this email is sent out to occur onOrderUpdate. You must have an orderUpdate occur for the email to be sent out while the connection status is not equal to Connected.
Also, did you just test this during the normal maintence or did you test by disconnecting an internet cable?
-
No, I mean that when PFG takes their servers down for maintenance. I do not have a internet connectivity issue during this time.
Are you saying that I should change the code to the following to bypass the order update issue?
Code:#region Variables // User defined variables (add any user defined variables below) private ConnectionStatus dataFeed = ConnectionStatus.Connected; // The next two sections send an email when the connection is lost protected override void OnConnectionStatus(ConnectionStatus orderStatus, ConnectionStatus priceStatus) { if (dataFeed != ConnectionStatus.Connected) { SendMail("[email protected]", "[email protected]", "Connection Lost", "Order Connection Lost"); SendMail("[email protected]", "[email protected]", "Connection to Order Server Lost.......Again!", "NT has lost connection to the order server causing a strategy failure. Please logon and shut down NT and restart the PFG connection and your autotrade strategy immediately or suffer crushing losses to your brokerage account."); PlaySound(@"C:\Program Files\NinjaTrader 7\sounds\Alert4.wav"); } dataFeed = orderStatus; }
Last edited by RDPoS; 12-21-2010, 07:44 PM.
Comment
-
Yea, didn't work again.
Connection lost and zero notification.
Changed to:
Code:#region Variables // User defined variables (add any user defined variables below) private ConnectionStatus dataFeed = ConnectionStatus.Connected; // The next two sections send an email when the connection is lost protected override void OnConnectionStatus(ConnectionStatus orderStatus, ConnectionStatus priceStatus) { if (dataFeed == ConnectionStatus.ConnectionLost) { SendMail("[email protected]", "[email protected]", "Connection Lost", "Order Connection Lost"); SendMail("[email protected]", "[email protected]", "Connection to Order Server Lost.......Again!", "NT has lost connection to the order server causing a strategy failure. Please logon and shut down NT and restart the PFG connection and your autotrade strategy immediately or suffer crushing losses to your brokerage account."); PlaySound(@"C:\Program Files\NinjaTrader 7\sounds\Alert4.wav"); } dataFeed = orderStatus; }
Last edited by RDPoS; 12-22-2010, 12:24 AM.
Comment
-
Hello,
Should work and I tested on my end and it works. Heres the next thing to try please add a Print Statement here, please add two one in OnConnectionStatus and the other after your check for if dataFeed == ConnectionStatus.ConnectionLost and then check to make sure that both prints show up in the log.
Want to make sure this code is actually running on your PC and you dont have something going on with email making it out.
I look forward to assisting you further.
Comment
-
How can I print() ConnectionStatus directly?
I wanted to have both the variable datafeed and ConnectionStatus printed as:
Print("dataFeed = " + dataFeed);
Print("ConnectionStatus = " + ConnectionStatus);
But that creates an error...
I did get a notification that NT was reconnected, but nothing for connection lost and reconnectingLast edited by RDPoS; 12-22-2010, 02:02 PM.
Comment
-
The code is now set up as follows:
Code:protected override void OnConnectionStatus(ConnectionStatus orderStatus, ConnectionStatus priceStatus) { Print("dataFeed Pre = " + dataFeed); Print("orderStatus Pre = " + orderStatus); Print("priceStatus Pre = " + priceStatus); if (dataFeed == ConnectionStatus.ConnectionLost) { SendMail("[email protected]", "[email protected]", "Connection Lost", "Order Connection Lost"); PlaySound(@"C:\Program Files\NinjaTrader 7\sounds\Alert4.wav"); } if (dataFeed == ConnectionStatus.Connecting) { SendMail("[email protected]", "[email protected]", "Connecting", "Connecting to Order Server"); PlaySound(@"C:\Program Files\NinjaTrader 7\sounds\Alert4.wav"); } if (dataFeed == ConnectionStatus.Connected) { SendMail("[email protected]", "[email protected]", "Connected", "Order Server Connected"); PlaySound(@"C:\Program Files\NinjaTrader 7\sounds\Alert4.wav"); } dataFeed = orderStatus; Print("dataFeed Post = " + dataFeed); Print("orderStatus Post = " + orderStatus); Print("priceStatus Post = " + priceStatus); }
Last edited by RDPoS; 12-22-2010, 02:16 PM.
Comment
-
Ok same problem as before, I receive no connection lost notification, I did receive a connected notification, but when I logged in to check, the platform was still in a lost connection state.
Excerpt from the API log
2010-12-23 02:49:10 - Closing Historic File
2010-12-23 20:38:54 - !DESKALL
#MESSAGE:
From the BEST Trading Desk
Maintenance will begin at 7:45 pm CST.
,|
`
!END |
2010-12-23 21:23:56 - 8=FIX.4.0.C|35=5|52=12/23/2010 8:26:58 PM|100=PFG|
2010-12-23 21:23:56 - Received Trade Server LogOut message
2010-12-23 21:23:56 - Restarting Trade Server Connection.
2010-12-23 21:23:58 - Closing Log File
2010-12-23 21:23:58 - Log File Opened
2010-12-23 21:23:58 - 8=FIX.4.0.C|35=A|9998=46550|9989=A|9996=46550|9997 =XXXXXXX|9995=PFGAPI-1.0.445|999991=40462|10=999|
2010-12-23 21:23:58 - Trade Socket Connected... Sending Login Message.
2010-12-23 21:23:59 - Connected at: 20101223 21:23:58
2010-12-23 21:23:59 - Trade Server Socket Error Code: 10053 Network connection aborted by local host
2010-12-23 21:23:59 - Disconnected at:20101223 21:23:59
2010-12-23 21:23:59 - Restarting Trade Server Connection.
2010-12-23 21:23:59 - Disconnected at:20101223 21:23:59
2010-12-23 21:23:59 - On Error: Restarting Trade Server Connection after error.
2010-12-23 21:23:59 - Trade Server On_Disconnect Fired
2010-12-23 21:23:59 - Socket Closed.
2010-12-23 21:23:59 - On-Disconnect: Restarting Trade Server Connection
2010-12-23 21:24:00 - Closing Log File
2010-12-23 21:24:00 - Log File Opened
2010-12-23 21:24:00 - 8=FIX.4.0.C|35=A|9998=46550|9989=A|9996=46550|9997 =XXXXXXX|9995=PFGAPI-1.0.445|999991=40462|10=999|
2010-12-23 21:24:00 - Trade Socket Connected... Sending Login Message.
2010-12-23 21:24:00 - Connected at: 20101223 21:24:00
2010-12-23 21:24:00 - 8=FIX.4.0.C|35=A|52=12/23/2010 8:27:02 PM|100=PFG|
Note that there was no disconnection of the API during the time the output file lost connection.
The script code is now setup as follows:
Code:private ConnectionStatus dataFeed = ConnectionStatus.[COLOR="Red"]Disconnected[/COLOR]; protected override void OnConnectionStatus(ConnectionStatus orderStatus, ConnectionStatus priceStatus) { Print(CurrentBar + " " + Time[0] + "PreLoop - dataFeed = " + dataFeed + ", orderStatus = " + orderStatus + ", priceStatus = " + priceStatus); if (dataFeed == ConnectionStatus.ConnectionLost) { SendMail("[email protected]", "[email protected]", "Connection Lost", "Order Connection Lost"); // SendMail("[email protected]", "[email protected]", "Connection to Order Server Lost!", "Please verify that the server's internet connection is still valid"); PlaySound(@"C:\Program Files\NinjaTrader 7\sounds\Alert4.wav"); Print(Time[0] + "ConnectionLost Loop - dataFeed = " + dataFeed + ", orderStatus = " + orderStatus + ", priceStatus = " + priceStatus); } if (dataFeed == ConnectionStatus.Connecting) { SendMail("[email protected]", "[email protected]", "Connecting", "Trying to reestablish Connection"); // SendMail("[email protected]", "[email protected]", "Connecting", "Trying to reestablish Order Server connection"); PlaySound(@"C:\Program Files\NinjaTrader 7\sounds\Alert4.wav"); Print(Time[0] + "ConnectingLoop - dataFeed = " + dataFeed + ", orderStatus = " + orderStatus + ", priceStatus = " + priceStatus); } if (dataFeed == ConnectionStatus.Connected) { SendMail("[email protected]", "[email protected]", "Connected", "Check that strategy is active"); // SendMail("[email protected]", "[email protected]", "Connected", "Connected"); PlaySound(@"C:\Program Files\NinjaTrader 7\sounds\Alert4.wav"); Print(Time[0] + "ConnectedLoop - dataFeed = " + dataFeed + ", orderStatus = " + orderStatus + ", priceStatus = " + priceStatus); } dataFeed = orderStatus; Print(Time[0] + "PostLoop - dataFeed = " + dataFeed + "orderStatus = " + orderStatus + ", priceStatus = " + priceStatus); }
340 12/23/2010 1:25:20 PMPreLoop - dataFeed = Connected, orderStatus = Connecting, priceStatus = Connected
12/23/2010 1:25:20 PMConnectedLoop - dataFeed = Connected, orderStatus = Connecting, priceStatus = Connected
12/23/2010 1:25:20 PMPostLoop - dataFeed = ConnectingorderStatus = Connecting, priceStatus = Connected
340 12/23/2010 1:25:20 PMPreLoop - dataFeed = Connecting, orderStatus = Connected, priceStatus = Connected
12/23/2010 1:25:20 PMConnectingLoop - dataFeed = Connecting, orderStatus = Connected, priceStatus = Connected
12/23/2010 1:25:20 PMPostLoop - dataFeed = ConnectedorderStatus = Connected, priceStatus = Connected
12/23/2010 1:33:57 PM Entered internal PlaceOrder() method at 12/23/2010 1:33:57 PM: BarsInProgress=0 Action=Buy OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1.3136 SignalName='' FromEntrySignal=''
12/23/2010 1:33:57 PM Ignored PlaceOrder() method: Action=Buy OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1.3136 SignalName=Buy' FromEntrySignal='' Reason='There already is a matching order with same prices and quantity'
12/23/2010 1:37:16 PM Entered internal PlaceOrder() method at 12/23/2010 1:37:16 PM: BarsInProgress=0 Action=Buy OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1.3136 SignalName='' FromEntrySignal=''
12/23/2010 1:37:16 PM Ignored PlaceOrder() method: Action=Buy OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1.3136 SignalName=Buy' FromEntrySignal='' Reason='There already is a matching order with same prices and quantity'
12/23/2010 2:20:44 PM Entered internal PlaceOrder() method at 12/23/2010 2:20:44 PM: BarsInProgress=0 Action=Buy OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1.3136 SignalName='' FromEntrySignal=''
12/23/2010 2:20:44 PM Ignored PlaceOrder() method: Action=Buy OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1.3136 SignalName=Buy' FromEntrySignal='' Reason='There already is a matching order with same prices and quantity'
12/23/2010 3:23:51 PM Entered internal PlaceOrder() method at 12/23/2010 3:23:51 PM: BarsInProgress=0 Action=Buy OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1.3136 SignalName='' FromEntrySignal=''
12/23/2010 3:23:51 PM Ignored PlaceOrder() method: Action=Buy OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1.3136 SignalName=Buy' FromEntrySignal='' Reason='There already is a matching order with same prices and quantity'
12/23/2010 4:43:07 PM Entered internal PlaceOrder() method at 12/23/2010 4:43:07 PM: BarsInProgress=0 Action=Buy OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1.3136 SignalName='' FromEntrySignal=''
12/23/2010 4:43:07 PM Ignored PlaceOrder() method: Action=Buy OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1.3136 SignalName=Buy' FromEntrySignal='' Reason='There already is a matching order with same prices and quantity'
**NT** Strategy 'FX6Long4/a38ee12661944a43aef4da0fa71e7bb3' lost order connection but will keep running.
344 12/23/2010 4:45:42 PMPreLoop - dataFeed = Connected, orderStatus = ConnectionLost, priceStatus = Connected
12/23/2010 4:45:42 PMConnectedLoop - dataFeed = Connected, orderStatus = ConnectionLost, priceStatus = Connected
12/23/2010 4:45:42 PMPostLoop - dataFeed = ConnectionLostorderStatus = ConnectionLost, priceStatus = Connected
Last edited by RDPoS; 12-24-2010, 01:02 AM.
Comment
-
Ok but when I first start up and activate the strategy I get the email about being disconnected. I then receive an email about connecting, but I still don't receive the email about being connected with that code. This is with a solid green connection already.
Reloading the historical data with a green connected indication on the control center does the same thing. An email showing disconnected, and another for connecting, but no email for connected.
The Level II stuff is a separate related to NT/PFG integration during nightly server maintenance which renders NT useless. I am looking forward to Jason Hilling's response to that at a later date.Last edited by RDPoS; 12-27-2010, 06:14 PM.
Comment
-
No they seem to be wrong.
At 10:09PM EST I received an email notification that says "Connected"
The output window shows the following:
The control center still shows connection lost. So no, the emails still do not correspond to the actual status it would seem.
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by helpwanted, Today, 03:06 AM
|
1 response
7 views
0 likes
|
Last Post Today, 03:35 AM | ||
Started by Brevo, Today, 01:45 AM
|
0 responses
7 views
0 likes
|
Last Post
by Brevo
Today, 01:45 AM
|
||
Started by aussugardefender, Today, 01:07 AM
|
0 responses
5 views
0 likes
|
Last Post Today, 01:07 AM | ||
Started by pvincent, 06-23-2022, 12:53 PM
|
14 responses
242 views
0 likes
|
Last Post
by Nyman
Today, 12:47 AM
|
||
Started by TraderG23, 12-08-2023, 07:56 AM
|
9 responses
384 views
1 like
|
Last Post
by Gavini
Today, 12:29 AM
|
Comment