dedup the cli/tui
This commit is contained in:
parent
ecadfb492d
commit
ac5e0639fc
1 changed files with 15 additions and 14 deletions
|
|
@ -22,18 +22,20 @@ pub fn loadData(app: *App) void {
|
|||
app.candle_first_date = null;
|
||||
app.candle_last_date = null;
|
||||
|
||||
const candle_result = app.svc.getCandles(app.symbol) catch |err| {
|
||||
const result = app.svc.getTrailingReturns(app.symbol) catch |err| {
|
||||
switch (err) {
|
||||
zfin.DataError.NoApiKey => app.setStatus("No API key. Set TWELVEDATA_API_KEY"),
|
||||
zfin.DataError.NoApiKey => app.setStatus("No API key. Set TIINGO_API_KEY"),
|
||||
zfin.DataError.FetchFailed => app.setStatus("Fetch failed (network error or rate limit)"),
|
||||
zfin.DataError.TransientError => app.setStatus("Provider temporarily unavailable — try again later"),
|
||||
zfin.DataError.AuthError => app.setStatus("API key auth failed — check TIINGO_API_KEY"),
|
||||
else => app.setStatus("Error loading data"),
|
||||
}
|
||||
return;
|
||||
};
|
||||
app.candles = candle_result.data;
|
||||
app.candle_timestamp = candle_result.timestamp;
|
||||
app.candles = result.candles;
|
||||
app.candle_timestamp = result.timestamp;
|
||||
|
||||
const c = app.candles.?;
|
||||
const c = result.candles;
|
||||
if (c.len == 0) {
|
||||
app.setStatus("No data available for symbol");
|
||||
return;
|
||||
|
|
@ -42,15 +44,14 @@ pub fn loadData(app: *App) void {
|
|||
app.candle_first_date = c[0].date;
|
||||
app.candle_last_date = c[c.len - 1].date;
|
||||
|
||||
const today = fmt.todayDate();
|
||||
app.trailing_price = zfin.performance.trailingReturns(c);
|
||||
app.trailing_me_price = zfin.performance.trailingReturnsMonthEnd(c, today);
|
||||
app.trailing_price = result.asof_price;
|
||||
app.trailing_me_price = result.me_price;
|
||||
app.trailing_total = result.asof_total;
|
||||
app.trailing_me_total = result.me_total;
|
||||
|
||||
if (app.svc.getDividends(app.symbol)) |div_result| {
|
||||
app.dividends = div_result.data;
|
||||
app.trailing_total = zfin.performance.trailingReturnsWithDividends(c, div_result.data);
|
||||
app.trailing_me_total = zfin.performance.trailingReturnsMonthEndWithDividends(c, div_result.data, today);
|
||||
} else |_| {}
|
||||
if (result.dividends) |divs| {
|
||||
app.dividends = divs;
|
||||
}
|
||||
|
||||
app.risk_metrics = zfin.risk.trailingRisk(c);
|
||||
|
||||
|
|
@ -64,7 +65,7 @@ pub fn loadData(app: *App) void {
|
|||
} else |_| {}
|
||||
}
|
||||
|
||||
app.setStatus(if (candle_result.source == .cached) "r/F5 to refresh" else "Fetched | r/F5 to refresh");
|
||||
app.setStatus(if (result.source == .cached) "r/F5 to refresh" else "Fetched | r/F5 to refresh");
|
||||
}
|
||||
|
||||
// ── Rendering ─────────────────────────────────────────────────
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue