コード例 #1
0
        public RealtimeData()
        {
            Console.WriteLine("Start the TWS Api Connection");

            EWrapperImpl ibClient = new EWrapperImpl();

            ibClient.ClientSocket.eConnect("127.0.0.1", 7496, 1);

            Contract contract = new Contract()
            {
                Symbol   = "IBM",
                SecType  = "STK",
                Exchange = "SMART",
                Currency = "USD"
            };

            List <TagValue> mktDataOptions = new List <TagValue>();

            Console.WriteLine("QuoteRequest for made" + contract.Symbol);

            ibClient.ClientSocket.reqMktData(1, contract, "", false, mktDataOptions);
            Console.ReadKey(); // Key main thread active so that the reqMktData tread can remain open.

            Console.WriteLine("QuoteCancel for " + contract.Symbol);

            ibClient.ClientSocket.cancelMktData(1);

            ibClient.ClientSocket.eDisconnect();
        }
コード例 #2
0
        public HistoricalData()
        {
            string strEndDate    = "20160528 16:00:00";
            string strDuration   = "1 M";
            string strBarSize    = "1 Day";
            string strWhatToShow = "TRADES";

            EWrapperImpl ibClient = new EWrapperImpl();

            ibClient.ClientSocket.eConnect("127.0.0.1", 7496, 1);

            Contract contract = new Contract()
            {
                Symbol   = "IBM",
                SecType  = "STK",
                Exchange = "SMART",
                Currency = "USD"
            };

            List <TagValue> historicalDataOptions = new List <TagValue>();

            ibClient.ClientSocket.reqHistoricalData(1, contract, strEndDate, strDuration, strBarSize, strWhatToShow, 1, 1, historicalDataOptions);


            Console.ReadKey();
            ibClient.ClientSocket.eDisconnect();
        }
コード例 #3
0
        public AccountManager()
        {
            Console.WriteLine("Connecting to TWS Api to Fetch Account Details");

            EWrapperImpl ibClient = new EWrapperImpl();

            ibClient.ClientSocket.eConnect("127.0.0.1", 7496, 1);
            ibClient.ClientSocket.reqAccountUpdates(true, "U4193925");
        }
コード例 #4
0
        public SubmitOrder()
        {
            int iOrderId = 3011;
            int giOrderId;

            EWrapperImpl ibClient = new EWrapperImpl();

            ibClient.ClientSocket.eConnect("127.0.01", 7496, 1);

            Contract contract = new Contract()
            {
                Symbol   = "IBM",
                SecType  = "STK",
                Exchange = "SMART",
                Currency = "USD"
            };

            /*
             * Order orderInfo = new Order()
             * {
             *  OrderId = iOrderId,
             *  Action = "BUY",
             *  OrderType = "LMT",
             *  TotalQuantity = 100,
             *  LmtPrice = 150.00,
             *  Tif = "DAY"
             * };*/

            Order limitBuy = new Order()
            {
                OrderId       = iOrderId + 1,
                Action        = "BUY",
                OrderType     = "LMT",
                TotalQuantity = 100,
                LmtPrice      = 150.00,
                Tif           = "DAY"
            };

            Order limitSell = new Order()
            {
                OrderId       = iOrderId + 2,
                Action        = "SELL",
                OrderType     = "LMT",
                TotalQuantity = 100,
                LmtPrice      = 160.00,
                Tif           = "DAY"
            };

            Console.WriteLine("Ready to place order. Press a Key");
            Console.ReadKey();

            ibClient.ClientSocket.placeOrder(iOrderId + 1, contract, limitBuy);
            ibClient.ClientSocket.placeOrder(iOrderId + 2, contract, limitSell);

            Console.WriteLine(Environment.NewLine + "Cancel order by pressing any key...");
            Console.ReadKey();

            ibClient.ClientSocket.cancelOrder(iOrderId + 1);
            ibClient.ClientSocket.cancelOrder(iOrderId + 2);

            ibClient.ClientSocket.eDisconnect();
        }