Exemplo n.º 1
0
def get_quote(symbol, series='EQ', instrument=None, expiry=None, option_type=None, strike=None):
    """
    1. Underlying security (stock symbol or index name)
    2. instrument (FUTSTK, OPTSTK, FUTIDX, OPTIDX)
    3. expiry (ddMMMyyyy)
    4. type (CE/PE for options, - for futures
    5. strike (strike price upto two decimal places
    """

    if instrument:
        #expiry_str = "%02d%s%d"%(expiry.day, months[expiry.month][0:3].upper(), expiry.year)
        quote_derivative_url.session.headers.update({'Referer': eq_quote_referer.format(symbol)})
        res = quote_derivative_url(symbol, instrument, expiry, option_type, strike)
    else:
        quote_eq_url.session.headers.update({'Referer': eq_quote_referer.format(symbol)})
        res = quote_eq_url(symbol, series)

    d =  json.loads(res.text)['data'][0]
    res = {}
    for k in d.keys():
        v = d[k]
        try:
            v_ = None
            if v.find('.') > 0:
                v_ = float(v.strip().replace(',', ''))
            else:
                v_ = int(v.strip().replace(',', ''))
        except:
            v_ = v
        res[k] = v_
    return res
Exemplo n.º 2
0
def get_quote(symbol, series='EQ', instrument=None, expiry=None, option_type=None, strike=None):
    """
    1. Underlying security (stock symbol or index name)
    2. instrument (FUTSTK, OPTSTK, FUTIDX, OPTIDX)
    3. expiry (ddMMMyyyy)
    4. type (CE/PE for options, - for futures
    5. strike (strike price upto two decimal places
    """

    if instrument:
        expiry_str = "%02d%s%d"%(expiry.day, months[expiry.month][0:3].upper(), expiry.year)
        res = quote_derivative_url(symbol, instrument, expiry_str, option_type, strike)

    res = quote_eq_url(symbol, series)

    return json.loads(res.text)['data'][0]
Exemplo n.º 3
0
def get_quote(symbol,
              series='EQ',
              instrument=None,
              expiry=None,
              option_type=None,
              strike=None):
    """
    1. Underlying security (stock symbol or index name)
    2. instrument (FUTSTK, OPTSTK, FUTIDX, OPTIDX)
    3. expiry (ddMMMyyyy)
    4. type (CE/PE for options, - for futures
    5. strike (strike price upto two decimal places
    """
    global d
    if instrument:
        expiry_str = "%02d%s%d" % (
            expiry.day, months[expiry.month][0:3].upper(), expiry.year)
        quote_derivative_url.session.headers.update(
            {'Referer': eq_quote_referer.format(symbol)})
        strike_str = "{:.2f}".format(strike) if strike else ""
        res = quote_derivative_url(symbol, instrument, expiry_str, option_type,
                                   strike_str)
    else:
        quote_eq_url.session.headers.update(
            {'Referer': eq_quote_referer.format(symbol)})
        res = quote_eq_url(symbol, series)

    html_soup = BeautifulSoup(res.text, 'lxml')
    hresponseDiv = html_soup.find("div", {"id": "responseDiv"})
    try:
        d = json.loads(hresponseDiv.get_text())
    except:
        print("Error >> ", hresponseDiv.get_text())
    #d = json.loads(res.text)['data'][0]
    res = {}
    for k in d['data'][0].keys():
        v = d['data'][0][k]
        try:
            v_ = None
            if v.find('.') > 0:
                v_ = float(v.strip().replace(',', ''))
            else:
                v_ = int(v.strip().replace(',', ''))
        except:
            v_ = v
        res[k] = v_
    return res
Exemplo n.º 4
0
 def test_quote_derivative_url(self):
     resp = quote_derivative_url("NIFTY", "FUTIDX", "26AUG2021", '-', '-')
     html_soup = BeautifulSoup(resp.text, 'lxml')
     hresponseDiv = html_soup.find("div", {"id": "responseDiv"})
     d = json.loads(hresponseDiv.get_text().strip())
     self.assertEqual(d['companyName'], 'Nifty 50')
Exemplo n.º 5
0
 def test_quote_derivative_url(self):
     resp = quote_derivative_url("NIFTY", "FUTIDX", "26SEP2019", '-', '-')
     html_soup = BeautifulSoup(resp.text, 'lxml')
     hresponseDiv = html_soup.find("div", {"id": "responseDiv"})
     d = json.loads(hresponseDiv.get_text())
     self.assertEqual(d['data'][0]['underlying'], 'NIFTY')
Exemplo n.º 6
0
 def test_quote_derivative_url(self):
     resp = quote_derivative_url("NIFTY", "FUTIDX", "29DEC2016", '-', '-')
     d = json.loads(resp.content)
     self.assertEqual(d['data'][0]['underlying'], 'NIFTY')
Exemplo n.º 7
0
 def test_quote_derivative_url(self):
     resp = quote_derivative_url("NIFTY", "FUTIDX", "29DEC2016", '-', '-')
     d = json.loads(resp.content)
     self.assertEqual(d['data'][0]['underlying'], 'NIFTY')