Example #1
0
        /// <summary>
        /// Working Orders Subscription details
        /// </summary>
        /// <param name="accountId"></param>
        /// <param name="tableListener"></param>

        public SubscribedTableKey SubscribeToWorkingOrders(string accountId, IHandyTableListener tableListener)
        {
            return(subscribeToTradeSubscription(accountId, tableListener,
                                                new string[] {
                "WOU"
            }));
        }
Example #2
0
        void IAbstractStreamingClient.Subscribe(string[] epics, IHandyTableListener tableListener)
        {
            string[] symbols = new string[1];
            symbols[0] = "MSFT";

            feed.SendQuoteStreamRequest(symbols, (short)ActiveTickFeedLib.ATStreamRequestEnum.ATStreamRequestSubscribe);
        }
 public SubscribedTableKey SubscribeToTradeSubscription(string accountId, IHandyTableListener tableListener)
 {
     return(subscribeToTradeSubscription(accountId, tableListener,
                                         new[] {
         "CONFIRMS", "OPU", "WOU"
     }));
 }
Example #4
0
        /// <summary>
        /// Positions Subscription details
        /// </summary>
        /// <param name="accountId"></param>
        /// <param name="tableListener"></param>

        public SubscribedTableKey SubscribeToPositions(string accountId, IHandyTableListener tableListener)
        {
            return(subscribeToTradeSubscription(accountId, tableListener,
                                                new string[] {
                "OPU"
            }));
        }
Example #5
0
        void IAbstractStreamingClient.Subscribe(string[] epics, IHandyTableListener tableListener)
        {
            string[] symbols = new string[1];
            symbols[0] = "MSFT";

            feed.SendQuoteStreamRequest(symbols, (short)ActiveTickFeedLib.ATStreamRequestEnum.ATStreamRequestSubscribe);
        }
 internal VirtualTableManager(ExtendedTableInfo table, IHandyTableListener listener)
 {
     this.managerWithListener = null;
     this.extListener = null;
     this.fastListener = null;
     this.table = (ExtendedTableInfo) table.Clone();
     this.managerWithListener = new FullTableManager(table, listener, false);
 }
 public SubscribedTableKey SubscribeToChartTicks(IEnumerable <string> epics, IHandyTableListener tableListener)
 {
     return(SubscribeToChartTicks(epics, tableListener,
                                  new[] {
         "BID", "OFR", "LTP", "LTV", "TTV", "UTM",
         "DAY_OPEN_MID", "DAY_NET_CHG_MID", "DAY_PERC_CHG_MID", "DAY_HIGH", "DAY_LOW"
     }));
 }
Example #8
0
 internal VirtualTableManager(ExtendedTableInfo table, IHandyTableListener listener)
 {
     this.managerWithListener = null;
     this.extListener         = null;
     this.fastListener        = null;
     this.table = table;
     this.managerWithListener = new FullTableManager(table, listener, false);
 }
Example #9
0
 public void Resume(IHandyTableListener tableListener)
 {
     while (_testReplayFiles.Count > 0)
     {
         replay(_priceData, tableListener);
         _testReplayFiles.RemoveAt(0);
     }
 }
Example #10
0
        /// <summary>
        /// account details subscription
        /// </summary>
        /// <param name="accountId"></param>
        /// <param name="tableListener"></param>

        public void subscribeToAccountDetails(string accountId, IHandyTableListener tableListener, string[] fields)
        {
            ExtendedTableInfo extTableInfo = new ExtendedTableInfo(
                new string[] { "ACCOUNT:" + accountId },
                "MERGE",
                fields,
                true
                );
            SubscribedTableKey tableKey = lsClient.SubscribeTable(extTableInfo, tableListener, false);
        }
Example #11
0
        /// <summary>
        /// L1 Prices subscription
        /// </summary>
        /// <param name="accountId"></param>
        /// <param name="tableListener"></param>
        public SubscribedTableKey subscribeToMarketDetails(string[] epics, IHandyTableListener tableListener)
        {
            return(subscribeToMarketDetails(epics, tableListener,
                                            new string[] {
                "MID_OPEN", "HIGH", "LOW", "CHANGE", "CHANGE_PCT", "UPDATE_TIME",
                "MARKET_DELAY", "MARKET_STATE", "BID", "OFFER"

                /*, "BID_QUOTE_ID", "OFR_QUOTE_ID"*/
            }));
        }
        public SubscribedTableKey SubscribeToAccountDetails(string accountId, IHandyTableListener tableListener, IEnumerable <string> fields)
        {
            ExtendedTableInfo extTableInfo = new ExtendedTableInfo(
                new[] { "ACCOUNT:" + accountId },
                "MERGE",
                fields.ToArray(),
                true
                );

            return(lsClient.SubscribeTable(extTableInfo, tableListener, false));
        }
        public SubscribedTableKey SubscribeToTradeSubscription(string accountId, IHandyTableListener tableListener, IEnumerable <string> fields)
        {
            ExtendedTableInfo extTableInfo = new ExtendedTableInfo(
                new[] { "TRADE:" + accountId },
                "DISTINCT",
                fields.ToArray(),
                true
                );

            return(lsClient.SubscribeTable(extTableInfo, tableListener, false));
        }
Example #14
0
        public SubscribedTableKey subscribeToTradeSubscription(string accountId, IHandyTableListener tableListener, string[] fields)
        {
            ExtendedTableInfo extTableInfo = new ExtendedTableInfo(
                new string[] { "TRADE:" + accountId },
                "DISTINCT",
                fields,
                true
                );

            return(lsClient.SubscribeTable(extTableInfo, tableListener, false));
        }
        public SubscribedTableKey SubscribeToChartTicks(IEnumerable <string> epics, IHandyTableListener tableListener, string[] fields)
        {
            string[]          items        = epics.Select(e => string.Format("CHART:{0}:TICK", e)).ToArray();
            ExtendedTableInfo extTableInfo = new ExtendedTableInfo(
                items,
                "DISTINCT",
                fields,
                true
                );

            return(lsClient.SubscribeTable(extTableInfo, tableListener, false));
        }
Example #16
0
        /*
         * void IAbstractStreamingClient.GetMarketDetails(MarketData mktData)
         * {
         *  var mktLevels = _reader.GetMarketLevels(_startTime, new List<string> { mktData.Id }).Values.First();
         *  Market mkt = new Market();
         *  mkt.epic = mktData.Id;
         *  mkt.high = mktLevels.High; mkt.low = mktLevels.Low; mkt.bid = mktLevels.CloseBid; mkt.offer = mktLevels.CloseOffer;
         *  mktData.Levels = new MarketLevels(mkt.epic, mkt.low.Value, mkt.high.Value, mkt.bid.Value, mkt.offer.Value);
         * }*/

        protected void replay(Dictionary <string, List <CqlQuote> > priceData, IHandyTableListener tableListener)
        {
            DateTime curtime = _startTime;

            while (priceData.Count > 0)
            {
                DateTimeOffset   minNextTime   = _stopTime;
                ReplayUpdateInfo nextUpdate    = null;
                List <string>    epicsToDelete = new List <string>();
                foreach (var epicQuotes in priceData)
                {
                    if (epicQuotes.Value.Count == 0)
                    {
                        epicsToDelete.Add(epicQuotes.Key);
                    }
                    else
                    {
                        if (epicQuotes.Value[0].t <= minNextTime)
                        {
                            minNextTime = epicQuotes.Value[0].t;
                            nextUpdate  = new ReplayUpdateInfo(epicQuotes.Value[0]);
                        }
                    }
                }
                if (nextUpdate == null)
                {
                    foreach (var epic in epicsToDelete)
                    {
                        priceData.Remove(epic);
                    }
                }
                else
                {
                    priceData[nextUpdate.Id].RemoveAt(0);
                    if (_samplingMs != -1)
                    {
                        if ((nextUpdate.Time - curtime).TotalMilliseconds < _samplingMs)
                        {
                            continue;
                        }
                        curtime = nextUpdate.Time;
                    }
                    tableListener.OnUpdate(0, nextUpdate.Id, nextUpdate);
                    if (_closing.Signaled)
                    {
                        _closing.Set();
                        break;
                    }
                }
            }
        }
Example #17
0
 public virtual void Subscribe(string[] epics, IHandyTableListener tableListener)
 {
     while (_testReplayFiles.Count > 0)
     {
         _priceData = GetReplayData(epics);
         if (_deleteDB)
         {
             delete(_priceData);
         }
         else
         {
             replay(_priceData, tableListener);
         }
         _testReplayFiles.RemoveAt(0);
     }
 }
Example #18
0
        public SubscribedTableKey SubscribeToIndexMarketData(IHandyTableListener iHandyTableListener, String Epic)
        {
            if (ConnectionEstablished == false)
            {
                throw new Exception();
            }

            String Trade = "MARKET:" + Epic;

            String[] Items  = new String[] { Trade };
            String[] Fields = new string[] { "BID", "OFFER", "UPDATE_TIME" };

            ExtendedTableInfo extendedTableInfo = new ExtendedTableInfo(Items, "MERGE", Fields, true);

            return(lsClient.SubscribeTable(extendedTableInfo, iHandyTableListener, false));
        }
Example #19
0
        /// <summary>
        /// L1 Prices subscription
        /// </summary>
        /// <param name="accountId"></param>
        /// <param name="tableListener"></param>
        public SubscribedTableKey subscribeToMarketDetails(string[] epics, IHandyTableListener tableListener, string[] fields)
        {
            string[] items = new string[epics.Length];
            for (int i = 0; i < epics.Length; i++)
            {
                items[i] = "L1:" + epics[i];
            }
            ExtendedTableInfo extTableInfo = new ExtendedTableInfo(
                items,
                "MERGE",
                fields,
                true
                );

            return(lsClient.SubscribeTable(extTableInfo, tableListener, false));
        }
Example #20
0
        public SubscribedTableKey SubscribeToTradeUpdates(IHandyTableListener iHandyTableListener)
        {
            if (ConnectionEstablished == false)
            {
                throw new Exception();
            }

            String Trade = "TRADE:" + Session.Response.Response.CurrentAccountId;

            String[] Items = new String[] { Trade };
            //String[] Fields = new string[] { "CONFIRMS" };
            String[] Fields = new string[] { "CONFIRMS", "OPU", "WOU" };

            ExtendedTableInfo extendedTableInfo = new ExtendedTableInfo(Items, "DISTINCT", Fields, true);

            return(lsClient.SubscribeTable(extendedTableInfo, iHandyTableListener, true));
        }
 internal FullTableManager(SimpleTableInfo table, IHandyTableListener listener, bool doCommandLogic)
 {
     this.baseInfo       = table;
     this.isCommandLogic = doCommandLogic;
     if (table is ExtendedTableInfo)
     {
         this.extInfo       = (ExtendedTableInfo)table;
         this.fieldIndexMap = new Hashtable();
         for (int i = 0; i < this.extInfo.fields.Length; i++)
         {
             this.fieldIndexMap[this.extInfo.fields[i]] = i;
         }
     }
     else
     {
         this.extInfo       = null;
         this.fieldIndexMap = null;
     }
     this.listener = listener;
 }
Example #22
0
 internal FullTableManager(SimpleTableInfo table, IHandyTableListener listener, bool doCommandLogic)
 {
     this.baseInfo = (SimpleTableInfo) table.Clone();
     this.isCommandLogic = doCommandLogic;
     if (table is ExtendedTableInfo)
     {
         this.extInfo = (ExtendedTableInfo) this.baseInfo;
         this.fieldIndexMap = new Dictionary<string, int>();
         for (int i = 0; i < this.extInfo.fields.Length; i++)
         {
             this.fieldIndexMap[this.extInfo.fields[i]] = i;
         }
     }
     else
     {
         this.extInfo = null;
         this.fieldIndexMap = null;
     }
     this.listener = listener;
 }
Example #23
0
 /// <summary>
 /// L1 Prices subscription
 /// </summary>
 /// <param name="accountId"></param>
 /// <param name="tableListener"></param>
 public SubscribedTableKey subscribeToMarketDetails(string[] epics, IHandyTableListener tableListener)
 {
     return subscribeToMarketDetails(epics, tableListener,
         new string[] { 
             "MID_OPEN", "HIGH", "LOW", "CHANGE", "CHANGE_PCT", "UPDATE_TIME", 
             "MARKET_DELAY", "MARKET_STATE", "BID", "OFFER" 
             
             /*, "BID_QUOTE_ID", "OFR_QUOTE_ID"*/
         });
 }
 public SubscribedTableKey SubscribeToAccountDetails(string accountId, IHandyTableListener tableListener)
 {
     return(SubscribeToAccountDetails(accountId, tableListener, new[] { "PNL", "DEPOSIT", "USED_MARGIN", "AMOUNT_DUE", "AVAILABLE_CASH" }));
 }
Example #25
0
        /// <summary>
        /// trade subscription details
        /// </summary>
        /// <param name="accountId"></param>
        /// <param name="tableListener"></param>

        public SubscribedTableKey subscribeToTradeSubscription(string accountId, IHandyTableListener tableListener)
        {
            return subscribeToTradeSubscription(accountId, tableListener,
                new string[] { 
                    "CONFIRMS", "OPU", "WOU"
                });
        }
Example #26
0
 SubscribedTableKey IAbstractStreamingClient.SubscribeToPositions(IHandyTableListener tableListener)
 {
     throw new ApplicationException("ActiveTick API is not for trading, only for market data");
 }
Example #27
0
 public void Resume(IHandyTableListener tableListener)
 {
     while (_testReplayFiles.Count > 0)
     {
         replay(_priceData, tableListener);
         _testReplayFiles.RemoveAt(0);
     }
 }
 public SubscribedTableKey SubscribeToChartCandleData(IEnumerable <string> epics, ChartScale scale, IHandyTableListener tableListener)
 {
     return(SubscribeToChartCandleData(epics, scale, tableListener,
                                       new[] {
         "LTV", "TTV", "UTM",
         "DAY_OPEN_MID", "DAY_NET_CHG_MID", "DAY_PERC_CHG_MID", "DAY_HIGH", "DAY_LOW",
         "OFR_OPEN", "OFR_HIGH", "OFR_LOW", "OFR_CLOSE",
         "BID_OPEN", "BID_HIGH", "BID_LOW", "BID_CLOSE",
         "LTP_OPEN", "LTP_HIGH", "LTP_LOW", "LTP_CLOSE",
         "CONS_END", "CONS_TICK_COUNT",
     }));
 }
Example #29
0
 public virtual SubscribedTableKey SubscribeTable(SimpleTableInfo table, IHandyTableListener listener, bool commandLogic)
 {
     SubscribedTableKey key;
     ServerManager connManager = this.ConnManager;
     ITableManager manager2 = new FullTableManager(table, listener, commandLogic);
     try
     {
         key = connManager.SubscrTable(manager2, true);
     }
     catch (PhaseException)
     {
         throw new SubscrException("Connection closed");
     }
     return key;
 }
 public SubscribedTableKey subscribeToMarketDetails(IEnumerable <string> epics, IHandyTableListener tableListener, IEnumerable <string> fields)
 {
     return(SubscribeToMarketDetails(epics, tableListener, fields));
 }
Example #31
0
        /// <summary>
        /// account details subscription
        /// </summary>
        /// <param name="accountId"></param>
        /// <param name="tableListener"></param>

        public void subscribeToAccountDetails(string accountId, IHandyTableListener tableListener)
        {
            subscribeToAccountDetails(accountId, tableListener, new string[] { "PNL", "DEPOSIT", "USED_MARGIN", "AMOUNT_DUE", "AVAILABLE_CASH" });
        }
Example #32
0
 public virtual SubscribedTableKey[] SubscribeItems(ExtendedTableInfo items, IHandyTableListener listener)
 {
     SubscribedTableKey[] keyArray;
     ServerManager connManager = this.ConnManager;
     VirtualTableManager table = new VirtualTableManager(items, listener);
     try
     {
         keyArray = connManager.SubscrItems(table, true);
     }
     catch (PhaseException)
     {
         throw new SubscrException("Connection closed");
     }
     return keyArray;
 }
Example #33
0
 public SubscribedTableKey subscribeToAccountDetailsKey(string accountId, IHandyTableListener tableListener)
 {
     return subscribeToAccountDetailsKey(accountId, tableListener, new string[] { "PNL", "DEPOSIT", "USED_MARGIN", "AMOUNT_DUE", "AVAILABLE_CASH" });
 }
Example #34
0
        /// <summary>
        /// Positions Subscription details
        /// </summary>
        /// <param name="accountId"></param>
        /// <param name="tableListener"></param>

        public SubscribedTableKey SubscribeToPositions(string accountId, IHandyTableListener tableListener)
        {
            return subscribeToTradeSubscription(accountId, tableListener,
               new string[] { 
                   "OPU"
                });
        }
Example #35
0
        /// <summary>
        /// Working Orders Subscription details
        /// </summary>
        /// <param name="accountId"></param>
        /// <param name="tableListener"></param>

        public SubscribedTableKey SubscribeToWorkingOrders(string accountId, IHandyTableListener tableListener)
        {
            return subscribeToTradeSubscription(accountId, tableListener,
               new string[] { 
                   "WOU"
                });
        }
 public SubscribedTableKey subscribeToAccountDetailsKey(string accountId, IHandyTableListener tableListener,
                                                        IEnumerable <string> fields)
 {
     return(SubscribeToAccountDetails(accountId, tableListener, fields));
 }
 public SubscribedTableKey subscribeToTradeSubscription(string accountId, IHandyTableListener tableListener)
 {
     return(SubscribeToTradeSubscription(accountId, tableListener));
 }
Example #38
0
 public virtual void Subscribe(string[] epics, IHandyTableListener tableListener)
 {
     while (_testReplayFiles.Count > 0)
     {
         _priceData = GetReplayData(epics);
         if (_deleteDB)
             delete(_priceData);
         else
             replay(_priceData, tableListener);
         _testReplayFiles.RemoveAt(0);
     }
 }
 private SubscribedTableKey subscribeToTradeSubscription(string accountId, IHandyTableListener tableListener,
                                                         string[] fields)
 {
     return(SubscribeToTradeSubscription(accountId, tableListener, fields));
 }
        public SubscribedTableKey SubscribeToMarketDetails(IEnumerable <string> epics, IHandyTableListener tableListener, IEnumerable <string> fields)
        {
            string[]          items        = epics.Select(e => string.Format("L1:{0}", e)).ToArray();
            ExtendedTableInfo extTableInfo = new ExtendedTableInfo(
                items,
                "MERGE",
                fields.ToArray(),
                true
                );

            return(lsClient.SubscribeTable(extTableInfo, tableListener, false));
        }
Example #41
0
 public virtual Lightstreamer.DotNet.Client.SubscribedTableKey[] SubscribeItems(ExtendedTableInfo items, IHandyTableListener listener)
 {
     Lightstreamer.DotNet.Client.SubscribedTableKey[] CS$1$0000;
     ServerManager currConnManager = this.ConnManager;
     VirtualTableManager tableInfo = new VirtualTableManager(items, listener);
     try
     {
         CS$1$0000 = currConnManager.SubscrItems(tableInfo, true);
     }
     catch (PhaseException)
     {
         throw new SubscrException("Connection closed");
     }
     return CS$1$0000;
 }
Example #42
0
 void IAbstractStreamingClient.UnsubscribeTradeSubscription(SubscribedTableKey tableListener)
 {
     _tradingEventTable = null;
 }
Example #43
0
 /// <summary>
 /// L1 Prices subscription
 /// </summary>
 /// <param name="accountId"></param>
 /// <param name="tableListener"></param>
 public SubscribedTableKey subscribeToMarketDetails(string[] epics, IHandyTableListener tableListener, string[] fields)
 {
     string[] items = new string[epics.Length];
     for (int i = 0; i < epics.Length; i++)
     {
         items[i] = "L1:" + epics[i];
     }
     ExtendedTableInfo extTableInfo = new ExtendedTableInfo(
         items,
         "MERGE",
         fields,
         true
         );
     return lsClient.SubscribeTable(extTableInfo, tableListener, false);
 }
        public SubscribedTableKey SubscribeToChartCandleData(IEnumerable <string> epics, ChartScale scale, IHandyTableListener tableListener, string[] fields)
        {
            string[]          items        = epics.Select(e => string.Format("CHART:{0}:{1}", e, GetScale(scale))).ToArray();
            ExtendedTableInfo extTableInfo = new ExtendedTableInfo(
                items,
                "MERGE",
                fields,
                true
                );

            return(lsClient.SubscribeTable(extTableInfo, tableListener, false));
        }
Example #45
0
 public SubscribedTableKey subscribeToTradeSubscription(string accountId, IHandyTableListener tableListener, string[] fields)
 {
     ExtendedTableInfo extTableInfo = new ExtendedTableInfo(
         new string[] { "TRADE:" + accountId },
         "DISTINCT",
         fields,
         true
         );
     return lsClient.SubscribeTable(extTableInfo, tableListener, false);
 }
Example #46
0
 SubscribedTableKey IAbstractStreamingClient.SubscribeToPositions(IHandyTableListener tableListener)
 {
     _tradingEventTable = tableListener;
     return null;
 }
Example #47
0
 void IAbstractStreamingClient.Resume(IHandyTableListener tableListener)
 {
 }
Example #48
0
        public override void Subscribe(string[] epics, IHandyTableListener tableListener)
        {
            Dictionary<string, List<CqlQuote>> priceData = GetReplayData(epics);

            foreach (var epic in epics)
            {
                // for each quote, associate the observed gains in the near future
                var mktData = new MarketData(epic);
                var wmaLow = new IndicatorWMA(mktData, 10);
                var wmaMid = new IndicatorWMA(mktData, 30);
                var wmaHigh = new IndicatorWMA(mktData, 90);
                var wmaDailyAvg = new IndicatorLevelMean(mktData);

                foreach (var quote in priceData[epic])
                    mktData.TimeSeries.Add(quote.t, new Price(quote.MidPrice()));
                foreach (var quote in ExpectedIndicatorData[wmaLow.Id])
                    wmaLow.TimeSeries.Add(quote.t, new Price(quote.ScaleValue(0, 1)));
                foreach (var quote in ExpectedIndicatorData[wmaLow.Id])
                    wmaLow.TimeSeries.Add(quote.t, new Price(quote.ScaleValue(0, 1)));

                var expectations = new Dictionary<DateTime, KeyValuePair<CqlQuote, decimal>>();
                var gainDistribution = new SortedList<int, DateTime>();
                KeyValuePair<int, DateTime> minProfit = new KeyValuePair<int, DateTime>(1000000, DateTime.MinValue);
                KeyValuePair<int, DateTime> maxProfit = new KeyValuePair<int, DateTime>(-1000000, DateTime.MinValue);
                var rnd = new Random(155);
                var openPrice = priceData[epic][0];
                foreach (var quote in priceData[epic])
                {
                    if (quote.t.TimeOfDay < Config.ParseDateTimeLocal(Config.Settings["TRADING_START_TIME"]).TimeOfDay)
                        continue;
                    var futureVal = wmaLow.Average(quote.t.AddMinutes(2));
                    var profit = (int)Math.Round(futureVal.Mid() - quote.MidPrice());
                    expectations.Add(quote.t, new KeyValuePair<CqlQuote, decimal>(quote, profit));
                    if (gainDistribution.ContainsKey(profit))
                    {
                        if ((quote.t - gainDistribution[profit]).Hours > 3 && (rnd.Next(100) == 0))
                            gainDistribution[profit] = quote.t;
                    }
                    else
                        gainDistribution[profit] = quote.t;
                    if (profit < minProfit.Key)
                        minProfit = new KeyValuePair<int, DateTime>(profit, gainDistribution[profit]);
                    if (profit > maxProfit.Key)
                        maxProfit = new KeyValuePair<int, DateTime>(profit, gainDistribution[profit]);
                    quote.b -= openPrice.MidPrice();
                    quote.o -= openPrice.MidPrice();
                }
                int nbPoints = 10;
                int idxProfit = 0;
                KeyValuePair<int, DateTime> nextProfit = minProfit;
                var selection = new SortedList<DateTime, KeyValuePair<int, CqlQuote>>();
                while (idxProfit++ < nbPoints)
                {
                    PublisherConnection.Instance.Insert(nextProfit.Value, epic, new Value(nextProfit.Key));
                    selection.Add(nextProfit.Value, new KeyValuePair<int, CqlQuote>(nextProfit.Key, expectations[nextProfit.Value].Key));
                    nextProfit = gainDistribution.First(keyVal => keyVal.Key >= ((decimal)minProfit.Key + (decimal)idxProfit * (decimal)(maxProfit.Key - minProfit.Key) / (decimal)nbPoints));
                }
                foreach (var profit in selection)
                {
                    PublisherConnection.Instance.Insert(gainDistribution[profit.Value.Key], wmaLow, wmaLow.Average(gainDistribution[profit.Value.Key]).Mid() - openPrice.MidPrice());
                    PublisherConnection.Instance.Insert(gainDistribution[profit.Value.Key], wmaMid, wmaMid.Average(gainDistribution[profit.Value.Key]).Mid() - openPrice.MidPrice());
                    PublisherConnection.Instance.Insert(gainDistribution[profit.Value.Key], wmaHigh, wmaHigh.Average(gainDistribution[profit.Value.Key]).Mid() - openPrice.MidPrice());
                    PublisherConnection.Instance.Insert(gainDistribution[profit.Value.Key], wmaDailyAvg, wmaDailyAvg.Average().Mid() - openPrice.MidPrice());
                }
                priceData[epic] = selection.Values.Select(keyVal => keyVal.Value).ToList();
            }
            replay(priceData, tableListener);
        }
Example #49
0
 /*
 void IAbstractStreamingClient.GetMarketDetails(MarketData mktData)
 {
     var mktLevels = _reader.GetMarketLevels(_startTime, new List<string> { mktData.Id }).Values.First();
     Market mkt = new Market();
     mkt.epic = mktData.Id;
     mkt.high = mktLevels.High; mkt.low = mktLevels.Low; mkt.bid = mktLevels.CloseBid; mkt.offer = mktLevels.CloseOffer;
     mktData.Levels = new MarketLevels(mkt.epic, mkt.low.Value, mkt.high.Value, mkt.bid.Value, mkt.offer.Value);
 }*/
 protected void replay(Dictionary<string, List<CqlQuote>> priceData, IHandyTableListener tableListener)
 {
     DateTime curtime = _startTime;
     while (priceData.Count > 0)
     {
         DateTimeOffset minNextTime = _stopTime;
         ReplayUpdateInfo nextUpdate = null;
         List<string> epicsToDelete = new List<string>();
         foreach (var epicQuotes in priceData)
         {
             if (epicQuotes.Value.Count == 0)
                 epicsToDelete.Add(epicQuotes.Key);
             else
             {
                 if (epicQuotes.Value[0].t <= minNextTime)
                 {
                     minNextTime = epicQuotes.Value[0].t;
                     nextUpdate = new ReplayUpdateInfo(epicQuotes.Value[0]);
                 }
             }
         }
         if (nextUpdate == null)
         {
             foreach (var epic in epicsToDelete)
                 priceData.Remove(epic);
         }
         else
         {
             priceData[nextUpdate.Id].RemoveAt(0);
             if (_samplingMs != -1)
             {
                 if ((nextUpdate.Time - curtime).TotalMilliseconds < _samplingMs)
                     continue;
                 curtime = nextUpdate.Time;
             }
             tableListener.OnUpdate(0, nextUpdate.Id, nextUpdate);
             if (_closing.Signaled)
             {
                 _closing.Set();
                 break;
             }
         }
     }
 }
Example #50
0
 public virtual Lightstreamer.DotNet.Client.SubscribedTableKey SubscribeTable(SimpleTableInfo table, IHandyTableListener listener, bool commandLogic)
 {
     Lightstreamer.DotNet.Client.SubscribedTableKey CS$1$0000;
     ServerManager currConnManager = this.ConnManager;
     ITableManager tableInfo = new FullTableManager(table, listener, commandLogic);
     try
     {
         CS$1$0000 = currConnManager.SubscrTable(tableInfo, true);
     }
     catch (PhaseException)
     {
         throw new SubscrException("Connection closed");
     }
     return CS$1$0000;
 }
Example #51
0
 SubscribedTableKey IAbstractStreamingClient.SubscribeToPositions(IHandyTableListener tableListener)
 {
     throw new ApplicationException("ActiveTick API is not for trading, only for market data");
 }
Example #52
0
 void IAbstractStreamingClient.Resume(IHandyTableListener tableListener)
 {
 }
 public SubscribedTableKey subscribeToAccountDetailsKey(string accountId, IHandyTableListener tableListener)
 {
     return(SubscribeToAccountDetails(accountId, tableListener));
 }
Example #54
0
        public override void Subscribe(string[] epics, IHandyTableListener tableListener)
        {
            Dictionary<string, List<CqlQuote>> priceData = GetReplayData(epics);
            if (priceData.Count == 0)
                return;

            Calendar dayCalendar = new Calendar(priceData.First().Value[0].t);

            foreach(var epic in epics){
                // for each quote, associate the observed gains in the near future
                var mktData = new MarketData(epic);
                var wmaLow = new IndicatorEMA(mktData, 2);
                var wmaMid = new IndicatorEMA(mktData, 10);
                var wmaHigh = new IndicatorEMA(mktData, 30);
                var wmaVeryHigh = new IndicatorEMA(mktData, 90);
                var rsiShort = new IndicatorRSI(mktData, 1, 14);
                var rsiLong = new IndicatorRSI(mktData, 2, 14);
                var trendShort = new IndicatorTrend(mktData, 90, 14, false);
                var trendLong = new IndicatorTrend(mktData, 180, 14, false);
                var wmvolLow = new IndicatorWMVol(mktData, wmaLow, 60, 90);
                var wmvolHigh = new IndicatorWMVol(mktData, wmaMid, 60, 90);
                var volTrendLow = new IndicatorTrend(wmvolLow, 30, 6, true);
                var volTrendHigh = new IndicatorTrend(wmvolHigh, 60, 6, true);
                var allIndicators = new List<IndicatorWMA>();
                allIndicators.Add(wmaLow);
                allIndicators.Add(wmaMid);
                allIndicators.Add(wmaHigh);
                allIndicators.Add(wmaVeryHigh);
                allIndicators.Add(rsiShort);
                allIndicators.Add(rsiLong);
                allIndicators.Add(trendShort);
                allIndicators.Add(trendLong);
                allIndicators.Add(wmvolLow);
                allIndicators.Add(wmvolHigh);
                allIndicators.Add(volTrendLow);
                allIndicators.Add(volTrendHigh);

                foreach (var quote in priceData[epic])
                {
                    var mktDataValue = new Price(quote.MidPrice());
                    mktData.Process(quote.t, mktDataValue);
                    foreach (var ind in allIndicators)
                        ind.Process(quote.t, mktDataValue);
                }

                var expectations = new Dictionary<DateTime, KeyValuePair<CqlQuote, decimal>>();
                var gainDistribution = new SortedList<int, DateTime>();
                KeyValuePair<int, DateTime> minProfit = new KeyValuePair<int, DateTime>(1000000, DateTime.MinValue);
                KeyValuePair<int, DateTime> maxProfit = new KeyValuePair<int, DateTime>(-1000000, DateTime.MinValue);
                var rnd = new Random(155);
                var tradingStart = Config.ParseDateTimeLocal(Config.Settings["TRADING_START_TIME"]);
                var tradingStop = Config.ParseDateTimeLocal(Config.Settings["TRADING_STOP_TIME"]);
                var wmaVeryHighStart = wmaVeryHigh.Average(tradingStart);
                var amplitude = 100.0m;
                foreach (var quote in priceData[epic])
                {
                    if (quote.t.TimeOfDay < tradingStart.TimeOfDay || quote.t.TimeOfDay > tradingStop.TimeOfDay)
                        continue;
                    string evtName = "";
                    if (dayCalendar.IsNearEvent(mktData.Name, quote.t, ref evtName))
                        continue;
                    var futureVal = (mktData.TimeSeries.Max(quote.t.AddMinutes(5), quote.t.AddMinutes(20)) +
                        mktData.TimeSeries.Min(quote.t.AddMinutes(5), quote.t.AddMinutes(20))) / 2m;
                    var profit = (int)Math.Round(futureVal - quote.MidPrice());
                    expectations.Add(quote.t, new KeyValuePair<CqlQuote, decimal>(quote, profit));
                    if (gainDistribution.ContainsKey(profit))
                    {
                        if ((quote.t - gainDistribution[profit]).Hours > 3 && (rnd.Next(100) == 0))
                            gainDistribution[profit] = quote.t;
                    }
                    else
                        gainDistribution[profit] = quote.t;
                    if (profit < minProfit.Key)
                        minProfit = new KeyValuePair<int, DateTime>(profit, gainDistribution[profit]);
                    if (profit > maxProfit.Key)
                        maxProfit = new KeyValuePair<int, DateTime>(profit, gainDistribution[profit]);
                    quote.b = (quote.b - wmaVeryHighStart.Bid) / amplitude;
                    quote.o = (quote.o - wmaVeryHighStart.Offer) / amplitude;
                }
                gainDistribution = new SortedList<int,DateTime>((from elt in gainDistribution
                                                                 where !isTooClose(elt, gainDistribution)
                                                                 select elt).ToDictionary(keyVal => keyVal.Key, keyVal => keyVal.Value));
                int nbPoints = 10;
                int idxProfit = 0;
                KeyValuePair<int, DateTime> nextProfit = minProfit;
                var selection = new SortedList<DateTime, KeyValuePair<int, CqlQuote>>();
                while (idxProfit++ < nbPoints)
                {
                    selection.Add(gainDistribution[nextProfit.Key], new KeyValuePair<int, CqlQuote>(nextProfit.Key, expectations[gainDistribution[nextProfit.Key]].Key));
                    var nextKeyVal = gainDistribution.FirstOrDefault(keyVal => keyVal.Key > nextProfit.Key &&
                        keyVal.Key >= ((decimal)minProfit.Key + (decimal)idxProfit * (decimal)(maxProfit.Key - minProfit.Key) / (decimal)nbPoints));
                    if (nextKeyVal.Equals(default(KeyValuePair<int, DateTime>)))
                        break;
                    nextProfit = nextKeyVal;
                }
                foreach (var dt in selection.Keys)
                {
                    bool allValid = true;
                    foreach (var ind in allIndicators)
                    {
                        if (ind.TimeSeries[dt] == null)
                        {
                            allValid = false;
                            break;
                        }
                    }
                    if (!allValid)
                        continue;
                    PublisherConnection.Instance.Insert(dt, wmaLow, (wmaLow.TimeSeries[dt].Value.Value.Mid() - wmaVeryHighStart.Mid()) / amplitude);
                    PublisherConnection.Instance.Insert(dt, wmaMid, (wmaMid.TimeSeries[dt].Value.Value.Mid() - wmaVeryHighStart.Mid()) / amplitude);
                    PublisherConnection.Instance.Insert(dt, wmaHigh, (wmaHigh.TimeSeries[dt].Value.Value.Mid() - wmaVeryHighStart.Mid()) / amplitude);
                    PublisherConnection.Instance.Insert(dt, wmaVeryHigh, (wmaVeryHigh.TimeSeries[dt].Value.Value.Mid() - wmaVeryHighStart.Mid()) / amplitude);
                    PublisherConnection.Instance.Insert(dt, rsiShort, (rsiShort.TimeSeries[dt].Value.Value.Mid() - 50m) / amplitude);
                    PublisherConnection.Instance.Insert(dt, rsiLong, (rsiLong.TimeSeries[dt].Value.Value.Mid() - 50m) / amplitude);
                    PublisherConnection.Instance.Insert(dt, trendShort, trendShort.TimeSeries[dt].Value.Value.Mid() / 1000m);
                    PublisherConnection.Instance.Insert(dt, trendLong, trendLong.TimeSeries[dt].Value.Value.Mid() / 1000m);
                    PublisherConnection.Instance.Insert(dt, wmvolLow, wmvolLow.TimeSeries[dt].Value.Value.Mid() / 10m);
                    PublisherConnection.Instance.Insert(dt, wmvolHigh, wmvolHigh.TimeSeries[dt].Value.Value.Mid() / 10m);
                    PublisherConnection.Instance.Insert(dt, volTrendLow, volTrendLow.TimeSeries[dt].Value.Value.Mid());
                    PublisherConnection.Instance.Insert(dt, volTrendHigh, volTrendHigh.TimeSeries[dt].Value.Value.Mid());
                    PublisherConnection.Instance.Insert(dt, epic, new Value((double)selection[dt].Key / ((double)amplitude / 2.0)));
                }
                priceData[epic] = selection.Values.Select(kv => kv.Value).ToList();
            }
            replay(priceData, tableListener);
        }
Example #55
0
        public SubscribedTableKey subscribeToAccountDetailsKey(string accountId, IHandyTableListener tableListener, string[] fields)
        {
            ExtendedTableInfo extTableInfo = new ExtendedTableInfo(
                new string[] { "ACCOUNT:" + accountId },
                "MERGE",
                fields,
                true
                );

            return lsClient.SubscribeTable(extTableInfo, tableListener, false);
        }