Giter Club home page Giter Club logo

Comments (1)

vi avatar vi commented on May 20, 2024

It is not a direct WebSocket API, it's is socket.io - a higher-level API which can use both polling and websockets.

Additionally this site has problems with subscribing to those events when using WebSocket part of socket.io exclusively. Try changing ('https://ws-api.iextrading.com/1.0/tops') to ('https://ws-api.iextrading.com/1.0/tops', {transports: ["websocket"]}) and ('https://ws-api.iextrading.com/1.0/tops', {transports: ['polling',"websocket"]}) to see the difference.

Nevertheless it is still possible to use Websocat to subscribe to those events:

$ curl 'https://ws-api.iextrading.com/socket.io/?EIO=3&transport=polling' ; echo
97:0{"sid":"uW7mDLs5qLKXxGRKAAdv","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":60000}

$ curl -X POST -H "Content-Type: text/plain;charset=UTF-8" -d '12:40/1.0/tops,' 'https://ws-api.iextrading.com/socket.io/?EIO=3&transport=polling&sid=uW7mDLs5qLKXxGRKAAdv' ; echo
ok

$ websocat -E --linemode-strip-newlines 'wss://ws-api.iextrading.com/socket.io/?EIO=3&transport=websocket&sid=uW7mDLs5qLKXxGRKAAdv' 
2probe
3probe
5
40
40/1.0/tops
42/1.0/tops,["subscribe", "fb"]
42/1.0/tops,["message","{\"symbol\":\"FB\",\"sector\":\"mediaentertainment\",\"securityType\":\"commonstock\",\"bidPrice\":138.0000,\"bidSize\":200,\"askPrice\":142.6400,\"askSize\":100,\"lastUpdated\":1542303584818,\"lastSalePrice\":142.5600,\"lastSaleSize\":100,\"lastSaleTime\":1542303578499,\"volume\":647393,\"marketPercent\":0.03941,\"seq\":220408}"]
42/1.0/tops,["message","{\"symbol\":\"FB\",\"sector\":\"mediaentertainment\",\"securityType\":\"commonstock\",\"bidPrice\":142.5800,\"bidSize\":100,\"askPrice\":142.6400,\"askSize\":100,\"lastUpdated\":1542303584819,\"lastSalePrice\":142.5600,\"lastSaleSize\":100,\"lastSaleTime\":1542303578499,\"volume\":647393,\"marketPercent\":0.03941,\"seq\":220409}"]
42/1.0/tops,["message","{\"symbol\":\"FB\",\"sector\":\"mediaentertainment\",\"securityType\":\"commonstock\",\"bidPrice\":138.0000,\"bidSize\":200,\"askPrice\":142.6400,\"askSize\":100,\"lastUpdated\":1542303584829,\"lastSalePrice\":142.5600,\"lastSaleSize\":100,\"lastSaleTime\":1542303578499,\"volume\":647393,\"marketPercent\":0.03941,\"seq\":220410}"]
42/1.0/tops,["message","{\"symbol\":\"FB\",\"sector\":\"mediaentertainment\",\"securityType\":\"commonstock\",\"bidPrice\":142.5800,\"bidSize\":100,\"askPrice\":142.6400,\"askSize\":100,\"lastUpdated\":1542303584899,\"lastSalePrice\":142.5600,\"lastSaleSize\":100,\"lastSaleTime\":1542303578499,\"volume\":647393,\"marketPercent\":0.03941,\"seq\":220411}"]
42/1.0/tops,["message","{\"symbol\":\"FB\",\"sector\":\"mediaentertainment\",\"securityType\":\"commonstock\",\"bidPrice\":138.0000,\"bidSize\":200,\"askPrice\":142.6400,\"askSize\":100,\"lastUpdated\":1542303584917,\"lastSalePrice\":142.5600,\"lastSaleSize\":100,\"lastSaleTime\":1542303578499,\"volume\":647393,\"marketPercent\":0.03941,\"seq\":220412}"]
42/1.0/tops,["message","{\"symbol\":\"FB\",\"sector\":\"mediaentertainment\",\"securityType\":\"commonstock\",\"bidPrice\":142.5700,\"bidSize\":100,\"askPrice\":142.6400,\"askSize\":100,\"lastUpdated\":1542303585024,\"lastSalePrice\":142.5600,\"lastSaleSize\":100,\"lastSaleTime\":1542303578499,\"volume\":647393,\"marketPercent\":0.03941,\"seq\":220413}"]
...

You type 2probe, 5 and 42/1.0/tops,["subscribe", "fb"] into Websocat and observe 3probe, 40, 40/1.0/tops, and 42/1.0/tops,["message",...] from it.

Future versions of Websocat may support socket.io more directly (although working without initial polling phase will be required). Example of simpler socket.io session using Websocat exclusively can be found here: https://stackoverflow.com/a/51190789/266720

from websocat.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.