mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 14:55:16 +00:00
ftx: subscribe order update
This commit is contained in:
parent
4ac67332a4
commit
2e2ae46bae
|
@ -32,9 +32,7 @@ func (s *Stream) Connect(ctx context.Context) error {
|
|||
// If it's not public only, let's do the authentication.
|
||||
if atomic.LoadInt32(&s.publicOnly) == 0 {
|
||||
logger.Infof("subscribe private events")
|
||||
s.wsService.Subscribe(
|
||||
newLoginRequest(s.wsService.key, s.wsService.secret, time.Now()),
|
||||
)
|
||||
s.subscribePrivateEvents()
|
||||
}
|
||||
|
||||
if err := s.wsService.Connect(ctx); err != nil {
|
||||
|
@ -44,6 +42,16 @@ func (s *Stream) Connect(ctx context.Context) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *Stream) subscribePrivateEvents() {
|
||||
s.wsService.Subscribe(
|
||||
newLoginRequest(s.wsService.key, s.wsService.secret, time.Now()),
|
||||
)
|
||||
s.wsService.Subscribe(websocketRequest{
|
||||
Operation: subscribe,
|
||||
Channel: privateOrdersChannel,
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Stream) SetPublicOnly() {
|
||||
atomic.StoreInt32(&s.publicOnly, 1)
|
||||
}
|
||||
|
|
|
@ -43,7 +43,6 @@ var errSubscriptionFailed = fmt.Errorf("failed to subscribe")
|
|||
func (w *WebsocketService) sendSubscriptions() error {
|
||||
conn := w.Conn()
|
||||
for _, s := range w.subscriptions {
|
||||
logger.Infof("s: %+v", s)
|
||||
if err := conn.WriteJSON(s); err != nil {
|
||||
return fmt.Errorf("can't send subscription request %+v: %w", s, errSubscriptionFailed)
|
||||
}
|
||||
|
|
|
@ -22,9 +22,14 @@ const unsubscribe operation = "unsubscribe"
|
|||
type channel string
|
||||
|
||||
const orderbook channel = "orderbook"
|
||||
const trades channel = "trades"
|
||||
const ticker channel = "ticker"
|
||||
const privateOrdersChannel channel = "orders"
|
||||
|
||||
/*
|
||||
Private:
|
||||
order update: `{'op': 'subscribe', 'channel': 'orders'}`
|
||||
login: `{"args": { "key": "<api_key>", "sign": "<signature>", "time": <ts> }, "op": "login" }`
|
||||
|
||||
*/
|
||||
type websocketRequest struct {
|
||||
Operation operation `json:"op"`
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user