Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.

flattrade api get potions

Last updated on 8 days ago
K
KevinMember
Posted 8 days ago
import requests
import json

# FlatTrade API credentials
BASE_URL = "https://piconnect.flattrade.in/PiConnectTP"
ACCESS_TOKEN = "3f5d7de21j1bbbb1d853ac4c18d221ab84b1ed79037dbc71d9720xa45a071dd6" # Replace with your current token
USER_ID = "XXXXXXX" # Replace with your User ID
ACCOUNT_ID = "XXXXXXX" # Replace with your Account ID

# Headers for API authentication
HEADERS = {
"Content-Type": "application/json",
}

def get_positions():
"""Fetch the current positions from FlatTrade"""
url = f"{BASE_URL}/PositionBook"
jData = {
"uid": USER_ID,
"actid": ACCOUNT_ID,
}
payload = f"jData={json.dumps(jData)}&jKey={ACCESS_TOKEN}"
response = requests.post(url, headers={"Content-Type": "application/x-www-form-urlencoded"}, data=payload)
if response.status_code == 200:
try:
positions = response.json()
if isinstance(positions, list):
return positions # Return the list of positions
else:
print("Unexpected response structure:", positions)
return []
except json.JSONDecodeError:
print("Failed to decode JSON response:", response.text)
return []
else:
print("Failed to fetch positions:", response.json())
return []

# Run the script
positions = get_positions()
if positions:
print("Positions:")
for position in positions:
print(position)
else:
print("No positions found.")
Edited by Kevin on 14-12-2024 00:49, 8 days ago
You can view all discussion threads in this forum.
You cannot start a new discussion thread in this forum.
You cannot reply in this discussion thread.
You cannot start on a poll in this forum.
You cannot upload attachments in this forum.
You cannot download attachments in this forum.
Sign In
Not a member yet? Click here to register.
Forgot Password?
Users Online Now
Guests Online 4
Members Online 0

Total Members: 11
Newest Member: Jhilam