Пример #1
0
def manage_trade(data, broker_order_with_controls):
    log = broker_order_with_controls.order.log_with_attributes(data.log)
    data_broker = dataBroker(data)

    trade_open = True
    log.msg("Managing trade %s with market order" %
            str(broker_order_with_controls.order))
    while trade_open:
        if broker_order_with_controls.message_required(
                messaging_frequency=MESSAGING_FREQUENCY):
            file_log_report_market_order(log, broker_order_with_controls)

        order_completed = broker_order_with_controls.completed()
        order_timeout = (broker_order_with_controls.seconds_since_submission()
                         > ORDER_TIME_OUT)
        order_cancelled = data_broker.check_order_is_cancelled_given_control_object(
            broker_order_with_controls)
        if order_completed:
            log.msg("Trade completed")
            break

        if order_timeout:
            log.msg("Run out of time: cancelling")
            broker_order_with_controls = cancel_order(
                data, broker_order_with_controls)
            break

        if order_cancelled:
            log.warn("Order has been cancelled: not by algo!")
            break

    return broker_order_with_controls
Пример #2
0
def file_log_report(log, aggressive, broker_order_with_controls):
    limit_trade = broker_order_with_controls.order.order_type == "limit"
    if limit_trade:
        file_log_report_limit_order(log, aggressive,
                                    broker_order_with_controls)
    else:
        file_log_report_market_order(log, broker_order_with_controls)
Пример #3
0
def file_log_report(log, is_aggressive: bool,
                    broker_order_with_controls: orderWithControls):
    limit_trade = broker_order_with_controls.order.order_type == limit_order_type
    if limit_trade:
        file_log_report_limit_order(log, is_aggressive,
                                    broker_order_with_controls)
    else:
        file_log_report_market_order(log, broker_order_with_controls)
Пример #4
0
    def manage_live_trade(
            self, broker_order_with_controls: orderWithControls
    ) -> orderWithControls:
        log = broker_order_with_controls.order.log_with_attributes(
            self.data.log)
        data_broker = self.data_broker

        trade_open = True
        log.msg("Managing trade %s with market order" %
                str(broker_order_with_controls.order))
        while trade_open:
            log_message_required = broker_order_with_controls.message_required(
                messaging_frequency_seconds=MESSAGING_FREQUENCY)
            if log_message_required:
                file_log_report_market_order(log, broker_order_with_controls)

            is_order_completed = broker_order_with_controls.completed()
            is_order_timeout = (
                broker_order_with_controls.seconds_since_submission() >
                ORDER_TIME_OUT)
            is_order_cancelled = (
                data_broker.check_order_is_cancelled_given_control_object(
                    broker_order_with_controls))
            if is_order_completed:
                log.msg("Trade completed")
                break

            if is_order_timeout:
                log.msg("Run out of time to execute: cancelling")
                broker_order_with_controls = cancel_order(
                    self.data, broker_order_with_controls)
                break

            if is_order_cancelled:
                log.warn(
                    "Order has been cancelled apparently by broker: not by algo!"
                )
                break

        return broker_order_with_controls