Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sreenivasdoosa
GitHub Repository: sreenivasdoosa/sdoosa-algo-trade-python
Path: blob/master/src/core/Quotes.py
297 views
1
import logging
2
3
from core.Controller import Controller
4
from models.Quote import Quote
5
6
class Quotes:
7
@staticmethod
8
def getQuote(tradingSymbol, isFnO = False):
9
broker = Controller.getBrokerName()
10
brokerHandle = Controller.getBrokerLogin().getBrokerHandle()
11
quote = None
12
if broker == "zerodha":
13
key = ('NFO:' + tradingSymbol) if isFnO == True else ('NSE:' + tradingSymbol)
14
bQuoteResp = brokerHandle.quote(key)
15
bQuote = bQuoteResp[key]
16
# convert broker quote to our system quote
17
quote = Quote(tradingSymbol)
18
quote.tradingSymbol = tradingSymbol
19
quote.lastTradedPrice = bQuote['last_price']
20
quote.lastTradedQuantity = bQuote['last_quantity']
21
quote.avgTradedPrice = bQuote['average_price']
22
quote.volume = bQuote['volume']
23
quote.totalBuyQuantity = bQuote['buy_quantity']
24
quote.totalSellQuantity = bQuote['sell_quantity']
25
ohlc = bQuote['ohlc']
26
quote.open = ohlc['open']
27
quote.high = ohlc['high']
28
quote.low = ohlc['low']
29
quote.close = ohlc['close']
30
quote.change = bQuote['net_change']
31
quote.oiDayHigh = bQuote['oi_day_high']
32
quote.oiDayLow = bQuote['oi_day_low']
33
quote.lowerCiruitLimit = bQuote['lower_circuit_limit']
34
quote.upperCircuitLimit = bQuote['upper_circuit_limit']
35
else:
36
# The logic may be different for other brokers
37
quote = None
38
return quote
39
40
@staticmethod
41
def getCMP(tradingSymbol):
42
quote = Quotes.getQuote(tradingSymbol)
43
if quote:
44
return quote.lastTradedPrice
45
else:
46
return 0
47