-
Notifications
You must be signed in to change notification settings - Fork 0
Add C# console example for requesting Databento quotes #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @username77, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a new C# console application designed to showcase how to programmatically fetch market-by-price level 1 (MBP-1) quotes from the Databento historical API. The example provides C# developers with a practical guide for integrating with the Databento service, illustrating the use of the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request adds a helpful C# example for fetching quotes. The code is well-structured, but I have a few suggestions for improvement. I've pointed out a common issue with HttpClient usage that can lead to socket exhaustion. I've also suggested a more memory-efficient way to process the response stream, which better aligns with the goal of streaming data. Lastly, I've noted a small discrepancy between the README and the code regarding command-line parameters, with a suggestion to align them.
| var end = options.GetValueOrDefault("end", DefaultEnd); | ||
| var limit = options.GetValueOrDefault("limit", DefaultLimit); | ||
|
|
||
| using var httpClient = new HttpClient(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HttpClient is designed to be instantiated once and reused throughout the application's lifecycle. Creating a new HttpClient for each request can lead to socket exhaustion under heavy loads, which is a common pitfall in .NET applications.
It's a best practice to declare it as a static field and reuse the same instance. For this example, you could define it at the class level:
internal static class Program
{
private static readonly HttpClient httpClient = new();
private static async Task<int> Main(string[] args)
{
// ... remove 'using var httpClient = new HttpClient();'
// and use the static instance instead.
httpClient.DefaultRequestHeaders.Authorization = BuildBasicAuthHeader(apiKey);
// ...
}
// ...
}| var csvPayload = await response.Content.ReadAsStringAsync(); | ||
| Console.WriteLine("First few CSV lines returned by the API:"); | ||
| foreach (var line in csvPayload | ||
| .Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries) | ||
| .Take(10)) | ||
| { | ||
| Console.WriteLine(line); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current implementation reads the entire response body into memory using ReadAsStringAsync before processing it. This approach is inefficient for large responses and doesn't align with the concept of "streaming" data, as mentioned in the pull request description.
A more memory-efficient and robust approach is to read the response as a stream, processing it line by line. This avoids buffering the entire content in memory.
Console.WriteLine("First few CSV lines returned by the API:");
await using var stream = await response.Content.ReadAsStreamAsync();
using var reader = new System.IO.StreamReader(stream);
var linesRead = 0;
while (linesRead < 10)
{
var line = await reader.ReadLineAsync();
if (line is null)
{
break;
}
if (string.IsNullOrEmpty(line))
{
continue;
}
Console.WriteLine(line);
linesRead++;
}
examples/csharp/README.md
Outdated
| `--encoding=json` or `--compression=zstd` is also possible if you prefer other | ||
| formats and handle the decoding yourself. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The README suggests that setting --encoding=json or --compression=zstd is possible, implying these are command-line arguments. However, the sample application does not currently parse these arguments and instead uses hardcoded values. This can be confusing for users.
To make the sample more flexible and align it with the documentation, I recommend adding support for these as command-line arguments in Program.cs, similar to how other parameters are handled.
Summary
timeseries.get_rangeto stream MBP-1 quotes through the historical APITesting
https://chatgpt.com/codex/tasks/task_e_68f699fdc8d48324ad3639b013b294d2