public static List <Types.Quote> GetQuoteList(string name)
 {
     if (quoteList == null)
     {
         DataFeedProcessor.GetFeed();
         return(null);
     }
     lock (quoteList)
     {
         return(quoteList.Where(x => x.Symbol.Name == name || x.Symbol.Feed1ShortName == name || x.Symbol.Feed2ShortName == name).ToList <Types.Quote>());
     }
 }
Ejemplo n.º 2
0
        private void OrderFeedSubscriberTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            try
            {
                var assets = DataProvider.GetAssets();
                if (DoesResetTempExoirt)
                {
                    //var timestamp = DataProvider.GetCurrentTimestamp();
                    var expiryList = DataProvider.ExpiryList.Where(x => x.ExpiryTimestamps > DataProvider.GetCurrentTimestamp()).ToList <ExpiryTime>();
                    if (expiryList != null && expiryList.Count > 0)
                    {
                        if (DoesResetTempExoirt)
                        {
                            tempLastExpiry      = expiryList.FirstOrDefault <ExpiryTime>();
                            DoesResetTempExoirt = false;
                        }

                        if (tempLastExpiry != null && (((tempLastExpiry.ExpiryTimestamps / 1000) - AppGlobals.Instance.SettlementPriceDuration[OptionType.Classic][0]) <= (DataProvider.GetCurrentTimestamp() / 1000)) && !IsSubscribed)
                        {
                            DoesResetTempExoirt = false;
                            IsSubscribed        = true;
                            //TaskFactory.Task
                            DataFeedProcessor.GetFeed();

                            //isupdated = false;
                        }
                        else if (tempLastExpiry != null && (((tempLastExpiry.ExpiryTimestamps / 1000) + AppGlobals.Instance.SettlementPriceDuration[OptionType.Classic][0]) <= (DataProvider.GetCurrentTimestamp() / 1000)) && IsSubscribed)
                        {
                            IsSubscribed = false;
                            DataFeedProcessor.StopFeed();
                            //DoesResetTempExoirt = true;
                            tempLastExpiry = DataProvider.ExpiryList.Where(x => x.ExpiryTimestamps > DataProvider.GetCurrentTimestamp()).FirstOrDefault <ExpiryTime>();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }
        }
        static void Main(string[] args)
        {
            AppDomain.CurrentDomain.ProcessExit += new EventHandler(CurrentDomain_ProcessExit);
            try
            {
                var feedName = System.Configuration.ConfigurationSettings.AppSettings["FeedName"];
                DataFeedProcessor.Start();
                //DataFeedProcessor.SubscribeSymbolList("AAPL");

                //System.Threading.Thread.Sleep(1000 * 10);

                //IList<OptionProcessingService.Types.SymbolNew> symbollist = DB.GetSymbolsNew();
                //foreach (var dbsymbol in symbollist)
                //{

                //    //var symbol=TimestampUtility.BuildSymbolName(dbsymbol.ShortName, dbsymbol.Type == SecurityType.Forex ?
                //    //CommonObjects.Unitity.Instrument.Forex : CommonObjects.Unitity.Instrument.Equity);
                //    DataFeedProcessor.SubscribeSymbolList(new ServerMess.SymbolItem() { Symbol=dbsymbol.ShortName, Type = ServerMess.Instrument.Equity, DataFeed = DataFeedProcessor.DataServerClient.DataFeed.Where(x => x.Name == feedName).FirstOrDefault().Name });
                //    System.Console.WriteLine("Subscribing for Symbol : " + dbsymbol.ShortName);
                //}
                string serverIP   = System.Configuration.ConfigurationSettings.AppSettings["server_ip"];
                int    serverPort = Int32.Parse(System.Configuration.ConfigurationSettings.AppSettings["server_port"]);

                Console.WriteLine("IP: {0}, Port: {1}", serverIP, serverPort);
                Server server = new Server(serverIP, serverPort);
                server.Start();

                Console.WriteLine("Started. Press Enter to exit.");


                Console.Read();
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }
        }
 static void CurrentDomain_ProcessExit(object sender, EventArgs e)
 {
     Console.WriteLine("Logout from server");
     DataFeedProcessor.Stop();
     Console.ReadLine();
 }
        public static IList <Order> FillOrdersByExpiryTimestamp(long expTimestamp)
        {
            List <Order> executedOrders = new List <Order>();

            lock (_openOrders)
            {
                for (var i = _openOrders.Count - 1; i >= 0; i--)
                {
                    var order = _openOrders[i];
                    if (order.OptionType == OptionType.Classic)
                    {
                        if (order.ExpiryTimestamp != expTimestamp)
                        {
                            continue;
                        }
                    }
                    else if (order.OptionType == OptionType.Express)
                    {
                        expTimestamp = DataProvider.GetCurrentTimestamp() + (AppGlobals.Instance.SettlementPriceDuration[OptionType.Express][order.ExpressExpiryInSeconds] * 1000);
                        if (order.ExpiryTimestamp > expTimestamp)
                        {
                            continue;
                        }
                    }
                    List <Quote> symbolTick = DataFeedProcessor.GetQuoteList(order.Symbol.Name);
                    if (symbolTick == null)
                    {
                        continue;
                    }
                    _openOrders.RemoveAt(i);
                    double currentMarketPrice = 0;
                    if (symbolTick.Count > 0) //&& symbolTick.Count > MinNumberOfFeed)
                    {
                        currentMarketPrice = symbolTick.Average(x => x.Price);
                        order.Successful   = DecideIfBetPlayed(order.Symbol, order.OptionType, order.OrderType, order.MarketPrice, currentMarketPrice);
                        order.State        = OrderState.Executed;
                    }
                    else
                    {
                        order.Reason = "Server unable to recieve required feeds. Count = " + symbolTick.Count;
                        order.State  = OrderState.Rejected;
                    }
                    order.ExecuteTimestamp = GetCurrentTimestamp();
                    lock (_orderHistory)
                    {
                        _orderHistory.Add(order);
                    }
                    DB.UpdateOrder(order);
                    var account = DB.GetAccountByUserID(order.UserID);
                    if (order.Successful)
                    {
                        account.Balance += order.Investment + order.Investment * order.ReturnCoefficient;
                        DB.UpdateAccount(account);
                    }
                    else if (order.State == OrderState.Rejected)
                    {
                        account.Balance += order.Investment;
                        DB.UpdateAccount(account);
                    }
                    FireExecution(order, new OrderExecutionResponse()
                    {
                        OrderID = order.ID, Status = order.Successful ? OrderState.Executed : OrderState.Rejected, Message = order.Reason
                    });
                    executedOrders.Add(order);
                }
            }
            return(executedOrders);
        }