Beispiel #1
0
def get_report_dates(data):
    end_date = get_datetime_input("End date for report?\n", allow_default=True)
    start_date = get_datetime_input("Start date for report? (SPACE to use an offset from end date)\n",
                                    allow_no_arg=True)
    if start_date is None:
        start_date = arg_not_supplied
        calendar_days = get_and_convert("Calendar days back from %s?" % str(end_date),
                                        type_expected=int, allow_default=True,
                                        default_value=1)

    else:
        calendar_days = arg_not_supplied

    return start_date, end_date, calendar_days
Beispiel #2
0
def generate_generic_manual_fill(data):
    stack = resolve_stack(data, exclude_instrument_stack=True)
    view_generic_stack(stack)
    order_id = get_and_convert("Enter order ID",
                               default_str="Cancel",
                               default_value="")
    if order_id == "":
        return None
    order = stack.get_order_with_id_from_stack(order_id)
    print("Order now %s" % str(order))
    # FIX ME HANDLE SPREAD ORDERS
    fill_qty = get_and_convert(
        "Quantity to fill (must be less than or equal to %s)" %
        str(order.trade),
        type_expected=int,
        allow_default=True,
        default_value=order.trade,
    )
    if isinstance(fill_qty, int):
        fill_qty = [fill_qty]
    filled_price = get_and_convert("Filled price",
                                   type_expected=float,
                                   allow_default=False)
    fill_datetime = get_datetime_input("Fill datetime", allow_default=True)

    stack.manual_fill_for_order_id(order_id,
                                   fill_qty,
                                   filled_price=filled_price,
                                   fill_datetime=fill_datetime)
    order = stack.get_order_with_id_from_stack(order_id)

    print("Order now %s" % str(order))
    print(
        "If stack process not running, your next job will be to pass fills upwards"
    )
Beispiel #3
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)
Beispiel #4
0
def get_order_pd(data, list_method = 'get_historic_instrument_orders_in_date_range',
                 getter_method = 'get_historic_instrument_order_from_order_id'):
    start_date = get_datetime_input("Start Date", allow_default = True)
    end_date = get_datetime_input("End Date", allow_default = True)

    data_orders = dataOrders(data)
    list_func = getattr(data_orders, list_method)
    getter_func  = getattr(data_orders, getter_method)

    order_id_list = list_func(start_date, end_date)
    order_list = [getter_func(id)
                  for id in order_id_list]
    order_list_object = listOfOrders(order_list)
    order_pd = order_list_object.as_pd()

    return order_pd
Beispiel #5
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)
def delete_capital_since_time(data: dataBlob):
    data_capital = dataCapital(data)

    start_date = get_datetime_input("Delete capital from when?")
    ans = input("Are you sure about this? Can't be undone Yes/<other for no>")
    if ans == "Yes":
        data_capital.total_capital_calculator.delete_recent_capital(
            start_date, are_you_sure=True)
def delete_capital_since_time(data_capital):
    start_date = get_datetime_input("Delete capital from when?")
    ans = input("Are you sure about this? Can't be undone Yes/<other for no>")
    if ans=="Yes":
        data_capital.total_capital_calculator.delete_recent_capital(start_date, are_you_sure=True)
    else:
        return failure

    return success
Beispiel #8
0
def generate_generic_manual_fill(data):
    stack = resolve_stack(data, exclude_instrument_stack=True)
    view_generic_stack(stack)
    order_id = get_and_convert("Enter order ID",
                               default_str="Cancel",
                               default_value="")
    if order_id == "":
        return None
    order = stack.get_order_with_id_from_stack(order_id)
    if order is missing_order:
        print("Order doesn't exist on stack")
        return None
    if len(order.trade) > 1:
        print(
            "Can't manually fill spread orders; delete and replace with legs")
        return None
    if not order.no_children():
        print(
            "Don't manually fill order with children: can cause problems! Manually fill the child instead"
        )
        return None
    print("Order now %s" % str(order))
    fill_qty = get_and_convert(
        "Quantity to fill (must be less than or equal to %s)" %
        str(order.trade),
        type_expected=int,
        allow_default=True,
        default_value=order.trade,
    )
    if isinstance(fill_qty, int):
        fill_qty = [fill_qty]
    filled_price = get_and_convert("Filled price",
                                   type_expected=float,
                                   allow_default=False)
    fill_datetime = get_datetime_input("Fill datetime", allow_default=True)

    order = stack.get_order_with_id_from_stack(order_id)

    order.fill_order(fill_qty=fill_qty,
                     filled_price=filled_price,
                     fill_datetime=fill_datetime)

    stack.mark_as_manual_fill_for_order_id(order_id)

    stack_handler = stackHandler()
    if type(order) is brokerOrder:
        ## pass up and change positions
        stack_handler.apply_broker_order_fills_to_database(order)
    else:
        stack_handler.apply_contract_order_fill_to_database(order)

    order = stack.get_order_with_id_from_stack(order_id)
    print("Order now %s" % str(order))
    print(
        "If stack process not running, your next job will be to pass fills upwards"
    )
Beispiel #9
0
def generate_manual_contract_fill(stack_handler):
    print(
        "Manually fill a contract order. Use only if no broker order has been generated."
    )
    order_id = get_and_convert("Enter contract order ID",
                               default_str="Cancel",
                               default_value="")
    if order_id == "":
        return None
    try:
        order = stack_handler.contract_stack.get_order_with_id_from_stack(
            order_id)
        print("Order now %s" % str(order))
        # FIX ME HANDLE SPREAD ORDERS
        fill_qty = get_and_convert(
            "Quantity to fill (must be less than or equal to %s)" %
            str(order.trade),
            type_expected=int,
            allow_default=True,
            default_value=order.trade)
        if type(fill_qty) is int:
            fill_qty = [fill_qty]
        filled_price = get_and_convert("Filled price",
                                       type_expected=float,
                                       allow_default=False)
        fill_datetime = get_datetime_input("Fill datetime", allow_default=True)

        stack_handler.contract_stack.manual_fill_for_contract_id(
            order_id,
            fill_qty,
            filled_price=filled_price,
            fill_datetime=fill_datetime)
        order = stack_handler.contract_stack.get_order_with_id_from_stack(
            order_id)

        print("Order now %s" % str(order))
        print(
            "If stack process not running, your next job will be to pass fills upwards"
        )

    except Exception as e:
        print("%s went wrong!" % e)