Skip to content

Websocketmain/sss 35#15

Merged
anurag-amx merged 7 commits intoangel-one:mainfrom
SameerShaikhAcc:websocketmain/SSS-35
Sep 22, 2023
Merged

Websocketmain/sss 35#15
anurag-amx merged 7 commits intoangel-one:mainfrom
SameerShaikhAcc:websocketmain/SSS-35

Conversation

@SameerShaikhAcc
Copy link
Copy Markdown

Integrated market data api.
added junit test cases for market data API.
updated readme.md file.

Copy link
Copy Markdown

@anurag-amx anurag-amx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String url = routes.get("api.market.data");
JSONObject response = smartAPIRequestHandler.postRequest(this.apiKey, url, params, accessToken);
return response.getJSONObject("data");
}catch (Exception | SmartAPIException e) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is need of calling SmartAPIException while you are already calling Exception?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SmartAPIException class catches custom messages and custom error codes.
also, it extends to the Throwable class. So need to catch it separately

JSONObject response = smartAPIRequestHandler.postRequest(this.apiKey, url, params, accessToken);
return response.getJSONObject("data");
}catch (Exception | SmartAPIException e) {
System.out.println(e.getMessage());
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you using System.out.println(e.getMessage());?

Copy link
Copy Markdown
Author

@SameerShaikhAcc SameerShaikhAcc Jul 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I Have taken references from other methods, In the catch block the error message is printed.
I can use logger instead of System.out.println and handle null but the code will differ from other methods.

some referred methods

public String candleData(JSONObject params) {
	try {
		String url = routes.get("api.candle.data");
		JSONObject response = smartAPIRequestHandler.postRequest(this.apiKey, url, params, accessToken);
		System.out.println(response);
		return response.getString("data");
	} catch (Exception | SmartAPIException e) {
		System.out.println(e.getMessage());
		return null;
	}
}

public JSONObject gttRuleDetails(Integer id) {
	try {

		JSONObject params = new JSONObject();
		params.put("id", id);

		String url = routes.get("api.gtt.details");
		JSONObject response = smartAPIRequestHandler.postRequest(this.apiKey, url, params, accessToken);
		System.out.println(response);

		return response.getJSONObject("data");
	} catch (Exception | SmartAPIException e) {
		System.out.println(e.getMessage());
		return null;
	}

}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is fine . Please start correcting code as suggested. We can start from marketdata.

Comment thread README.md
public void getMarketData(SmartConnect smartConnect) {

JSONObject payload = new JSONObject();
payload.put("mode", "FULL");
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is 3 modes. LTP("LTP"),
OHLC("OHLC"),
FULL("FULL");

why did you cover FULL only? What about the rest?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies for the confusion. I demonstrated the "FULL" mode in the code snippet for simplicity. However, users can easily modify the code to request data in "LTP" or "OHLC" modes by changing the value within the payload JSON object. For "LTP" mode, they should replace the value with "LTP," and for "OHLC" mode, they should use "OHLC" instead.
For EG:
payload.put("mode", "FULL");
payload.put("mode", "LTP");
payload.put("mode", "OHLC");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should mention this in comment section

/** Market Data */
public void getMarketData(SmartConnect smartConnect) {
// Create the payload object
JSONObject payload = new JSONObject();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cover all 3 modes in 3 different funtion.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is rest of function?

response.getJSONObject("data");
}catch (Exception | SmartAPIException e) {
e.printStackTrace();
System.out.println(e.getMessage());
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why you need SmartAPIException e while you capturing Exception?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it extends to the Throwable class. So need to catch it separately.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please read java document again and comment carefully. If java doc is not understood, we can connect.

response.getJSONObject("data");
}catch (Exception | SmartAPIException e) {
e.printStackTrace();
System.out.println(e.getMessage());
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

System.out.println(e.getMessage());?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I Have taken references from other methods, In the catch block the error message is printed.
I can use logger instead of System.out.println and handle null but the code will differ from other methods.

return payload;
}

private static JSONObject createMarketDataResponse() { JSONObject jsonObject = new JSONObject();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cover test cases for all 3 modes.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay




@Test
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Write Method level comment on each method.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay

Comment thread README.md
public void getMarketData(SmartConnect smartConnect) {

JSONObject payload = new JSONObject();
payload.put("mode", "FULL");
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should mention this in comment section

JSONObject response = smartAPIRequestHandler.postRequest(this.apiKey, url, params, accessToken);
return response.getJSONObject("data");
}catch (Exception | SmartAPIException e) {
System.out.println(e.getMessage());
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is fine . Please start correcting code as suggested. We can start from marketdata.

/** Market Data */
public void getMarketData(SmartConnect smartConnect) {
// Create the payload object
JSONObject payload = new JSONObject();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is rest of function?

response.getJSONObject("data");
}catch (Exception | SmartAPIException e) {
e.printStackTrace();
System.out.println(e.getMessage());
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please read java document again and comment carefully. If java doc is not understood, we can connect.

@anurag-amx anurag-amx merged commit f2f8556 into angel-one:main Sep 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants