【问题标题】:IBKR API buy fractional stocksIBKR API购买零碎股票
【发布时间】:2021-08-18 19:20:04
【问题描述】:

我正在使用 Visual Studio 设计一个使用 IBKR API 购买股票的软件。如果我购买整数股票,但我无法购买小数股票,它工作正常。

我找到了 order.CashQty 函数,但它不起作用..这是我用来购买的代码,当我尝试购买整数股票时它正在工作。你有什么建议吗?

public void send_order(string side)
{
    IBApi.Contract contract = new IBApi.Contract();
    contract.Symbol = Global_variable.stock_sel;
    contract.SecType = "STK";
    contract.Exchange = cbMarket.Text;
    contract.PrimaryExch = "ISLAND";
    contract.Currency = "USD";

    IBApi.Order order = new IBApi.Order();
    order.OrderId = order_id;
    order.Action = side;
    order.OrderType = cbOrderType.Text;

    //order.CashQty = 33.5; <-- maybe is this the way to buy fractionale share?
    order.TotalQuantity = 1;

    if (cbOrderType.Text == "STP")
    {
        order.AuxPrice = Convert.ToDouble(numPrice.Value);
    }

    order.DisplaySize = Convert.ToInt32(tbVisible.Text);
    order.OutsideRth = chkOutside.Checked;
    ibClient.ClientSocket.placeOrder(order_id, contract, order);

    order_id++;
    tbValid_Id.Text = Convert.ToString(order_id);
}

非常感谢!

【问题讨论】:

  • 根据forum discussion 的说法,IB 似乎不打算允许通过 API 进行部分交易。

标签: c# trading interactive-brokers


【解决方案1】:

我的程序代码,希望对你有帮助:

private void buyStock(string symbol)
    {
        // Create a new contract to specify the security we are searching for
        IBApi.Contract contract = new IBApi.Contract();

        // Set the underlying stock symbol from the cbSymbol combobox
        contract.Symbol = symbol.ToUpper();
        // 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";

        IBApi.Order order = new IBApi.Order();
        // gets the next order id from the text box
        order.OrderId = order_id;
        // gets the side of the order (BUY, or SELL)
        order.Action = "BUY";
        // gets order type from combobox market or limit order(MKT, or LMT)
        order.OrderType = "MKT";
        // number of shares from Quantity
        order.TotalQuantity = 400;
        // Value from limit price
        //order.LmtPrice = Convert.ToDouble(numPrice.Text);
        //

        //Visible shares to the market
        //  order.DisplaySize = Convert.ToInt32(tbVisible.Text);
        //order.OutsideRth = cbOutsideRTH.Checked;
        //order.OutsideRth = chkOutside.Checked;


        // Place the order
        ibClient.ClientSocket.placeOrder(order_id, contract, order);

        // increase the order id value
        order_id++;
    }

【讨论】:

  • 您对问题的order.CashQty 部分有任何答案吗?你的代码是如何解决问题的?
猜你喜欢
  • 2011-03-15
  • 1970-01-01
  • 2017-09-26
  • 2019-10-26
  • 2021-09-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多