intriniorealtime


Nameintriniorealtime JSON
Version 5.2.1 PyPI version JSON
download
home_pagehttps://intrinio.com
SummaryIntrinio Python SDK for Real-Time Stock Prices
upload_time2024-02-01 18:15:19
maintainer
docs_urlNone
authorIntrinio Python SDK for Real-Time Stock Prices
requires_python~=3.10
license
keywords realtime stock prices intrinio stock market stock data financial
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # intrinio realtime python sdk
SDK for working with Intrinio's realtime Multi-Exchange prices feed.  Intrinio’s Multi-Exchange feed bridges the gap by merging real-time equity pricing from the IEX and MEMX exchanges. Get a comprehensive view with increased market volume and enjoy no exchange fees, no per-user requirements, no permissions or authorizations, and little to no paperwork.

[Intrinio](https://intrinio.com/) provides real-time stock prices via a two-way WebSocket connection. To get started, [subscribe to a real-time data feed](https://intrinio.com/real-time-multi-exchange) and follow the instructions below.

[Documentation for our legacy realtime client](https://github.com/intrinio/intrinio-realtime-python-sdk/tree/2.2.0)

## Requirements

- Python 3.10
- You need https://pypi.org/project/websocket-client/, not https://pypi.org/project/websocket/.

## Docker
Add your API key to the example_app.py file, then
```
docker compose build
docker compose run client
```

## Features

* Receive streaming, real-time price quotes (last trade, bid, ask)
* Subscribe to updates from individual securities
* Subscribe to updates for all securities
* Multiple sources of data - REALTIME or DELAYED_SIP or NASDAQ_BASIC

## Installation
```
pip install intriniorealtime
```

## Example Usage
```python
import threading
import time
from threading import Timer,Thread,Event
from intriniorealtime.client import IntrinioRealtimeClient

trade_count = 0
ask_count = 0
bid_count = 0
backlog_count = 0

def on_quote(quote, backlog):
        global ask_count
        global bid_count
        global backlog_count
        backlog_count = backlog
        if 'type' in quote.__dict__:
            if quote.type == "ask": ask_count += 1
            else: bid_count += 1

def on_trade(trade, backlog): 
        global trade_count
        global backlog_count
        backlog_count = backlog
        trade_count += 1

class Summarize(threading.Thread):
    def __init__(self, event):
        threading.Thread.__init__(self, args=(), kwargs=None)
        self.daemon = True
        self.stopped = event

    def run(self):
        global trade_count
        global bid_count
        global ask_count
        global backlog_count
        while not self.stopped.wait(5):
            print("trades: " + str(trade_count) + "; asks: " + str(ask_count) + "; bids: " + str(bid_count) + "; backlog: " + str(backlog_count))

options = {
    'api_key': 'API_KEY_HERE',
    'provider': 'REALTIME' # REALTIME or DELAYED_SIP or NASDAQ_BASIC
}

client = IntrinioRealtimeClient(options, on_trade, on_quote)
client.join(['AAPL','GE','MSFT'])
#client.join(['lobby'])
client.connect()
stopFlag = Event()
summarize_thread = Summarize(stopFlag)
summarize_thread.start()
time.sleep(10)
client.disconnect()
# this will stop the summarize thread
stopFlag.set()
```

## Handling Quotes and the Queue

There are thousands of securities, each with their own feed of activity.  We highly encourage you to make your trade and quote handlers has short as possible and follow a queue pattern so your app can handle the volume of activity.

## Quote Data Format

### Quote Message

```python
{ 'symbol': 'AAPL',
  'type': 'ask',
  'price': '102.3',
  'size': 100,
  'timestamp': 1636395583000000000,
  'subprovider': 'UTP',
  'market_center': '',
  'condition': '' }
```

*   **symbol** - the ticker of the security
*   **type** - the quote type
  *    **`ask`** - represents the top-of-book ask price
  *    **`bid`** - represents the top-of-book bid price
*   **price** - the price in USD
*   **size** - the size of the `last` trade, or total volume of orders at the top-of-book `bid` or `ask` price
*   **timestamp** - a Unix timestamp (nanoseconds since unix epoch)
*   **subprovider** - Denotes the detailed source within grouped sources.
  *    **`NO_SUBPROVIDER`** - No subtype specified.
  *    **`CTA_A`** - CTA_A in the DELAYED_SIP provider.
  *    **`CTA_B`** - CTA_B in the DELAYED_SIP provider.
  *    **`UTP`** - UTP in the DELAYED_SIP provider.
  *    **`OTC`** - OTC in the DELAYED_SIP provider.
  *    **`NASDAQ_BASIC`** - NASDAQ Basic in the NASDAQ_BASIC provider.
  *    **`IEX`** - From the IEX exchange in the REALTIME provider.
* **market_center** - Provides the market center
* **condition** - Provides the condition


### Trade Message

```python
{ 'symbol': 'AAPL',
  'total_volume': '106812',
  'price': '102.3',
  'size': 100,
  'timestamp': 1636395583000000000,
  'subprovider': 'IEX',
  'market_center': '',
  'condition': '' }
```

*   **symbol** - the ticker of the security
*   **total_volume** - the total volume of trades for the security so far today.
*   **price** - the price in USD
*   **size** - the size of the `last` trade, or total volume of orders at the top-of-book `bid` or `ask` price
*   **timestamp** - a Unix timestamp (nanoseconds since unix epoch)
*   **subprovider** - Denotes the detailed source within grouped sources.
  *    **`NO_SUBPROVIDER`** - No subtype specified.
  *    **`CTA_A`** - CTA_A in the DELAYED_SIP provider.
  *    **`CTA_B`** - CTA_B in the DELAYED_SIP provider.
  *    **`UTP`** - UTP in the DELAYED_SIP provider.
  *    **`OTC`** - OTC in the DELAYED_SIP provider.
  *    **`NASDAQ_BASIC`** - NASDAQ Basic in the NASDAQ_BASIC provider.
  *    **`IEX`** - From the IEX exchange in the REALTIME provider.
* **market_center** - Provides the market center
* **condition** - Provides the condition


## API Keys
You will receive your Intrinio API Key after [creating an account](https://intrinio.com/signup). You will need a subscription to a [realtime data feed](https://intrinio.com/real-time-multi-exchange) as well.

## Documentation

### Methods

`client = IntrinioRealtimeClient(options)` - Creates an Intrinio Realtime client
* **Parameter** `options.api_key`: Your Intrinio API Key
* **Parameter** `options.provider`: The real-time data provider to use ("REALTIME" or "DELAYED_SIP" or "NASDAQ_BASIC")
* **Parameter** `options.on_quote(quote, backlog)`: A function that handles received quotes. `backlog` is an integer representing the approximate size of the queue of unhandled quote/trade events.
* **Parameter** `options.on_trade(quote, backlog)`: A function that handles received trades. `backlog` is an integer representing the approximate size of the queue of unhandled quote/trade events.
* **Parameter** `options.logger`: (optional) A Python Logger instance to use for logging

```python
def on_quote(quote, backlog):
    print("QUOTE: " , quote, "BACKLOG LENGTH: ", backlog)
def on_trade(trade, backlog):
    print("TRADE: " , trade, "BACKLOG LENGTH: ", backlog)
    
options = {
    'api_key': '',
    'provider': 'REALTIME', # REALTIME or DELAYED_SIP or NASDAQ_BASIC
    'on_quote': on_quote,
    'on_trade': on_trade
}

client = IntrinioRealtimeClient(options)
```

---------

`client.join(channels)` - Joins the given channels. This can be called at any time. The client will automatically register joined channels and establish the proper subscriptions with the WebSocket connection.
* **Parameter** `channels` - A single channel or list of channels. You can also use the special symbol, "lobby" to join the firehose channel and recieved updates for all ticker symbols (you must have a valid "firehose" subscription).
```python
client.join(["AAPL", "MSFT", "GE"])
client.join("GOOG")
client.join("lobby")
```
---------

`client.connect()` - Retrieves an auth token, opens the WebSocket connection, starts the self-healing and heartbeat intervals, joins requested channels.

---------

`client.keep_alive()` - Runs an infinite loop to keep the thread alive, so that the client continues to receive prices. You may call this function after `connect()` or use your own timing logic (for example: connect, listen for quotes for x minutes, disconnect).

---------

`client.disconnect()` - Closes the WebSocket, stops the self-healing and heartbeat intervals. You _must_ call this to dispose of the client.

---------

`client.on_quote(quote, backlog)` - Changes the quote handler function
```python
def on_quote(quote, backlog):
    print("QUOTE: " , quote, "BACKLOG LENGTH: ", backlog)
    
client.on_quote = on_quote
```

---------

`client.leave(channels)` - Leaves the given channels.
* **Parameter** `channels` - A single channel or list of channels
```python
client.leave(["AAPL", "MSFT", "GE"])
client.leave("GOOG")
```

---------

`client.leave_all()` - Leaves all channels.

---------
## Example Replay Client Usage
```python
def on_quote(quote, backlog):
    print("QUOTE: " , quote, "BACKLOG LENGTH: ", backlog)
def on_trade(trade, backlog):
    print("TRADE: " , trade, "BACKLOG LENGTH: ", backlog)
    
options = {
    'api_key': '',
    'provider': 'REALTIME', # REALTIME or DELAYED_SIP or NASDAQ_BASIC
    'replay_date': datetime.date.today(),
    'with_simulated_delay': False,  # This plays back the events at the same rate they happened in market.
    'delete_file_when_done': True
}

client = IntrinioReplayClient(options, on_trade, on_quote)
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://intrinio.com",
    "name": "intriniorealtime",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "~=3.10",
    "maintainer_email": "",
    "keywords": "realtime,stock prices,intrinio,stock market,stock data,financial",
    "author": "Intrinio Python SDK for Real-Time Stock Prices",
    "author_email": "success@intrinio.com",
    "download_url": "https://files.pythonhosted.org/packages/fa/bd/6739522889614d1d7e00f993594e194e5b2c97195c862593075d306bc3f5/intriniorealtime-5.2.1.tar.gz",
    "platform": null,
    "description": "# intrinio realtime python sdk\nSDK for working with Intrinio's realtime Multi-Exchange prices feed.  Intrinio\u2019s Multi-Exchange feed bridges the gap by merging real-time equity pricing from the IEX and MEMX exchanges. Get a comprehensive view with increased market volume and enjoy no exchange fees, no per-user requirements, no permissions or authorizations, and little to no paperwork.\n\n[Intrinio](https://intrinio.com/) provides real-time stock prices via a two-way WebSocket connection. To get started, [subscribe to a real-time data feed](https://intrinio.com/real-time-multi-exchange) and follow the instructions below.\n\n[Documentation for our legacy realtime client](https://github.com/intrinio/intrinio-realtime-python-sdk/tree/2.2.0)\n\n## Requirements\n\n- Python 3.10\n- You need https://pypi.org/project/websocket-client/, not https://pypi.org/project/websocket/.\n\n## Docker\nAdd your API key to the example_app.py file, then\n```\ndocker compose build\ndocker compose run client\n```\n\n## Features\n\n* Receive streaming, real-time price quotes (last trade, bid, ask)\n* Subscribe to updates from individual securities\n* Subscribe to updates for all securities\n* Multiple sources of data - REALTIME or DELAYED_SIP or NASDAQ_BASIC\n\n## Installation\n```\npip install intriniorealtime\n```\n\n## Example Usage\n```python\nimport threading\nimport time\nfrom threading import Timer,Thread,Event\nfrom intriniorealtime.client import IntrinioRealtimeClient\n\ntrade_count = 0\nask_count = 0\nbid_count = 0\nbacklog_count = 0\n\ndef on_quote(quote, backlog):\n        global ask_count\n        global bid_count\n        global backlog_count\n        backlog_count = backlog\n        if 'type' in quote.__dict__:\n            if quote.type == \"ask\": ask_count += 1\n            else: bid_count += 1\n\ndef on_trade(trade, backlog): \n        global trade_count\n        global backlog_count\n        backlog_count = backlog\n        trade_count += 1\n\nclass Summarize(threading.Thread):\n    def __init__(self, event):\n        threading.Thread.__init__(self, args=(), kwargs=None)\n        self.daemon = True\n        self.stopped = event\n\n    def run(self):\n        global trade_count\n        global bid_count\n        global ask_count\n        global backlog_count\n        while not self.stopped.wait(5):\n            print(\"trades: \" + str(trade_count) + \"; asks: \" + str(ask_count) + \"; bids: \" + str(bid_count) + \"; backlog: \" + str(backlog_count))\n\noptions = {\n    'api_key': 'API_KEY_HERE',\n    'provider': 'REALTIME' # REALTIME or DELAYED_SIP or NASDAQ_BASIC\n}\n\nclient = IntrinioRealtimeClient(options, on_trade, on_quote)\nclient.join(['AAPL','GE','MSFT'])\n#client.join(['lobby'])\nclient.connect()\nstopFlag = Event()\nsummarize_thread = Summarize(stopFlag)\nsummarize_thread.start()\ntime.sleep(10)\nclient.disconnect()\n# this will stop the summarize thread\nstopFlag.set()\n```\n\n## Handling Quotes and the Queue\n\nThere are thousands of securities, each with their own feed of activity.  We highly encourage you to make your trade and quote handlers has short as possible and follow a queue pattern so your app can handle the volume of activity.\n\n## Quote Data Format\n\n### Quote Message\n\n```python\n{ 'symbol': 'AAPL',\n  'type': 'ask',\n  'price': '102.3',\n  'size': 100,\n  'timestamp': 1636395583000000000,\n  'subprovider': 'UTP',\n  'market_center': '',\n  'condition': '' }\n```\n\n*   **symbol** - the ticker of the security\n*   **type** - the quote type\n  *    **`ask`** - represents the top-of-book ask price\n  *    **`bid`** - represents the top-of-book bid price\n*   **price** - the price in USD\n*   **size** - the size of the `last` trade, or total volume of orders at the top-of-book `bid` or `ask` price\n*   **timestamp** - a Unix timestamp (nanoseconds since unix epoch)\n*   **subprovider** - Denotes the detailed source within grouped sources.\n  *    **`NO_SUBPROVIDER`** - No subtype specified.\n  *    **`CTA_A`** - CTA_A in the DELAYED_SIP provider.\n  *    **`CTA_B`** - CTA_B in the DELAYED_SIP provider.\n  *    **`UTP`** - UTP in the DELAYED_SIP provider.\n  *    **`OTC`** - OTC in the DELAYED_SIP provider.\n  *    **`NASDAQ_BASIC`** - NASDAQ Basic in the NASDAQ_BASIC provider.\n  *    **`IEX`** - From the IEX exchange in the REALTIME provider.\n* **market_center** - Provides the market center\n* **condition** - Provides the condition\n\n\n### Trade Message\n\n```python\n{ 'symbol': 'AAPL',\n  'total_volume': '106812',\n  'price': '102.3',\n  'size': 100,\n  'timestamp': 1636395583000000000,\n  'subprovider': 'IEX',\n  'market_center': '',\n  'condition': '' }\n```\n\n*   **symbol** - the ticker of the security\n*   **total_volume** - the total volume of trades for the security so far today.\n*   **price** - the price in USD\n*   **size** - the size of the `last` trade, or total volume of orders at the top-of-book `bid` or `ask` price\n*   **timestamp** - a Unix timestamp (nanoseconds since unix epoch)\n*   **subprovider** - Denotes the detailed source within grouped sources.\n  *    **`NO_SUBPROVIDER`** - No subtype specified.\n  *    **`CTA_A`** - CTA_A in the DELAYED_SIP provider.\n  *    **`CTA_B`** - CTA_B in the DELAYED_SIP provider.\n  *    **`UTP`** - UTP in the DELAYED_SIP provider.\n  *    **`OTC`** - OTC in the DELAYED_SIP provider.\n  *    **`NASDAQ_BASIC`** - NASDAQ Basic in the NASDAQ_BASIC provider.\n  *    **`IEX`** - From the IEX exchange in the REALTIME provider.\n* **market_center** - Provides the market center\n* **condition** - Provides the condition\n\n\n## API Keys\nYou will receive your Intrinio API Key after [creating an account](https://intrinio.com/signup). You will need a subscription to a [realtime data feed](https://intrinio.com/real-time-multi-exchange) as well.\n\n## Documentation\n\n### Methods\n\n`client = IntrinioRealtimeClient(options)` - Creates an Intrinio Realtime client\n* **Parameter** `options.api_key`: Your Intrinio API Key\n* **Parameter** `options.provider`: The real-time data provider to use (\"REALTIME\" or \"DELAYED_SIP\" or \"NASDAQ_BASIC\")\n* **Parameter** `options.on_quote(quote, backlog)`: A function that handles received quotes. `backlog` is an integer representing the approximate size of the queue of unhandled quote/trade events.\n* **Parameter** `options.on_trade(quote, backlog)`: A function that handles received trades. `backlog` is an integer representing the approximate size of the queue of unhandled quote/trade events.\n* **Parameter** `options.logger`: (optional) A Python Logger instance to use for logging\n\n```python\ndef on_quote(quote, backlog):\n    print(\"QUOTE: \" , quote, \"BACKLOG LENGTH: \", backlog)\ndef on_trade(trade, backlog):\n    print(\"TRADE: \" , trade, \"BACKLOG LENGTH: \", backlog)\n    \noptions = {\n    'api_key': '',\n    'provider': 'REALTIME', # REALTIME or DELAYED_SIP or NASDAQ_BASIC\n    'on_quote': on_quote,\n    'on_trade': on_trade\n}\n\nclient = IntrinioRealtimeClient(options)\n```\n\n---------\n\n`client.join(channels)` - Joins the given channels. This can be called at any time. The client will automatically register joined channels and establish the proper subscriptions with the WebSocket connection.\n* **Parameter** `channels` - A single channel or list of channels. You can also use the special symbol, \"lobby\" to join the firehose channel and recieved updates for all ticker symbols (you must have a valid \"firehose\" subscription).\n```python\nclient.join([\"AAPL\", \"MSFT\", \"GE\"])\nclient.join(\"GOOG\")\nclient.join(\"lobby\")\n```\n---------\n\n`client.connect()` - Retrieves an auth token, opens the WebSocket connection, starts the self-healing and heartbeat intervals, joins requested channels.\n\n---------\n\n`client.keep_alive()` - Runs an infinite loop to keep the thread alive, so that the client continues to receive prices. You may call this function after `connect()` or use your own timing logic (for example: connect, listen for quotes for x minutes, disconnect).\n\n---------\n\n`client.disconnect()` - Closes the WebSocket, stops the self-healing and heartbeat intervals. You _must_ call this to dispose of the client.\n\n---------\n\n`client.on_quote(quote, backlog)` - Changes the quote handler function\n```python\ndef on_quote(quote, backlog):\n    print(\"QUOTE: \" , quote, \"BACKLOG LENGTH: \", backlog)\n    \nclient.on_quote = on_quote\n```\n\n---------\n\n`client.leave(channels)` - Leaves the given channels.\n* **Parameter** `channels` - A single channel or list of channels\n```python\nclient.leave([\"AAPL\", \"MSFT\", \"GE\"])\nclient.leave(\"GOOG\")\n```\n\n---------\n\n`client.leave_all()` - Leaves all channels.\n\n---------\n## Example Replay Client Usage\n```python\ndef on_quote(quote, backlog):\n    print(\"QUOTE: \" , quote, \"BACKLOG LENGTH: \", backlog)\ndef on_trade(trade, backlog):\n    print(\"TRADE: \" , trade, \"BACKLOG LENGTH: \", backlog)\n    \noptions = {\n    'api_key': '',\n    'provider': 'REALTIME', # REALTIME or DELAYED_SIP or NASDAQ_BASIC\n    'replay_date': datetime.date.today(),\n    'with_simulated_delay': False,  # This plays back the events at the same rate they happened in market.\n    'delete_file_when_done': True\n}\n\nclient = IntrinioReplayClient(options, on_trade, on_quote)\n```\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Intrinio Python SDK for Real-Time Stock Prices",
    "version": "5.2.1",
    "project_urls": {
        "Download": "https://github.com/intrinio/intrinio-realtime-python-sdk/archive/v5.1.0.tar.gz",
        "Homepage": "https://intrinio.com"
    },
    "split_keywords": [
        "realtime",
        "stock prices",
        "intrinio",
        "stock market",
        "stock data",
        "financial"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "37b8dd09dd6265ad04658a05af77ad849d0ea3f33ca7e918119379e41f33adfb",
                "md5": "db6ea75d72044bff688639802b52a5cf",
                "sha256": "f6c3ccc9a39f672bd6998184e5b16b1ac312fef5c0edcaf288b4ffb181746cd6"
            },
            "downloads": -1,
            "filename": "intriniorealtime-5.2.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "db6ea75d72044bff688639802b52a5cf",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "~=3.10",
            "size": 25781,
            "upload_time": "2024-02-01T18:15:17",
            "upload_time_iso_8601": "2024-02-01T18:15:17.944575Z",
            "url": "https://files.pythonhosted.org/packages/37/b8/dd09dd6265ad04658a05af77ad849d0ea3f33ca7e918119379e41f33adfb/intriniorealtime-5.2.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fabd6739522889614d1d7e00f993594e194e5b2c97195c862593075d306bc3f5",
                "md5": "b75b9f9d2576c1c4588b0b2eb084eb30",
                "sha256": "97d6e62c4022873f71476ec0ae8b5c3ad213f8a5a94dda5b153cf026b9d9290f"
            },
            "downloads": -1,
            "filename": "intriniorealtime-5.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "b75b9f9d2576c1c4588b0b2eb084eb30",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "~=3.10",
            "size": 26078,
            "upload_time": "2024-02-01T18:15:19",
            "upload_time_iso_8601": "2024-02-01T18:15:19.145175Z",
            "url": "https://files.pythonhosted.org/packages/fa/bd/6739522889614d1d7e00f993594e194e5b2c97195c862593075d306bc3f5/intriniorealtime-5.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-01 18:15:19",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "intrinio",
    "github_project": "intrinio-realtime-python-sdk",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "intriniorealtime"
}
        
Elapsed time: 0.18163s