コード例 #1
0
ファイル: Form1.cs プロジェクト: dacoders77/tbr
        private void IbClient_TickPrice(IBSampleApp.messages.TickPriceMessage obj)            // ReqMktData. Get quote. Tick types https://interactivebrokers.github.io/tws-api/rtd_simple_syntax.html
        {
            char requestCode = obj.RequestId.ToString()[obj.RequestId.ToString().Length - 1]; // First char is the code. C# requests: 5 - fx, 6 - stock. PHP: 7 - stock


            // Tick types: Close - for FX quotes. DelayedCLose - for stock quotes
            //ListViewLog.AddRecord(this, "brokerListBox", "Form1.cs line 215", "IbClient_TickPrice. Price " + obj.Price + " requestId: " + obj.RequestId + " tick type: " + TickType.getField(obj.Field), "yellow");

            // FX quote. C# while executing a basket
            // When a fx quote is received, ExecuteBasketThread() checks it and requests a stock quote
            if (TickType.getField(obj.Field) == "close")             // bidPrice = -1. This value returned when market is closed. https://interactivebrokers.github.io/tws-api/md_receive.html
            {
                basket.assetForexQuote = obj.Price;
                ListViewLog.AddRecord(this, "brokerListBox", "Form1.cs line 210", "IbClient_TickPrice. FX Quote: " + obj.Price + " " + obj.RequestId, "yellow");

                basket.UpdateInfoJson(string.Format("FX quote successfully recevied. FX quote: {0}. RequestID: {1}", obj.Price, obj.RequestId), "fxQuoteRequest", "ok", obj.RequestId, "fx_request_id"); // Update json info feild in DB
                basket.addForexQuoteToDB(obj.RequestId, obj.Price);                                                                                                                                      // Update fx quote in the BD
            }


            // For stock. A request from PHP. While adding an asset to a basket
            // In this case we do not record this price to the DB. It is recorded from PHP
            if (TickType.getField(obj.Field) == "delayedLast" && requestCode.ToString() == "7")             // PHP. Stock quote request
            {
                ListViewLog.AddRecord(this, "brokerListBox", "Form1.cs line 221", "IbClient_TickPrice. PHP req. price: " + obj.Price + " reqId: " + obj.RequestId, "white");

                quoteResponse.symbolPrice = obj.Price;
                quoteResponse.symbolName  = apiManager.symbolPass;          // We have to store symbol name and basket number as apiManager fields. Symbol name is not returned with IbClient_TickPrice response as well as basket number. Then basket number will be returnet to php and passed as the parameter to Quote.php class where price field will be updated. Symbol name and basket number are the key
                quoteResponse.basketNum   = apiManager.basketNumber;        // Pass basket number to api manager. First basket number was assigned to a class field basketNumber of apiManager class

                foreach (var socket in allSockets.ToList())                 // Loop through all connections/connected clients and send each of them a message
                {
                    socket.Send(quoteResponse.ReturnJson());
                }
            }


            // C#. ApiManager stock quote request
            if (TickType.getField(obj.Field) == "delayedLast" && requestCode.ToString() == "6")
            {
                // Updte quote value in DB
                basket.UpdateStockQuoteValue(obj.RequestId, obj.Price, this);
                ListViewLog.AddRecord(this, "brokerListBox", "Form1.cs", "IbClient_TickPrice. C# 6 req. price: " + obj.Price + " " + obj.RequestId, "white");

                basket.UpdateInfoJson(string.Format("Stock quote successfully recevied. Stock quote: {0}. RequestID: {1}", obj.Price, obj.RequestId), "stockQuoteRequest", "ok", obj.RequestId, "quote_request_id");                 // Update json info feild in DB
            }
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: dacoders77/tfr_noform
        private void IbClient_TickPrice(IBSampleApp.messages.TickPriceMessage msg)         // reqMktData event. reqMarketData Request market data event
        {
            //ListViewLog.AddRecord(this, "brokerListBox", "Form1.cs", "TickPriceMessage. tick type: " + TickType.getField(msg.Field) + " price: " + msg.Price, "white");
            if (TickType.getField(msg.Field) == "delayedLast")
            {
                double calculatedVolume        = Settings.useFunds / (double)msg.Price;
                int    calculatedVolumeRounded = (int)Math.Floor(calculatedVolume);
                ListViewLog.AddRecord(this, "brokerListBox", "Form1.cs", "IbClient_TickPrice. Funds to use: " + Settings.useFunds + "$ Ticker: " + parser.contractParser.Symbol + " Price: " + msg.Price + " Calculated volume (not rounded): " + calculatedVolume + " Rounded: " + calculatedVolumeRounded, "white");
                Email.Send("Volume", "Funds to use: " + Settings.useFunds + "$ Ticker: " + parser.contractParser.Symbol + " Price: " + msg.Price + " Calculated volume (no round): " + calculatedVolume + " Rounded: " + calculatedVolumeRounded);


                // SEND ORDER GOES HERE (close orders is sent from parser when close signal is detected)

                apiManager.symbol    = parser.contractParser.Symbol;
                apiManager.volume    = calculatedVolumeRounded;
                apiManager.direction = "BUY";
                apiManager.PlaceOrder();
            }
        }