-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode.py
39 lines (28 loc) · 1006 Bytes
/
code.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from nsetools import Nse
nse = Nse()
#api doc http://nsetools.readthedocs.io/en/latest/
all_stock_codes = nse.get_stock_codes()
test = nse.get_quote(input("Enter NSE SYMBOL : "))
from pprint import pprint
#pprint (all_stock_codes)
#user input such as quantity and the price at which the stock was bought
qty = int(input("Enter Quantity Purchased : "))
user_price = float(input("Enter Price : "))
#calculating total price and current price
tot = qty * user_price
present_value = test['lastPrice'] * qty
#checking for profit or loss
if tot>present_value :
difference = - (tot-present_value)
else :
difference = + (present_value - tot)
#loop to generate lastprice traded and the symbol
for key in ['lastPrice', 'symbol']:
print(test[key])
percentage = (difference/tot)*100
print("Quantity Purchased :" , qty)
print("Purchased at :" , user_price)
print("Total Price : %.2f" % tot)
print("Current Price :" , present_value)
print("Profit / Loss : %.2f" % difference)
print(percentage)