The official Python client for the Tiqs trading API
Project description
TIQS API Client
Official Python client for Tiqs.
Documentation
Installation
You can install the package using:
python3 -m pip install pytiqs
update to latest version
python3 -m pip install -U pytiqs
API Usage
import logging
from pytiqs import Tiqs, constants
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s | %(levelname)s | %(name)s:%(lineno)d | %(message)s')
tiqs = Tiqs(app_id="<APP_ID>")
# login and generate the request token from the URL obtained from tiqs.login_url()
tiqs.generate_session(request_token="<REQUEST_TOKEN>", api_secret="<API_SECRET>")
try:
order_no = tiqs.place_order(
exchange=constants.Exchange.NFO,
token="46338",
qty=15,
disclosed_qty=0,
product=constants.ProductType.NRML,
symbol="BANKNIFTY2441048900CE",
transaction_type=constants.TransactionType.BUY,
order_type=constants.OrderType.MARKET,
variety=constants.Variety.REGULAR,
price=0,
validity=constants.Retention.DAY,
tags=None,
amo=False,
trigger_price=None
)
logging.info("order id: {}".format(order_no))
except Exception as e:
logging.error("error in order placement: {}".format(e))
# get order by order number
order = tiqs.get_order("24040200000302")
# delete order
response = tiqs.delete_order("24040200000302")
# all orders
user_orders = tiqs.get_user_orders()
# all trades
user_trades = tiqs.get_user_trades()
# user details
tiqs.user_details()
# positions
tiqs.get_positions()
# all instruments
tiqs.get_instruments()
# market holidays
holidays = tiqs.holidays()
# index list
index_list = tiqs.index_list()
# option chain for an underlying asset for a give expiry date
option_chain = tiqs.option_chain(params={
"token": "26009",
"exchange": "INDEX",
"count": "10",
"expiry": "10-APR-2024"
})
Websockets
import time
import logging
from pytiqs import TiqsSocket
def on_ticks(ws, ticks):
logging.debug("Ticks: {}".format(ticks))
def on_connect(ws, response):
ws.subscribe([7929])
time.sleep(5)
ws.set_mode(socketClient.MODE_LTP, [7929])
def on_close(ws, code, reason):
logging.debug("closed, {}, {}".format(code, reason))
ws.stop()
socketClient = TiqsSocket(app_id="<APP_ID>", token="<token>")
socketClient.on_ticks = on_ticks
socketClient.on_connect = on_connect
socketClient.on_close = on_close
# if you want to keep this as non-blocking code use socketClient.connect(threaded=True)
socketClient.connect()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pytiqs-1.0.8.tar.gz
(13.1 kB
view hashes)
Built Distribution
pytiqs-1.0.8-py3-none-any.whl
(12.8 kB
view hashes)