예제 #1
0
 def what_trade_is_possible(self, strategy_name, instrument_code,
                            proposed_trade):
     #FIXME DELETE
     instrument_strategy = instrumentStrategy(
         instrument_code=instrument_code, strategy_name=strategy_name)
     return self.what_trade_is_possible_for_strategy_instrument(
         instrument_strategy, proposed_trade)
예제 #2
0
 def get_cumulative_override_for_strategy_and_instrument(
         self, strategy_name, instrument_code):
     # FIXME REMOVE
     instrument_strategy = instrumentStrategy(
         strategy_name=strategy_name, instrument_code=instrument_code)
     return \
         self.get_cumulative_override_for_instrument_strategy(instrument_strategy)
예제 #3
0
    def cut_down_proposed_instrument_trade_okay(self, instrument_trade):

        strategy_name = instrument_trade.strategy_name
        instrument_code = instrument_trade.instrument_code
        proposed_trade = instrument_trade.trade.as_int()

        ## want to CUT DOWN rather than bool possible trades
        ## FIXME:
        ## underneath should be using tradeQuantity and position objects
        ## these will handle abs cases plus legs if required in future
        # :FIXME
        instrument_strategy = instrumentStrategy(
            strategy_name=strategy_name, instrument_code=instrument_code)

        max_trade_ok_against_instrument_strategy = \
            self.check_if_proposed_trade_okay_against_instrument_strategy_constraint(instrument_strategy,
                                                                                    proposed_trade)
        max_trade_ok_against_instrument = \
            self.check_if_proposed_trade_okay_against_instrument_constraint(instrument_code,
                                                                            proposed_trade)

        ## FIXME THIS IS UGLY WOULD BE BETTER IF DONE INSIDE TRADE SIZE OBJECT
        mini_max_trade = sign(proposed_trade) * \
                         min([abs(max_trade_ok_against_instrument),
                        abs(max_trade_ok_against_instrument_strategy)])

        instrument_trade = instrument_trade.replace_trade_only_use_for_unsubmitted_trades(
            mini_max_trade)

        return instrument_trade
예제 #4
0
 def update_optimal_position_for_strategy_and_instrument(
     self, strategy_name, instrument_code, position_entry
 ):
     #FIXME REMOVE
     self.update_optimal_position_for_instrument_strategy(
         instrumentStrategy(strategy_name=strategy_name, instrument_code=instrument_code),
         position_entry)
예제 #5
0
    def update_override_for_strategy_instrument(self, strategy_name,
                                                instrument_code, new_override):
        # FIXME REMOVE
        instrument_strategy = instrumentStrategy(
            strategy_name=strategy_name, instrument_code=instrument_code)

        self.update_override_for_instrument_strategy(instrument_strategy,
                                                     new_override)
예제 #6
0
 def get_current_position_for_strategy_and_instrument(
         self, strategy_name, instrument_code):
     #FIXME THINK ABOUT REMOVING
     instrument_strategy = instrumentStrategy(
         strategy_name=strategy_name, instrument_code=instrument_code)
     position = self.get_current_position_for_instrument_strategy(
         instrument_strategy)
     return position
예제 #7
0
    def update_instrument_strategy_limit_with_new_limit(
            self, strategy_name, instrument_code, period_days, new_limit):
        #FIXME DELETE REPLACE WITH '2'
        instrument_strategy = instrumentStrategy(
            strategy_name=strategy_name, instrument_code=instrument_code)

        self.update_instrument_strategy_limit_with_new_limit2(
            instrument_strategy, period_days, new_limit)
예제 #8
0
    def get_position_df_for_strategy_and_instrument(
        self, strategy_name:str, instrument_code:str
    ):
        #FIXME THINK ABOUT REMOVING
        instrument_strategy = instrumentStrategy(strategy_name=strategy_name, instrument_code=instrument_code)
        position_df = self.get_position_df_for_instrument_strategy_object(instrument_strategy)

        return position_df
예제 #9
0
    def get_current_optimal_position_for_strategy_and_instrument(
        self, strategy_name, instrument_code
    ):
        # FIX ME REMOVE
        instrument_strategy = instrumentStrategy(strategy_name=strategy_name,
                                                 instrument_code=instrument_code)

        return self.get_current_optimal_position_for_instrument_strategy(instrument_strategy)
예제 #10
0
    def set_abs_position_limit_for_strategy_instrument(self, strategy_name,
                                                       instrument_code,
                                                       new_position_limit):

        #FIXME DELETE
        instrument_strategy = instrumentStrategy(
            strategy_name=strategy_name, instrument_code=instrument_code)
        self.set_position_limit_for_instrument_strategy(
            instrument_strategy, new_position_limit)
예제 #11
0
    def get_tradeable_object_and_optimal_position(self, strategy_name,
                                                  instrument_code):
        optimal_position = (
            self.get_current_optimal_position_for_strategy_and_instrument(
                strategy_name, instrument_code))
        tradeable_object = instrumentStrategy(strategy_name, instrument_code)
        tradeable_object_and_optimal_position = tradeableObjectAndOptimalPosition(
            tradeable_object, optimal_position)

        return tradeable_object_and_optimal_position
예제 #12
0
def _from_trade_limit_dict_to_required_dict(trade_limit_dict: dict) -> dict:
    if INSTRUMENT_STRATEGY_KEY in trade_limit_dict.keys():
        ## NEW STYLE
        return trade_limit_dict

    ## OLD STYLE
    instrument_strategy = instrumentStrategy(
        instrument_code=trade_limit_dict.pop(LEGACY_INSTRUMENT_KEY),
        strategy_name=trade_limit_dict.pop(LEGACY_STRATEGY_KEY))
    trade_limit_dict[INSTRUMENT_STRATEGY_KEY] = instrument_strategy.key

    return trade_limit_dict
예제 #13
0
def _from_result_dict_to_isd(
        result_dict: dict) -> instrumentStrategyKeyAndDays:
    if INSTRUMENT_STRATEGY_KEY in result_dict.keys():
        ## NEW STYLE
        instrument_strategy_key = result_dict[INSTRUMENT_STRATEGY_KEY]
    else:
        ## LEGACY
        instrument_strategy = instrumentStrategy(
            strategy_name=result_dict[LEGACY_STRATEGY_KEY],
            instrument_code=result_dict[LEGACY_INSTRUMENT_KEY])
        instrument_strategy_key = instrument_strategy.key

    return instrumentStrategyKeyAndDays(instrument_strategy_key,
                                        result_dict[PERIOD_KEY])
예제 #14
0
def backup_strategy_position_data(data):
    strategy_list = get_list_of_strategies(data)
    instrument_list = (data.mongo_contract_position.
                       get_list_of_instruments_with_any_position())
    for strategy_name in strategy_list:
        for instrument_code in instrument_list:
            instrument_strategy = instrumentStrategy(
                strategy_name=strategy_name, instrument_code=instrument_code)
            mongo_data = data.mongo_strategy_position.get_position_as_df_for_instrument_strategy_object(
                instrument_strategy)
            if mongo_data is missing_data:
                continue
            data.csv_strategy_position.write_position_df_for_instrument_strategy(
                instrument_strategy, mongo_data)
            data.log.msg("Backed up %s %s strategy position data" %
                         (instrument_code, strategy_name))
예제 #15
0
    def get_all_instrument_strategies_with_limits(
            self) -> listOfInstrumentStrategies:

        dict_of_keys = {MARKER_KEY: MARKER_STRATEGY_INSTRUMENT}
        list_of_dicts = self.mongo_data.get_list_of_result_dicts_for_dict_keys(
            dict_of_keys)

        list_of_instrument_strategies = [
            instrumentStrategy(strategy_name=db_entry[STRATEGY_KEY],
                               instrument_code=db_entry[INSTRUMENT_KEY])
            for db_entry in list_of_dicts
        ]

        list_of_instrument_strategies = listOfInstrumentStrategies(
            list_of_instrument_strategies)

        return list_of_instrument_strategies
예제 #16
0
    def update_strategy_position_table_with_instrument_order(
        self, instrument_order, new_fill
    ):
        """
        Alter the strategy position table according to instrument order fill value

        :param instrument_order:
        :return:
        """

        # FIXME WOULD BE NICE IF COULD GET DIRECTLY FROM ORDER
        strategy_name = instrument_order.strategy_name
        instrument_code = instrument_order.instrument_code
        instrument_strategy = instrumentStrategy(strategy_name=strategy_name, instrument_code=instrument_code)

        current_position = self.diag_positions.get_current_position_for_instrument_strategy(instrument_strategy)
        trade_done = new_fill.as_int()
        if trade_done is missing_order:
            self.log.critical("Instrument orders can't be spread orders!")
            return failure

        new_position = current_position + trade_done

        self.data.db_strategy_position.update_position_for_instrument_strategy_object(
            instrument_strategy, new_position)

        self.log.msg(
            "Updated position of %s/%s from %d to %d because of trade %s %d"
            % (
                strategy_name,
                instrument_code,
                current_position,
                new_position,
                str(instrument_order),
                instrument_order.order_id,
            )
        )

        return success
예제 #17
0
 def reset_instrument_strategy_limit(self, strategy_name, instrument_code,
                                     period_days):
     #FIXME REPLACE WITH 2
     instrument_strategy = instrumentStrategy(
         strategy_name=strategy_name, instrument_code=instrument_code)
     self.reset_instrument_strategy_limit2(instrument_strategy, period_days)
예제 #18
0
def instrument_strategy_for_instrument_only(
        instrument_code) -> instrumentStrategy:
    return instrumentStrategy(strategy_name="",
                              instrument_code=instrument_code)
예제 #19
0
 def get_optimal_position_as_df_for_strategy_and_instrument(
     self, strategy_name: str, instrument_code: str
 ):
     # FIX ME REMOVE
     return self.get_optimal_position_as_df_for_instrument_strategy(instrumentStrategy(instrument_code=instrument_code, strategy_name=strategy_name))
예제 #20
0
 def remove_trade(self, strategy_name, instrument_code, trade):
     instrument_strategy = instrumentStrategy(
         strategy_name=strategy_name, instrument_code=instrument_code)
     self.remove_trade_for_instrument_strategy(instrument_strategy, trade)
예제 #21
0
 def add_trade(self, strategy_name, instrument_code, trade):
     #FIXME REMOVE
     instrument_strategy = instrumentStrategy(
         strategy_name=strategy_name, instrument_code=instrument_code)
     self.add_trade_for_instrument_strategy(instrument_strategy, trade)
예제 #22
0
 def delete_position_limit_for_strategy_instrument(self, strategy_name: str,
                                                   instrument_code: str):
     ## FIXME DELETE
     instrument_strategy = instrumentStrategy(
         strategy_name=strategy_name, instrument_code=instrument_code)
     self.delete_position_limit_for_instrument_strategy(instrument_strategy)
예제 #23
0
    def __init__(self, position: int, strategy_name: str, instrument_code: str):
        tradeable_object = instrumentStrategy(strategy_name, instrument_code)

        super().__init__(position, tradeable_object)