mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 17:13:51 +00:00
32 lines
724 B
Go
32 lines
724 B
Go
|
package ftx
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
|
||
|
"github.com/c9s/bbgo/pkg/types"
|
||
|
)
|
||
|
|
||
|
type messageHandler struct {
|
||
|
types.StandardStream
|
||
|
}
|
||
|
|
||
|
func (h messageHandler) handleMessage(message []byte) {
|
||
|
var r rawResponse
|
||
|
if err := json.Unmarshal(message, &r); err != nil {
|
||
|
logger.WithError(err).Errorf("failed to unmarshal resp: %s", string(message))
|
||
|
return
|
||
|
}
|
||
|
|
||
|
switch r.Type {
|
||
|
case subscribedRespType:
|
||
|
h.handleSubscribedMessage(r)
|
||
|
default:
|
||
|
logger.Errorf("unsupported message type: %+v", r.Type)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// {"type": "subscribed", "channel": "orderbook", "market": "BTC/USDT"}
|
||
|
func (h messageHandler) handleSubscribedMessage(response rawResponse) {
|
||
|
logger.Infof("%s orderbook is subscribed", response.toSubscribedResp().Market)
|
||
|
}
|