/***********************************************
         *
         * Constructor
         *
         * ********************************************/

//        internal frmCloseTrade (frmPos pos, LogCtl log, AxTWSLib.AxTws axtws, List<LegData> Legs)
        internal frmCloseTrade(frmPos pos, LogCtl log, /*AxTWSLib.AxTws axtws,*/ List <LegData> Legs)
        {
            InitializeComponent();

//            m_axTws = axtws;
            //m_Legs = new SortableBindingList<LegData> (Legs);
            m_Legs = Legs;
            m_Pos  = pos;
            m_Log  = log;

            lbMissingRemotePosition.Visible = false;

            dgvCloseTrade.AutoGenerateColumns = false;
            dgvCloseTrade.DataSource          = m_Legs;

            dgvCloseTrade.RowsDefaultCellStyle.BackColor            = Color.Bisque;
            dgvCloseTrade.AlternatingRowsDefaultCellStyle.BackColor = Color.Beige;
            dgvCloseTrade.CellBorderStyle = DataGridViewCellBorderStyle.None;
            dgvCloseTrade.DefaultCellStyle.SelectionBackColor = Color.FromArgb(252, 150, 29);
            dgvCloseTrade.DefaultCellStyle.SelectionForeColor = Color.Black;

            CheckForValidPositions();

            FetchBidAskMarketData();
        }
Exemple #2
0
        internal frmBestStrangle(string ticker, frmPos pos, LogCtl log /*, AxTWSLib.AxTws axtws*/)
        {
            InitializeComponent();

            //           m_axTws = axtws;
            m_Pos    = pos;
            m_Log    = log;
            m_ticker = ticker;

            dgvBestStrangle.RowsDefaultCellStyle.BackColor            = Color.Bisque;
            dgvBestStrangle.AlternatingRowsDefaultCellStyle.BackColor = Color.Beige;
            dgvBestStrangle.CellBorderStyle = DataGridViewCellBorderStyle.None;

            {
                DataGridViewComboBoxColumn oc = (DataGridViewComboBoxColumn)dgvBestStrangle.Columns[colbsCALLPUT];
                oc.DataSource    = CallPutT.Choices();
                oc.DisplayMember = "Name";
                oc.ValueMember   = "Value";
            }
            {
                DataGridViewComboBoxColumn oc = (DataGridViewComboBoxColumn)dgvBestStrangle.Columns[colbsBUYSELL];
                oc.DataSource    = BuySellT.Choices();
                oc.DisplayMember = "Name";
                oc.ValueMember   = "Value";
            }
        }
        /***********************************************
         *
         * Constructor
         *
         * ********************************************/

        internal frmOpenTrade(frmPos pos, LogCtl log, /*AxTWSLib.AxTws axtws,*/ List <LegData> Legs)
        {
            InitializeComponent();

            //m_axTws = axtws;

            /*           m_Legs = Legs;
             *         m_Pos = pos;
             *         m_Log = log;
             *
             *         dgvOpenTrade.AutoGenerateColumns = false;
             *         dgvOpenTrade.DataSource = m_Legs;
             *
             *         dgvOpenTrade.RowsDefaultCellStyle.BackColor = Color.Bisque;
             *         dgvOpenTrade.AlternatingRowsDefaultCellStyle.BackColor = Color.Beige;
             *         dgvOpenTrade.CellBorderStyle = DataGridViewCellBorderStyle.None;
             *
             *         m_axTws.tickPrice += m_axTws_tickPrice;
             *         m_axTws.tickSize += m_axTws_tickSize;
             *         m_axTws.tickOptionComputation += m_axTws_tickOptionComputation;
             *         m_axTws.tickGeneric +=m_axTws_tickGeneric;
             *         m_axTws.tickString +=m_axTws_tickString;
             *         m_axTws.tickEFP += m_axTws_tickEFP;
             *         m_axTws.tickSnapshotEnd +=m_axTws_tickSnapshotEnd;
             *
             *
             *         FetchOpenTradeMarketData ();*/
        }
Exemple #4
0
 public StockInfoQueue(LogCtl log, EWrapperImpl Ib)
 {
     m_Log        = log;
     ib           = Ib;
     m_q          = new Queue <StockPars> ();
     cancellation = new CancellationTokenSource();
 }
Exemple #5
0
        /****************************
         *
         * Constructor
         *
         * *************************/

        public BestStrangleQueue(LogCtl log, /* AxTWSLib.AxTws axtws,*/ List <OptionInfo> options)
        {
            m_bAbort           = false;
            m_OutstandingCalls = 0;
            m_Log = log;
//            m_axTws = axtws;
            m_Options = options;
            m_Event   = new AutoResetEvent(true); // make sure set to go
            m_q       = new Queue <int> ();

            for (int index = 0; index < m_Options.Count; index++)
            {
                m_q.Enqueue(index);
            }
            m_thr = new Thread(new ThreadStart(this.FetchOptionData));
            m_thr.Start();
        }
Exemple #6
0
        /***********************************************************************
         *
         * Fetch Prices on LegData list
         *
         * ********************************************************************/

        public static Task <bool> FetchLastPrice(LogCtl log, SortableBindingList <LegData> leglist)
        {
            /*           int Cntr = leglist.Count;
             *
             *         log.Log (ErrorLevel.logINF, "FetchLastPrice: Calling FetchLastPrice");
             *
             *         PriceData[] prices = new PriceData[leglist.Count];
             *         for (int i = 0; i < leglist.Count; i++)
             *         {
             *             prices[i] = new PriceData ();
             *         }
             *
             *         System.Timers.Timer timer = new System.Timers.Timer ();
             *
             *         timer.AutoReset = false;
             *         timer.Interval = 5000;
             * //            timer.Interval = 30000;
             *
             *         var tcs = new TaskCompletionSource<bool> ();
             *
             *         var errhandler = default (AxTWSLib._DTwsEvents_errMsgEventHandler);
             *         var endhandler = default (AxTWSLib._DTwsEvents_tickSnapshotEndEventHandler);
             *         var pricehandler = default (AxTWSLib._DTwsEvents_tickPriceEventHandler);
             *         var optioncomputehandler = default (AxTWSLib._DTwsEvents_tickOptionComputationEventHandler);
             *         var generichandler = default (AxTWSLib._DTwsEvents_tickGenericEventHandler);
             *         var sizehander = default (AxTWSLib._DTwsEvents_tickSizeEventHandler);
             *         var timerhandler = default (System.Timers.ElapsedEventHandler);
             *
             *         errhandler = new AxTWSLib._DTwsEvents_errMsgEventHandler ((s, e) =>
             *         {
             *             if (e.id != -1)
             *             {
             *                 if ((e.id & 0xFFFF0000) == Utils.ibBETAPRICE)
             *                 {
             *                     e.id &= 0xFFFF;
             *                     log.Log (ErrorLevel.logERR, string.Format ("FetchLastPrice: error {0} {1}", leglist[e.id].Ticker, e.errorMsg));
             *
             *                     axTws.errMsg -= errhandler;
             *                     axTws.tickGeneric -= generichandler;
             *                     axTws.tickPrice -= pricehandler;
             *                     axTws.tickOptionComputation -= optioncomputehandler;
             *                     axTws.tickSnapshotEnd -= endhandler;
             *                     axTws.tickSize -= sizehander;
             *                     timer.Elapsed -= timerhandler;
             *                     timer.Stop ();
             *
             *                     for (int leg_no = 0; leg_no < leglist.Count; leg_no++)
             *                     {
             *                         axTws.cancelMktData (Utils.ibBETAPRICE | leg_no);
             *                     }
             *                     tcs.SetException (new Exception (e.errorMsg));
             *                 }
             *             }
             *             else
             *             {
             *                 log.Log (ErrorLevel.logERR, string.Format ("FetchLastPrice: error {0}", e.errorMsg));
             *             }
             *         });
             *
             *         pricehandler = new AxTWSLib._DTwsEvents_tickPriceEventHandler ((s, e) =>
             *         {
             *             if ((e.id & 0xFFFF0000) != Utils.ibBETAPRICE)
             *             {
             *                 return;
             *             }
             *             e.id &= 0xFFFF;
             *             log.Log (ErrorLevel.logINF, string.Format ("FetchLastPrice: axTws_tickPrice for {0} tickType:{1} {2} value: {3}", leglist[e.id].Ticker, e.tickType, TickType.Display (e.tickType), e.price));
             *
             *             int leg_no = e.id;
             *             PriceData p = prices[leg_no];
             *
             *             switch (e.tickType)
             *             {
             *                 case TickType.CLOSE:
             *                     p.Close = (float) e.price;
             *                     break;
             *
             *                 case TickType.BID:
             *                     p.Bid = (float) e.price;
             *                     break;
             *
             *                 case TickType.LAST:
             *                     p.Last = (float) e.price;
             *                     break;
             *
             *                 case TickType.ASK:
             *                     p.Ask = (float) e.price;
             *                     break;
             *
             *                 default:
             *                     break;
             *             }
             *         });
             *
             *         sizehander = new AxTWSLib._DTwsEvents_tickSizeEventHandler ((s, e) =>
             *         {
             *             if ((e.id & 0xFFFF0000) != Utils.ibBETAPRICE)
             *             {
             *                 return;
             *             }
             *             e.id &= 0xFFFF;
             *             log.Log (ErrorLevel.logINF, string.Format ("FetchLastPrice: axTws_tickSize for {0} tickType: {1} {2} value: {3}", leglist[e.id].Ticker, e.tickType, TickType.Display (e.tickType), e.size));
             *             //switch (e.tickType)
             *             //{
             *             //    case TickType.OPTION_PUT_OPEN_INTEREST:
             *             //        {
             *             //            e.id &= 0xFFFF;
             *             //            int s_no = e.id >> 8;
             *             //            int opt_no = e.id & 0xFF;
             *             //            StockAnal st = m_SelectedStocks[s_no];
             *             //            OptionInfo option = st.OptionChain[opt_no];
             *             //            if (option.Right == "P")
             *             //            {
             *             //                option.OpenInterest = e.size;
             *             //            }
             *             //        }
             *             //        break;
             *             //    case TickType.OPTION_CALL_OPEN_INTEREST:
             *             //        {
             *             //            e.id &= 0xFFFF;
             *             //            int s_no = e.id >> 8;
             *             //            int opt_no = e.id & 0xFF;
             *             //            StockAnal st = m_SelectedStocks[s_no];
             *             //            OptionInfo option = st.OptionChain[opt_no];
             *             //            if (option.Right == "C")
             *             //            {
             *             //                option.OpenInterest = e.size;
             *             //            }
             *             //        }
             *             //        break;
             *
             *             //    default:
             *             //        break;
             *             //}
             *         });
             *
             *         generichandler = new AxTWSLib._DTwsEvents_tickGenericEventHandler ((s, e) =>
             *         {
             *             if ((e.id & 0xFFFF0000) != Utils.ibBETAPRICE)
             *             {
             *                 return;
             *             }
             *             e.id &= 0xFFFF;
             *             log.Log (ErrorLevel.logINF, string.Format ("FetchLastPrice: axTws_tickGeneric for {0} tickType: {1} {2} value: {3}", leglist[e.id].Ticker, e.tickType, TickType.Display (e.tickType), e.value));
             *         });
             *
             *         optioncomputehandler = new AxTWSLib._DTwsEvents_tickOptionComputationEventHandler ((s, e) =>
             *         {
             *             if ((e.id & 0xFFFF0000) != Utils.ibBETAPRICE)
             *             {
             *                 return;
             *             }
             *             e.id &= 0xFFFF;
             *
             *             string szUndPrice = "Invalid";
             *             if (e.undPrice < double.MaxValue)
             *             {
             *                 szUndPrice = e.undPrice.ToString ("N3");
             *             }
             *             string szOptPrice = "Invalid";
             *             if (e.optPrice < double.MaxValue)
             *             {
             *                 szOptPrice = e.optPrice.ToString ("N3");
             *             }
             *
             *             log.Log (ErrorLevel.logINF, string.Format ("FetchLastPrice: axTws_tickOptionComputation for {0} ticktype: {1} {2} optPrice {3} undPrice {4} delta {5:F5}", leglist[e.id].Ticker, e.tickType, TickType.Display (e.tickType), szOptPrice, szUndPrice, e.delta));
             *
             *             if (e.optPrice == double.MaxValue)
             *             {
             *                 return; // ignore it
             *             }
             *
             *             PriceData p = prices[e.id];
             *
             *             switch (e.tickType)
             *             {
             *                 case TickType.MODEL_OPTION:
             *                     p.OptPrice = (float) e.optPrice;
             *                     break;
             *
             *                 case TickType.LAST_OPTION:
             *                     p.Last = (float) e.optPrice;
             *                     break;
             *
             *                 default:
             *                     return;
             *
             *             }
             *
             *
             *             p.Delta = e.delta;
             *         });
             *
             *         /* This won't be called since we aren't taking a snapshot
             * ------------------------------------------------------ */

            /*           endhandler = new AxTWSLib._DTwsEvents_tickSnapshotEndEventHandler ((s, e) =>
             *         {
             *             if ((e.reqId & 0xFFFF0000) != Utils.ibBETAPRICE)
             *             {
             *                 return;
             *             }
             *             e.reqId &= 0xFFFF;
             *             log.Log (ErrorLevel.logINF, string.Format ("FetchLastPrice: axTws_tickSnapshotEnd for {0}", leglist[e.reqId].Ticker));
             *
             *             if (--Cntr <= 0)
             *             {
             *                 axTws.errMsg -= errhandler;
             *                 axTws.tickGeneric -= generichandler;
             *                 axTws.tickPrice -= pricehandler;
             *                 axTws.tickOptionComputation -= optioncomputehandler;
             *                 axTws.tickSnapshotEnd -= endhandler;
             *                 axTws.tickSize -= sizehander;
             *                 timer.Elapsed -= timerhandler;
             *                 timer.Stop ();
             *
             *                 tcs.SetResult (true);
             *             }
             *         });
             *
             *         timerhandler = new System.Timers.ElapsedEventHandler ((s, e) =>
             *         {
             *             log.Log (ErrorLevel.logINF, string.Format ("FetchLastPrice: timer.ElapsedEventHandler. CUTTING SHORT"));
             *
             *             axTws.errMsg -= errhandler;
             *             axTws.tickGeneric -= generichandler;
             *             axTws.tickPrice -= pricehandler;
             *             axTws.tickOptionComputation -= optioncomputehandler;
             *             axTws.tickSnapshotEnd -= endhandler;
             *             axTws.tickSize -= sizehander;
             *             timer.Elapsed -= timerhandler;
             *
             *             for (int no = 0; no < leglist.Count; no++)
             *             {
             *                 axTws.cancelMktData (Utils.ibBETAPRICE | no);
             *             }
             *
             *             for (int i = 0; i < leglist.Count; i++)
             *             {
             *                 var p = prices[i];
             *                 var l = leglist[i];
             *
             *                 if (p.Last != null)
             *                 {
             *                     l.LastPrice = p.Last;
             *                 }
             *                 else if (p.Close != null)
             *                 {
             *                     l.LastPrice = p.Close;
             *                 }
             *                 else if (p.Ask >= 0.0 && p.Bid >= 0.0)
             *                 {
             *                     l.LastPrice = (p.Ask + p.Bid) / 2.0;
             *                 }
             *                 else if (p.OptPrice != null)
             *                 {
             *                     l.LastPrice = p.OptPrice;
             *                 }
             *             }
             *             tcs.SetResult (true);
             *         });
             *
             *         axTws.errMsg += errhandler;
             *         axTws.tickGeneric += generichandler;
             *         axTws.tickPrice += pricehandler;
             *         axTws.tickOptionComputation += optioncomputehandler;
             *         axTws.tickSnapshotEnd += endhandler;
             *         timer.Elapsed += timerhandler;
             *         axTws.tickSize += sizehander;
             *
             *         timer.Start ();
             *
             *         /* Don't exceed 100
             * ---------------- */
            /*
             *          if (Cntr > 96)
             *          {
             *              log.Log (ErrorLevel.logERR, string.Format ("FetchLastPrice: No. in option chain {0} reduced to 96", Cntr));
             *              Cntr = 96;
             *          }
             *
             *          for (int index = 0; index < Cntr; index++)
             *          //for (int index = 0; index < 2; index++ )
             *          {
             *              var leg = leglist[index];
             *
             *              IContract contract = axTws.createContract ();
             *
             *              contract.symbol = "";
             *
             *              if (leg.Equity == EquityType.Stock)
             *              {
             *                  contract.secType = "STK";
             *                  contract.symbol = leg.Ticker;
             *                  contract.currency = "USD";
             *                  contract.exchange = leg.Exchange;
             *                  //contract.conId = (int) leg.ConId;
             *                  contract.localSymbol = leg.LocalSymbol;
             *              }
             *              else if (leg.Equity == EquityType.Option)
             *              {
             *                  contract.secType = "OPT";
             *                  contract.exchange = "SMART";
             *                  //contract.conId = (int) leg.ConId;
             *                  contract.localSymbol = leg.LocalSymbol;
             *              }
             *              else if (leg.Equity == EquityType.Future)
             *              {
             *                  contract.secType = "FUT";
             *                  contract.exchange = leg.Exchange;
             *                  contract.currency = "USD";
             *                  contract.localSymbol = leg.LocalSymbol;
             *              }
             *              else if (leg.Equity == EquityType.FutOpt)
             *              {
             *                  contract.secType = "FOP";
             *                  contract.exchange = leg.Exchange;
             *                  contract.currency = "USD";
             *                  contract.localSymbol = leg.LocalSymbol;
             *              }
             *              else if (leg.Equity == EquityType.Index)
             *              {
             *                  contract.secType = "IND";
             *                  contract.exchange = leg.Exchange;
             *                  contract.currency = "USD";
             *                  contract.localSymbol = leg.LocalSymbol;
             *              }
             *              else
             *              {
             *                  throw new Exception (string.Format ("One of the legs [{0}] has a bad EquityType.", leg.Ticker));
             *              }
             *
             *              //axTws.reqMktDataEx (Utils.ibDATA | index, contract, "", 1, null);
             *              axTws.reqMktDataEx (Utils.ibBETAPRICE | index, contract, "", 0, null);
             *              //axTws.reqMktDataEx (Constants.ANALYZE_OPTIONS_MARKET_DATA | ((stock_no << 8) + option_no), contract, "100, 101, 104, 106", 0, null);
             *          }
             *          return tcs.Task;*/
            return(null); /*remove later*/
        }
Exemple #7
0
 public EWrapperImpl(LogCtl l)
 {
     log          = l;
     Signal       = new EReaderMonitorSignal();
     clientSocket = new EClientSocket(this, Signal);
 }
Exemple #8
0
 public frmAddFuture(LogCtl log)
 {
     m_Log = log;
     InitializeComponent();
 }