diff --git a/bbgo/parser.go b/bbgo/parser.go index 0687e0a8e..e6fc8ded7 100644 --- a/bbgo/parser.go +++ b/bbgo/parser.go @@ -2,7 +2,10 @@ package bbgo import ( "encoding/json" + "errors" "fmt" + "time" + "github.com/valyala/fastjson" ) @@ -62,7 +65,7 @@ type ExecutionReportEvent struct { IsMaker bool `json:"m"` CommissionAmount string `json:"n"` - CommissionAsset string `json:"N"` + CommissionAsset string `json:"N"` CurrentExecutionType string `json:"x"` CurrentOrderStatus string `json:"X"` @@ -79,6 +82,25 @@ type ExecutionReportEvent struct { OrderCreationTime int `json:"O"` } +func (e *ExecutionReportEvent) Trade() (*Trade, error) { + if e.CurrentExecutionType != "TRADE" { + return nil, errors.New("execution report is not a trade") + } + + tt := time.Unix(0, e.TransactionTime/1000000) + return &Trade{ + ID: e.TradeID, + Symbol: e.Symbol, + Price: MustParseFloat(e.LastExecutedPrice), + Volume: MustParseFloat(e.LastExecutedQuantity), + IsBuyer: e.Side == "BUY", + IsMaker: e.IsMaker, + Time: tt, + Fee: MustParseFloat(e.CommissionAmount), + FeeCurrency: e.CommissionAsset, + }, nil +} + /* balanceUpdate diff --git a/bbgo/trade.go b/bbgo/trade.go index a31570b25..10027d79c 100644 --- a/bbgo/trade.go +++ b/bbgo/trade.go @@ -15,7 +15,7 @@ type Trade struct { IsBuyer bool IsMaker bool Time time.Time - + Symbol string Fee float64 FeeCurrency string }