Exemplo n.º 1
0
        private void OnRspQryPosition(object sender, RspEventArgs e)
        {
            switch (sender.ToString())
            {
            case "ProgramTradeApi.XTradeSpi":
                if (e.ErrorID == 0)
                {
                    var pos = PositionDetail.CreateDetail((e as TypedRspEventArgs <CLRDFITCPositionInfoRtnField, CLRDFITCErrorRtnField>).Data);
                    if (pos.InstrumentID != "")
                    {
                        Positions.AddOrUpdate(pos.InstrumentID + pos.Direction, pos, (k, v) => v);

                        /*if (e.IsLast)
                         * {
                         *  Thread.Sleep(500);
                         *  eventPositionChanged?.Invoke(this, null);
                         * }*/
                        eventPositionChanged?.Invoke(pos, null);
                    }
                }
                else
                {
                    var err = (e as TypedRspEventArgs <CLRDFITCPositionInfoRtnField, CLRDFITCErrorRtnField>).Error;
                }
                break;
            }
        }
Exemplo n.º 2
0
        public static PositionDetail CreateDetail(CLRDFITCMatchRtnField pos)
        {
            PositionDetail result = new PositionDetail();

            switch (pos.exchangeID)
            {
            case "DCE":
                result.ExchangeID = ExchangeID.DCE;
                break;

            case "CZCE":
                result.ExchangeID = ExchangeID.CZCE;
                break;

            case "SHFE":
                result.ExchangeID = ExchangeID.SHFE;
                break;

            case "CFFEX":
                result.ExchangeID = ExchangeID.CFFEX;
                break;

            case "INE":
                result.ExchangeID = ExchangeID.INE;
                break;
            }
            result.InstrumentID = pos.instrumentID;
            switch (pos.buySellType)
            {
            case (short)CLRDFITCBuySellType.SPD_BUY:
                result.Direction = Direction.Buy;
                break;

            case (short)CLRDFITCBuySellType.SPD_SELL:
                result.Direction = Direction.Sell;
                break;
            }
            result.PositionPrice = pos.matchedPrice;
            result.VolumeAll     = pos.matchedAmount;
            switch (pos.speculator)
            {
            case (int)CLRDFITCSpeculatorType.SPD_SPECULATOR:
                result.Flag = Flag.Speculator;
                break;

            case (int)CLRDFITCSpeculatorType.SPD_HEDGE:
                result.Flag = Flag.Hedge;
                break;

            case (int)CLRDFITCSpeculatorType.SPD_ARBITRAGE:
                result.Flag = Flag.Arbitrage;
                break;
            }
            return(result);
        }
Exemplo n.º 3
0
 private void OnOrderDeal(object sender, RspEventArgs e)
 {
     switch (sender.ToString())
     {
     case "ProgramTradeApi.XTradeSpi":
         PositionDetail odr = PositionDetail.CreateDetail((e as TypedRspEventArgs <CLRDFITCMatchRtnField, object>).Data);
         try
         {
             Positions.AddOrUpdate(odr.InstrumentID + odr.Direction, odr, (k, v) => { return(v += odr); });
             eventPositionChanged?.Invoke(this, null);
         }
         catch (Exception)
         {
             //deal exception
         }
         break;
     }
 }