studerw / td-ameritrade-client

TD Ameritrade Java Client
Apache License 2.0
69 stars 47 forks source link

How to place an option order #26

Closed vdzoba closed 3 years ago

vdzoba commented 4 years ago

Hi. I'm trying to place an option order. But, get errors from TD: Non 200 response: [400 - { "error" : "Following parameters are not allowed when placing an order: optionDeliverables" }] Here is how i submit an order. I do not set optionDeliverables. There is no setter for it. Order order = new Order(); order.setOrderType(OrderType.LIMIT); order.setSession(Session.NORMAL); order.setDuration(Duration.DAY); order.setPrice(new BigDecimal("1")); order.setOrderStrategyType(OrderStrategyType.SINGLE);

    OrderLegCollection olc = new OrderLegCollection();
    order.getOrderLegCollection().add(olc);

    olc.setInstruction(OrderLegCollection.Instruction.BUY_TO_OPEN);
    olc.setOrderLegType(OrderLegCollection.OrderLegType.OPTION);
    olc.setQuantity(defaultOptionQuantity);

    OptionInstrument instrument = new OptionInstrument();
    instrument.setSymbol(symbol);
    instrument.setAssetType(Instrument.AssetType.OPTION);
    olc.setInstrument(instrument);
studerw commented 4 years ago

Can you me in layman’s terms what you’re trying to buy? Are you just trying to buy a call contract?

On Fri, Aug 14, 2020, at 16:41, vdzoba wrote:

Hi. I'm trying to place an option order. But, get errors from TD: Non 200 response: [400 - { "error" : "Following parameters are not allowed when placing an order: optionDeliverables" }] Here is how i submit an order. I do not set optionDeliverables. There is no setter for it. Order order = new Order(); order.setOrderType(OrderType.LIMIT); order.setSession(Session.NORMAL); order.setDuration(Duration.DAY); order.setPrice(new BigDecimal("1")); order.setOrderStrategyType(OrderStrategyType.SINGLE);

` OrderLegCollection olc = new OrderLegCollection(); order.getOrderLegCollection().add(olc);

olc.setInstruction(OrderLegCollection.Instruction.BUY_TO_OPEN);
olc.setOrderLegType(OrderLegCollection.OrderLegType.OPTION);
olc.setQuantity(defaultOptionQuantity);

OptionInstrument instrument = new OptionInstrument();
instrument.setSymbol(symbol);
instrument.setAssetType(Instrument.AssetType.OPTION);
olc.setInstrument(instrument);

`

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/studerw/td-ameritrade-client/issues/26, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABQHJA5IAA3AGBIE57YC463SAWVSLANCNFSM4P74JPVQ.

vdzoba commented 4 years ago

Yes. I'm trying to buy a call. Looks like I need to properly set symbol, which includes date, strike price and type (call/put). Do I need to set anything else?

vdzoba commented 4 years ago

In Debug I just set to null optionDeliverables variable and order was successfully placed. But, there is no setter for this field. Can you introduce a setter there?

outstaller commented 4 years ago

I can confirm I see the same issue. optionDeliverables should be null when an order is placed. Worked around by: FieldUtils.writeField(instrument, "optionDeliverables", null, true);

but yeah, a setter is needed (and default to null).

studerw commented 3 years ago

Added setters to all the fields in OptionInstrument in case they're used in creating Option Orders (and must be set null or otherwise).