0

我正在学习 python 和 dash,我正在构建一个应用程序来监控我的交易。

我已经改编了代码:“实时更新组件”示例(轨道卫星)。它在 jupyter notebook 和 repl.it 上运行良好,但在我的计算机上尝试时出现错误:

“回溯(最近一次调用最后一次):文件“orbital.py”,第 62 行,输入('interval-component','n_intervals'))“

“输入参数 interval-component.n_intervals 必须是 dash.dependencies.Inputs 的列表或元组。”</p>

我不明白为什么

这是我的代码:

import ccxt
import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly
from dash.dependencies import Input, Output
import pandas as pd



app = dash.Dash(__name__)

ftx = ccxt.ftx({'verbose': True})
ftx = ccxt.ftx({
    'apiKey': '',
    'secret': '',

    
})


app.layout = html.Div(
    html.Div([
        html.H4('FTX Live Feed'),
        html.Div(id='live-update-text'),
        dcc.Interval(
            id='interval-component',
            interval=1*1000, # in milliseconds
            n_intervals=0
        )
    ])
)

class Client:
    """A sample client class"""

    def __init__(self):
        self.pnl = []

    @classmethod
    def get_balances(client):
        try:
            balance = ftx.fetch_balance()
        except ccxt.BaseError as e:
            print(f"Could not get account with error: {e}")
            raise e
        else:
            result = balance["info"]["result"]
            total = []
            for x in result:
                if float(x["free"]) > 0.0:
                    total.append(x["usdValue"])
                    a = list(map(float, total))

            df = pd.Series(a)
            # global totCap
            totCap = df.sum()
            return totCap

@app.callback(Output('live-update-text', 'children'),
              Input('interval-component', 'n_intervals'))


def update_metrics(n):

    arc = Client().get_balances()
    style = {'padding': '5px', 'fontSize': '16px'}
    return [
        html.Span('Balance: {0:.2f}'.format(arc), style=style)
    ]



if __name__ == '__main__':
    app.run_server(host="0.0.0.0", port="8050")

这是 replit 应用程序的屏幕截图: replit dash

4

1 回答 1

0

正如错误试图说的那样,您需要将您的列表包含Input在一个列表中,如下所示:

@app.callback(Output('live-update-text', 'children'),
              [Input('interval-component', 'n_intervals')])
于 2021-04-04T15:14:20.967 回答