mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-25 16:25:16 +00:00
add reportTrade method
This commit is contained in:
parent
f4bf79d842
commit
88c7049a99
|
@ -2,7 +2,10 @@ package bbgo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/valyala/fastjson"
|
"github.com/valyala/fastjson"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -79,6 +82,25 @@ type ExecutionReportEvent struct {
|
||||||
OrderCreationTime int `json:"O"`
|
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
|
balanceUpdate
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ type Trade struct {
|
||||||
IsBuyer bool
|
IsBuyer bool
|
||||||
IsMaker bool
|
IsMaker bool
|
||||||
Time time.Time
|
Time time.Time
|
||||||
|
Symbol string
|
||||||
Fee float64
|
Fee float64
|
||||||
FeeCurrency string
|
FeeCurrency string
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user