通过外部类将双倍合格

时间:2018-11-03 02:21:33

标签: c# api

请帮助,我是一个完全菜鸟。但是,我正在使用一些复杂的API。

我有外部课程:

namespace IB_CSharp_RealTime_WinForms_CS
{
    //! [ewrapperimpl]
    public class EWrapperImpl : EWrapper 
    {
...
//! [historicaldata]
        public virtual void historicalData(int reqId, string date, double open, double high, double low, double close, int volume, int count, double WAP, bool hasGaps)
        {
            Console.WriteLine("HistoricalData. "+reqId+" - Date: "+date+", Open: "+open+", High: "+high+", Low: "+low+", Close: "+close+", Volume: "+volume+", Count: "+count+", WAP: "+WAP+", HasGaps: "+hasGaps);
        }
...

我有一个表格

namespace IB_CSharp_RealTime_WinForms_CS
{
    public partial class Form1 : Form
    {
...

如何将我的外部课程的“双重高分”传递给我的表格? 预先谢谢你!

我的完整代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using System.Threading;     // Add this for multi-threading support
using IBApi;        // Add this for IB API Support

namespace IB_CSharp_RealTime_WinForms_CS
{
    public partial class Form1 : Form
    {
        // This delegate enables asynchronous calls for setting
        // the text property on a ListBox control.
        delegate void SetTextCallback(string text);

        public void AddListBoxItem(string text)
        {
            // See if a new invocation is required form a different thread
            if (this.lbData.InvokeRequired)
            {
                SetTextCallback d = new SetTextCallback(AddListBoxItem);
                this.Invoke(d, new object[] { text });
            }
            else
            {
                // Add the text string to the list box
                this.lbData.Items.Add(text);

            }
        }
               // Create the ibClient object to represent the connection
        // This will be used throughout the form
        IB_CSharp_RealTime_WinForms_CS.EWrapperImpl ibClient;
        private string tickerId;

        public Form1()
        {         


            InitializeComponent();

            // Instantiate the ibClient
            ibClient = new IB_CSharp_RealTime_WinForms_CS.EWrapperImpl();

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void btnConnect_Click(object sender, EventArgs e)
        {

            ibClient.ClientSocket.eConnect("", 7496, 0);

            var reader = new EReader(ibClient.ClientSocket, ibClient.Signal);
            reader.Start();
            new Thread(() => {
                while (ibClient.ClientSocket.IsConnected())
                {
                    ibClient.Signal.waitForSignal();
                    reader.processMsgs();
                }
            })
            { IsBackground = true }.Start();    

            while (ibClient.NextOrderId <= 0) { }

            // Set up the form object in the EWrapper
            ibClient.myform = (Form1)Application.OpenForms[0];
        }

        private void btnDisconnect_Click(object sender, EventArgs e)
        {

            // Disconnect from interactive Brokers
            ibClient.ClientSocket.eDisconnect();
        }

        private void btnStart_Click(object sender, EventArgs e)
        {

            // Create a new contract to specify the security we are searching for
            IBApi.Contract contract = new IBApi.Contract();
            // Create a new TagValueList object (for API version 9.71 and later) 
            List < IBApi.TagValue > mktDataOptions = new List<IBApi.TagValue>();

            // Set the underlying stock symbol from the tbSymbol text box
            contract.Symbol = tbSymbol.Text;
            // Set the Security type to STK for a Stock
            contract.SecType = "STK";
            // Use "SMART" as the general exchange
            contract.Exchange = "SMART";
            // Set the primary exchange (sometimes called Listing exchange)
            // Use either NYSE or ISLAND
            contract.PrimaryExch = "ISLAND";
            // Set the currency to USD
            contract.Currency = "USD";

            // Kick off the subscription for real-time data (add the mktDataOptions list for API v9.71)
            ibClient.ClientSocket.reqMktData(1, contract, "", false, mktDataOptions);
            // For API v9.72 and higher, add one more parameter for regulatory snapshot
            // ibClient.ClientSocket.reqMktData(1, contract, "", false, false, mktDataOptions);

        } // end btnStart_Click

        private void btnStop_Click(object sender, EventArgs e)
        {

            // Make the call to cancel the market data subscription
            ibClient.ClientSocket.cancelMktData(1);
        }

   }
}

我想要的是TextBox1.Text以显示“ high”的值。基本上,如果我可以学习如何传递该值,则可以使用它传递所有其他值。

0 个答案:

没有答案