Angel Broking openApi integration
Project description
SMARTAPI-PYTHON
SMARTAPI-PYTHON is a Python library for dealing AMX,that is a set of REST-like HTTP APIs that expose many capabilities required to build stock market investment and trading platforms. It lets you execute orders in real time.
Installation
Use the package manager pip to install smartapi-python.
pip install smartapi-python
Usage
# package import statement
from smartapi import SmartConnect
#create object of call
obj=SmartConnect()
#login api call
data = obj.generateSession("D88311","Angel@444")
refreshToken= data['data']['refreshToken']
#fetch User Profile
userProfile= obj.getProfile(refreshToken)
#place order
try:
orderparams = {
"variety": "NORMAL",
"tradingsymbol": "SBIN-EQ",
"symboltoken": "3045",
"transactiontype": "BUY",
"exchange": "NSE",
"ordertype": "LIMIT",
"producttype": "INTRADAY",
"duration": "DAY",
"price": "19500",
"squareoff": "0",
"stoploss": "0",
"quantity": "1"
}
orderId=obj.placeOrder(orderparams)
print("The order id is: {}".format(orderId))
except Exception as e:
print("Order placement failed: {}".format(e.message))
#logout
try:
logout=obj.terminateSession('D88311')
print("Logout Successfull")
except Exception as e:
print("Logout failed: {}".format(e.message))
#websocket
from smartapi import SmartSocket
FEED_TOKEN= "your feed token"
CLIENT_CODE="your client code"
token="channel you want the information of" #"nse_cm|2885&nse_cm|1594&nse_cm|11536"
ss = SmartSocket(FEED_TOKEN, CLIENT_CODE)
def on_tick(ws, tick):
print("Ticks: {}".format(tick))
def on_connect(ws, response):
ws.send_request(token)
def on_close(ws, code, reason):
ws.stop()
# Assign the callbacks.
ss.on_ticks = on_tick
ss.on_connect = on_connect
ss.on_close = on_close
ss.connect( )
License
MIT
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
smartapi-python-1.0.3.tar.gz
(11.2 kB
view hashes)
Built Distribution
Close
Hashes for smartapi_python-1.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d44d61a831e19c4b3f8590f0db64d116d8cae4344f0bf78cd941eb03c3ac802 |
|
MD5 | 713956d05804b8b49406073936b27e92 |
|
BLAKE2b-256 | 31c473091863c32291141a2a60fd34e136e6c23469ac5dd2e521d73fade648d3 |