ftx: subscribe order update

This commit is contained in:
ycdesu 2021-03-27 19:02:19 +08:00
parent 4ac67332a4
commit 2e2ae46bae
3 changed files with 18 additions and 6 deletions

View File

@ -32,9 +32,7 @@ func (s *Stream) Connect(ctx context.Context) error {
// If it's not public only, let's do the authentication. // If it's not public only, let's do the authentication.
if atomic.LoadInt32(&s.publicOnly) == 0 { if atomic.LoadInt32(&s.publicOnly) == 0 {
logger.Infof("subscribe private events") logger.Infof("subscribe private events")
s.wsService.Subscribe( s.subscribePrivateEvents()
newLoginRequest(s.wsService.key, s.wsService.secret, time.Now()),
)
} }
if err := s.wsService.Connect(ctx); err != nil { if err := s.wsService.Connect(ctx); err != nil {
@ -44,6 +42,16 @@ func (s *Stream) Connect(ctx context.Context) error {
return nil 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() { func (s *Stream) SetPublicOnly() {
atomic.StoreInt32(&s.publicOnly, 1) atomic.StoreInt32(&s.publicOnly, 1)
} }

View File

@ -43,7 +43,6 @@ var errSubscriptionFailed = fmt.Errorf("failed to subscribe")
func (w *WebsocketService) sendSubscriptions() error { func (w *WebsocketService) sendSubscriptions() error {
conn := w.Conn() conn := w.Conn()
for _, s := range w.subscriptions { for _, s := range w.subscriptions {
logger.Infof("s: %+v", s)
if err := conn.WriteJSON(s); err != nil { if err := conn.WriteJSON(s); err != nil {
return fmt.Errorf("can't send subscription request %+v: %w", s, errSubscriptionFailed) return fmt.Errorf("can't send subscription request %+v: %w", s, errSubscriptionFailed)
} }

View File

@ -22,9 +22,14 @@ const unsubscribe operation = "unsubscribe"
type channel string type channel string
const orderbook channel = "orderbook" const orderbook channel = "orderbook"
const trades channel = "trades" const privateOrdersChannel channel = "orders"
const ticker channel = "ticker"
/*
Private:
order update: `{'op': 'subscribe', 'channel': 'orders'}`
login: `{"args": { "key": "<api_key>", "sign": "<signature>", "time": <ts> }, "op": "login" }`
*/
type websocketRequest struct { type websocketRequest struct {
Operation operation `json:"op"` Operation operation `json:"op"`