mirror of
https://github.com/c9s/bbgo.git
synced 2024-09-20 16:21:09 +00:00
feat: tickers for asset calculation
This commit is contained in:
parent
bff8e3e285
commit
61c98432f2
|
@ -492,19 +492,19 @@ func (session *ExchangeSession) UpdatePrices(ctx context.Context) (err error) {
|
||||||
|
|
||||||
balances := session.Account.Balances()
|
balances := session.Account.Balances()
|
||||||
|
|
||||||
|
symbols := make([]string, len(balances))
|
||||||
for _, b := range balances {
|
for _, b := range balances {
|
||||||
priceSymbol := b.Currency + "USDT"
|
symbols[len(symbols)] = b.Currency + "USDT"
|
||||||
startTime := time.Now().Add(-10 * time.Minute)
|
}
|
||||||
klines, err := session.Exchange.QueryKLines(ctx, priceSymbol, types.Interval1m, types.KLineQueryOptions{
|
|
||||||
Limit: 100,
|
|
||||||
StartTime: &startTime,
|
|
||||||
})
|
|
||||||
|
|
||||||
if err != nil || len(klines) == 0 {
|
tickers, err := session.Exchange.QueryTickers(ctx, symbols...)
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
session.lastPrices[priceSymbol] = klines[len(klines)-1].Close
|
if err != nil || len(tickers) == 0 {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for k, v := range tickers {
|
||||||
|
session.lastPrices[k] = v.Last
|
||||||
}
|
}
|
||||||
|
|
||||||
session.lastPriceUpdatedAt = time.Now()
|
session.lastPriceUpdatedAt = time.Now()
|
||||||
|
|
|
@ -94,17 +94,20 @@ var PnLCmd = &cobra.Command{
|
||||||
log.Infof("found checkpoints: %+v", checkpoints)
|
log.Infof("found checkpoints: %+v", checkpoints)
|
||||||
log.Infof("stock: %f", stockManager.Stocks.Quantity())
|
log.Infof("stock: %f", stockManager.Stocks.Quantity())
|
||||||
|
|
||||||
now := time.Now()
|
tickers, err := exchange.QueryTickers(ctx, symbol)
|
||||||
kLines, err := exchange.QueryKLines(ctx, symbol, types.Interval1m, types.KLineQueryOptions{
|
|
||||||
Limit: 100,
|
|
||||||
EndTime: &now,
|
|
||||||
})
|
|
||||||
|
|
||||||
if len(kLines) == 0 {
|
if err != nil {
|
||||||
return errors.New("no kline data for current price")
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
currentPrice := kLines[len(kLines)-1].Close
|
currentTick, ok := tickers[strings.ToUpper(symbol)]
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
return errors.New("no ticker data for current price")
|
||||||
|
}
|
||||||
|
|
||||||
|
currentPrice := currentTick.Last
|
||||||
|
|
||||||
calculator := &pnl.AverageCostCalculator{
|
calculator := &pnl.AverageCostCalculator{
|
||||||
TradingFeeCurrency: tradingFeeCurrency,
|
TradingFeeCurrency: tradingFeeCurrency,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user