Usage

To use Tiingo Python in a project:

import tiingo

Next, initialize your client object. It is recommended to use an environment variable to initialize your client object for convenience.

from tiingo import TiingoClient
# Set TIINGO_API_KEY in your environment variables in your .bash_profile, OR
# pass a dictionary with 'api_key' as a key into the TiingoClient.

client = TiingoClient()

Alternately, you may use a dictionary to customize/authorize your client.

Now you can use TiingoClient to make your API calls. (Other parameters are available for each endpoint beyond what has been written below, see the Tiingo website for full details).

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