mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 08:45:16 +00:00
parse ResultEvent
This commit is contained in:
parent
4cd96360b3
commit
1ca46435c3
|
@ -113,7 +113,7 @@ func (s *PrivateStream) Read(ctx context.Context, eventC chan interface{}) {
|
||||||
|
|
||||||
log.Debugf("[binance] recv: %s", message)
|
log.Debugf("[binance] recv: %s", message)
|
||||||
|
|
||||||
e, err := ParseBinanceEvent(string(message))
|
e, err := parseEvent(string(message))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithError(err).Errorf("[binance] event parse error")
|
log.WithError(err).Errorf("[binance] event parse error")
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -112,7 +112,7 @@ balanceUpdate
|
||||||
"T": 1573200697068 //Clear Time
|
"T": 1573200697068 //Clear Time
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
type BinanceBalanceUpdateEvent struct {
|
type BalanceUpdateEvent struct {
|
||||||
EventBase
|
EventBase
|
||||||
|
|
||||||
Asset string `json:"a"`
|
Asset string `json:"a"`
|
||||||
|
@ -192,7 +192,12 @@ type OutboundAccountInfoEvent struct {
|
||||||
Permissions []string `json:"P,omitempty"`
|
Permissions []string `json:"P,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseBinanceEvent(message string) (interface{}, error) {
|
type ResultEvent struct {
|
||||||
|
Result interface{} `json:"result,omitempty"`
|
||||||
|
ID int `json:"id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseEvent(message string) (interface{}, error) {
|
||||||
val, err := fastjson.Parse(message)
|
val, err := fastjson.Parse(message)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -212,7 +217,7 @@ func ParseBinanceEvent(message string) (interface{}, error) {
|
||||||
return &event, err
|
return &event, err
|
||||||
|
|
||||||
case "balanceUpdate":
|
case "balanceUpdate":
|
||||||
var event BinanceBalanceUpdateEvent
|
var event BalanceUpdateEvent
|
||||||
err := json.Unmarshal([]byte(message), &event)
|
err := json.Unmarshal([]byte(message), &event)
|
||||||
return &event, err
|
return &event, err
|
||||||
|
|
||||||
|
@ -221,6 +226,11 @@ func ParseBinanceEvent(message string) (interface{}, error) {
|
||||||
err := json.Unmarshal([]byte(message), &event)
|
err := json.Unmarshal([]byte(message), &event)
|
||||||
return &event, err
|
return &event, err
|
||||||
|
|
||||||
|
default:
|
||||||
|
id := val.GetInt("id")
|
||||||
|
if id > 0 {
|
||||||
|
return &ResultEvent{ID: id}, nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, fmt.Errorf("unsupported message: %s", message)
|
return nil, fmt.Errorf("unsupported message: %s", message)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user