Aliceblue tick data reading and extraction ltp and other key value

Respected Sir,



                           i need to learning about data extraction tick by tick provided by aliceblue python api.

please can u guide me something for this. about extraction in loop



sample as below





quote update {'exchange': 'MCX', 'token': 217622, 'ltp': 117.2, 'ltt': 1584950285, 'ltq': 1, 'volume': 19101, 'best_bid_price': 117.1, 'best_bid_quantity': 234, 'best_ask_price': 117.2, 'best_ask_quantity': 234, 'total_buy_quantity': 1283, 'total_sell_quantity': 1282, 'atp': 117.68, 'exchange_time_stamp': 1584950290, 'open': 121.3, 'high': 121.3, 'low': 117.0, 'close': 122.5, 'yearly_high': 158.7, 'yearly_low': 117.0, 'instrument': Instrument(exchange='MCX', token='217622', symbol='NATURALGAS MAR FUT', name='', expiry=datetime.date(2020, 3, 26), lot_size=None)}





quote update {'exchange': 'MCX', 'token': 217622, 'ltp': 117.2, 'ltt': 1584950285, 'ltq': 1, 'volume': 19101, 'best_bid_price': 117.1, 'best_bid_quantity': 234, 'best_ask_price': 117.2, 'best_ask_quantity': 233, 'total_buy_quantity': 1283, 'total_sell_quantity': 1282, 'atp': 117.68, 'exchange_time_stamp': 1584950291, 'open': 121.3, 'high': 121.3, 'low': 117.0, 'close': 122.5, 'yearly_high': 158.7, 'yearly_low': 117.0, 'instrument': Instrument(exchange='MCX', token='217622', symbol='NATURALGAS MAR FUT', name='', expiry=datetime.date(2020, 3, 26), lot_size=None)}







quote update {'exchange': 'MCX', 'token': 217622, 'ltp': 117.2, 'ltt': 1584950285, 'ltq': 1, 'volume': 19101, 'best_bid_price': 117.1, 'best_bid_quantity': 234, 'best_ask_price': 117.2, 'best_ask_quantity': 233, 'total_buy_quantity': 1283, 'total_sell_quantity': 1282, 'atp': 117.68, 'exchange_time_stamp': 1584950291, 'open': 121.3, 'high': 121.3, 'low': 117.0, 'close': 122.5, 'yearly_high': 158.7, 'yearly_low': 117.0, 'instrument': Instrument(exchange='MCX', token='217622', symbol='NATURALGAS MAR FUT', name='', expiry=datetime.date(2020, 3, 26), lot_size=None)}                      



                                              

Hello Neelam,

Alice blue as far as I know is a json wrapper for HTTP. Are you talking about this library? Also, could you please elaborate on how you're re getting this data? As in the python script or commands used? Will be able to help you out better thereafter.

HOW TO GET A OBJECT WITH LTP FOR USE MY FURTHER ALGO



import logging

import pandas as pd

import numpy as np

import json

from alice_blue import *

import protlib

from websocket import *

import websocket

import threading

import json

import time

import timedelta

from pprint import pprint

import requests

import bs4

import datetime

from ws_client import handle_streams

import pprint

import pandas as pd


logging.basicConfig(level=logging.DEBUG)


access_token = AliceBlue.login_and_get_access_token(username='AB059096', password='abcd1234', twoFA='7',  api_secret='NUK5FHNRSINTR32FKEU29PFGOCF4BT1G9NE4GKEPE40P95CNN9P7W6Y7ODQCBSQ8')
alice = AliceBlue(username='username', password='password', access_token=access_token)

alice.get_all_subscriptions() # All


alice = AliceBlue(username='username', password='password', access_token=access_token, master_contracts_to_download=['NSE', 'BSE','MCX','NFO'])

socket_opened = False
def event_handler_quote_update(message):
    print(f"quote update {message}")

def open_callback():
    global socket_opened
    socket_opened = True
    # for lastprice in ngprice:
    #     print (lastprice['ltp'])

alice.start_websocket(subscribe_callback=event_handler_quote_update,
                      socket_open_callback=open_callback,
                      run_in_background=True)
while(socket_opened==False):
    pass

NG = alice.get_instrument_by_token(217897)
instrument = alice.subscribe((NG), LiveFeedType.MARKET_DATA)


th = threading.Thread(target=handle_streams, args=(access_token,))
pprint.pprint (th.start())

# success

From the documentation, you can create an AliceBlue object with your access_token, username and password as shown below and then check the your connectivity

alice = AliceBlue(username='username', password='password', access_token=access_token)

Source: https://github.com/krishnavelu/alice_blue#create-aliceblue-object

my question r too simple

how to extract ltp for making indicator parameter or in using pandas/numpy/talib



formula for use ltp and other key and value…



i can't



please help me…

You can refer to below blog to get the historical data in Python

https://blog.quantinsti.com/stock-market-data-analysis-python/



And below blog to learn to create technical indicators

https://blog.quantinsti.com/build-technical-indicators-in-python/



If you want to learn to fetch the live data, then you can refer to below course

https://quantra.quantinsti.com/course/Automated-Trading-IBridgePY-Interactive-Brokers-Platform



I hope this helps.



Thanks

Respected Sir,



i want to learn about particular extract ltp of given above data to manupulation 





you want to learn to fetch the live data of aliceblue placeform …i m already able to fetch but can't extract 

ltp and other key or value 



please guide me about fetch specially ltp then create indicator from ltp…



ibridge is good but i want to learn about my aliceblue data fetching and extraction for next level …



this just like 

i demand a pizza  and u r suggest try  burger…

 i want learn about aliceblue data fetching specially ltp and other key and value for making more using talib





please understand my need

if u can't please tell me

mo…8104093607



please call if u need

I would like to tell you that the overall framework for live trading remains the same. You can refer to the alice-blue documentation for more details. It can be accessed from here: https://pypi.org/project/alice-blue/

 
Moreover, I believe the below piece of code would help you to get the data. There are four types of feed data, you can select as per your requirements. 
 
alice.subscribe(alice.get_instrument_by_symbol('NSE', 'ONGC'), LiveFeedType.MARKET_DATA)

Thank you

Sir, you are right sir, but 

alice.subscribe(alice.get_instrument_by_symbol('NSE', 'ONGC'), LiveFeedType.MARKET_DATA)

this code give me all data set 
but i can't iterate this data  like ltp bid and ask price and volume (iteration not allowed)
or can't use this for algo till now...

so a little help for generate a code to extract ltp then make a pandas series to generate indicator based signals
how it's possible please help me......

your given code are produced return data like as above i show in my first query....

You can write an infinite while loop as below. It returns a dictionary from which you can extract ltp and other required fields from it.

while True:
    alice.subscribe(alice.get_instrument_by_symbol('NSE', 'ONGC'), LiveFeedType.MARKET_DATA)
    sleep(10)

You can learn about the dictionary and while loop from below



1. https://quantra.quantinsti.com/course/python-trading-basic

2. w3schools: https://www.w3schools.com/python/python_dictionaries.asp

def event_handler_quote_update(message):
    print(f"quote update {message}")
    global ltp
    ltp = message['ltp']
    print(ltp)

Thanks a lot brother for this .

If you are still not able to resove this issue, let me know. I can help you. I know this is older thread and just now I saw while searching something else. If you still want answer for this, ping me on 7013909937.