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 { type Balance struct {
Asset string `json:"a"` Asset string `json:"a"`
Free string `json:"f"` Free fixedpoint.Value `json:"f"`
Locked string `json:"l"` Locked fixedpoint.Value `json:"l"`
} }
type OutboundAccountPositionEvent struct { type OutboundAccountPositionEvent struct {

View File

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