mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-25 16:25:16 +00:00
bbgo: pass price time into the asset conversion function
This commit is contained in:
parent
3b25db31df
commit
95f7d85183
|
@ -659,7 +659,9 @@ func (environ *Environment) RecordAsset(t time.Time, sessionName string, exchang
|
|||
return
|
||||
}
|
||||
|
||||
environ.AccountService.InsertAsset(t, sessionName, exchangeName, account, assets)
|
||||
if err := environ.AccountService.InsertAsset(t, sessionName, exchangeName, account, assets); err != nil {
|
||||
log.WithError(err).Errorf("can not insert asset record")
|
||||
}
|
||||
}
|
||||
|
||||
func (environ *Environment) RecordPosition(position *types.Position, trade types.Trade, profit *types.Profit) {
|
||||
|
|
|
@ -646,21 +646,18 @@ func (session *ExchangeSession) FormatOrder(order types.SubmitOrder) (types.Subm
|
|||
return order, nil
|
||||
}
|
||||
|
||||
func (session *ExchangeSession) UpdatePrices(ctx context.Context) (err error) {
|
||||
func (session *ExchangeSession) UpdatePrices(ctx context.Context, currencies []string, fiat string) (err error) {
|
||||
if session.lastPriceUpdatedAt.After(time.Now().Add(-time.Hour)) {
|
||||
return nil
|
||||
}
|
||||
|
||||
balances := session.GetAccount().Balances()
|
||||
|
||||
var symbols []string
|
||||
for _, b := range balances {
|
||||
symbols = append(symbols, b.Currency+"USDT")
|
||||
symbols = append(symbols, "USDT"+b.Currency)
|
||||
for _, c := range currencies {
|
||||
symbols = append(symbols, c+fiat) // BTC/USDT
|
||||
symbols = append(symbols, fiat+c) // USDT/TWD
|
||||
}
|
||||
|
||||
tickers, err := session.Exchange.QueryTickers(ctx, symbols...)
|
||||
|
||||
if err != nil || len(tickers) == 0 {
|
||||
return err
|
||||
}
|
||||
|
@ -668,12 +665,7 @@ func (session *ExchangeSession) UpdatePrices(ctx context.Context) (err error) {
|
|||
var lastTime time.Time
|
||||
for k, v := range tickers {
|
||||
// for {Crypto}/USDT markets
|
||||
if strings.HasSuffix(k, "USDT") {
|
||||
session.lastPrices[k] = v.Last
|
||||
} else if strings.HasPrefix(k, "USDT") {
|
||||
session.lastPrices[k] = fixedpoint.One.Div(v.Last)
|
||||
}
|
||||
|
||||
if v.Time.After(lastTime) {
|
||||
lastTime = v.Time
|
||||
}
|
||||
|
|
|
@ -442,7 +442,7 @@ func genFakeAssets() types.AssetMap {
|
|||
"DOTUSDT": fixedpoint.NewFromFloat(20.0),
|
||||
"SANDUSDT": fixedpoint.NewFromFloat(0.13),
|
||||
"MAXUSDT": fixedpoint.NewFromFloat(0.122),
|
||||
})
|
||||
}, time.Now())
|
||||
for currency, asset := range assets {
|
||||
totalAssets[currency] = asset
|
||||
}
|
||||
|
@ -460,13 +460,13 @@ func (s *Server) listAssets(c *gin.Context) {
|
|||
for _, session := range s.Environ.Sessions() {
|
||||
balances := session.GetAccount().Balances()
|
||||
|
||||
if err := session.UpdatePrices(c); err != nil {
|
||||
if err := session.UpdatePrices(c, balances.Currencies(), "USDT"); err != nil {
|
||||
logrus.WithError(err).Error("price update failed")
|
||||
c.Status(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
assets := balances.Assets(session.LastPrices())
|
||||
assets := balances.Assets(session.LastPrices(), time.Now())
|
||||
|
||||
for currency, asset := range assets {
|
||||
totalAssets[currency] = asset
|
||||
|
|
Loading…
Reference in New Issue
Block a user