Last active
February 18, 2025 15:20
-
-
Save prabuinet/9daf8ddbf6a0dbbfd945cf2e50be46f3 to your computer and use it in GitHub Desktop.
Shoonya GetOrderMargin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public Result<string> GetOrderMargin() | |
| { | |
| string jsonString = $$""" | |
| { | |
| "uid":"{{loggedInUser.UserId}}", | |
| "actid":"{{loggedInUser.UserId}}", | |
| "exch":"NSE", | |
| "tsym":"ASHOKLEY-EQ", | |
| "qty":"1", | |
| "prc":"0.0", | |
| "prd":"I", | |
| "trantype":"B", | |
| "prctyp":"MKT" | |
| } | |
| """; | |
| HttpClient client = new HttpClient(); | |
| var content = new StringContent($"jData={jsonString.ToString()}&jKey={sessionToken}", Encoding.UTF8, "application/json"); | |
| var str = content.ReadAsStringAsync().GetAwaiter().GetResult(); | |
| var result = client.PostAsync(BASE_URL + "GetOrderMargin", content).GetAwaiter().GetResult(); | |
| if (result.StatusCode == System.Net.HttpStatusCode.OK) | |
| { | |
| string json_str = result.Content.ReadAsStringAsync().Result; | |
| dynamic json_obj = JsonNode.Parse(json_str); | |
| if (json_obj!["stat"].GetValue<string>() == "Ok") | |
| { | |
| Log.Information("get order margin success"); | |
| return ""; | |
| } | |
| else | |
| { | |
| var error = $"ShoonyaBorker Login failed: {json_obj!["emsg"].GetValue<string>()}"; | |
| Log.Error(error); | |
| return new Error(error); | |
| } | |
| } | |
| else | |
| { | |
| var error = $"Invalid status code: ShoonyaBorker Login {result.StatusCode}"; | |
| Log.Error(error); | |
| return new Error(error); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment