Exemple #1
0
def update_main_graphs(gui: QMainWindow, caller: int, valueDict: dict):
    """
    Updates graphs and moving averages from statistics based on caller.
    :param gui: GUI in which to update main graphs.
    :param valueDict: Dictionary with required values.
    :param caller: Caller that decides which graphs get updated.
    """
    precision = gui.get_trader(caller=caller).precision
    interfaceDict = gui.interfaceDictionary[caller]
    currentUTC = datetime.utcnow().timestamp()
    net = valueDict['net']

    netGraph = interfaceDict['mainInterface']['graph']
    averageGraph = interfaceDict['mainInterface']['averageGraph']

    graphDict = get_graph_dictionary(gui, netGraph)
    graphXSize = len(graphDict['plots'][0]['x']) + GRAPH_LEEWAY
    netGraph.setLimits(xMin=0, xMax=graphXSize)
    add_data_to_plot(gui, netGraph, 0, y=round(net, 2), timestamp=currentUTC)

    averageGraphDict = get_graph_dictionary(gui, averageGraph)
    if averageGraphDict['enable']:
        averageGraph.setLimits(xMin=0, xMax=graphXSize)
        for index, optionDetail in enumerate(valueDict['optionDetails']):
            initialAverage, finalAverage = optionDetail[:2]
            add_data_to_plot(gui, averageGraph, index * 2,
                             round(initialAverage, precision), currentUTC)
            add_data_to_plot(gui, averageGraph, index * 2 + 1,
                             round(finalAverage, precision), currentUTC)

        add_data_to_plot(gui,
                         averageGraph,
                         -1,
                         y=round(valueDict['price'], precision),
                         timestamp=currentUTC)
Exemple #2
0
def update_main_graphs(gui: QMainWindow, caller: int, valueDict: dict):
    """
    Updates graphs and moving averages from statistics based on caller.
    :param gui: GUI in which to update main graphs.
    :param valueDict: Dictionary with required values.
    :param caller: Caller that decides which graphs get updated.
    """
    precision = gui.get_trader(caller=caller).precision
    interfaceDict = gui.interfaceDictionary[caller]
    currentUTC = datetime.utcnow().timestamp()
    net = valueDict['net']

    netGraph = interfaceDict['mainInterface']['graph']
    averageGraph = interfaceDict['mainInterface']['averageGraph']

    graphDict = get_graph_dictionary(gui, netGraph)
    graphXSize = len(graphDict['plots'][0]['x']) + GRAPH_LEEWAY
    netGraph.setLimits(xMin=0, xMax=graphXSize)
    add_data_to_plot(gui, netGraph, 0, y=round(net, 2), timestamp=currentUTC)
    smart_update(graphDict)

    averageGraphDict = get_graph_dictionary(gui, averageGraph)
    if averageGraphDict['enable']:
        averageGraph.setLimits(xMin=0, xMax=graphXSize)
        add_data_to_plot(gui,
                         averageGraph,
                         0,
                         y=round(valueDict['price'], precision),
                         timestamp=currentUTC)

        trader = gui.get_trader(caller=caller)
        for strategy in trader.strategies.values():
            strategy_plot_dict = strategy.get_plot_data()
            index = strategy_plot_dict['index']
            for name, combined_data in strategy_plot_dict.items():

                if name == 'index':
                    continue

                value, _ = combined_data
                add_data_to_plot(gui=gui,
                                 targetGraph=averageGraph,
                                 plotIndex=index,
                                 y=round(value, trader.precision),
                                 timestamp=currentUTC)
                index += 1
        smart_update(averageGraphDict)