예제 #1
0
    def iyo_result_to_mongo_db(coin_name: str, start_time: int, end_time: int):
        Global.configure_default_root_logging(should_log_to_file=False,
                                              log_level=logging.CRITICAL)
        SharedMongoClient.initialize(should_use_localhost_db=True)
        db_client = SharedMongoClient.instance()

        # convert epoch time to local_time and log
        local_st = Global.convert_epoch_to_local_datetime(start_time,
                                                          timezone="kr")
        local_et = Global.convert_epoch_to_local_datetime(end_time,
                                                          timezone="kr")

        # create combination of coin that is injected by validating if the exchange has that coin
        rfab_combi_list = Global.get_rfab_combination_tuples(coin_name)

        for _combi in rfab_combi_list:
            logging.critical(
                "[%s-%s-%s] IYO conducting -> start_time: %s, end_time: %s" %
                (coin_name.upper(), str(_combi[0]).upper(), str(
                    _combi[1]).upper(), local_st, local_et))

            # draw iyo_config for bal & factor_setting
            iyo_config = Global.read_iyo_setting_config(coin_name)

            settings = TradeSettingConfig.get_settings(
                mm1_name=_combi[0],
                mm2_name=_combi[1],
                target_currency=coin_name,
                start_time=start_time,
                end_time=end_time,
                division=iyo_config["division"],
                depth=iyo_config["depth"],
                consecution_time=iyo_config["consecution_time"],
                is_virtual_mm=True)
            # todo
            bal_factor_settings = TradeSettingConfig.get_bal_fact_settings(
                iyo_config["krw_seq_end"], iyo_config["coin_seq_end"])

            factor_settings = TradeSettingConfig.get_factor_settings(
                _combi[0], _combi[1], coin_name,
                iyo_config["max_trade_coin_end"], iyo_config["threshold_end"],
                iyo_config["appx_unit_coin_price"])

            try:
                iyo_result = IntegratedYieldOptimizer.run(
                    settings, bal_factor_settings, factor_settings)

                # finally save to mongoDB
                if len(iyo_result) > 0:
                    db_client["statistics"]["iyo"].insert_many(iyo_result)
                else:
                    logging.critical(
                        "There was no oppty!! Skipping to next combination!")
                    continue

            except TypeError as e:
                Global.send_to_slack_channel(
                    Global.SLACK_BOT_STATUS_URL,
                    "Something went wrong in IYO Schduler! >> %s" % e)
                pass
예제 #2
0
    def run_inner_or_outer_ocat(self, set_point_market: str,
                                target_currency: str, is_inner_ocat: bool):
        if is_inner_ocat:
            # create combination of coin that is injected by validating if the exchange has that coin
            logging.critical("Set Point Market is: [%s]" %
                             set_point_market.upper())
            inner_ocat_list = Global.get_inner_ocat_combination(
                set_point_market, target_currency)
            logging.critical("--------Conducting Inner OCAT--------")
            ocat_final_result = self.otc_all_combination_by_one_coin(
                target_currency, inner_ocat_list)

        elif not is_inner_ocat:
            logging.critical("--------Conducting Outer OCAT--------")
            ocat_final_result = []
            for outer_ocat_coin in list(Global.get_avail_coin_in_list()):
                logging.warning("Now conducting [%s]" %
                                outer_ocat_coin.upper())
                outer_ocat_list = Global.get_rfab_combination_tuples(
                    outer_ocat_coin)
                ocat_result = self.otc_all_combination_by_one_coin(
                    outer_ocat_coin, outer_ocat_list)
                ocat_final_result.extend(ocat_result)

            # save this setting for updating IYO setting in future ref
            self.ocat_final_result = ocat_final_result

        else:
            raise Exception("Please indicate if it is Inner OCAT or not")

        descending_order_result = OTCScheduler.sort_by_logest_oppty_time_to_lowest(
            ocat_final_result)
        top_ten_descend_order_result = descending_order_result[:10]

        for result in top_ten_descend_order_result:
            new_percent = (result["new"] / self.INITIATION_REWEIND_TIME) * 100
            rev_percent = (result["rev"] / self.INITIATION_REWEIND_TIME) * 100
            new_spread_strength = result["new_spread_ratio"] * 100
            rev_spread_strength = result["rev_spread_ratio"] * 100

            logging.warning(
                "[%s] NEW: %.2f%%, REV: %.2f%% // NEW_SPREAD_STRENGTH: %.2f%%, REV_SPREAD_STRENGTH: %.2f%%"
                % (result["combination"], new_percent, rev_percent,
                   new_spread_strength, rev_spread_strength))
예제 #3
0
    def otc_all_mm_comb_by_one_coin(coin_name: str, start_time: int,
                                    end_time: int) -> list:

        # create combination of coin that is injected by validating if the exchange has that coin
        rfab_combi_list = Global.get_rfab_combination_tuples(coin_name)

        all_comb_result_by_one_coin = []
        for _combi in rfab_combi_list:
            logging.critical(
                "[%s-%s-%s] OTC conducting -> start_time: %s, end_time: %s" %
                (coin_name.upper(), str(_combi[0]).upper(), str(
                    _combi[1]).upper(), start_time, end_time))

            # draw iyo_config for settings
            iyo_config = Global.read_iyo_setting_config(coin_name)

            settings = TradeSettingConfig.get_settings(
                mm1_name=_combi[0],
                mm2_name=_combi[1],
                target_currency=coin_name,
                start_time=start_time,
                end_time=end_time,
                division=iyo_config["division"],
                depth=iyo_config["depth"],
                consecution_time=iyo_config["consecution_time"],
                is_virtual_mm=True)
            try:
                otc_result_dict = OpptyTimeCollector.run(settings=settings)
                total_dur_dict = OpptyTimeCollector.get_total_duration_time(
                    otc_result_dict)
                total_dur_dict["combination"] = \
                    "%s-%s-%s" % (coin_name.upper(), str(_combi[0]).upper(), str(_combi[1]).upper())
                all_comb_result_by_one_coin.append(total_dur_dict)
            except TypeError as e:
                logging.error("Something went wrong in OTC scheduler", e)
                continue
        return all_comb_result_by_one_coin