Connect() public method

public Connect ( string host, int port, int clientId, bool extraAuth = false ) : void
host string
port int
clientId int
extraAuth bool
return void
Exemplo n.º 1
0
        public static int Main(string[] args)
        {
            Console.WriteLine("Thread {0}: Starting...", Thread.CurrentThread.ManagedThreadId);
            using (var ibClient = new IbClient())
            {
                try
                {
                    ProcessContractDetails(ibClient);

                    ibClient.Connect("127.0.0.1", 7496, 0);

                    //We can request the whole option's chain by giving a brief description of the contract
                    //i.e. we only specify symbol, currency, secType and exchange (SMART)
                    Contract optionContract = ContractSamples.getOptionForQuery();

                    var endContractDetailsTask = ibClient.Response.ContractDetailsEndAsync();
                    ibClient.Request.ReqContractDetails(1, optionContract);

                    endContractDetailsTask.Wait();
                    Console.WriteLine("Finished receiving all matching contracts.");
                    Thread.Sleep(1000);
                    Console.WriteLine("Disconnecting...");
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
            return 0;
        }
Exemplo n.º 2
0
        public static int Main(string[] args)
        {
            Console.WriteLine("Thread {0}: Starting...", Thread.CurrentThread.ManagedThreadId);
            using (var ibClient = new IbClient())
            {
                try
                {
                    // these methods replace the EWrapperImpl class so you only need to implement handlers for what you care about
                    ProcessErrors(ibClient);
                    ProcessTickPrices(ibClient);
                    ProcessTickSizes(ibClient);

                    Console.WriteLine("Connecting to IB...");
                    ibClient.Connect("127.0.0.1", 7496, 0);


                    var t = ibClient.Response.CurrentTimeAsync();
                    ibClient.Request.ReqCurrentTime();
                    t.Wait(); // get time from server synchronously by waiting on the Task to complete
                    Console.WriteLine("Thread {0}: Server time is {1}", Thread.CurrentThread.ManagedThreadId, t.Result);

                    // test IB methods asynchronously
                    TestIbMethods(ibClient);

                    Console.ReadLine();
                    Console.WriteLine("Disconnecting...");
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
            return 0;
        }