Skip to main content

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 #or from smartapi.smartConnect import SmartConnect
#import smartapi.smartExceptions(for smartExceptions)

#create object of call
obj=SmartConnect(api_key="your api key")

#login api call

data = obj.generateSession("Your Client ID","Your Password")
refreshToken= data['data']['refreshToken']

#fetch the feedtoken
feedToken=obj.getfeedToken()

#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('Your Client Id')
    print("Logout Successfull")
except Exception as e:
    print("Logout failed: {}".format(e.message))

##------websocket------
from smartapi import WebSocket 
FEED_TOKEN= "your feed token"
CLIENT_CODE="your client Id"
token="channel you want the information of" #"nse_cm|2885&nse_cm|1594&nse_cm|11536"

ss = WebSocket(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( )

Project details


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.5.5.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

smartapi_python-1.0.5.5-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file smartapi-python-1.0.5.5.tar.gz.

File metadata

  • Download URL: smartapi-python-1.0.5.5.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.6.0

File hashes

Hashes for smartapi-python-1.0.5.5.tar.gz
Algorithm Hash digest
SHA256 6463de37824a58cfeddd0654440c8aa09d412e5ee9f79347ac28a85269c45756
MD5 502fab34df655473070913b744a010af
BLAKE2b-256 8afd70662f542a002c325e077ce3d5948d30e3788d160d6f23a8714f75be8c72

See more details on using hashes here.

File details

Details for the file smartapi_python-1.0.5.5-py3-none-any.whl.

File metadata

  • Download URL: smartapi_python-1.0.5.5-py3-none-any.whl
  • Upload date:
  • Size: 11.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.6.0

File hashes

Hashes for smartapi_python-1.0.5.5-py3-none-any.whl
Algorithm Hash digest
SHA256 77062710a275172cd732b1d9a8bbf387bfac4470eeb401de7d0643a7f5cd0315
MD5 925e6b1e87bccc5ad6169baf13615f88
BLAKE2b-256 c13df5d0d0799d4ae2ca88ba976a8aa8b7f851c8202c12226b4c7eae82e48df4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page