예제 #1
0
 void trade_OnRtnTrade(object sender, TradeArgs e)
 {
     _queueTradeFresh.Enqueue(e.Value.TradeID);	//刷新时用
     if (e.Value.Offset == OffsetType.Open)
         _queuePositionFresh.Enqueue(e.Value.InstrumentID + "_" + e.Value.Direction);	//刷持仓
     else
         _queuePositionFresh.Enqueue(e.Value.InstrumentID + "_" + (e.Value.Direction == DirectionType.Buy ? "Sell" : "Buy"));	//刷持仓
     Ring("成交通知");
 }
예제 #2
0
        void _t_OnRtnTrade(object sender, TradeArgs e)
        {
            var trade = (Trade)sender;
            var field = e.Value;

            var vap = _straOrdersId.FirstOrDefault(n => n.Value.IndexOf(e.Value.OrderID) >= 0);
            if (vap.Key == null)
                return;
            var ids = vap.Value;
            var o1 = _t.DicOrderField.Values.Where(n => ids.IndexOf(n.OrderID) >= 0 && n.InstrumentID == vap.Key.Instrument1);
            vap.Key.VolumeTraded1 = o1.Sum(n => n.Volume - n.VolumeLeft);

            var p1 = o1.Sum(n => n.AvgPrice * (n.Volume - n.VolumeLeft)) / vap.Key.VolumeTraded1;
            var o2 = _t.DicOrderField.Values.Where(n => ids.IndexOf(n.OrderID) >= 0 && n.InstrumentID == vap.Key.Instrument2);
            vap.Key.VolumeTraded2 = o2.Sum(n => n.Volume - n.VolumeLeft);

            if (vap.Key.Instrument1 == field.InstrumentID)
                _queueModifiedStra.Enqueue(new Tuple<Stra, string>(vap.Key, "VolumeTraded1")); //用于刷新
            else if (vap.Key.Instrument2 == field.InstrumentID)
                _queueModifiedStra.Enqueue(new Tuple<Stra, string>(vap.Key, "VolumeTraded2")); //用于刷新

            var p2 = o2.Sum(n => n.AvgPrice * (n.Volume - n.VolumeLeft)) / vap.Key.VolumeTraded2;
            double p = p1 - p2;

            if (!double.IsNaN(p))
            {
                vap.Key.PriceTraded = p;
                if (vap.Key.VolumeTraded1 == vap.Key.Volume1 && vap.Key.Volume2 == vap.Key.VolumeTraded2)
                    vap.Key.Status = ArbStatus.Filled;
                else
                    vap.Key.Status = ArbStatus.Partial;
                _queueModifiedStra.Enqueue(new Tuple<Stra, string>(vap.Key, "Status")); //用于刷新
                _queueModifiedStra.Enqueue(new Tuple<Stra, string>(vap.Key, "PriceTraded")); //用于刷新
            }
        }