public API_CMA() { this._batchOperation = new TableBatchOperation(); this._track = new ConcurrentDictionary <int, string>(); this._orders = new ConcurrentDictionary <string, NewOrderData>(); this._lasttime = new ConcurrentDictionary <string, DateTime>(); this._keealiveoms = true; this._omsclient = new RoboTrading(); this._omsclient.OnStatusChanged += _omsclient_OnStatusChanged; this._omsclient.OnNewOrderReply += _omsclient_OnNewOrderReply; this._omsclient.OnCancelOrderReply += _omsclient_OnCancelOrderReply; this._omsclient.OnOrderListReply += _omsclient_OnOrderListReply; this._omsclient.OnOrderListUpdate += _omsclient_OnOrderListUpdate; this._lasttime.TryAdd("NPC", BvspTime); this._keealivenpc = true; this._npcClient = new DdeClient("profitchart", "cot"); this._npcClient.Advise += OnTickArrived; this._npcClient.Disconnected += (s, e) => { IsDDEAvailable(_npcClient); }; this._npcSymbols = new ConcurrentDictionary <string, DateTime>(); this._lasttime.TryAdd("CMA", BvspTime); this._keealivecma = true; this._cmaClient = new DdeClient("TWSVR", "CMA"); this._cmaClient.Advise += OnTickArrived; this._cmaClient.Disconnected += (s, e) => { IsDDEAvailable(_cmaClient); }; this._cmaSymbols = new ConcurrentDictionary <string, DateTime>(); }
/// <summary> /// Keep alive connection to CMA OMS /// </summary> private void KeepAliveOMS() { while (true) { Thread.Sleep(60000); if (Process.GetProcessesByName("cmas4").Length < 1) { NotifyOMS("OFF CMA indisponível."); continue; } var ireply = this.RoboStart(); while (ireply == 90130) { _omsclient = null; Thread.Sleep(10000); ireply = this.RoboStart(); } if (ireply > 1 && ireply != 90140) { this.Stop(); this.RoboStart(); this.OrderList(); } } }
private void Dispose() { if (_ddeclient != null) { _ddeclient.Dispose(); } NotifyDDE("OFF Conexão ao DDE server parada"); this.Stop(); _omsclient = null; _ddeclient = null; }
public void Dispose() { NotifyDDE("OFF Conexão ao DDE server parada"); _keealiveoms = false; _keealivecma = false; _keealivenpc = false; if (_cmaClient != null) { _cmaClient.Dispose(); } if (_npcClient != null) { _npcClient.Dispose(); } _omsclient = null; _cmaClient = null; _npcClient = null; }
private void CreateInstance() { _omsclient = new RoboTrading(); #region OnStatusChanged _omsclient.OnStatusChanged += (iStat, sDesc) => { if (iStat == 100) { this.Start(); } if (iStat == 110) { this.Stop(); } }; #endregion #region OnNewOrderReply _omsclient.OnNewOrderReply += (id, key, sDesc, iStat) => { var info = ""; if (iStat == 1) { return; } _track.TryRemove(id, out info); if (sDesc.Contains("Erro de acesso a base de dados")) { // var detail = info.Split(' '); // var order = new NewOrderData(); // _orders.TryGetValue(detail[0], out order); // order.Symbol = detail[1]; // order.ClientID = detail[4]; // order.Quantity = double.Parse(detail[5]); // var iReqID = 0; // var status = "OK"; // if (_rt != null) _rt.NewOrder(order, out iReqID, out status); // if (status != "OK") OnStatusChanged("Nova tentativa para: " + info); // else OnStatusChanged("OFF " + status + " " + info); // _track.TryAdd(iReqID, info); // return; } NotifyOMS(info + sDesc.Trim()); }; #endregion #region OnCancelOrderReply _omsclient.OnCancelOrderReply += (key, sDesc, iStat) => { if (iStat > 1) { NotifyOMS("Falha ao cancelar ordem #" + key.Trim() + " " + sDesc); return; } //var info = new OrderInfo(); //var output = "Ordem " + key.Trim() + " cancelada com sucesso"; ////if (iStat == 1) ShadowOrders.TryRemove(key.Trim(), out info); //if (iStat != 1) output = output // .Replace("cancelada com sucesso", " nao foi cancelada. Motivo: " + sDesc); }; #endregion #region OnOrderListReply _omsclient.OnOrderListReply += (iCount, s, i) => { #region Save all pending order in a list //int iNumOrders; //var data = new string[3]; //var iReply = _rt.GetOrderIDsFromList(new IDFilter(), // out data[0], out iNumOrders, out data[1], out data[2]); //foreach (var id in data[0].Trim().Split('\t')) //{ // var info = new OrderInfo(); // iReply = _rt.GetOrderInfo(id.Trim(), "F", info, out data[2]); // if (info.Identificator.Length > 0) // { // if (info.OrderStatus == "E") // ReferencePrice.TryAdd(info.Identificator, info.Price); // Debug.WriteLine(info.Identificator); // } //} #endregion #region OnOrderListUpdate _omsclient.OnOrderListUpdate += (key, sDesc, iStat) => { var info = new OrderInfo(); iStat = _omsclient.GetOrderInfo(key.Trim(), "F", info, out sDesc); sDesc = iStat + ": " + sDesc + " > " + info.OrderID + " " + info.OrderStatus + " " + info.Quantity; Debug.WriteLine(sDesc); if (!info.Identificator.Contains(":")) { return; } if (info.OrderStatus == "X") { } //if (info.OrderStatus == "E") // _porders.TryAdd(info.OrderID, info); }; #endregion }; #endregion }