Skip to content

Create Order Book || Holdings || Positions || Details.py #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions Order Book || Holdings || Positions || Details.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/usr/bin/env python





from smartapi import SmartConnect
apikey = 'api_key' # Intentially hidden
username = 'username'
pwd = 'password'

obj=SmartConnect(api_key=apikey)
data = obj.generateSession(username,pwd)
refreshToken= data['data']['refreshToken']
feedToken=obj.getfeedToken()
userProfile= obj.getProfile(refreshToken)
userProfile





obj.tradeBook()


# In[ ]:Object returns Tradebook


obj.orderBook()


# In[ ]:Object returns orderbook


obj.position()


# In[ ]:The current position is returned


obj.holding()


# In[ ]:Holding is displayed


obj.ltpData('NFO','NIFTY24JUN21FUT','48508') #Nifty futures expiry on JUN21


# In[ ]:LTP and orther details are displayed


import json
import pandas as pd
from datetime import datetime
def historicaldata ():
try:
historicParam={
"exchange": "NSE",
"symboltoken": "3045",
"interval": "FIFTEEN_MINUTE",
"fromdate": "2021-05-11 09:15",
"todate": "2021-05-12 10:30"
}

return obj.getCandleData(historicParam)
except Exception as e:
print("Historic Api failed: {}".format(e.message))


# In[ ]:


res_json = historicaldata()
columns = ['timestamp','O','H','L','C','V']
df = pd.DataFrame(res_json['data'], columns=columns)
df['timestamp'] = pd.to_datetime(df['timestamp'],format = '%Y-%m-%dT%H:%M:%S')
df


# In[ ]: