예제 #1
0
파일: common_test.py 프로젝트: yc0/tda-api
 def test_oco(self):
     self.assertFalse(has_diff({
         'orderStrategyType': 'OCO',
         'childOrderStrategies': [
             {'session': 'NORMAL'},
             {'duration': 'DAY'},
         ]
     }, one_cancels_other(
         OrderBuilder().set_session(Session.NORMAL),
         OrderBuilder().set_duration(Duration.DAY)).build()))
예제 #2
0
파일: common_test.py 프로젝트: yc0/tda-api
 def test_trigger(self):
     self.assertFalse(has_diff({
         'orderStrategyType': 'TRIGGER',
         'session': 'NORMAL',
         'childOrderStrategies': [
             {'duration': 'DAY'},
         ]
     }, first_triggers_second(
         OrderBuilder().set_session(Session.NORMAL),
         OrderBuilder().set_duration(Duration.DAY)).build()))
예제 #3
0
def one_cancels_other(order1, order2):
    '''
    If one of the orders is executed, immediately cancel the other.
    '''
    from tda.orders.generic import OrderBuilder

    return (OrderBuilder().set_order_strategy_type(
        OrderStrategyType.OCO).add_child_order_strategy(
            order1).add_child_order_strategy(order2))
예제 #4
0
파일: options.py 프로젝트: h00shi/tda-api
def option_buy_to_close_market(symbol, quantity):
    '''
    Returns a pre-filled :class:`~tda.orders.generic.OrderBuilder` for a
    buy-to-close market order.
    '''
    from tda.orders.common import Duration, OptionInstruction, OrderType
    from tda.orders.common import OrderStrategyType, Session

    return (OrderBuilder().set_session(Session.NORMAL).set_duration(
        Duration.DAY).set_order_type(OrderType.MARKET).set_order_strategy_type(
            OrderStrategyType.SINGLE).add_option_leg(
                OptionInstruction.BUY_TO_CLOSE, symbol, quantity))
예제 #5
0
def equity_buy_to_cover_market(symbol, quantity):
    '''
    Returns a pre-filled :class:`~tda.orders.generic.OrderBuilder` for an equity
    buy-to-cover market order.
    '''
    from tda.orders.common import Duration, EquityInstruction
    from tda.orders.common import OrderStrategyType, OrderType, Session
    from tda.orders.generic import OrderBuilder

    return (OrderBuilder().set_order_type(OrderType.MARKET).set_session(
        Session.NORMAL).set_duration(Duration.DAY).set_order_strategy_type(
            OrderStrategyType.SINGLE).add_equity_leg(
                EquityInstruction.BUY_TO_COVER, symbol, quantity))
예제 #6
0
def equity_sell_short_market(symbol, quantity):
    '''
    Returns a pre-filled :class:`~tda.orders.generic.OrderBuilder` for an equity
    short sell market order.
    '''
    from tda.orders.common import Duration, EquityInstruction
    from tda.orders.common import OrderStrategyType, OrderType, Session
    from tda.orders.generic import OrderBuilder

    return (OrderBuilder().set_order_type(OrderType.MARKET).set_session(
        Session.NORMAL).set_duration(Duration.DAY).set_order_strategy_type(
            OrderStrategyType.SINGLE).add_equity_leg(
                EquityInstruction.SELL_SHORT, symbol, quantity))
예제 #7
0
파일: options.py 프로젝트: h00shi/tda-api
def option_sell_to_open_limit(symbol, quantity, price):
    '''
    Returns a pre-filled :class:`~tda.orders.generic.OrderBuilder` for a
    sell-to-open limit order.
    '''
    from tda.orders.common import Duration, OptionInstruction, OrderType
    from tda.orders.common import OrderStrategyType, Session

    return (OrderBuilder().set_session(Session.NORMAL).set_duration(
        Duration.DAY).set_order_type(
            OrderType.LIMIT).set_price(price).set_order_strategy_type(
                OrderStrategyType.SINGLE).add_option_leg(
                    OptionInstruction.SELL_TO_OPEN, symbol, quantity))
예제 #8
0
def equity_sell_limit(symbol, quantity, price):
    '''
    Returns a pre-filled :class:`~tda.orders.generic.OrderBuilder` for an equity
    sell limit order.
    '''
    from tda.orders.common import Duration, EquityInstruction
    from tda.orders.common import OrderStrategyType, OrderType, Session
    from tda.orders.generic import OrderBuilder

    return (OrderBuilder().set_order_type(
        OrderType.LIMIT).set_price(price).set_session(
            Session.NORMAL).set_duration(Duration.DAY).set_order_strategy_type(
                OrderStrategyType.SINGLE).add_equity_leg(
                    EquityInstruction.SELL, symbol, quantity))
예제 #9
0
파일: options.py 프로젝트: mnylyb/tda-api
def __base_builder():
    from tda.orders.common import Duration, Session

    return (OrderBuilder().set_session(Session.NORMAL).set_duration(
        Duration.DAY))
예제 #10
0
import config  # stored in parent directory for security

token_path = 'token'
redirect_uri = "https://localhost"

DRIVER_PATH = "/home/hopper/chromedriver"
driver = webdriver.Chrome(DRIVER_PATH)

try:
    c = auth.client_from_token_file(token_path, config.api_key)
except FileNotFoundError:
    c = auth.client_from_login_flow(
        driver, config.api_key, redirect_uri, token_path
    )
time.sleep(2)


# print(c.place_order(config.tda_acct_num, equity_buy_market('SNDL', 1).set_duration(Duration.GOOD_TILL_CANCEL).set_session(Session.SEAMLESS).build()))

builder = OrderBuilder('SNDL', 1)
builder.set_instruction(OrderBuilder.instruction.BUY)
builder.set_order_type(OrderBuilder.OrderType.MARKET)
builder.set_duration(Duration.DAY)
builder.set_session(Session.NORMAL)

response = c.place_order(config.tda_acct_num, builder.build())

print(response)

time.sleep(2)
driver.quit()