alexgolec / tda-api

A TD Ameritrade API client for Python. Includes historical data for equities and ETFs, options chains, streaming order book data, complex order construction, and more.
https://tda-api.readthedocs.io
MIT License
1.26k stars 338 forks source link

Feature Request: Return an "order" variable in the generated code when using `tda-order-codegen.py` command-line script #249

Open meltdown03 opened 3 years ago

meltdown03 commented 3 years ago

Currently, it prints code that just sets everything in the class OrderBuilder, not an instance of it. The code could return a variable called "order" (or something else) that can then be used to edit/place the order more easily. Example of current code:

from tda.orders.common import (
    Destination,
    OrderStrategyType,
    ComplexOrderStrategyType,
    Session,
    Duration,
    OptionInstruction,
    OrderType
)

OrderBuilder() \ 
    .set_complex_order_strategy_type(ComplexOrderStrategyType.VERTICAL) \
    .set_duration(Duration.DAY) \
    .set_order_strategy_type(OrderStrategyType.SINGLE) \
    .set_order_type(OrderType.NET_CREDIT) \
    .copy_price(1.2) \
    .set_quantity(1.0) \
    .set_requested_destination(Destination.AUTO) \
    .set_session(Session.NORMAL) \
    .add_option_leg(OptionInstruction.SELL_TO_OPEN, "SNAP_073021C80", 1.0) \
    .add_option_leg(OptionInstruction.BUY_TO_OPEN, "SNAP_073021C85", 1.0)

suggested output:

from tda.orders.generic import OrderBuilder
from tda.orders.common import (
    Destination,
    OrderStrategyType,
    ComplexOrderStrategyType,
    Session,
    Duration,
    OptionInstruction,
    OrderType
)

order = OrderBuilder() \    ### changed to set OrderBuilder instance named "order"
    .set_complex_order_strategy_type(ComplexOrderStrategyType.VERTICAL) \
    .set_duration(Duration.DAY) \
    .set_order_strategy_type(OrderStrategyType.SINGLE) \
    .set_order_type(OrderType.NET_CREDIT) \
    .copy_price(1.2) \
    .set_quantity(1.0) \
    .set_requested_destination(Destination.AUTO) \
    .set_session(Session.NORMAL) \
    .add_option_leg(OptionInstruction.SELL_TO_OPEN, "SNAP_073021C80", 1.0) \
    .add_option_leg(OptionInstruction.BUY_TO_OPEN, "SNAP_073021C85", 1.0)
meltdown03 commented 3 years ago

An alternative would be to have an optional command line argument for the name of the variable that defaults to "order" if none is entered