Beispiel #1
0
def get_quote(symbol,exchange = 'NSE'):
    session = requests.Session()
    post_data = symbol +  '|^ALL|^Q|^|$'
    resp = session.post(ICICI_QUOTE_URL, data = post_data)
    q_resp = resp.text.replace('0|$','').replace('|$','').split('|^')
    #print q_resp
    q_NSE = QuoteInfo()
    q_BSE = QuoteInfo()
    now = datetime.datetime.now()
    q_NSE.symbol = symbol
    q_NSE.exchange = 'NSE'    
    q_NSE.date = now.date()
    q_NSE.local_time = now.time()
    q_NSE.price = float(q_resp[19])
    q_NSE.volume = int(q_resp[31])
    q_NSE.changepct = float(q_resp[20])
    dt = time.strptime(q_resp[22],'%d-%b-%Y %H:%M:%S')
    q_NSE.time = datetime.time(hour=dt.tm_hour,minute=dt.tm_min,second=dt.tm_sec)
    
    q_BSE.symbol = symbol
    q_BSE.exchange = 'BSE'    
    q_BSE.date = now.date()
    q_BSE.local_time = now.time()
    q_BSE.price = float(q_resp[2])
    q_BSE.volume = int(q_resp[14])
    q_BSE.changepct = float(q_resp[3])
    dt = time.strptime(q_resp[5],'%d-%b-%Y %H:%M:%S')
    q_BSE.time = datetime.time(hour=dt.tm_hour,minute=dt.tm_min,second=dt.tm_sec)
      
    if exchange == 'NSE':
        return [q_NSE]
    elif exchange == 'BSE':
        return [q_BSE]
    elif exchange == 'ALL':
        return [q_NSE,q_BSE]
Beispiel #2
0
def get_quote(symbol, exchange='NSE'):
    #cj = cookielib.CookieJar()
    #opener = urllib2.build_opener(HTTPHandler(),HTTPSHandler(),HTTPErrorProcessor(),HTTPCookieProcessor(cj))
    req = requests.Session()
    post_data = symbol + '|^ALL|^Q|^|$'
    resp = req.post(ICICI_QUOTE_URL, data=post_data)
    q_resp = resp.text.replace('0|$', '').replace('|$', '').split('|^')
    q_NSE = QuoteInfo()
    q_BSE = QuoteInfo()
    now = datetime.datetime.now()
    q_NSE.symbol = symbol
    q_NSE.exchange = 'NSE'
    q_NSE.date = now.date()
    q_NSE.local_time = now.time()
    q_NSE.price = float(q_resp[19])
    q_NSE.volume = int(q_resp[31])
    q_NSE.changepct = float(q_resp[20])
    dt = time.strptime(q_resp[22], '%d-%b-%Y %H:%M:%S')
    q_NSE.time = datetime.time(hour=dt.tm_hour,
                               minute=dt.tm_min,
                               second=dt.tm_sec)

    q_BSE.symbol = symbol
    q_BSE.exchange = 'BSE'
    q_BSE.date = now.date()
    q_BSE.local_time = now.time()
    q_BSE.price = float(q_resp[2])
    q_BSE.volume = int(q_resp[14])
    q_BSE.changepct = float(q_resp[3])
    dt = time.strptime(q_resp[5], '%d-%b-%Y %H:%M:%S')
    q_BSE.time = datetime.time(hour=dt.tm_hour,
                               minute=dt.tm_min,
                               second=dt.tm_sec)

    if exchange == 'NSE':
        return [q_NSE]
    elif exchange == 'BSE':
        return [q_BSE]
    elif exchange == 'ALL':
        return [q_NSE, q_BSE]
Beispiel #3
0
def get_quote(symbol, exchange='NSE'):
    session = requests.Session()
    post_data = symbol + '|^ALL|^Q|^|$'
    resp = session.post(ICICI_QUOTE_URL, data=post_data)
    q_resp = resp.text.replace('0|$', '').replace('|$', '').split('|^')
    #print q_resp
    q_NSE = QuoteInfo()
    q_BSE = QuoteInfo()
    now = datetime.datetime.now()
    q_NSE.symbol = symbol
    q_NSE.exchange = 'NSE'
    q_NSE.date = now.date()
    q_NSE.local_time = now.time()
    q_NSE.price = float(q_resp[19])
    q_NSE.volume = int(q_resp[31])
    q_NSE.changepct = float(q_resp[20])
    dt = time.strptime(q_resp[22], '%d-%b-%Y %H:%M:%S')
    q_NSE.time = datetime.time(hour=dt.tm_hour,
                               minute=dt.tm_min,
                               second=dt.tm_sec)

    q_BSE.symbol = symbol
    q_BSE.exchange = 'BSE'
    q_BSE.date = now.date()
    q_BSE.local_time = now.time()
    q_BSE.price = float(q_resp[2])
    q_BSE.volume = int(q_resp[14])
    q_BSE.changepct = float(q_resp[3])
    dt = time.strptime(q_resp[5], '%d-%b-%Y %H:%M:%S')
    q_BSE.time = datetime.time(hour=dt.tm_hour,
                               minute=dt.tm_min,
                               second=dt.tm_sec)

    if exchange == 'NSE':
        return [q_NSE]
    elif exchange == 'BSE':
        return [q_BSE]
    elif exchange == 'ALL':
        return [q_NSE, q_BSE]
Beispiel #4
0
def get_quote(symbol,exchange = 'NSE'):
    #cj = cookielib.CookieJar()
    #opener = urllib2.build_opener(HTTPHandler(),HTTPSHandler(),HTTPErrorProcessor(),HTTPCookieProcessor(cj))
    req = requests.Session()
    post_data = symbol +  '|^ALL|^Q|^|$'
    resp = req.post(ICICI_QUOTE_URL,data = post_data)
    q_resp = resp.text.replace('0|$','').replace('|$','').split('|^')
    q_NSE = QuoteInfo()
    q_BSE = QuoteInfo()
    now = datetime.datetime.now()
    q_NSE.symbol = symbol
    q_NSE.exchange = 'NSE'    
    q_NSE.date = now.date()
    q_NSE.local_time = now.time()
    q_NSE.price = float(q_resp[19])
    q_NSE.volume = int(q_resp[31])
    q_NSE.changepct = float(q_resp[20])
    dt = time.strptime(q_resp[22],'%d-%b-%Y %H:%M:%S')
    q_NSE.time = datetime.time(hour=dt.tm_hour,minute=dt.tm_min,second=dt.tm_sec)
    
    q_BSE.symbol = symbol
    q_BSE.exchange = 'BSE'    
    q_BSE.date = now.date()
    q_BSE.local_time = now.time()
    q_BSE.price = float(q_resp[2])
    q_BSE.volume = int(q_resp[14])
    q_BSE.changepct = float(q_resp[3])
    dt = time.strptime(q_resp[5],'%d-%b-%Y %H:%M:%S')
    q_BSE.time = datetime.time(hour=dt.tm_hour,minute=dt.tm_min,second=dt.tm_sec)
      
    if exchange == 'NSE':
        return [q_NSE]
    elif exchange == 'BSE':
        return [q_BSE]
    elif exchange == 'ALL':
        return [q_NSE,q_BSE]