Class ITER_WebSocket

  • All Implemented Interfaces:
    IteratorFunction

    public class ITER_WebSocket
    extends IteratorStreamFunctionBase
    Iterator function iter:WebSocket connects to a WebSocket server, and iteratively binds the messages that are received.

    See Live example

    Optionally, a specific message can be sent to the WebSocket server as a first step (This message is usually a query that specifies what stream of data is to be retrieved).
    • Param 1: (a String or URI) is the WebSocket server URI to connect to;
    • Param 3: (a String, optional) is the message that will be first sent to the server (e.g., a json query).

    Example:

    The clause

    ITERATOR iter:WebSocket("wss://api.gemini.com/v1/marketdata/BTCUSD") AS ?events

    will connect to the Gemini WebSocket server (a cryptocurrency exchange platform) forever and iteratively produce the following bindings:

     ?events => {"type":"update","eventId":4568099292,"timestamp":1537974017,"timestampms":1537974017597,"socket_sequence":1,"events":[{"type":"change","side":"ask","price":"6513.20","remaining":"0","delta":"-1.321","reason":"cancel"}]}
     ?events => {"type":"update","eventId":4568099362,"timestamp":1537974018,"timestampms":1537974018434,"socket_sequence":2,"events":[{"type":"change","side":"bid","price":"1.00","remaining":"5666.001","delta":"0.001","reason":"place"}]}
     ?events => {"type":"update","eventId":4568099456,"timestamp":1537974019,"timestampms":1537974019735,"socket_sequence":3,"events":[{"type":"change","side":"bid","price":"6504.97","remaining":"0","delta":"-1","reason":"cancel"}]}
     ?events => {"type":"update","eventId":4568099464,"timestamp":1537974019,"timestampms":1537974019919,"socket_sequence":4,"events":[{"type":"change","side":"ask","price":"6513.20","remaining":"0.104","delta":"0.104","reason":"place"}]}
     ?events => {"type":"update","eventId":4568099470,"timestamp":1537974020,"timestampms":1537974020197,"socket_sequence":5,"events":[{"type":"trade","tid":4568099470,"price":"6508.45","amount":"0.02441407","makerSide":"ask"},{"type":"change","side":"ask","price":"6508.45","remaining":"0.45117186","delta":"-0.02441407","reason":"trade"}]}
     ?events => {"type":"update","eventId":4568099488,"timestamp":1537974020,"timestampms":1537974020414,"socket_sequence":6,"events":[{"type":"change","side":"bid","price":"6492.03","remaining":"0","delta":"-0.2","reason":"cancel"}]}
     ?events => {"type":"update","eventId":4568099494,"timestamp":1537974020,"timestampms":1537974020515,"socket_sequence":7,"events":[{"type":"change","side":"ask","price":"6544.36","remaining":"0","delta":"-0.2","reason":"cancel"}]}
     ?events => {"type":"update","eventId":4568099498,"timestamp":1537974020,"timestampms":1537974020542,"socket_sequence":8,"events":[{"type":"change","side":"ask","price":"6513.20","remaining":"0","delta":"-0.104","reason":"cancel"}]}
     ?events => {"type":"update","eventId":4568099513,"timestamp":1537974020,"timestampms":1537974020623,"socket_sequence":9,"events":[{"type":"change","side":"bid","price":"6491.40","remaining":"0.2","delta":"0.2","reason":"place"}]}
     ?events => {"type":"update","eventId":4568099529,"timestamp":1537974020,"timestampms":1537974020723,"socket_sequence":10,"events":[{"type":"change","side":"ask","price":"6543.79","remaining":"0.2","delta":"0.2","reason":"place"}]}
     ?events => {"type":"update","eventId":4568099531,"timestamp":1537974020,"timestampms":1537974020726,"socket_sequence":11,"events":[{"type":"change","side":"bid","price":"1.00","remaining":"5666","delta":"-0.001","reason":"cancel"}]}
     ?events => {"type":"update","eventId":4568099631,"timestamp":1537974021,"timestampms":1537974021785,"socket_sequence":12,"events":[{"type":"change","side":"bid","price":"6504.37","remaining":"1","delta":"1","reason":"place"}]}
     
    Since:
    2018-09-26
    Author:
    El-Mehdi Khalfi
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String URI
      The SPARQL function URI.
    • Constructor Summary

      Constructors 
      Constructor Description
      ITER_WebSocket()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void checkBuild​(ExprList args)
      Partially checks if the iterator function can be executed with the given arguments.
      void exec​(java.util.List<NodeValue> args, java.util.function.Consumer<java.util.List<java.util.List<NodeValue>>> listListNodeValue)
      IteratorFunction call to a list of evaluated argument values.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

    • Constructor Detail

      • ITER_WebSocket

        public ITER_WebSocket()