简体   繁体   中英

How to convert live stock market API data into a usable format to calculate technical indicators?

I'm trying to automate a trading strategy using python. I already have angelbroking stock market API which fetches open high low close values of a stock.

The problem is, by default the API prints the data. I'm unable to understand how to convert this data to a usable format like DataFrames that will update prices accordingly.

In case of historic data, I can create DataFrames to plot various charts with Matplotlib, Plotly and calculate indicators using TA-lib or math formulas in some cases.

So, how to convert the live stock market API data into a usable format to calculate the technical indicators?

Below is the API:

from smartapi import 
SmartWebSocket

# feed_token=092017047
FEED_TOKEN="YOUR_FEED_TOKEN"
CLIENT_CODE="YOUR_CLIENT_CODE"
# token="mcx_fo|224395"
token="EXCHANGE|TOKEN_SYMBOL"    
#SAMPLE: nse_cm|2885&nse_cm|1594&nse_cm|11536&nse_cm|3045
task="mw"   # mw|sfi|dp

ss = SmartWebSocket(FEED_TOKEN, CLIENT_CODE)

def on_message(ws, message):
    print("Ticks: {}".format(message))

def on_open(ws):
    print("on open")
    ss.subscribe(task,token)

def on_error(ws, error):
    print(error)

def on_close(ws):
    print("Close")

# Assign the callbacks.
ss._on_open = on_open
ss._on_message = on_message
ss._on_error = on_error
ss._on_close = on_close

ss.connect()

Any suggestion is helpful. Thanks for your valuable time.

You have access to the documentation since you have an account. Please read it first and watch some tutorials before asking questions. I do not have access to the documentation since there is an account wall.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM