Announcing Top Gainers/ Losers, PCR and OI BuildUp APIs for SmartAPI Users
-
@Moderator_1 Hi Team, I am also getting the same error.
Response: {'success': False, 'message': 'Invalid API Key', 'errorCode': 'AG8004', 'data': ''}.
Below is the code I tried. Could you please helpimport requests
Define the API endpoint
url = "https://apiconnect.angelbroking.com/rest/secure/angelbroking/marketData/v1/gainersLosers"
Define the headers (replace with actual values as required)
headers = {
"Authorization": "Bearer eyJhbGciOiJIUzxxxxxxx", #token
"Content-Type": "application/json",
"Accept": "application/json"
}Define the request packet
payload = {
"datatype": "PercPriceGainers", # datatype
"expirytype": "NEAR" # expiry type
}Send the POST request
response = requests.post(url, headers=headers, json=payload)
Check the response
if response.status_code == 200:
print("Request Successful")
print("Response:", response.json())
else:
print(f"Request Failed with status code {response.status_code}")
print("Response:", response.text) -
@omcv It is not supported via websocket.
-
I got a question after going through the documentation of smart-api websocket2.0.
Question: Can we get top gainers/losers through the websocket ?
Is this currently supported ?Can some one kindly address my question. Thanks!
-
Is it still not working for you?
Since you're getting Invalid API key error, can you please confirm that you're able to consume other APIs? Click here -
Hello @SIMAMONDAL
Please go through the below link to get the idea
https://github.com/angel-one/smartapi-python
Regards,
SmartAPI Team -
@Moderator_3 Please explain how to update the sdk to the latest version
Please explain. Thanks for the previous reply.
-
Hello @SIMAMONDAL
Have you updated the sdk to the latest version and please check after the update .
Regards,
SmartAPI Team -
When i write the above code for fetching details of Gainers/ Losers, and call for obj.gainersLosers(params) it shows Attribute Error: 'SmartConnect' object has no attribute 'gainersLosers'
Please help me why the code generate error message and how to solve it .
Thanks in advance.![Screenshot 2024-05-13 074420.png]
-
Hello @Purushottam,
Is it still not working for you?
Since you're getting Invalid API key error, can you please confirm that you're able to consume other APIs?It is working at our end.
Thank you.
Regards
SmartAPI Team -
@Moderator_1 for this api i am getting error of Invalid api Key, though i am having valid API key. Even i tried all four type of API i.e. trading, market, publish, historical