Beispiel #1
0
 void IHandyTableListener.OnUpdate(int itemPos, string itemName, IUpdateInfo update)
 {
     if (update != null)
     {
         if (update.NumFields != 0)
         {
             if ((update.ToString().Replace(" ", "") == "[(null)]") ||
                 (update.ToString().Replace(" ", "") == "[null]"))
             {
                 if (_lastUpdate.HasValue)
                 {
                     if ((DateTime.Now - _lastUpdate.Value).TotalSeconds < 10)
                     {
                         if (_nullUpdateCount++ % 5 == 0)
                         {
                             Log.Instance.WriteEntry("Ignored null update", System.Diagnostics.EventLogEntryType.Warning);
                         }
                         return;
                     }
                     _lastUpdate      = DateTime.Now;
                     _nullUpdateCount = 0;
                 }
                 else
                 {
                     _lastUpdate = DateTime.Now;
                     return;
                 }
                 Log.Instance.WriteEntry("Null update, synchronizing positions...", System.Diagnostics.EventLogEntryType.Warning);
                 Synchronize();
                 return;
             }
             Log.Instance.WriteEntry("Incoming position update: " + update.ToString());
             bool updateProcessed = false;
             foreach (var item in _positions)
             {
                 if (item.Value.OnUpdate(update))
                 {
                     updateProcessed = true;
                     break;
                 }
             }
             foreach (var tradingSet in _tradingSets)
             {
                 foreach (var pos in tradingSet.Value.Positions)
                 {
                     if (pos.OnUpdate(update))
                     {
                         updateProcessed = true;
                         break;
                     }
                 }
             }
             if (!updateProcessed)
             {
                 Log.Instance.WriteEntry("Unexpected update, synchronizing positions... update: " + update.ToString(), System.Diagnostics.EventLogEntryType.Warning);
                 Synchronize();
             }
         }
     }
 }
 public void OnUpdate(int itemPos, string itemName, IUpdateInfo update)
 {
     //listener.OnItemUpdate(phase, itemPos, itemName, update);
     Debug.WriteLine(update.ToString());
 }
Beispiel #3
0
 public bool OnUpdate(IUpdateInfo update)
 {
     try
     {
         JavaScriptSerializer json_serializer = new JavaScriptSerializer();
         var json = json_serializer.DeserializeObject(update.ToString());
         if (json.GetType().ToString() == "System.Object[]")
         {
             object[] objs = (object[])json;
             if (objs != null)
             {
                 foreach (var obj in objs)
                 {
                     var trade_notification = (Dictionary <string, object>)obj;
                     if (trade_notification != null)
                     {
                         if (trade_notification["epic"].ToString() == _name)
                         {
                             if (trade_notification["dealStatus"].ToString() == "ACCEPTED")
                             {
                                 if (trade_notification["status"].ToString() == "OPEN")
                                 {
                                     if (!openTrade(trade_notification))
                                     {
                                         Log.Instance.WriteEntry("Could not process an open order: " + _name, System.Diagnostics.EventLogEntryType.Error);
                                     }
                                 }
                                 else if (trade_notification["status"].ToString() == "DELETED")
                                 {
                                     if (!closeTrade(trade_notification))
                                     {
                                         Log.Instance.WriteEntry("Could not process an close order: " + _name, System.Diagnostics.EventLogEntryType.Error);
                                     }
                                 }
                             }
                             else
                             {
                                 // deal rejected
                                 // return rejectTrade(trade_notification);
                                 Log.Instance.WriteEntry("A deal has been rejected: " + _name, System.Diagnostics.EventLogEntryType.Error);
                             }
                             return(true);
                         }
                         else
                         {
                             return(false);
                         }
                     }
                 }
             }
         }
         Log.Instance.WriteEntry("Unable to process a position update", System.Diagnostics.EventLogEntryType.Error);
     }
     catch (Exception e)
     {
         Log.Instance.WriteEntry("Caught an exception during a position update: " + e.ToString(), System.Diagnostics.EventLogEntryType.Error);
     }
     if (Portfolio.Instance.ShutDownFunc != null)
     {
         Log.Instance.WriteEntry("Terminating...", System.Diagnostics.EventLogEntryType.Error);
         Portfolio.Instance.ShutDownFunc();
     }
     return(true);
 }
Beispiel #4
0
 public bool OnUpdate(IUpdateInfo update)
 {
     if (update == null)
         return false;
     if (update.NumFields == 0)
         return false;
     JavaScriptSerializer json_serializer = new JavaScriptSerializer();
     if ((update.ToString().Replace(" ", "") == "[(null)]") || (update.ToString().Replace(" ", "") == "[null]"))
         return false;
     Log.Instance.WriteEntry("Incoming position update: " + update.ToString());
     var json = json_serializer.DeserializeObject(update.ToString());
     if (json.GetType().ToString() == "System.Object[]")
     {
         object[] objs = (object[])json;
         if (objs != null)
         {
             foreach (var obj in objs)
             {
                 var trade_notification = (Dictionary<string, object>)obj;
                 if (trade_notification != null)
                 {
                     if (trade_notification["channel"].ToString() != "PublicRestOTC")
                     {
                         Log.Instance.WriteEntry("Incoming trade from a different channel: " + trade_notification["channel"].ToString(), System.Diagnostics.EventLogEntryType.Information);
                         return false;
                     }
                     if (trade_notification["epic"].ToString() == _name)
                     {
                         if (trade_notification["dealStatus"].ToString() == "ACCEPTED")
                         {
                             if (trade_notification["status"].ToString() == "OPEN")
                             {
                                 if (!openTrade(trade_notification))
                                 {
                                     Log.Instance.WriteEntry("Could not process an open order: " + update.ToString(), System.Diagnostics.EventLogEntryType.Error);
                                     return false;
                                 }
                                 return true;
                             }
                             else if (trade_notification["status"].ToString() == "DELETED")
                             {
                                 if (!closeTrade(trade_notification))
                                 {
                                     Log.Instance.WriteEntry("Could not process an close order: " + update.ToString(), System.Diagnostics.EventLogEntryType.Error);
                                     return false;
                                 }
                                 return true;
                             }
                         }
                         else
                         {
                             // deal rejected
                             return rejectTrade(trade_notification);
                         }
                     }
                 }
             }
         }
     }
     return false;
 }