Пример #1
0
    def _get_trade_limit_object_from_isd_key(
            self,
            isd_key: instrumentStrategyKeyAndDays) -> tradeLimit:
            instrument_strategy = instrumentStrategy.from_key(isd_key.instrument_strategy_key)
            period_days = isd_key.period_days

            return self._get_trade_limit_object(instrument_strategy, period_days)
Пример #2
0
    def from_dict(tradeLimit, trade_limit_dict):
        ## new style
        instrument_strategy_key = trade_limit_dict.pop(
            'instrument_strategy_key')
        instrument_strategy = instrumentStrategy.from_key(
            instrument_strategy_key)
        trade_limit_dict['instrument_strategy'] = instrument_strategy

        return tradeLimit(**trade_limit_dict)
Пример #3
0
 def _delete_old_style_data(self, instrument_strategy_key: str,
                            period_days: int):
     instrument_strategy = instrumentStrategy.from_key(
         instrument_strategy_key)
     dict_of_keys = {
         LEGACY_STRATEGY_KEY: instrument_strategy.strategy_name,
         LEGACY_INSTRUMENT_KEY: instrument_strategy.instrument_code,
         PERIOD_KEY: period_days,
     }
     self.mongo_data.delete_data_without_any_warning(dict_of_keys)
Пример #4
0
    def __init__(self,
                 *args,
                 fill: tradeQuantity = None,
                 filled_price: float = None,
                 fill_datetime: datetime.datetime = None,
                 locked: bool = False,
                 order_id: int = no_order_id,
                 parent: int = no_parent,
                 children: list = no_children,
                 active: bool = True,
                 order_type: instrumentOrderType = instrumentOrderType("best"),
                 limit_price: float = None,
                 limit_contract: str = None,
                 reference_datetime: datetime.datetime = None,
                 reference_price: float = None,
                 reference_contract: str = None,
                 generated_datetime: datetime.datetime = None,
                 manual_trade: bool = False,
                 roll_order: bool = False,
                 **kwargs_not_used):
        """

        :param args: Either a single argument 'strategy/instrument' str, or strategy, instrument; followed by trade
        i.e. instrumentOrder(strategy, instrument, trade,  **kwargs) or 'strategy/instrument', trade, type, **kwargs)

        :param fill: fill done so far, int
        :param locked: if locked an order can't be modified, bool
        :param order_id: ID given to orders once in the stack, do not use when creating order
        :param modification_status: NOT USED
        :param modification_quantity: NOT USED
        :param parent: int, order ID of parent order in upward stack
        :param children: list of int, order IDs of child orders in downward stack
        :param active: bool, inactive orders have been filled or cancelled
        :param order_type: str, type of execution required
        :param limit_price: float, limit orders only
        :param limit_contract: YYYYMM string, contract that limit price references
        :param reference_price: float, used for execution calculations
        :param reference_contract: YYYYMM string, contract that relates to reference price
        :param filled_price: float, used for execution calculations and p&l
        :param reference_datetime: datetime, when reference price captured
        :param fill_datetime: datetime used for p&l
        :param generated_datetime: when order generated
        :param manual_trade: bool, was trade iniated manually
        :param roll_order: bool, is this a roll order

        """
        """

        :param trade: float
        :param args: Either 2: strategy, instrument; or 1: instrumentTradeableObject
        :param type: str
        """
        if len(args) == 2:
            tradeable_object = instrumentStrategy.from_key(args[0])
            trade = args[1]
        else:
            strategy = args[0]
            instrument = args[1]
            trade = args[2]
            tradeable_object = instrumentStrategy(strategy, instrument)

        if generated_datetime is None:
            generated_datetime = datetime.datetime.now()

        order_info = dict(
            limit_contract=limit_contract,
            limit_price=limit_price,
            reference_contract=reference_contract,
            reference_price=reference_price,
            manual_trade=manual_trade,
            roll_order=roll_order,
            reference_datetime=reference_datetime,
            generated_datetime=generated_datetime,
        )

        super().__init__(tradeable_object,
                         trade=trade,
                         fill=fill,
                         filled_price=filled_price,
                         fill_datetime=fill_datetime,
                         locked=locked,
                         order_id=order_id,
                         parent=parent,
                         children=children,
                         active=active,
                         order_type=order_type,
                         **order_info)