mirror of
https://github.com/hydrosquall/tiingo-python.git
synced 2026-02-01 00:54:21 +01:00
Merge pull request #508 from Mohamedemad4/added-websocket-client
feature(websocket): Add websocket client
This commit is contained in:
@@ -61,6 +61,41 @@ Now you can use ``TiingoClient`` to make your API calls. (Other parameters are a
|
||||
startDate='2017-01-01',
|
||||
endDate='2017-08-31')
|
||||
|
||||
Websocket support::
|
||||
|
||||
.. code-block:: python
|
||||
from tiingo import TiingoWebsocketClient
|
||||
|
||||
def cb_fn(msg):
|
||||
|
||||
# Example response
|
||||
# msg = {
|
||||
# "service":"iex" # An identifier telling you this is IEX data.
|
||||
# The value returned by this will correspond to the endpoint argument.
|
||||
#
|
||||
# # Will always return "A" meaning new price quotes. There are also H type Heartbeat msgs used to keep the connection alive
|
||||
# "messageType":"A" # A value telling you what kind of data packet this is from our IEX feed.
|
||||
#
|
||||
# # see https://api.tiingo.com/documentation/websockets/iex > Response for more info
|
||||
# "data":[] # an array containing trade information and a timestamp
|
||||
#
|
||||
# }
|
||||
|
||||
print(msg)
|
||||
|
||||
subscribe = {
|
||||
'eventName':'subscribe',
|
||||
'authorization':'API_KEY_GOES_HERE',
|
||||
#see https://api.tiingo.com/documentation/websockets/iex > Request for more info
|
||||
'eventData': {
|
||||
'thresholdLevel':5
|
||||
}
|
||||
}
|
||||
# notice how the object isn't needed after using it
|
||||
# any logic should be implemented in the callback function
|
||||
TiingoWebsocketClient(subscribe,endpoint="iex",on_msg_cb=cb_fn)
|
||||
while True:pass
|
||||
|
||||
|
||||
Further Docs
|
||||
--------
|
||||
|
||||
Reference in New Issue
Block a user