Exemplo n.º 1
0
def create_balance_trade(data):
    data_broker = dataBroker(data)
    default_account = data_broker.get_broker_account()

    print("Most likely use case here is that IB has closed one of your positions as close to the expiry")
    print("Or an edge case in which an order was submitted and then filled whilst you were not monitoring fills")
    print("Trades have to be attributed to a strategy (even roll trades)")
    strategy_name = get_valid_strategy_name_from_user()
    instrument_code, contract_date = get_valid_instrument_code_and_contractid_from_user(data)
    fill_qty = get_and_convert("Quantity ", type_expected=int, allow_default=False)
    filled_price = get_and_convert("Filled price", type_expected=float, allow_default=False)
    fill_datetime  =get_datetime_input("Fill datetime", allow_default=True)
    commission = get_and_convert("Commission", type_expected=float, allow_default=True, default_value=0.0)
    broker_account = get_and_convert("Account ID", type_expected=str, allow_default=True, default_value=default_account)

    broker_order = brokerOrder(strategy_name, instrument_code, contract_date, [fill_qty],
                               fill = [fill_qty],
                               algo_used="balance_trade",
                               order_type="balance_trade",
                               filled_price = filled_price,
                               fill_datetime = fill_datetime,
                               broker_account = broker_account,
                               commission = commission, manual_fill=True,
                               active = False)

    print(broker_order)
    ans = input("Are you sure? (Y/other)")
    if ans !="Y":
        return None

    stack_handler = stackHandlerCreateBalanceTrades(data)

    stack_handler.create_balance_trade(broker_order)
Exemplo n.º 2
0
def create_instrument_balance_trade(data):
    data_broker = dataBroker(data)
    default_account = data_broker.get_broker_account()

    print(
        "Use to fix breaks between instrument strategy and contract level positions"
    )
    strategy_name = get_valid_strategy_name_from_user(data=data)
    instrument_code = get_valid_instrument_code_from_user(data)
    fill_qty = get_and_convert("Quantity ",
                               type_expected=int,
                               allow_default=False)
    filled_price = get_and_convert("Filled price",
                                   type_expected=float,
                                   allow_default=False)
    fill_datetime = get_datetime_input("Fill datetime", allow_default=True)

    instrument_order = instrumentOrder(
        strategy_name,
        instrument_code,
        fill_qty,
        fill=fill_qty,
        order_type="balance_trade",
        filled_price=filled_price,
        fill_datetime=fill_datetime,
    )

    print(instrument_order)
    ans = input("Are you sure? (Y/other)")
    if ans != "Y":
        return None

    stack_handler = stackHandlerCreateBalanceTrades(data)

    stack_handler.create_balance_instrument_trade(instrument_order)
Exemplo n.º 3
0
def balance_trade(data, strategy_name: str, instrument_code: str,
                  fill_qty: int, filled_price: float):
    instrument_order = instrumentOrder(
        strategy_name,
        instrument_code,
        fill_qty,
        fill=fill_qty,
        order_type=transfer_order_type,
        filled_price=filled_price,
    )

    stack_handler = stackHandlerCreateBalanceTrades(data)

    stack_handler.create_balance_instrument_trade(instrument_order)