You must be logged in to post your query.
Home › Forums › StockChart Support › Candlestick Chart
I want to modify this charts-https://canvasjs.com/python-charts/python-combination-charts/candlestick-line-chart/ according to my django web application views.py which is attached here. Please suggest me how I can do this? The candle stick chart will be shown as nifty 200 symobols historical data with json format. views.py-import http.client import json import time from django.shortcuts import render
def index(request): name = ‘KothaEd’ stock_name = ‘ABB’ from_date = ‘240120T09:00:00’ to_date = ‘240129T18:30:00’ interval = ‘eod’
if ‘stockname’ in request.POST: stock_name = request.POST[‘stockname’] if ‘from_date’ in request.POST: from_date = request.POST[‘from_date’] if ‘to_date’ in request.POST: to_date = request.POST[‘to_date’] if ‘interval’ in request.POST: interval = request.POST[‘interval’]
# Credentials username = ‘wssand033’ password = ‘rajdip033′
# Get access token conn = http.client.HTTPSConnection(“auth.truedata.in”) payload = f’username={username}&password={password}&grant_type=password’ headers = {‘Content-Type’: ‘application/x-www-form-urlencoded’} conn.request(“POST”, “/token”, payload, headers) res = conn.getresponse() data = res.read() token_resp = json.loads(data.decode(“utf-8”)) access_token = token_resp.get(‘access_token’, None)
if access_token: # Fetch historical data for the given symbol, from_date, to_date, and interval connHistory = http.client.HTTPSConnection(“history.truedata.in”) payload = ” headers = {‘Authorization’: ‘Bearer ‘ + access_token} endpoint = f”/getbars?symbol={stock_name}&from={from_date}&to={to_date}&response=json&interval={interval}” connHistory.request(“GET”, endpoint, payload, headers) res = connHistory.getresponse() data = res.read().decode(“utf-8”)
# Simulate data fetching delay time.sleep(1)
# Return render to print json data in the template return render(request, ‘stocky/index.html’, {‘name’: name, ‘stockname’: stock_name, ‘from_date’: from_date, ‘to_date’: to_date, ‘interval’: interval, ‘data’: data}) else: print(“Error: ‘access_token’ not found”) return render(request, ‘stocky/index.html’, {‘error’: ‘Access token not found’})
@dbrtechnopharma,
In this example, we are reading data from /static/btc-usd-weekly-2021.json file. In your case, you can store the Nifty 200 data in a JSON format and pass it as datapoints to the chart.
— Manoj Mohan Team CanvasJS
You must be logged in to reply to this topic. Login/Register