binance: embed fixedpoint.Value into binance Balance struct

This commit is contained in:
c9s 2021-05-30 23:32:01 +08:00
parent e3473572e9
commit bf73def701
2 changed files with 5 additions and 8 deletions

View File

@ -220,9 +220,9 @@ outboundAccountInfo
*/
type Balance struct {
Asset string `json:"a"`
Free string `json:"f"`
Locked string `json:"l"`
Asset string `json:"a"`
Free fixedpoint.Value `json:"f"`
Locked fixedpoint.Value `json:"l"`
}
type OutboundAccountPositionEvent struct {

View File

@ -11,7 +11,6 @@ import (
"time"
"github.com/adshao/go-binance/v2"
"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/gorilla/websocket"
"github.com/c9s/bbgo/pkg/types"
@ -134,12 +133,10 @@ func NewStream(client *binance.Client) *Stream {
stream.OnOutboundAccountPositionEvent(func(e *OutboundAccountPositionEvent) {
snapshot := types.BalanceMap{}
for _, balance := range e.Balances {
available := fixedpoint.Must(fixedpoint.NewFromString(balance.Free))
locked := fixedpoint.Must(fixedpoint.NewFromString(balance.Locked))
snapshot[balance.Asset] = types.Balance{
Currency: balance.Asset,
Available: available,
Locked: locked,
Available: balance.Free,
Locked: balance.Locked,
}
}
stream.EmitBalanceSnapshot(snapshot)