public FuturesButterflyTTAPI(string u, string p)
        {
            m_username = u;
            m_password = p;

            mysql connection = new mysql();

            conn = connection.conn;

            string       OutputFolder = TA.DirectoryNames.GetDirectoryName("daily");
            StreamWriter LogFile      = new StreamWriter(OutputFolder + "/FuturesButterfly.txt", true);

            ButterflyLogger = new Logger(LogFile);

            AutoSpreaderList             = new List <ttapiUtils.AutoSpreader>();
            AutoSpreaderDictionary       = new Dictionary <string, ttapiUtils.AutoSpreader>();
            Alias2AutoSpreaderDictionary = new Dictionary <string, string>();
            TagDictionary = new Dictionary <string, string>();
            LogTime1      = DateTime.MinValue;

            PriceTableSymbolsReceived  = new List <string>();
            StrategyPositionDictionary = new Dictionary <string, DataTable>();

            TTAPISubs  = new ttapiUtils.Subscription(m_username, m_password);
            SpreadList = new List <string>();

            DateTime ReportDate = CalendarUtilities.BusinessDays.GetBusinessDayShifted(shiftInDays: -1);
            DateTime TodayDate  = DateTime.Now.Date;



            ButterflyLogger.SW.WriteLine();
            ButterflyLogger.Log("NOTES FOR " + TodayDate.ToString("MM/dd/yyyy"));
            ButterflyLogger.Log(new String('-', 20));

            string DirectoryName = TA.DirectoryNames.GetDirectoryName(ext: "ta");
            string ButterflyOutputDirectoryName = TA.DirectoryNames.GetDirectoryName(ext: "futuresButterflyOutput");
            string DirectoryExtension           = TA.DirectoryNames.GetDirectoryExtension(directoryDate: ReportDate);

            DataSet   FollowupOutput           = IOUtilities.ExcelDataReader.LoadFile(DirectoryName + "/" + DirectoryExtension + "/followup.xlsx");
            DataTable ButterfliesFollowupSheet = FollowupOutput.Tables["butterflies"];

            DataSet   ButterfliesOutput = IOUtilities.ExcelDataReader.LoadFile(ButterflyOutputDirectoryName + "/" + DirectoryExtension + "/butterflies.xlsx");
            DataTable ButterfliesSheet  = ButterfliesOutput.Tables["good"];

            PeriodicTimer          = new System.Timers.Timer();
            PeriodicTimer.Elapsed += new ElapsedEventHandler(PeriodicCall);
            PeriodicTimer.Interval = 30000;
            // And start it
            PeriodicTimer.Enabled = true;



            DataColumn SizeColumn = new DataColumn("Size", typeof(double));

            SizeColumn.DefaultValue = 0;
            ButterfliesSheet.Columns.Add(SizeColumn);

            ButterfliesSheet.Columns.Add("Theme", typeof(string));

            DataColumn ExistingThemePositionColumn = new DataColumn("ExistingThemePosition", typeof(double));

            ExistingThemePositionColumn.DefaultValue = 0;
            ButterfliesSheet.Columns.Add(ExistingThemePositionColumn);

            ButterfliesSheet.Columns.Add("SlackFromTheme", typeof(double));



            for (int i = 0; i < ButterfliesFollowupSheet.Rows.Count; i++)
            {
                StrategyUtilities.PositionManagerOutput PositionManagerOut = PositionManager.GetFuturesButterflyPosition(alias: ButterfliesFollowupSheet.Rows[i].Field <string>("Alias"),
                                                                                                                         asOfDate: TodayDate, conn: conn);
                if (PositionManagerOut.CorrectPositionQ)
                {
                    StrategyPositionDictionary.Add(ButterfliesFollowupSheet.Rows[i].Field <string>("Alias"), PositionManagerOut.SortedPosition);
                }
            }


            DataTable ButterfliesFollowupSheetAdjusted = RiskManager.CalculateAdjustedDownside(dataTableInput: ButterfliesFollowupSheet, newTradesTable: ButterfliesSheet,
                                                                                               strategyPositionDictionary: StrategyPositionDictionary);

            DataTable RiskAcrossTickerhead = RiskManager.AggregateRiskAcrossTickerHead(dataTableInput: ButterfliesFollowupSheetAdjusted);

            Dictionary <string, double> RiskAcrossTheme = RiskManager.GetRiskAcrossTheme(dataTableInput: ButterfliesFollowupSheetAdjusted,
                                                                                         strategyPositionDictionary: StrategyPositionDictionary);



            ButterfliesSheetFiltered = Filtering.GetFilteredNewTrades(butterfliesSheet: ButterfliesSheet, riskAcrossTickerhead: RiskAcrossTickerhead, riskAcrossTheme: RiskAcrossTheme);

            DataColumn ButterflyQuantityColumn = new DataColumn("ButterflyQuantity", typeof(int));

            ButterflyQuantityColumn.DefaultValue = 0;
            ButterfliesSheetFiltered.Columns.Add(ButterflyQuantityColumn);

            DataColumn Spread1QuantityColumn = new DataColumn("Spread1Quantity", typeof(int));

            Spread1QuantityColumn.DefaultValue = 0;
            ButterfliesSheetFiltered.Columns.Add(Spread1QuantityColumn);

            DataColumn Spread2QuantityColumn = new DataColumn("Spread2Quantity", typeof(int));

            Spread2QuantityColumn.DefaultValue = 0;
            ButterfliesSheetFiltered.Columns.Add(Spread2QuantityColumn);

            ButterfliesSheetFiltered.Columns.Add("Alias", typeof(string));

            PriceTable = new DataTable();
            PriceTable.Columns.Add("Ticker", typeof(string));
            PriceTable.Columns.Add("TickerHead", typeof(string));
            PriceTable.Columns.Add("IsAutoSpreaderQ", typeof(bool));

            DataColumn BidPriceColumn = new DataColumn("BidPrice", typeof(double));

            BidPriceColumn.DefaultValue = Double.NaN;
            PriceTable.Columns.Add(BidPriceColumn);

            DataColumn AskPriceColumn = new DataColumn("AskPrice", typeof(double));

            AskPriceColumn.DefaultValue = Double.NaN;
            PriceTable.Columns.Add(AskPriceColumn);

            PriceTable.Columns.Add("BidQ", typeof(int));
            PriceTable.Columns.Add("AskQ", typeof(int));



            DataColumn ValidPriceColumn = new DataColumn("ValidPriceQ", typeof(bool));

            ValidPriceColumn.DefaultValue = false;
            PriceTable.Columns.Add(ValidPriceColumn);

            for (int i = 0; i < ButterfliesSheetFiltered.Rows.Count; i++)
            {
                DataRow SelectedRow = ButterfliesSheetFiltered.Rows[i];
                string  Alias       = "";
                string  Ticker1     = SelectedRow.Field <string>("ticker1");
                string  Ticker2     = SelectedRow.Field <string>("ticker2");
                string  Ticker3     = SelectedRow.Field <string>("ticker3");


                if (SelectedRow.Field <double>("z1") < 0)
                {
                    double FirstSpreadQuantity  = Math.Round(SelectedRow.Field <double>("Size") / Math.Abs(SelectedRow.Field <double>("Downside")));
                    double SecondSpreadQuantity = Math.Round(FirstSpreadQuantity * SelectedRow.Field <double>("second_spread_weight_1"));

                    if (FirstSpreadQuantity < SecondSpreadQuantity)
                    {
                        SelectedRow["ButterflyQuantity"] = (int)FirstSpreadQuantity;
                        SelectedRow["Spread2Quantity"]   = -(int)(SecondSpreadQuantity - FirstSpreadQuantity);
                    }
                    else if (FirstSpreadQuantity > SecondSpreadQuantity)
                    {
                        SelectedRow["ButterflyQuantity"] = (int)SecondSpreadQuantity;
                        SelectedRow["Spread1Quantity"]   = (int)(FirstSpreadQuantity - SecondSpreadQuantity);
                    }

                    else
                    {
                        ButterfliesSheetFiltered.Rows[i]["ButterflyQuantity"] = (int)FirstSpreadQuantity;
                    }

                    Alias = SelectedRow.Field <string>("tickerHead") + Ticker1.Substring(Ticker1.Count() - 5, 5) + Ticker2.Substring(Ticker2.Count() - 5, 5) +
                            Ticker2.Substring(Ticker2.Count() - 5, 5) + Ticker3.Substring(Ticker3.Count() - 5, 5);
                }
                else if (ButterfliesSheetFiltered.Rows[i].Field <double>("z1") > 0)
                {
                    double FirstSpreadQuantity  = Math.Round(ButterfliesSheetFiltered.Rows[i].Field <double>("Size") / Math.Abs(ButterfliesSheetFiltered.Rows[i].Field <double>("Upside")));
                    double SecondSpreadQuantity = Math.Round(FirstSpreadQuantity * ButterfliesSheetFiltered.Rows[i].Field <double>("second_spread_weight_1"));

                    if (FirstSpreadQuantity < SecondSpreadQuantity)
                    {
                        SelectedRow["ButterflyQuantity"] = -(int)FirstSpreadQuantity;
                        SelectedRow["Spread2Quantity"]   = (int)(SecondSpreadQuantity - FirstSpreadQuantity);
                    }
                    else if (FirstSpreadQuantity > SecondSpreadQuantity)
                    {
                        SelectedRow["ButterflyQuantity"] = -(int)SecondSpreadQuantity;
                        SelectedRow["Spread1Quantity"]   = -(int)(FirstSpreadQuantity - SecondSpreadQuantity);
                    }

                    else
                    {
                        SelectedRow["ButterflyQuantity"] = (int)FirstSpreadQuantity;
                    }

                    Alias = SelectedRow.Field <string>("tickerHead") + Ticker2.Substring(Ticker2.Count() - 5, 5) + Ticker3.Substring(Ticker3.Count() - 5, 5) +
                            Ticker1.Substring(Ticker1.Count() - 5, 5) + Ticker2.Substring(Ticker2.Count() - 5, 5);
                }

                SelectedRow["Alias"] = Alias;

                List <string> TickerList = new List <string> {
                    Ticker1 + "-" + Ticker2,
                    Ticker2 + "-" + Ticker3
                };

                ttapiUtils.AutoSpreader As = new ttapiUtils.AutoSpreader(dbTickerList: TickerList, payUpTicks: 2);

                SpreadList.AddRange(TickerList);
                AutoSpreaderList.Add(As);
                AutoSpreaderDictionary.Add(As.AutoSpreaderName, As);
                Alias2AutoSpreaderDictionary.Add(Alias, As.AutoSpreaderName);
                TagDictionary.Add(As.AutoSpreaderName, "fut_but_fol_" + i);

                DataRow PriceRow = PriceTable.NewRow();
                PriceRow["Ticker"]          = As.AutoSpreaderName;
                PriceRow["TickerHead"]      = SelectedRow.Field <string>("tickerHead");
                PriceRow["IsAutoSpreaderQ"] = true;
                PriceTable.Rows.Add(PriceRow);
            }



            HistoricPriceTable = GetPrice.GetFuturesPrice.getFuturesPrice4Ticker(tickerHeadList: ContractUtilities.ContractMetaInfo.FuturesButterflyTickerheadList,
                                                                                 dateTimeFrom: ReportDate, dateTimeTo: ReportDate, conn: conn);

            DataRow [] StopList = ButterfliesFollowupSheet.Select("Recommendation='STOP'");

            if (StopList.Length > 0)
            {
                ButterfliesStopSheet = StopList.CopyToDataTable();
                ButterfliesStopSheet.Columns.Add("PnlMid", typeof(double));
                ButterfliesStopSheet.Columns.Add("PnlWorst", typeof(double));
                ButterfliesStopSheet.Columns.Add("ButterflyMidPrice", typeof(double));
                ButterfliesStopSheet.Columns.Add("ButterflyWorstPrice", typeof(double));
                ButterfliesStopSheet.Columns.Add("ButterflyQuantity", typeof(int));
                ButterfliesStopSheet.Columns.Add("SpreadMidPrice", typeof(double));
                ButterfliesStopSheet.Columns.Add("SpreadWorstPrice", typeof(double));
                ButterfliesStopSheet.Columns.Add("SpreadQuantity", typeof(int));

                DataColumn WorkingButterflyOrdersColumn = new DataColumn("WorkingButterflyOrders", typeof(int));
                WorkingButterflyOrdersColumn.DefaultValue = 0;
                ButterfliesStopSheet.Columns.Add(WorkingButterflyOrdersColumn);

                DataColumn WorkingSpreadOrdersColumn = new DataColumn("WorkingSpreadOrders", typeof(int));
                WorkingSpreadOrdersColumn.DefaultValue = 0;
                ButterfliesStopSheet.Columns.Add(WorkingSpreadOrdersColumn);

                for (int i = 0; i < StopList.Length; i++)
                {
                    string Alias = StopList[i].Field <string>("Alias");
                    StrategyUtilities.PositionManagerOutput PositionManagerOut = PositionManager.GetFuturesButterflyPosition(alias: Alias, asOfDate: TodayDate, conn: conn);
                    DataTable StrategyPosition = PositionManagerOut.SortedPosition;

                    StrategyPosition.Columns.Add("ClosePrice", typeof(double));

                    for (int j = 0; j < StrategyPosition.Rows.Count; j++)
                    {
                        DataRow SelectedHistRow = HistoricPriceTable.Select("ticker='" + StrategyPosition.Rows[j].Field <string>("Ticker") + "'")[0];
                        StrategyPosition.Rows[j]["ClosePrice"] = SelectedHistRow.Field <decimal>("close_price");
                    }


                    List <string> TickerList = new List <string> {
                        StrategyPosition.Rows[0].Field <string>("Ticker") + "-" + StrategyPosition.Rows[1].Field <string>("Ticker"),
                        StrategyPosition.Rows[1].Field <string>("Ticker") + "-" + StrategyPosition.Rows[2].Field <string>("Ticker")
                    };
                    StrategyPositionDictionary[Alias] = StrategyPosition;

                    SpreadList.AddRange(TickerList);

                    if (PositionManagerOut.CorrectPositionQ)
                    {
                        ttapiUtils.AutoSpreader As = new ttapiUtils.AutoSpreader(dbTickerList: TickerList, payUpTicks: 2);

                        AutoSpreaderList.Add(As);
                        AutoSpreaderDictionary.Add(As.AutoSpreaderName, As);
                        Alias2AutoSpreaderDictionary.Add(Alias, As.AutoSpreaderName);
                        TagDictionary.Add(As.AutoSpreaderName, "fut_but_fol_" + (i + ButterfliesSheetFiltered.Rows.Count));


                        DataRow PriceRow = PriceTable.NewRow();
                        PriceRow["Ticker"]          = As.AutoSpreaderName;
                        PriceRow["TickerHead"]      = StrategyPosition.Rows[0].Field <string>("TickerHead");
                        PriceRow["IsAutoSpreaderQ"] = true;
                        PriceTable.Rows.Add(PriceRow);
                    }
                    else
                    {
                        ButterflyLogger.Log("Check " + Alias + " ! Position may be incorrect.");
                    }
                }


                SpreadList = SpreadList.Distinct().ToList();

                SpreadTable = new DataTable();
                SpreadTable.Columns.Add("Ticker", typeof(string));
                SpreadTable.Columns.Add("IsSpreadQ", typeof(bool));

                for (int i = 0; i < SpreadList.Count; i++)
                {
                    DataRow SpreadRow = SpreadTable.NewRow();
                    SpreadRow["Ticker"]    = SpreadList[i];
                    SpreadRow["IsSpreadQ"] = true;
                    SpreadTable.Rows.Add(SpreadRow);

                    DataRow PriceRow = PriceTable.NewRow();
                    PriceRow["Ticker"] = SpreadList[i];
                    string[] SpreadAsArray = SpreadList[i].Split(new char[] { '-' });
                    PriceRow["TickerHead"]      = ContractUtilities.ContractMetaInfo.GetContractSpecs(SpreadAsArray[0]).tickerHead;
                    PriceRow["IsAutoSpreaderQ"] = false;
                    PriceTable.Rows.Add(PriceRow);
                }
            }



            PriceTableSymbols = DataAnalysis.DataTableFunctions.GetColumnAsList <string>(dataTableInput: PriceTable, columnName: "Ticker");


            TTAPISubs.TickerTable      = SpreadTable;
            TTAPISubs.AutoSpreaderList = AutoSpreaderList;
            TTAPISubs.AsuUpdateList    = new List <EventHandler <AuthenticationStatusUpdateEventArgs> > {
                TTAPISubs.StartASESubscriptions, TTAPISubs.startInstrumentLookupSubscriptionsFromDataTable
            };
            //TTAPISubs.AsuUpdateList = new List<EventHandler<AuthenticationStatusUpdateEventArgs>> {TTAPISubs.startInstrumentLookupSubscriptionsFromDataTable };
            TTAPISubs.ilsUpdateList = new List <EventHandler <InstrumentLookupSubscriptionEventArgs> > {
                TTAPISubs.startPriceSubscriptions, TTAPISubs.startTradeSubscriptions
            };
            //TTAPISubs.ilsUpdateList = new List<EventHandler<InstrumentLookupSubscriptionEventArgs>> { TTAPISubs.startPriceSubscriptions};
            TTAPISubs.priceUpdatedEventHandler = m_ps_FieldsUpdated;
            TTAPISubs.orderFilledEventHandler  = m_ts_OrderFilled;
        }
Esempio n. 2
0
        public Algo(string u, string p)
        {
            m_username = u;
            m_password = p;

            NumBets    = 3;
            MaxBetSize = 700;

            connection = new mysql();
            conn       = connection.conn;

            string       OutputFolder = TA.DirectoryNames.GetDirectoryName("daily");
            StreamWriter LogFile      = new StreamWriter(OutputFolder + "/IFS.txt", true);

            IFSLogger = new Logger(LogFile);

            DateTime ReportDate = CalendarUtilities.BusinessDays.GetBusinessDayShifted(shiftInDays: -1);
            DateTime TodayDate  = DateTime.Now.Date;

            IFSLogger.SW.WriteLine();
            IFSLogger.Log("NOTES FOR " + TodayDate.ToString("MM/dd/yyyy"));
            IFSLogger.Log(new String('-', 20));

            string DirectoryName      = TA.DirectoryNames.GetDirectoryName(ext: "ifsOutput");
            string DirectoryExtension = TA.DirectoryNames.GetDirectoryExtension(directoryDate: ReportDate);

            DataSet   PythonOutput = IOUtilities.ExcelDataReader.LoadFile(DirectoryName + "/" + DirectoryExtension + "/ifs.xlsx");
            DataTable IfsSheet     = PythonOutput.Tables["all"];

            TradeTimer          = new System.Timers.Timer();
            TradeTimer.Elapsed += new ElapsedEventHandler(PeriodicCall);
            TradeTimer.Interval = 30000;
            // And start it
            TradeTimer.Enabled = true;

            DataColumn ExistingPositionColumn = new DataColumn("ExistingPosition", typeof(int));

            ExistingPositionColumn.DefaultValue = 0;
            IfsSheet.Columns.Add(ExistingPositionColumn);

            DataColumn ExistingPositionAbsColumn = new DataColumn("ExistingPositionAbs", typeof(int));

            ExistingPositionAbsColumn.DefaultValue = 0;
            IfsSheet.Columns.Add(ExistingPositionAbsColumn);

            IfsSheet.Columns.Add("Alias", typeof(string));

            AutoSpreaderList       = new List <ttapiUtils.AutoSpreader>();
            AutoSpreaderDictionary = new Dictionary <string, ttapiUtils.AutoSpreader>();

            SummaryTable = new DataTable();
            SummaryTable.Columns.Add("Ticker", typeof(string));
            SummaryTable.Columns.Add("TickerHead", typeof(string));
            SummaryTable.Columns.Add("Tag", typeof(string));
            SummaryTable.Columns.Add("Alias", typeof(string));
            SummaryTable.Columns.Add("DescriptionString", typeof(string));
            SummaryTable.Columns.Add("Settle", typeof(decimal));
            SummaryTable.Columns.Add("Bid", typeof(double));
            SummaryTable.Columns.Add("Ask", typeof(double));
            SummaryTable.Columns.Add("Mid", typeof(double));
            SummaryTable.Columns.Add("MidConverted", typeof(double));
            SummaryTable.Columns.Add("SuggestedSize", typeof(int));
            SummaryTable.Columns.Add("WorkingPosition", typeof(int));
            DataColumn ExistingPositionColumn2 = new DataColumn("ExistingPosition", typeof(int));

            ExistingPositionColumn2.DefaultValue = 0;
            SummaryTable.Columns.Add(ExistingPositionColumn2);

            DataColumn ExistingPositionTickerHeadColumn = new DataColumn("ExistingPositionTickerHead", typeof(int));

            ExistingPositionTickerHeadColumn.DefaultValue = 0;
            SummaryTable.Columns.Add(ExistingPositionTickerHeadColumn);

            DataColumn ValidPriceColumn = new DataColumn("ValidPrice", typeof(bool));

            ValidPriceColumn.DefaultValue = false;
            SummaryTable.Columns.Add(ValidPriceColumn);

            SummaryTable.Columns.Add("Mean", typeof(double));
            SummaryTable.Columns.Add("Std", typeof(double));

            List <string> OpenStrategyList = TA.Strategy.GetFilteredOpenStrategyList(asOfDate: TodayDate, conn: conn, strategyClass: "ifs");

            for (int i = 0; i < OpenStrategyList.Count; i++)
            {
                StrategyUtilities.PositionManagerOutput PositionManagerOut = PositionManager.GetIfsPosition(alias: OpenStrategyList[i], asOfDate: TodayDate, conn: conn);

                if (PositionManagerOut.CorrectPositionQ)
                {
                    string SelectString = "contract1='" + PositionManagerOut.SortedPosition.Rows[0].Field <string>("Ticker") + "' and contract2='" +
                                          PositionManagerOut.SortedPosition.Rows[1].Field <string>("Ticker") + "'";

                    if (PositionManagerOut.SortedPosition.Rows.Count == 3)
                    {
                        SelectString = SelectString + " and contract3='" + PositionManagerOut.SortedPosition.Rows[2].Field <string>("Ticker") + "'";
                    }

                    DataRow Row = IfsSheet.Select(SelectString)[0];
                    Row["ExistingPosition"]    = Math.Round(PositionManagerOut.Scale);
                    Row["ExistingPositionAbs"] = Math.Abs(PositionManagerOut.Scale);
                    Row["Alias"] = OpenStrategyList[i];
                }
                else
                {
                    IFSLogger.Log("Check " + OpenStrategyList[i] + " ! Position may be incorrect.");
                }
            }

            DataTable newDataTable = IfsSheet.AsEnumerable()
                                     .OrderBy(r => r.Field <string>("spread_description"))
                                     .ThenByDescending(r => r.Field <double>("min_volume"))
                                     .ThenByDescending(r => r.Field <int>("ExistingPositionAbs"))
                                     .CopyToDataTable();

            DataRow[] ExistingPositions = IfsSheet.Select("ExistingPositionAbs>0");

            LiquidSpreads = newDataTable.AsEnumerable().GroupBy(r => r["spread_description"]).Select(w => w.First()).CopyToDataTable();

            LiquidSpreads = LiquidSpreads.Select("upside<" + MaxBetSize).CopyToDataTable();
            LiquidSpreads = LiquidSpreads.Select("spread_description='C_W' or spread_description='W_KW' or spread_description='S_BO_SM'").CopyToDataTable();

            foreach (DataRow item in ExistingPositions)
            {
                LiquidSpreads.ImportRow(item);
            }

            LiquidSpreads = LiquidSpreads.AsEnumerable().GroupBy(r => r["ticker"]).Select(w => w.First()).CopyToDataTable();

            for (int i = 0; i < LiquidSpreads.Rows.Count; i++)
            {
                List <string> TickerList = new List <string> {
                    LiquidSpreads.Rows[i].Field <string>("Contract1"), LiquidSpreads.Rows[i].Field <string>("Contract2"), LiquidSpreads.Rows[i].Field <string>("Contract3")
                };
                TickerList.RemoveAll(item => item == null);
                AutoSpreaderList.Add(new ttapiUtils.AutoSpreader(dbTickerList: TickerList, payUpTicks: 2));

                AutoSpreaderDictionary.Add(AutoSpreaderList[i].AutoSpreaderName, AutoSpreaderList[i]);

                DataRow Row = SummaryTable.NewRow();
                Row["Ticker"]     = AutoSpreaderList[i].AutoSpreaderName;
                Row["TickerHead"] = LiquidSpreads.Rows[i].Field <string>("spread_description");
                Row["Tag"]        = "ifs_" + i.ToString();

                if (LiquidSpreads.Rows[i].Field <int>("ExistingPositionAbs") != 0)
                {
                    Row["Alias"]            = LiquidSpreads.Rows[i].Field <string>("alias");
                    Row["ExistingPosition"] = LiquidSpreads.Rows[i].Field <int>("ExistingPosition");
                }
                else
                {
                    Row["Alias"] = LiquidSpreads.Rows[i].Field <string>("spread_description") + "_ifs_" + DateTime.Now.ToString("MMM-yyyy");
                }

                Row["DescriptionString"] = "strategy_class=ifs&betsize=" + MaxBetSize.ToString();
                Row["WorkingPosition"]   = 0;
                Row["Settle"]            = LiquidSpreads.Rows[i].Field <double>("settle");
                Row["Mean"]          = LiquidSpreads.Rows[i].Field <double>("mean10");
                Row["Std"]           = LiquidSpreads.Rows[i].Field <double>("std10");
                Row["SuggestedSize"] = Math.Min(10, Math.Round(2 * MaxBetSize / (LiquidSpreads.Rows[i].Field <double>("upside") + Math.Abs(LiquidSpreads.Rows[i].Field <double>("downside")))));

                SummaryTable.Rows.Add(Row);
            }

            List <string> TickerHeadList = DataAnalysis.DataTableFunctions.GetColumnAsList <string>(dataTableInput: SummaryTable, columnName: "TickerHead", uniqueQ: true);

            foreach (string item in TickerHeadList)
            {
                DataRow[] RowList       = SummaryTable.Select("TickerHead='" + item + "'");
                int       TotalPosition = 0;

                foreach (DataRow Row in RowList)
                {
                    TotalPosition += Row.Field <int>("ExistingPosition");
                }

                foreach (DataRow Row in RowList)
                {
                    Row["ExistingPositionTickerHead"] = TotalPosition;
                }
            }


            ASENameList = SummaryTable.AsEnumerable().Select(x => x.Field <string>("Ticker")).ToList();
            TagList     = SummaryTable.AsEnumerable().Select(x => x.Field <string>("Tag")).ToList();

            TTAPISubs = new ttapiUtils.Subscription(m_username, m_password);
            TTAPISubs.AutoSpreaderList = AutoSpreaderList;
            TTAPISubs.AsuUpdateList    = new List <EventHandler <AuthenticationStatusUpdateEventArgs> > {
                TTAPISubs.StartASESubscriptions
            };
            TTAPISubs.priceUpdatedEventHandler = m_ps_FieldsUpdated;
            TTAPISubs.orderFilledEventHandler  = m_ts_OrderFilled;
            TTAPISubs.OrderDeletedEventHandler = OrderDeleted;
        }