Ejemplo n.º 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
Ejemplo n.º 2
0
def main(coin_name: str, mm1_name: str, mm2_name: str):
    Global.configure_default_root_logging(should_log_to_file=False,
                                          log_level=logging.INFO)
    SharedMongoClient.initialize(should_use_localhost_db=False)
    start_time = Global.convert_local_datetime_to_epoch("2018.08.20 09:00:00",
                                                        timezone="kr")
    end_time = Global.convert_local_datetime_to_epoch("2018.08.20 13:00:00",
                                                      timezone="kr")

    iyo_config = Global.read_iyo_setting_config(coin_name)

    # set settings // fix manually if you need to
    settings = TradeSettingConfig.get_settings(
        mm1_name=mm1_name,
        mm2_name=mm2_name,
        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)

    bal_factor_settings = TradeSettingConfig.get_bal_fact_settings(
        iyo_config["krw_seq_end"], iyo_config["coin_seq_end"])

    ibo_result = InitialBalanceOptimizer.run(settings, bal_factor_settings)
    print(ibo_result)
def main(coin_name: str, mm1_name: str, mm2_name: str, start_time: str,
         end_time: str):
    Global.configure_default_root_logging(should_log_to_file=False,
                                          log_level=logging.INFO)
    SharedMongoClient.initialize(should_use_localhost_db=False)

    logging.warning("Nohup conducting -> start_time: %s, end_time: %s" %
                    (start_time, end_time))
    # Global.send_to_slack_channel("IYO Initiated!! start_time: %s, end_time: %s" % (prev_time, cur_time))

    start_time = Global.convert_local_datetime_to_epoch(start_time,
                                                        timezone="kr")
    end_time = Global.convert_local_datetime_to_epoch(end_time, timezone="kr")

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

    logging.critical(
        "[%s-%s-%s] IYO conducting -> start_time: %s, end_time: %s" %
        (coin_name.upper(), mm1_name.upper(), mm2_name.upper(), start_time,
         end_time))

    # set settings, bal_fact_settings, factor_settings
    settings = TradeSettingConfig.get_settings(
        mm1_name=mm1_name,
        mm2_name=mm2_name,
        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)

    bal_factor_settings = TradeSettingConfig.get_bal_fact_settings(
        iyo_config["krw_seq_end"], iyo_config["coin_seq_end"])

    factor_settings = TradeSettingConfig.get_factor_settings(
        mm1_name, mm2_name, coin_name, iyo_config["max_trade_coin_end"],
        iyo_config["threshold_end"], iyo_config["appx_unit_coin_price"])

    iyo_result = IntegratedYieldOptimizer.run(settings,
                                              bal_factor_settings,
                                              factor_settings,
                                              is_stat_appender=False,
                                              is_slicing_dur=False)
    logging.critical("Final IYO result: %s" % iyo_result)
    return iyo_result
    def get_otc_result_init_mode(self, rewined_time: int, anal_end_time: int):
        # OTC target combination
        iyo_config = Global.read_iyo_setting_config(self.target_currency)

        target_settings = TradeSettingConfig.get_settings(mm1_name=self.mm1_name,
                                                          mm2_name=self.mm2_name,
                                                          target_currency=self.target_currency,
                                                          start_time=rewined_time,
                                                          end_time=anal_end_time,
                                                          division=iyo_config["division"],
                                                          depth=iyo_config["depth"],
                                                          consecution_time=iyo_config["consecution_time"],
                                                          is_virtual_mm=True)
        target_settings["mm1"]["krw_balance"] = self.mm1_krw_bal
        target_settings["mm1"]["coin_balance"] = self.mm1_coin_bal
        target_settings["mm2"]["krw_balance"] = self.mm2_krw_bal
        target_settings["mm2"]["coin_balance"] = self.mm2_coin_bal

        return OpptyTimeCollector.run(settings=target_settings)
Ejemplo n.º 5
0
    def otc_all_combination_by_one_coin(self, target_currency: str,
                                        combination_list: list):
        all_ocat_result_by_one_coin = []
        for _combi in combination_list:
            # draw iyo_config for settings
            iyo_config = Global.read_iyo_setting_config(target_currency)

            settings = TradeSettingConfig.get_settings(
                mm1_name=_combi[0],
                mm2_name=_combi[1],
                target_currency=target_currency,
                start_time=self.init_s_iyo_rewined_time,
                end_time=self.streamer_start_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["new_spread_ratio"] = otc_result_dict[
                    "new_spread_ratio"]
                total_dur_dict["rev_spread_ratio"] = otc_result_dict[
                    "rev_spread_ratio"]
                total_dur_dict["new_max_unit_spread"] = otc_result_dict[
                    "new_max_unit_spread"]
                total_dur_dict["rev_max_unit_spread"] = otc_result_dict[
                    "rev_max_unit_spread"]
                total_dur_dict["avg_new_mid_price"] = otc_result_dict[
                    "avg_new_mid_price"]
                total_dur_dict["avg_rev_mid_price"] = otc_result_dict[
                    "avg_rev_mid_price"]
                total_dur_dict["combination"] = \
                    "%s-%s-%s" % (target_currency.upper(), str(_combi[0]).upper(), str(_combi[1]).upper())

                all_ocat_result_by_one_coin.append(total_dur_dict)
            except TypeError as e:
                logging.error("Something went wrong in OTC scheduler", e)
                continue

        return all_ocat_result_by_one_coin
Ejemplo n.º 6
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
def main(coin_name: str, init_time: str, final_time: str):
    Global.configure_default_root_logging(should_log_to_file=False,
                                          log_level=logging.INFO)
    SharedMongoClient.initialize(should_use_localhost_db=False)
    db_client = SharedMongoClient.instance()

    time_list = make_time_list(init_time, final_time)

    prev_time = None
    for cur_time in time_list:
        if prev_time is None:
            prev_time = cur_time
            continue
        logging.warning("Nohup conducting -> start_time: %s, end_time: %s" %
                        (prev_time, cur_time))
        # Global.send_to_slack_channel("IYO Initiated!! start_time: %s, end_time: %s" % (prev_time, cur_time))

        start_time = Global.convert_local_datetime_to_epoch(prev_time,
                                                            timezone="kr")
        end_time = Global.convert_local_datetime_to_epoch(cur_time,
                                                          timezone="kr")

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

        # FIXME: 빗썸 등등 거래소 생긴 날부터는 밑에 주석 쓰기
        # rfab_combi_list = Global.get_rfab_combination_list(coin_name)
        rfab_combi_list = list(it.combinations(["okcoin", "coinnest"], 2))
        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(), start_time, end_time))

            # set settings, bal_fact_settings, factor_settings
            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)

            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"])

            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
            logging.warning("Nohup done, now conducting next time set!!")
            prev_time = cur_time