Skip to content

Commit

Permalink
Merge pull request #1 from AsthaTech/websocket
Browse files Browse the repository at this point in the history
Websocket
  • Loading branch information
brisingr123 committed May 28, 2023
2 parents e8ccce2 + df6e71f commit 3ee2205
Show file tree
Hide file tree
Showing 7 changed files with 647 additions and 8 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
deploy:
rm -rf dist/*
python -m build
twine upload dist/*
43 changes: 43 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,49 @@ client.place_order(
client.orders(limit=20,offset=1)


```

# Connecting to websocket

Using the feed, you can listen to both price quote changes and order/trade updates. You need to define your own callbacks for `on_price_update`
and `on_order_update`. The packet structure for `on_order_update` is the same as that received in postbacks and is available [here](https://vortex.asthatrade.com/docs/postbacks/)

```python
from vortex_api import VortexFeed
from vortex_api import Constants as Vc
import time

def main():
# Get access token from any of the login methods
wire = VortexFeed(access_token)

wire.on_price_update = on_price_update
wire.on_order_update = on_order_update
wire.on_connect = on_connect
wire.connect(threaded=True)
# If you make threaded = False, anything after this line will not execute

time.sleep(10)

wire.unsubscribe(Vc.ExchangeTypes.NSE_EQUITY, 26000)
wire.unsubscribe(Vc.ExchangeTypes.NSE_EQUITY, 26009)
wire.unsubscribe(Vc.ExchangeTypes.NSE_EQUITY, 2885)


def on_price_update(ws,data):
print(data)

def on_order_update(ws,data):
print(data)

def on_connect(ws, response):
ws.subscribe(Vc.ExchangeTypes.NSE_EQUITY, 26000, Vc.QuoteModes.LTP) #Subscribe to NIFTY
ws.subscribe(Vc.ExchangeTypes.NSE_EQUITY, 26009,Vc.QuoteModes.OHLCV) # Subscribe to BANKNIFTY
ws.subscribe(Vc.ExchangeTypes.NSE_EQUITY, 2885,Vc.QuoteModes.FULL) # Subscribe to RELIANCE

if __name__ == "__main__":
main()

```
Refer to the [python document](https://vortex.asthatrade.com/docs/pyvortex/vortex_api.html) for all methods and features

7 changes: 6 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@
packages=["vortex_api"],
install_requires=[
"requests>=2.25.1",
"wrapt>=1.15.0"
"wrapt>=1.15.0",
"six>=1.11.0",
"pyOpenSSL>=17.5.0",
"python-dateutil>=2.6.1",
"autobahn[twisted]==19.11.2",
"service_identity>=18.1.0"
],
classifiers=[
"Intended Audience :: Developers",
Expand Down
3 changes: 2 additions & 1 deletion vortex_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@
"""
from __future__ import unicode_literals, absolute_import
from vortex_api.api import AsthaTradeVortexAPI,Constants
__all__ = [AsthaTradeVortexAPI,Constants]
from vortex_api.vortex_feed import VortexFeed
__all__ = [AsthaTradeVortexAPI,Constants,VortexFeed]
2 changes: 1 addition & 1 deletion vortex_api/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
__description__ = "Vortex APIs to place orders in AsthaTrade Flow application"
__url__ = "https://vortex.asthatrade.com"
__download_url__ = "https://github.com/AsthaTech/pyvortex"
__version__ = "1.0.5"
__version__ = "1.0.6"
__author__ = "Astha Credit & Securities Pvt Ltd."
__author_email__ = "tech@asthatrade.com"
__license__ = "MIT"
5 changes: 0 additions & 5 deletions vortex_api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import datetime
import logging
from enum import Enum
from functools import wraps
from typing import Type
import inspect
import wrapt

Expand Down Expand Up @@ -571,6 +569,3 @@ def _setup_client_code(self, login_object: dict) -> bool:

return False




Loading

0 comments on commit 3ee2205

Please sign in to comment.