private void btnConnect_Click(object sender, EventArgs e) { bool ret = client.ConnectToTWS(txtIP.Text, int.Parse(txtPort.Text)); if (ret) { MessageBox.Show("Connect to TWS success", "TWS Proxy"); } else { MessageBox.Show("Something wrong", "TWS Proxy", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
static void Main() { IB_Client client = new IB_Client(); bool ret = client.ConnectToTWS("127.0.0.1", 7496); if (ret) { Console.WriteLine("connect successful."); } //client = new IB_Client(); //client.ConnectToTWS("127.0.0.1", 7496); //client.DefaultAccout = "DU229332"; string acc_id = client.DefaultAccout; Console.WriteLine(acc_id); client.add("AAPL"); client.add("FOP.CL.201807.C.71", "NYMEX", "USD"); //client.add("EURUSD"); var es = client.get("FOP.CL.201807.C.71"); var ask = es.Ask; var bid = es.Bid; var ask_size = es.Ask_Size; var bid_size = es.Bid_Size; int a = 2; while (a-- > 1) { //client.BuyLimitOrder("AAPL", 1000, 170); //Console.ReadKey(); Thread.Sleep(1000); } Thread.Sleep(1000); //string str = client.wrapper.orderInfo; //Console.WriteLine(str); client.CancelAllOrders(); //client.wrapper.ClientSocket.reqPositions(); //Console.WriteLine(client.ReqPositions()); Thread.Sleep(1000); Console.WriteLine("Open Order Begin"); client.wrapper.ClientSocket.reqAllOpenOrders(); Thread.Sleep(20000); client.Disconnect(); Console.ReadKey(); }
public bool Connect(string host, int port = 7496) { bool ret = client.ConnectToTWS(host, Port: port); return(ret); }