Example #1
0
def dashboard_view(request):
    context = {}

    # Check to see if haas is working
    haasCheck = HaasManager.haasomeClient.test_credentials()

    if HaasManager.verify_haas_connectivity():

        #Continue
        customBots = HaasManager.get_all_custom_bots()
        tradeBots = HaasManager.get_all_trade_bots()

        context = {'customBots': customBots, 
                   'tradeBots': tradeBots,
                   'amountOfCustomBots': len(customBots),
                   'amountOfTradeBots': len(tradeBots),
                   'totalBotsCount': len(tradeBots) + len(customBots),
                   'totalRoi': UtilManager.get_roi_from_bot_list(tradeBots) + UtilManager.get_roi_from_bot_list(customBots),
                   'totalTradeCount': UtilManager.get_total_trades_from_bot_list(tradeBots) + UtilManager.get_total_trades_from_bot_list(customBots),
                   'totalActivatedBots': UtilManager.get_activated_count_from_bot_list(tradeBots) + UtilManager.get_activated_count_from_bot_list(customBots)}

        if 'successNotification' in request.session:
            context['successNotification'] = request.session['successNotification']

        if 'failureNotification' in request.session:
            context['failureNotification'] = request.session['failureNotification']

        request = UtilManager.clear_session_notifications(request)

    else:
        context = {'connectFailure': True}

    return render(request, 'authed/dashboard.html', context)
Example #2
0
def start_basic_analyzer_action(request):

    if request.method == "POST":
        accountGuid = request.POST.get('accountselection', '')
        botGuid = request.POST.get('botselection', '')
        timeFrameToTest = request.POST.get('timeframetotest', 1440)

        botGuidSplit = botGuid.split(':')
        
        botType = botGuidSplit[0]
        botGuid = botGuidSplit[1]

        config = ConfigManager.get_or_create_config()
        markets = HaasManager.get_all_markets_for_guid(accountGuid)

        HistoryRetrievalManager.reset_retrieval_info()
        HistoryRetrievalManager.set_retrieval_info(accountGuid, len(markets))

        HistoryRetrievalManager.mark_started()

        BasicAnalysisManager.set_account_guid(accountGuid)
        BasicAnalysisManager.set_bot_guid(botGuid)
        BasicAnalysisManager.set_time_frame_in_minutes(int(timeFrameToTest)*2)

        if botType == "CB":
            BasicAnalysisManager.set_is_custom_bot(True)

        download_history_for_all_markets_task(config.haasIp, config.haasPort, config.haasSecret, accountGuid, int(timeFrameToTest)*2)

        return redirect('/analyzer/basic')
    else:
        print("derp")
        return redirect('/')
Example #3
0
def download_history_for_all_markets_task(haasip: str, haasport: int,
                                          haassecret: str, accountguid: str,
                                          depth: int):

    logging.info("Started the download all market history for exchange task")

    HaasManager.init_haas_manager(haasip, haasport, haassecret)

    historyTasks = {}
    historyResults = {}

    count = 0

    markets = HaasManager.get_all_markets_for_guid(accountguid)

    for market in markets:
        task = download_history_for_market_task(haasip, haasport, haassecret,
                                                market.priceSource,
                                                market.primaryCurrency,
                                                market.secondaryCurrency, "",
                                                1, depth)
        historyTasks[count] = task
        count = count + 1

    lastUpdateCount = 0

    while len(historyResults) != len(historyTasks):
        for k, v in historyTasks.items():
            result = v.get()
            if result != None:
                if k in historyResults:
                    pass
                else:
                    historyResults[k] = result

        if len(historyResults) > lastUpdateCount:
            HistoryRetrievalManager.update_amount_retrieved(
                len(historyResults))
            lastUpdateCount = len(historyResults)

        time.sleep(1)

    HistoryRetrievalManager.mark_completed()

    logging.info("Completed the download all market history for exchange task")
Example #4
0
def backtest_trade_bot_on_market(haasip: str, haasport: int, haassecret: str,
                                 accountguid: str, botguid: str,
                                 timeframeinminutes: int, primarycurrency: str,
                                 secondarycurrency: str, contractname: str):

    logging.info("Started backtest on pair  " + primarycurrency + "/" +
                 secondarycurrency)

    HaasManager.init_haas_manager(haasip, haasport, haassecret)

    accountInfo = HaasManager.haasomeClient.accountDataApi.get_account_details(
        accountguid).result

    backTestResult = HaasManager.haasomeClient.customBotApi.backtest_custom_bot_on_market(
        accountguid, botguid, timeframeinminutes, primarycurrency,
        secondarycurrency, contractname)

    return backTestResult.result
Example #5
0
def deactivate_trade_bot_action(request, botguid):

    context = {}

    if HaasManager.deactivate_trade_bot_by_guid(botguid):
        request.session['successNotification'] = "Deactivated Trade Bot: " + botguid
    else:
        request.session['failureNotification'] = "Failed to deactivate Trade Bot: " + botguid

    return redirect('/')
Example #6
0
def delete_custom_bot_action(request, botguid):

    context = {}

    if HaasManager.delete_custom_bot_by_guid(botguid):
        request.session['successNotification'] = "Deleted Custom Bot: " + botguid
    else:
        request.session['failureNotification'] = "Failed to delete Custom Bot: " + botguid

    return redirect('/')
Example #7
0
def download_history_for_market_task(haasip: str, haasport: int,
                                     haassecret: str,
                                     pricesource: EnumPriceSource,
                                     primarycurrency: str,
                                     secondarycurrency: str, contractname: str,
                                     interval: int, depth: int):

    logging.info("Started the download history for " + primarycurrency + "/" +
                 secondarycurrency)

    HaasManager.init_haas_manager(haasip, haasport, haassecret)

    history = safeHistoryGet(pricesource, primarycurrency, secondarycurrency,
                             contractname, interval, depth)

    logging.info("Completed the download history for " + primarycurrency +
                 "/" + secondarycurrency)

    return history
Example #8
0
def save_settings_action(request):

    context = {}

    if request.method == "POST":
        haasIp = request.POST.get('haasip', '')
        haasPort = request.POST.get('haasport', 0)
        haasSecret = request.POST.get('haassecret', '')
        numConcurrentTask = request.POST.get('numconcurrenttest', 0)

        ConfigManager.set_haas_configuration(haasIp, haasPort, haasSecret)
        ConfigManager.set_num_concurrent_test(numConcurrentTask)

        if HaasManager.quick_test_haas_creds(haasIp, haasPort, haasSecret):
            context = {'success': True,
            'config': ConfigManager.get_or_create_config()}
            HaasManager.init_haas_manager(haasIp, haasPort, haasSecret)
        else:
            context = {'success': False,
            'config': ConfigManager.get_or_create_config()}

        return render(request, 'authed/settings.html', context)
    else:
        return redirect('/settings')
Example #9
0
def basic_analyzer_view(request):

    config = ConfigManager.get_or_create_config()
    history = HistoryRetrievalManager.get_or_create_history_retrieval_model()
    basicAnalysis = BasicAnalysisManager.get_or_create_basic_analysis_run_model()

    context = {'accounts': HaasManager.get_all_accounts(),
                'customBots': HaasManager.get_all_custom_bots(),
                'tradeBots': HaasManager.get_all_trade_bots(),
                'history': HistoryRetrievalManager.get_or_create_history_retrieval_model(),
                'basicAnalysis': BasicAnalysisManager.get_or_create_basic_analysis_run_model()
                }

    if history.completed == True and basicAnalysis.started == False:
        basicAnalysis.started = True
        context['basicAnalysis'] = basicAnalysis
        markets = HaasManager.get_all_markets_for_guid(basicAnalysis.accountGuid)
        BasicAnalysisManager.set_total_to_retrieve(len(markets))
        BasicAnalysisManager.mark_started()

        backtest_all_markets_with_bot(config.haasIp, config.haasPort, config.haasSecret, basicAnalysis.accountGuid, 
            basicAnalysis.botGuid, basicAnalysis.timeFrameInMinutes, "", basicAnalysis.isCustomBot)

    return render(request, 'authed/basic_analyzer.html', context)
Example #10
0
def account_id_to_name(accountid: int):
    return HaasManager.get_account_info_for_id(accountid).name
Example #11
0
def startup():
    configModel = ConfigManager.get_or_create_config()
    HaasManager.init_haas_manager(configModel.haasIp, configModel.haasPort, configModel.haasSecret)
Example #12
0
def backtest_all_markets_with_bot(haasip: str, haasport: int, haassecret: str,
                                  accountguid: str, botguid: str,
                                  timeframeinminutes: int, contractname: str,
                                  iscustombot: bool):

    logging.info("Started the backtest of all markets")

    HaasManager.init_haas_manager(haasip, haasport, haassecret)

    backtestTasks = {}
    backtestResults = {}

    count = 0

    markets = HaasManager.get_all_markets_for_guid(accountguid)

    accountInfo = HaasManager.get_account_info_for_id(accountguid)

    baseBotInfo = None

    if iscustombot:
        baseBotInfo = HaasManager.get_custom_bot_by_id(botguid)
    else:
        baseBotInfo = HaasManager.get_trade_bot_by_id(botguid)

    logging.info(baseBotInfo)
    logging.info(baseBotInfo.name)

    for market in markets:
        task = None

        if iscustombot:
            task = backtest_custom_bot_on_market(haasip, haasport, haassecret,
                                                 accountguid, botguid,
                                                 timeframeinminutes,
                                                 market.primaryCurrency,
                                                 market.secondaryCurrency,
                                                 contractname)
        else:
            task = backtest_trade_bot_on_market(haasip, haasport, haassecret,
                                                accountguid, botguid,
                                                timeframeinminutes,
                                                market.primaryCurrency,
                                                market.secondaryCurrency,
                                                contractname)

        backtestTasks[count] = task
        count = count + 1

    lastUpdateCount = 0

    while len(backtestResults) != len(backtestTasks):
        for k, v in backtestTasks.items():
            result = v.get()
            if result != None:
                if k in backtestResults:
                    pass
                else:
                    backtestResults[k] = result
                    BasicAnalysisManager.create_basic_analysis_results_model(
                        accountguid,
                        EnumPriceSource(accountInfo.connectedPriceSource).name,
                        botguid, baseBotInfo.name,
                        result.priceMarket.primaryCurrency,
                        result.priceMarket.secondaryCurrency, result.roi,
                        iscustombot)

        if len(backtestResults) > lastUpdateCount:
            BasicAnalysisManager.update_amount_retrieved(len(backtestResults))
            lastUpdateCount = len(backtestResults)

        time.sleep(1)

    BasicAnalysisManager.mark_completed()

    logging.info("Completed the backtest of all markets task")