public void ApplyDOMUpdate(IProduct product, KaiTrade.Interfaces.IPXUpdate update)
        {
            try
            {

                KaiTrade.Interfaces.IDOM dom = _mnemonicDOM[product.Mnemonic];
                if (dom == null)
                {
                    // must have a least a price
                    decimal? initPx = null;
                    if (update.BidPrice.HasValue)
                    {
                        initPx = update.BidPrice;
                    }
                    else if (update.OfferPrice.HasValue)
                    {
                        initPx = update.OfferPrice;
                    }
                    else if (update.TradePrice.HasValue)
                    {
                        initPx = update.TradePrice;
                    }
                    if (initPx.HasValue)
                    {
                        dom = GetProductDOM(product, initPx.Value);

                    }
                }
                dom.Update(update);

            }
            catch
            {
            }
        }
Exemple #2
0
 public void SetRangeType(KaiTrade.Interfaces.TSRangeType rangeType)
 {
     foreach (TSQueryGroupTSDataSet dataSet in TsQueryGroup.TSDataSet)
     {
         dataSet.RangeType = (byte) rangeType;
     }
 }
Exemple #3
0
        public CancelRequestData(crrType type, KaiTrade.Interfaces.ICancelOrderRequest cancelRequest)
        {
            _cancelRequest = cancelRequest;
            if(_cancelRequest == null)
            {
                Exception myE = new Exception("a non null cancel request must be supplied");
                throw myE;
            }

            Mnemonic = cancelRequest.Mnemonic;

            _lastChangeTicks = DateTime.Now.Ticks;

            if(_cancelRequest.ClOrdID.Length == 0 )
            {
                Exception myE = new Exception("a clordid must be specified on a cancelOrder");
                throw myE;
            }
            if (_cancelRequest.OrigClOrdID.Length == 0)
            {
                Exception myE = new Exception("a original clordid must be specified on a cancelOrder");
                throw myE;
            }
            ClOrdID = cancelRequest.ClOrdID;
            OrigClOrdID = cancelRequest.OrigClOrdID;
            CRRType = crrType.cancel;
        }
Exemple #4
0
        public void UpdateVenue(KaiTrade.Interfaces.IVenue myVenue)
        {
            try
                {
                    using (K2DataObjects.DataContext db = Factory.Instance().GetDSContext())
                    {
                        var venue = db.Venues.Where(s => s.Name == myVenue.Name).FirstOrDefault();
                        venue.AccountNumber = myVenue.AccountNumber;
                        venue.Code = myVenue.Code;
                        venue.DataFeedVenue = myVenue.DataFeedVenue;
                        venue.DefaultCFICode = myVenue.DefaultCFICode;
                        venue.DefaultCurrencyCode = myVenue.DefaultCurrencyCode;
                        venue.DefaultSecurityExchange = myVenue.DefaultSecurityExchange;
                        venue.DriverCode = myVenue.DriverCode;
                        venue.TargetVenue = myVenue.TargetVenue;
                        venue.UseSymbol = myVenue.UseSymbol;

                        db.SubmitChanges();
                    }

                }
                catch (Exception myE)
                {

                    m_Log.Error("Update Venue", myE);
                }
        }
Exemple #5
0
 /// <summary>
 /// Gets the curve values contained in a TSItem
 /// </summary>
 /// <returns>
 /// The curve value.
 /// </returns>
 /// <param name='tsItem'>
 /// Ts item.
 /// </param>
 public static K2DataObjects.CurveValue[] GetCurveValue(KaiTrade.Interfaces.ITSItem tsItem)
 {
     if (tsItem.CurveValues.Length > 0)
     {
         K2DataObjects.CurveValue[] curveVals = new K2DataObjects.CurveValue[tsItem.CurveValues.Length];
         int i = 0;
         foreach (var parm in tsItem.CurveValues)
         {
             try
             {
                 K2DataObjects.CurveValue cv = new K2DataObjects.CurveValue();
                 cv.Mnemonic = tsItem.Mnemonic;
                 cv.HeaderID = parm.ParameterName;
                 cv.TimeStamp = tsItem.TimeStamp.Ticks;
                 cv.ItemType = (int)tsItem.ItemType;
                 cv.ItemSize = 1;
                 cv.RequestID = "1";
                 cv.Value = decimal.Parse(parm.ParameterValue);
                 curveVals[i++] = cv;
             }
             catch (Exception ex)
             {
             }
         }
         return curveVals;
     }
     return null;
 }
Exemple #6
0
 public void PriceUpdate(KaiTrade.Interfaces.IPXUpdate pxUpdate)
 {
     if (_priceHandler != null)
     {
         _priceHandler.ApplyPriceUpdate(pxUpdate);
     }
 }
Exemple #7
0
 public void ProductUpdate(string updateType, KaiTrade.Interfaces.IProduct product)
 {
     if (product != null)
     {
         string jsonData = JsonConvert.SerializeObject(product);
         rmqHelper.Publish("", product);
     }
 }
Exemple #8
0
 public void OnBarUpdate(string requestID, KaiTrade.Interfaces.ITSItem[] bars)
 {
     if (bars.Length > 0)
     {
         //rmqHelper.Publish("IBM", tsi);
         rmqPub.Publish("", bars);
     }
 }
 private void addProductPriceFile(string filepath, KaiTrade.Interfaces.IProduct prod, int interval, bool runRealTime, bool repeatOnEnd, bool playOnSubscribe)
 {
     try
     {
         m_Simulator.AddPriceFile(prod.Mnemonic, filepath, interval, runRealTime, repeatOnEnd, playOnSubscribe);
     }
     catch (Exception myE)
     {
     }
 }
Exemple #10
0
 /// <summary>
 /// Add/replace a publisher to the manager
 /// </summary>
 /// <param name="myPub"></param>
 public void Add(KaiTrade.Interfaces.Publisher myPub)
 {
     if(m_PublisherMap.ContainsKey(myPub.TopicID()))
     {
         m_PublisherMap[myPub.TopicID()] = myPub;
     }
     else
     {
         m_PublisherMap.Add(myPub.TopicID(), myPub);
     }
 }
Exemple #11
0
        /// <summary>
        /// Get a trade given the order
        /// </summary>
        /// <param name="o"></param>
        /// <returns></returns>
        public KaiTrade.Interfaces.ITrade GetTrade(KaiTrade.Interfaces.IOrder o)
        {
            K2DS.K2TradeDS tradeDS = new K2DS.K2TradeDS();
            IEnumerable<K2DataObjects.Trade> trades = tradeDS.GetTrade((o as K2DataObjects.Order));

            foreach(K2DataObjects.Trade t in trades)
            {
                return t;
            }
            return null;
        }
Exemple #12
0
 public void InsertFill(KaiTrade.Interfaces.IFill f)
 {
     try
     {
         K2DS.K2TradeDS tradeDS = new K2DS.K2TradeDS();
         tradeDS.InsertFill(f as K2DataObjects.Fill,true);
     }
     catch (Exception myE)
     {
     }
 }
Exemple #13
0
 public void InsertOrder(KaiTrade.Interfaces.IOrder o)
 {
     try
     {
         K2DS.K2OrderDS orderDS = new K2DS.K2OrderDS();
         orderDS.InsertOrder(o as K2DataObjects.Order, true);
     }
     catch (Exception myE)
     {
         m_Log.Error("InsertOrder", myE);
     }
 }
Exemple #14
0
 private void recordMessage(KaiTrade.Interfaces.IMessage message)
 {
     if (_messages == null)
     {
         _messages = new Dictionary<string, List<KaiTrade.Interfaces.IMessage>>();
     }
     if (!_messages.ContainsKey(message.Label))
     {
         _messages.Add(message.Label, new List<KaiTrade.Interfaces.IMessage>());
     }
     _messages[message.Label].Add(message);
 }
Exemple #15
0
 public PXUpdateBase(KaiTrade.Interfaces.IProduct myProduct)
 {
     try
     {
         m_DataArray = new decimal?[KaiTrade.Interfaces.PXFields.MAXPXFIELDS];
         throw new Exception("Not Implimemnted");
         //this.From(myProduct.Mnemonic, myProduct.L1PX);
     }
     catch
     {
     }
 }
Exemple #16
0
        public void Publish(string routingKey, KaiTrade.Interfaces.ITSItem[] tsBars)
        {
            try
            {
                routingKey = KaiTrade.Interfaces.MQRoutingKeyPrefix.TSBAR + routingKey;
                string jsonData = Newtonsoft.Json.JsonConvert.SerializeObject(tsBars);
                byte[] messageBody = Encoding.UTF8.GetBytes(jsonData);
                Publish(KaiTrade.Interfaces.MQExchanges.DEFAULT, KaiTrade.Interfaces.MQType.TSBAR, routingKey, messageBody);

            }
            catch (Exception myE)
            {
            }
        }
Exemple #17
0
        public void Publish(string routingKey, KaiTrade.Interfaces.IAccount account)
        {
            try
            {
                routingKey = KaiTrade.Interfaces.MQRoutingKeyPrefix.ACCOUNT + routingKey;
                string jsonData = Newtonsoft.Json.JsonConvert.SerializeObject(account);
                byte[] messageBody = Encoding.UTF8.GetBytes(jsonData);
                Publish(KaiTrade.Interfaces.MQExchanges.DEFAULT, KaiTrade.Interfaces.MQType.ACCOUNT, routingKey, messageBody);

            }
            catch (Exception myE)
            {
            }
        }
Exemple #18
0
        /// <summary>
        /// Reject a cancel request
        /// </summary>
        /// <param name="myReq"></param>
        public static string DoRejectModReq(KaiTrade.Interfaces.IModifyOrderRequst mod, string orderID, KaiTrade.Interfaces.CxlRejReason myReason, string myReasonText)
        {
            KaiTrade.Interfaces.IRequestCancelRejectResponse cxl = new K2DataObjects.RequestCancelRejectResponse();
            cxl.OrderID = orderID;
            cxl.ClOrdID = mod.ClOrdID;
            cxl.OrdStatus = KaiTrade.Interfaces.OrderStatus.REJECTED;
            cxl.OrigClOrdID = mod.OrigClOrdID;
            cxl.CxlRejResponseTo = KaiTrade.Interfaces.CxlRejResponseTo.Modify;
            cxl.ReasonText = myReasonText;
            cxl.TransactTime = DateTime.Now;
            cxl.CxlRejReason = myReason;

            // send our response message back to the clients of the adapter
            return JsonConvert.SerializeObject(cxl);
        }
        public void ApplyDOMUpdate(IProduct product, KaiTrade.Interfaces.IDOMSlot[] slots)
        {
            try
            {
                if (slots.Length > 0)
                {
                    KaiTrade.Interfaces.IDOM DOM = GetProductDOM(product, slots[0].Price);

                    DOM.Update(slots);

                }
            }
            catch
            {
            }
        }
Exemple #20
0
        public void AddVenue(KaiTrade.Interfaces.IVenue myVenue)
        {
            try
                {
                    using (K2DataObjects.DataContext db = Factory.Instance().GetDSContext())
                    {
                        var venue = (K2DataObjects.TradeVenue)myVenue;
                        db.Venues.InsertOnSubmit(venue);

                        db.SubmitChanges();
                    }
                }
                catch (Exception myE)
                {

                    m_Log.Error("Add Venue", myE);
                }
        }
Exemple #21
0
 /// <summary>
 /// Gets the price bar from a ITSItem, TSItem is data returned from a driver
 /// that connects to the prices source CQG, IB,  etc
 /// </summary>
 /// <returns>
 /// The price bar.
 /// </returns>
 /// <param name='tsItem'>
 /// Ts item.
 /// </param>
 public static K2DataObjects.PriceBar GetPriceBar(KaiTrade.Interfaces.ITSItem tsItem)
 {
     K2DataObjects.PriceBar bar = new K2DataObjects.PriceBar();
     bar.High = (decimal) tsItem.High;
     bar.AskVolume = (decimal)tsItem.AskVolume;
     bar.Avg = (decimal)tsItem.Avg;
     bar.BidVolume = (decimal)tsItem.BidVolume;
     bar.Close = (decimal)tsItem.Close;
     bar.Low = (decimal)tsItem.Low;
     bar.Mnemonic = tsItem.Mnemonic;
     bar.Open = (decimal)tsItem.Open;
     bar.Volume = (decimal)tsItem.Volume;
     bar.TimeStamp = tsItem.TimeStamp.Ticks;
     bar.ItemType = (int)tsItem.ItemType;
     bar.ItemSize = 1;
     bar.RequestID = "1";
     return bar;
 }
Exemple #22
0
        public void DeleteVenue(KaiTrade.Interfaces.IVenue myVenue)
        {
            try
                {
                    using (K2DataObjects.DataContext db = Factory.Instance().GetDSContext())
                    {
                        var venue = db.Venues.Where(s => s.Name == myVenue.Name).FirstOrDefault();
                        db.Venues.DeleteOnSubmit(venue);
                        db.SubmitChanges();
                    }

                }
                catch (Exception myE)
                {

                    m_Log.Error("Delete Venue", myE);
                }
        }
Exemple #23
0
        /// <summary>
        /// Update a trade using an order
        /// </summary>
        /// <param name="trade"></param>
        /// <param name="o"></param>
        public void UpdateTrade(KaiTrade.Interfaces.ITrade trade, KaiTrade.Interfaces.IOrder o)
        {
            try
            {
                if (o.OrdStatus == KaiTrade.Interfaces.OrderStatus.FILLED.ToString())
                {
                    if (trade.ClOrdID != null)
                    {
                        if (trade.ClOrdID != o.ClOrdID)
                        {
                            trade.ClOrdID2 = o.ClOrdID;
                        }
                    }
                    else
                    {
                        trade.ClOrdID = o.ClOrdID;
                    }
                    trade.Mnemonic = o.Mnemonic;

                    trade.LastPx = (decimal)o.LastPx;
                    trade.LastQty = (decimal)o.LastQty;
                    //trade.TransactTime = o.TransactTime;
                    //trade.TradeDate = o.TransactTime;
                    trade.Side = o.Side;

                    /*

                    if (tcr.IsValidExecID)
                    {
                        trade.ExecutionID = tcr.ExecID;
                    }
                     */
                }
            }
            catch (Exception myE)
            {
            }
        }
Exemple #24
0
        private void modifyOrder(KaiTrade.Interfaces.IMessage msg)
        {
            KaiTrade.Interfaces.IModifyOrderRequst mod = null;
            try
            {
                mod = JsonConvert.DeserializeObject<K2DataObjects.ModifyOrderRequest>(msg.Data);
                // Extract the raw FIX Message from the inbound message
                string strOrder = msg.Data;

                KaiTrade.Interfaces.IFill fill = new K2DataObjects.Fill();
                fill.OrderStatus = KaiTrade.Interfaces.OrderStatus.REPLACED;
                fill.ExecType = KaiTrade.Interfaces.ExecType.ORDER_STATUS;
                fill.OrderID = DriverBase.Identities.Instance.getNextOrderID();

                if (mod.ClOrdID.Length == 0)
                {

                    sendCancelReplaceRej(mod, KaiTrade.Interfaces.CxlRejReason.UnknownOrder, "a clordid must be specified on a modify order");
                    Exception myE = new Exception("a clordid must be specified on a modify order");
                    throw myE;
                }

                if (mod.OrigClOrdID.Length == 0)
                {
                    sendCancelReplaceRej(mod, KaiTrade.Interfaces.CxlRejReason.UnknownOrder, "a original clordid must be specified on a modify order");
                    Exception myE = new Exception("an original clordid must be specified on a modify order");
                    throw myE;
                }

                int myIBOrderID = 0;

                    DriverBase.OrderContext myCntx = GetOrderContextClID(mod.OrigClOrdID);
                    if (myCntx == null)
                    {
                        throw new Exception("Cannot locate order context on modify request");
                    }
                    // record the context against the incomming request
                    RecordOrderContext(mod.ClOrdID, myCntx);

                // get the contract
                TWSLib.IContract myContract = getIBContract(myCntx.QFOrder);
                if (myContract == null)
                {
                    this.SendAdvisoryMessage("IB TWS: cannot find a valid contract");
                    throw new Exception("IB TWS: cannot find a valid contract");
                }

                // create an IB Order
                TWSLib.IOrder myIBOrder = m_Host.TWS.createOrder();

                myIBOrder.whatIf = 0;
                myIBOrder.account = myCntx.OriginalOrder.Account;

                if (myCntx.OriginalOrder.OrdType == KaiTrade.Interfaces.OrderType.LIMIT)
                {
                    myIBOrder.orderType = "LMT";
                }
                else if (myCntx.OriginalOrder.OrdType == KaiTrade.Interfaces.OrderType.MARKET)
                {
                    myIBOrder.orderType = "MKT";
                }
                else
                {
                    this.SendAdvisoryMessage("IB TWS: order type not supported");
                    throw new Exception("IB TWS: order type not supported");
                }

                myIBOrder.totalQuantity = (int)myCntx.OriginalOrder.OrderQty;

                // Side
                string myAction = myCntx.OriginalOrder.Side;
                myIBOrder.action = myAction;

                // Time in force
                string myTIF = myCntx.OriginalOrder.TimeInForce;
                myIBOrder.timeInForce = myTIF;

                if (myCntx.OriginalOrder.OrdType == KaiTrade.Interfaces.OrderType.LIMIT)
                {
                    myIBOrder.lmtPrice = myCntx.Price;
                }

                myCntx.ClOrdID = mod.ClOrdID;
                //int myIBOrderID = 0;
                myIBOrderID = int.Parse(myCntx.APIOrderID);

                m_Host.TWS.placeOrderEx(myIBOrderID, myContract, myIBOrder);
            }
            catch (Exception myE)
            {
                sendCancelReplaceRej(mod, KaiTrade.Interfaces.CxlRejReason.Other, myE.Message);

                _log.Error("modifyOrder", myE);
                _log.Error("modifyOrder:req:"+msg.Data);
            }
        }
Exemple #25
0
        private string getIBDuration(KaiTrade.Interfaces.TSPeriod period, int count, TimeSpan? reqSpan)
        {
            string duration="";
            duration = count.ToString();

            switch (period)
            {
                case KaiTrade.Interfaces.TSPeriod.Day:
                    if (reqSpan.HasValue)
                    {
                        duration = ((int)reqSpan.Value.TotalDays).ToString();
                    }
                    duration += " D";
                    break;
                case KaiTrade.Interfaces.TSPeriod.Week:
                    if (reqSpan.HasValue)
                    {
                        duration = ((int)reqSpan.Value.TotalDays/7).ToString();
                    }
                    duration += " W";
                    break;
                case KaiTrade.Interfaces.TSPeriod.Year:
                    duration = count.ToString();
                    duration += " Y";
                    break;
                case KaiTrade.Interfaces.TSPeriod.Month:
                    duration = count.ToString();
                    duration += " M";
                    break;
                default:
                    if (reqSpan.HasValue)
                    {
                        duration = ((int)reqSpan.Value.TotalSeconds).ToString();
                    }
                    duration += " S";
                    break;
            }
            return duration;
        }
Exemple #26
0
        private TWSLib.IContract getIBContract(KaiTrade.Interfaces.TradableProduct myProduct)
        {
            TWSLib.IContract myContract = null;
            try
            {
                if (m_ExternalProduct.ContainsKey(myProduct.Identity))
                {
                    myContract = m_ExternalProduct[myProduct.Identity] as TWSLib.IContract;
                    if (myContract != null)
                    {
                        return myContract;
                    }
                }
                myContract = m_Host.TWS.createContract();
                // Sumbol takes priority over the security ID
                if (myProduct.Symbol.Length> 0 )
                {
                    myContract.symbol = myProduct.Symbol;
                }
                else
                {
                    if (myProduct.SecurityID != null)
                    {
                        myContract.symbol = myProduct.SecurityID;
                    }
                }

                myContract.secType = CFI2IBSecType(myProduct.CFICode);

                if (myProduct.Exchange != null)
                {

                    myContract.primaryExchange = myProduct.Exchange;
                }

                if (myProduct.ExDestination != null)
                {

                    myContract.exchange = myProduct.ExDestination;
                }

                if (myProduct.Currency != null)
                {

                    //myContract.currency = myProduct.Currency;
                }
                else
                {
                    //myContract.currency = "GBP"; ;
                }

                switch (myProduct.CFICode)
                {
                    case KaiTrade.Interfaces.CFICode.STOCK:
                        // no action
                        break;
                    case KaiTrade.Interfaces.CFICode.FX:
                        // no action
                        break;
                    case KaiTrade.Interfaces.CFICode.FUTURE:
                        // get the mmy
                        if (myProduct.MMY != null)
                        {
                            myContract.expiry = myProduct.MMY.ToString();
                        }
                        break;
                    case KaiTrade.Interfaces.CFICode.PUTOPTION:
                    case KaiTrade.Interfaces.CFICode.PUTOPTIONFUTURE:
                        // get MMY, and strike
                        if (myProduct.MMY != null)
                        {
                            myContract.expiry = myProduct.MMY.ToString();
                        }
                        if (myProduct.StrikePrice.HasValue)
                        {
                            myContract.strike = (double)myProduct.StrikePrice;
                        }
                        myContract.right = "P";
                        break;
                    case KaiTrade.Interfaces.CFICode.CALLOPTION:
                    case KaiTrade.Interfaces.CFICode.CALLOPTIONFUTURE:
                        // get MMY, and strike
                        if (myProduct.MMY != null)
                        {
                            myContract.expiry = myProduct.MMY.ToString();
                        }
                        if (myProduct.StrikePrice.HasValue)
                        {
                            myContract.strike = (double) myProduct.StrikePrice;
                        }
                        myContract.right = "C";
                        break;
                    default:
                        break;
                }

            }
            catch (Exception myE)
            {
                _log.Error("getIBContract:product", myE);
            }
            return myContract;
        }
Exemple #27
0
 private string getIBBReqDuration(KaiTrade.Interfaces.ITSSet myTSSet)
 {
     string duration = "";
     string mult = Math.Abs(myTSSet.IntEnd).ToString();
     duration += mult;
     switch (myTSSet.Period)
     {
         case KaiTrade.Interfaces.TSPeriod.Day:
             duration += " D";
             break;
         case KaiTrade.Interfaces.TSPeriod.Week:
             duration += " W";
             break;
         case KaiTrade.Interfaces.TSPeriod.Year:
             duration += " Y";
             break;
         case KaiTrade.Interfaces.TSPeriod.IntraDay:
             mult = Math.Abs(myTSSet.IntEnd*60).ToString();
             duration = mult.ToString()+" S";
             //duration ="3600 S";
             break;
         case KaiTrade.Interfaces.TSPeriod.Month:
             duration += " M";
             break;
         default:
             duration += " Y";
             break;
     }
     return duration;
 }
Exemple #28
0
        private void getIBBReqBarSize(KaiTrade.Interfaces.ITSSet myTSSet, out string barSize, out string duration)
        {
            barSize = "";

            duration = "";

            TimeSpan? reqDuration = null;
            switch (myTSSet.Period)
            {
                case KaiTrade.Interfaces.TSPeriod.Day:
                    barSize = "1 day";
                    reqDuration = new TimeSpan(Math.Abs(myTSSet.IntEnd), 0, 0, 0);
                    break;
                case KaiTrade.Interfaces.TSPeriod.Week:
                    barSize = "1 week";
                    reqDuration = new TimeSpan(Math.Abs(myTSSet.IntEnd)*7, 0, 0, 0);
                    break;
                case KaiTrade.Interfaces.TSPeriod.Year:
                    barSize = "1 year";
                    break;
                case KaiTrade.Interfaces.TSPeriod.hour:
                    barSize = "1 hour";
                    reqDuration = new TimeSpan(Math.Abs(myTSSet.IntEnd), 0, 0);
                    break;
                case KaiTrade.Interfaces.TSPeriod.minute:
                    barSize = "1 min";

                    reqDuration = new TimeSpan(0,Math.Abs(myTSSet.IntEnd), 0);
                    break;
                case KaiTrade.Interfaces.TSPeriod.two_minute:
                    barSize = "2 mins";
                    reqDuration = new TimeSpan(0, Math.Abs(myTSSet.IntEnd)*2, 0);

                    break;
                case KaiTrade.Interfaces.TSPeriod.three_minute:
                    barSize = "3 mins";
                    reqDuration = new TimeSpan(0, Math.Abs(myTSSet.IntEnd) * 3, 0);

                    break;
                case KaiTrade.Interfaces.TSPeriod.five_minute:
                    barSize = "5 mins";
                    reqDuration = new TimeSpan(0, Math.Abs(myTSSet.IntEnd) * 5, 0);

                    break;
                case KaiTrade.Interfaces.TSPeriod.fifteen_minute:
                    barSize = "15 mins";
                    reqDuration = new TimeSpan(0, Math.Abs(myTSSet.IntEnd) * 15, 0);

                    break;
                case KaiTrade.Interfaces.TSPeriod.thirty_minute:
                    barSize = "30 mins";
                    reqDuration = new TimeSpan(0, Math.Abs(myTSSet.IntEnd) * 30, 0);

                    break;
                case KaiTrade.Interfaces.TSPeriod.IntraDay:
                    reqDuration = new TimeSpan(0, Math.Abs(myTSSet.IntEnd) , 0);
                    barSize = "1 min";
                    break;
                case KaiTrade.Interfaces.TSPeriod.Month:
                    barSize = "1 month";
                    break;
                default:
                    barSize = "";
                    break;
            }

            // Now work out duration
            // if myTSSet.IntEnd

            duration="";
            if (myTSSet.IntEnd == 0)
            {
                // do all from start to now
                DateTime reqEnd = DateTime.Now;
                reqDuration = new TimeSpan(reqEnd.Ticks - myTSSet.DateTimeStart.Ticks);
                duration=getIBDuration(myTSSet.Period, myTSSet.IntEnd, reqDuration);

            }
            else if (myTSSet.IntEnd < 0)
            {
                // get the last N bars
                duration=getIBDuration(myTSSet.Period, myTSSet.IntEnd, reqDuration);
            }
            else
            {
                // get the number they ask for
                duration = getIBDuration(myTSSet.Period, myTSSet.IntEnd, reqDuration);
            }
        }
Exemple #29
0
        private void getBarData(KaiTrade.Interfaces.ITSSet myTSSet)
        {
            try
            {

                // get the product
                KaiTrade.Interfaces.TradableProduct product = m_Facade.Factory.GetProductManager().GetProductMnemonic(myTSSet.Mnemonic);

                // IB's newest API uses its IContract
                // Note the PXPublisher must have a valid product
                if (product == null)
                {
                    throw new Exception("TSData set does not have a valid product");
                }

                // register the pub against the IB ReqID - updates pass that back

                m_IBReqIDTSSet.Add(++m_NextID, myTSSet);

                TWSLib.IContract myContract = getIBContract(product);

                myContract.multiplier = "0";

                // m_Host.TWS.reqMktDataEx(m_NextID, myContract, m_QuoteFields, 0);
                string endTime =myTSSet.DateTimeEnd.ToString("yyyyMMdd HH:mm:ss");
                string barSize ="";
                string duration ="";
                getIBBReqBarSize(myTSSet, out barSize, out duration);
                //string duration = getIBBReqDuration(myTSSet);
                //string barSize = getIBBReqBarSize(myTSSet);
                string headers = "TRADES";
                if (product.CFICode == KaiTrade.Interfaces.CFICode.FX)
                {

                    headers = "MIDPOINT";
                }

                //"1 M","1 day"
                //m_Host.TWS.reqHistoricalDataEx(m_NextID, myContract, endTime, "1 M", "1 day", headers, 0, 2);
                m_Host.TWS.reqHistoricalDataEx(m_NextID, myContract, endTime, duration, barSize, headers, 0, 1);
                if (myTSSet.UpdatesEnabled)
                {
                    m_IBReqIDTSSet.Add(++m_NextID, myTSSet);
                    m_Host.TWS.reqRealTimeBarsEx(m_NextID, myContract, 5, headers, 0);
                }
            }
            catch (Exception myE)
            {
                _log.Error("getBarData", myE);

            }
        }
Exemple #30
0
        private void DumpRecord(KaiTrade.Interfaces.ITSItem tsItem, KaiTrade.Interfaces.ITSSet tsSet, AxTWSLib._DTwsEvents_historicalDataEvent e)
        {
            try
            {
                // get a new TS item
                tsItem.Index = e.barCount;

                tsItem.Tag = e.date;
                //tsItem.TimeStamp = e.date
                //tsItem.TimeStamp = e.date;
                tsItem.Open = e.open;
                tsItem.High = e.high;
                tsItem.Low = e.low;
                tsItem.Close =e.close;
                tsItem.Volume = e.volume;
                DateTime result;
                if (e.date.Length > 10)
                {
                    DriverBase.DriverUtils.FromLocalMktDate(out result, e.date.Substring(0, 8), e.date.Substring(10, 8));
                }
                else
                {
                    DriverBase.DriverUtils.FromLocalMktDate(out result, e.date);
                }

                tsItem.TimeStamp = result;

                //tsItem.AskVolume = e.;
                //tsItem.BidVolume = myBar.BidVolume;
                // e.volume
                //tsItem.Mid = e.m;

                //tsItem.HLC3 = myBar.HLC3;
                //tsItem.Avg = myBar.Avg;
                //tsItem.TrueHigh = myBar.TrueHigh;
                //tsItem.TrueLow = myBar.TrueLow;
                //tsItem.Range = myBar.Range;
                //tsItem.TrueRange = myBar.TrueRange;
                //tsItem.Index = int.Parse(e.date);

            }
            catch (Exception myE)
            {
                _log.Error("DumpRecord", myE);
            }
        }