How to read websocket response in linux shell

后端 未结 5 1948
既然无缘
既然无缘 2020-12-24 07:18

Writing a bash script to connect to GDAX\'s Websocket Feed at wss://ws-feed.gdax.com but curl doesn\'t seem to support this as I get

curl \"wss://ws-feed.gd         


        
5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-24 07:29

    I'd like to add my own tool for this: websocat.

    Example session with the service in question:

    $ rlwrap  websocat wss://ws-feed.gdax.com
    
    # Now enter this line (without the #) for the required JSON request:
    # {"type":"subscribe","channels": [{ "name": "heartbeat", "product_ids": ["BTC-USD"] }]}
    
    {"type":"subscriptions","channels":[{"name":"heartbeat","product_ids":["BTC-USD"]}]}
    {"type":"heartbeat","last_trade_id":46274575,"product_id":"BTC-USD","sequence":6312079752,"time":"2018-07-12T22:32:42.655000Z"}
    {"type":"heartbeat","last_trade_id":46274575,"product_id":"BTC-USD","sequence":6312079800,"time":"2018-07-12T22:32:43.656000Z"}
    {"type":"heartbeat","last_trade_id":46274575,"product_id":"BTC-USD","sequence":6312079834,"time":"2018-07-12T22:32:44.656000Z"}
    {"type":"heartbeat","last_trade_id":46274575,"product_id":"BTC-USD","sequence":6312079945,"time":"2018-07-12T22:32:45.656000Z"}
    {"type":"heartbeat","last_trade_id":46274575,"product_id":"BTC-USD","sequence":6312079990,"time":"2018-07-12T22:32:46.657000Z"}
    {"type":"heartbeat","last_trade_id":46274575,"product_id":"BTC-USD","sequence":6312080042,"time":"2018-07-12T22:32:47.657000Z"}
    {"type":"heartbeat","last_trade_id":46274576,"product_id":"BTC-USD","sequence":6312080169,"time":"2018-07-12T22:32:48.657000Z"}
    
    # To stop the feed, type this line: 
    {"type":"unsubscribe","channels": [{ "name": "heartbeat", "product_ids": ["BTC-USD"] }]}
    {"type":"subscriptions","channels":[]}
    

    Besides a websocket client, websocat supports WebSocket server and other modes and is aimed to integrate websockets into "UNIX" world in general.

提交回复
热议问题