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); }
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); }
/// <summary> /// connect to API /// подсоединиться к апи /// </summary> public void Connect() { if (_client == null) { _client = new IbClient(); _client.ConnectionFail += _ibClient_ConnectionFail; _client.ConnectionSucsess += _ibClient_ConnectionSucsess; _client.LogMessageEvent += SendLogMessage; _client.NewAccauntValue += _ibClient_NewAccauntValue; _client.NewPortfolioPosition += _ibClient_NewPortfolioPosition; _client.NewContractEvent += _ibClient_NewContractEvent; _client.NewMarketDepth += _ibClient_NewMarketDepth; _client.NewMyTradeEvent += _ibClient_NewMyTradeEvent; _client.NewOrderEvent += _ibClient_NewOrderEvent; _client.NewTradeEvent += AddTick; _client.CandlesUpdateEvent += _client_CandlesUpdateEvent; } _client.Connect( ((ServerParameterString)ServerParameters[0]).Value, ((ServerParameterInt)ServerParameters[1]).Value); }