Skip to content

Conversation

@username77
Copy link
Owner

Summary

  • add a .NET console project that calls timeseries.get_range to stream MBP-1 quotes through the historical API
  • document how to run the sample and map its parameters to the existing C++ client

Testing

  • not run (dotnet CLI is unavailable in the execution environment)

https://chatgpt.com/codex/tasks/task_e_68f699fdc8d48324ad3639b013b294d2

@gemini-code-assist
Copy link

Summary of Changes

Hello @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 timeseries.get_range endpoint and clarifying the correspondence of its parameters with existing client implementations.

Highlights

  • New C# Console Example: A new .NET console project, QuotesSample, has been added to demonstrate how to retrieve Databento quotes.
  • Historical API Integration: The sample utilizes the timeseries.get_range endpoint of the historical API to stream Market-By-Price Level 1 (MBP-1) quotes.
  • Documentation for C# Sample: Comprehensive documentation is included, detailing how to run the C# sample and mapping its parameters to the existing C++ client for clarity.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a 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();

Choose a reason for hiding this comment

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

high

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);
        // ...
    }
    // ...
}

Comment on lines +68 to +75
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);
}

Choose a reason for hiding this comment

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

medium

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++;
        }

Comment on lines 35 to 36
`--encoding=json` or `--compression=zstd` is also possible if you prefer other
formats and handle the decoding yourself.

Choose a reason for hiding this comment

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

medium

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants