Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

Commit

Permalink
Add async streaming ticks recipe.
Browse files Browse the repository at this point in the history
  • Loading branch information
erdewit committed Sep 18, 2020
1 parent 9badbc8 commit a7603b6
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion docs/recipes.rst
Expand Up @@ -169,6 +169,41 @@ Fundemental ratios
ib.sleep(2)
print(ticker.fundamentalRatios)
Async streaming ticks
^^^^^^^^^^^^^^^^^^^^^

.. code-block:: python
import asyncio
import ib_insync as ibi
class App:
async def run(self):
self.ib = ibi.IB()
with await self.ib.connectAsync():
contracts = [
ibi.Stock(symbol, 'SMART', 'USD')
for symbol in ['AAPL', 'TSLA', 'AMD', 'INTC']]
for contract in contracts:
self.ib.reqMktData(contract)
async for tickers in self.ib.pendingTickersEvent:
for ticker in tickers:
print(ticker)
def stop(self):
self.ib.disconnect()
app = App()
try:
asyncio.run(app.run())
except (KeyboardInterrupt, SystemExit):
app.stop()
Integration with PyQt5 or PySide2
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down Expand Up @@ -197,4 +232,4 @@ Integration with Tkinter
^^^^^^^^^^^^^^^^^^^^^^^^

To integrate with the Tkinter event loop, take a look at
`this example app <https://github.com/erdewit/ib_insync/blob/master/examples/tk.py>`_.
`this example app <https://github.com/erdewit/ib_insync/blob/master/examples/tk.py>`_.

0 comments on commit a7603b6

Please sign in to comment.