mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
ftx: define subscribed msg
This commit is contained in:
parent
73d05fe7bb
commit
d9ad022a81
|
@ -1,5 +1,7 @@
|
||||||
package ftx
|
package ftx
|
||||||
|
|
||||||
|
import "encoding/json"
|
||||||
|
|
||||||
type operation string
|
type operation string
|
||||||
|
|
||||||
const subscribe operation = "subscribe"
|
const subscribe operation = "subscribe"
|
||||||
|
@ -17,3 +19,44 @@ type SubscribeRequest struct {
|
||||||
Channel channel `json:"channel"`
|
Channel channel `json:"channel"`
|
||||||
Market string `json:"market"`
|
Market string `json:"market"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type respType string
|
||||||
|
|
||||||
|
const errRespType respType = "error"
|
||||||
|
const subscribedRespType respType = "subscribed"
|
||||||
|
const unsubscribedRespType respType = "unsubscribed"
|
||||||
|
const infoRespType respType = "info"
|
||||||
|
const partialRespType respType = "partial"
|
||||||
|
const updateRespType respType = "update"
|
||||||
|
|
||||||
|
type mandatoryFields struct {
|
||||||
|
Type respType `json:"type"`
|
||||||
|
|
||||||
|
// Channel is mandatory
|
||||||
|
Channel channel `json:"channel"`
|
||||||
|
|
||||||
|
// Market is mandatory
|
||||||
|
Market string `json:"market"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// doc: https://docs.ftx.com/#response-format
|
||||||
|
type rawResponse struct {
|
||||||
|
mandatoryFields
|
||||||
|
|
||||||
|
// The following fields are optional.
|
||||||
|
// Example 1: {"type": "error", "code": 404, "msg": "No such market: BTCUSDT"}
|
||||||
|
Code int64 `json:"code"`
|
||||||
|
Message string `json:"msg"`
|
||||||
|
Data map[string]json.RawMessage `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r rawResponse) toSubscribedResp() subscribedResponse {
|
||||||
|
return subscribedResponse{
|
||||||
|
mandatoryFields: r.mandatoryFields,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// {"type": "subscribed", "channel": "orderbook", "market": "BTC/USDT"}
|
||||||
|
type subscribedResponse struct {
|
||||||
|
mandatoryFields
|
||||||
|
}
|
||||||
|
|
18
pkg/exchange/ftx/websocket_messages_test.go
Normal file
18
pkg/exchange/ftx/websocket_messages_test.go
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
package ftx
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_rawResponse_toSubscribedResp(t *testing.T) {
|
||||||
|
input := `{"type": "subscribed", "channel": "orderbook", "market": "BTC/USDT"}`
|
||||||
|
var m rawResponse
|
||||||
|
assert.NoError(t, json.Unmarshal([]byte(input), &m))
|
||||||
|
r := m.toSubscribedResp()
|
||||||
|
assert.Equal(t, subscribedRespType, r.Type)
|
||||||
|
assert.Equal(t, orderbook, r.Channel)
|
||||||
|
assert.Equal(t, "BTC/USDT", r.Market)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user