Beispiel #1
0
def enter_manual_instrument_order(data):
    strategy_name = get_valid_strategy_name_from_user(data=data,
                                                      source="positions")
    instrument_code = get_valid_instrument_code_from_user(data)
    qty = get_and_convert("Quantity (-ve for sell, +ve for buy?)",
                          type_expected=int,
                          allow_default=False)
    order_type = input("Order type (one of %s)?" % str(possible_order_types))
    limit_price = get_and_convert(
        "Limit price? (if you put None you can still add one to the contract order)",
        type_expected=float,
        default_value=None,
        default_str="None",
    )
    if limit_price is None:
        limit_contract = None
    else:
        print("Enter contractid that limit price is referenced to")
        _, contract_date = get_valid_instrument_code_and_contractid_from_user(
            data, instrument_code=instrument_code)
        limit_contract = contract_date

    instrument_order = instrumentOrder(
        strategy_name,
        instrument_code,
        qty,
        order_type=order_type,
        limit_price=limit_price,
        limit_contract=limit_contract,
        manual_trade=True,
        roll_order=False,
    )

    return instrument_order
def enter_manual_contract_order(data, instrument_order):
    strategy_name = instrument_order.strategy_name
    instrument_code = instrument_order.instrument_code
    qty = instrument_order.trade

    leg_count = get_and_convert("How many legs?", type_expected=int, default_value=1)
    contract_id_list = []
    for leg_idx in range(leg_count):
        print("Choose contract for leg %d" % leg_idx)
        _, contract_date = get_valid_instrument_code_and_contractid_from_user(
            data, instrument_code=instrument_code
        )
        contract_id_list.append(contract_date)

    trade_qty_list = []
    for trade_idx in range(leg_count):
        trade_qty = get_and_convert(
            "Enter quantity for leg %d" % trade_idx,
            type_expected=int,
            allow_default=False,
        )
        trade_qty_list.append(trade_qty)

    if sum(trade_qty_list) != sum(qty):
        print(
            "Sum of instrument quantity %s is different from sum of contract quantity %s"
            % (str(qty), str(trade_qty_list))
        )
        print("It's unlikely you meant to do this...")

    NO_ALGO = "None: allow system to allocate"
    algo_to_use = print_menu_of_values_and_get_response(
        list_of_algos, default_str=NO_ALGO
    )
    if algo_to_use == NO_ALGO:
        algo_to_use = ""

    limit_price = get_and_convert(
        "Limit price? (will override instrument order limit price, will be ignored by some algo types",
        type_expected=float,
        default_str="None",
        default_value=None,
    )

    order_type = map_instrument_order_type_to_contract_order_type(
        instrument_order.order_type
    )
    contract_order = contractOrder(
        strategy_name,
        instrument_code,
        contract_id_list,
        trade_qty_list,
        algo_to_use=algo_to_use,
        order_type=order_type,
        reference_price=None,
        limit_price=limit_price,
        manual_trade=True,
    )

    return contract_order
Beispiel #3
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)
Beispiel #4
0
def individual_prices(data):
    instrument_code, contract_date = get_valid_instrument_code_and_contractid_from_user(data)
    diag_prices = diagPrices(data)
    prices = diag_prices.get_prices_for_instrument_code_and_contract_date(instrument_code, contract_date)

    print(prices)

    return None
Beispiel #5
0
def view_contract_config(data):
    instrument_code, contract_id = get_valid_instrument_code_and_contractid_from_user(data)
    diag_contracts = diagContracts(data)
    contract_object = diag_contracts.get_contract_object(instrument_code, contract_id)
    contract_date = diag_contracts.get_contract_date_object_with_roll_parameters(instrument_code, contract_id)
    print(contract_object.as_dict())
    print(contract_date.roll_parameters)

    return None
def enter_manual_contract_order(data, instrument_order):
    strategy_name = instrument_order.strategy_name
    instrument_code = instrument_order.instrument_code
    qty = instrument_order.trade

    leg_count = get_and_convert("How many legs?",
                                type_expected=int,
                                default_value=1)
    contract_id_list = []
    for leg_idx in range(leg_count):
        print("Choose contract for leg %d" % leg_idx)
        _, contract_date = get_valid_instrument_code_and_contractid_from_user(
            data, instrument_code=instrument_code)
        contract_id_list.append(contract_date)

    trade_qty_list = []
    for trade_idx in range(leg_count):
        trade_qty = get_and_convert("Enter quantity for leg %d" % trade_idx,
                                    type_expected=int,
                                    allow_default=False)
        trade_qty_list.append(trade_qty)

    if sum(trade_qty_list) != sum(qty):
        print(
            "Sum of instrument quantity %s is different from sum of contract quantity %s"
            % (str(qty), str(trade_qty_list)))
        print("It's unlikely you meant to do this...")

    algo_to_use = get_and_convert(
        "Algo to use (Full function eg sysexecution.algos.algo_market.algo_market)",
        type_expected=str,
        default_str="None: Algo will be allocated automatically",
        default_value="")
    limit_price = get_and_convert(
        "Limit price? (will override instrument order limit price, will be ignored by some algo types",
        type_expected=float,
        default_str="None",
        default_value=None)

    contract_order = contractOrder(
        strategy_name,
        instrument_code,
        contract_id_list,
        trade_qty_list,
        algo_to_use=algo_to_use,
        reference_price=None,
        limit_price=limit_price,
        manual_trade=True,
    )

    return contract_order