Skip to content
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

add formatted console output for ISeries classes #1293

Closed
DaveSkender opened this issue Dec 21, 2024 · 0 comments · Fixed by #1150
Closed

add formatted console output for ISeries classes #1293

DaveSkender opened this issue Dec 21, 2024 · 0 comments · Fixed by #1150
Assignees
Labels
enhancement New feature or request

Comments

@DaveSkender
Copy link
Owner

DaveSkender commented Dec 21, 2024

the problem

When I'm using online code sharing tools like https://dotnetfiddle.net I like to use Console.WriteLine(results) to simply visualize on of the ISeries or IReusable records from the indicators results.

These POCO classes have their own unique set of properties. I'd like the output to look like this example, for all such property types, where the description is based on XML comments. Any JsonIngore attributed fields are excluded.

# inputs
private static readonly CultureInfo EnglishCulture = new("en-US", false);
DateTime timestamp = DateTime.TryParse("2017-02-03", EnglishCulture, out DateTime d) ? d : default
Quote quote = new Quote(timestamp,216.18,216.87,215.84,216.67,85273832)

# string output for Quote class
Property   Type           Value  Description
-------------------------------------------------------------------
Timestamp  DateTime  2024-02-02  Gets the date/time of the record.
Open       Decimal       216.18  Aggregate bar's first tick price
High       Decimal       216.87  Aggregate bar's highest tick price
Low        Decimal       215.84  Aggregate bar's lowest tick price
Close      Decimal       216.67  Aggregate bar's last tick price
Volume     Decimal     85273832  Aggregate bar's tick volume

References

Quote class

namespace Skender.Stock.Indicators;

// QUOTE MODELS

public interface IQuote : IReusable
{
    /// <summary>
    /// Aggregate bar's first tick price
    /// </summary>
    decimal Open { get; }

    /// <summary>
    /// Aggregate bar's highest tick price
    /// </summary>
    decimal High { get; }

    /// <summary>
    /// Aggregate bar's lowest tick price
    /// </summary>
    decimal Low { get; }

    /// <summary>
    /// Aggregate bar's last tick price
    /// </summary>
    decimal Close { get; }

    /// <summary>
    /// Aggregate bar's tick volume
    /// </summary>
    decimal Volume { get; }
}

[Serializable]
public record Quote
(
    DateTime Timestamp,
    decimal Open,
    decimal High,
    decimal Low,
    decimal Close,
    decimal Volume
) : IQuote
{
    [JsonIgnore]
    public double Value => (double)Close;
}

IReusable interface

public interface IReusable : ISeries
{
    /// <summary>
    /// Value that is passed to chained indicators.
    /// </summary>
    [JsonIgnore]
    double Value { get; }
}

ISeries interface

/// <summary>
/// Time-series base interface.
/// </summary>
public interface ISeries
{
    /// <summary>
    /// Gets the date/time of the record.
    /// </summary>
    DateTime Timestamp { get; }
}

Related to:

an idea

string out = quote.ToStringOut(args);
Console.WriteLine(out);
  • All fields can have named formatting preferences in args, for example:

    Dictionary<string, string> args new() = 
    {
        { "Open", "N2" },
        { "High", "N2" },
        { "Low", "N2" },
        { "Close", "N2" },
        { "Volume", "N0" }, // No decimal places
        { "Date", "yyyy-MM-dd HH:mm" } // Include milliseconds
    };
  • args can also target specific primitive types, but also allow overrides based on sequencing in the args list (last format wins)

    Dictionary<string, string> args new() = 
    {
        { "decimal", "N2" },
        { "Volume", "N0" },            // override decimal places
        { "Date", "yyyy-MM-dd HH:mm" } // Include milliseconds
    };
  • when args or individual properties aren't covered, do not apply formatting

code example

# inputs
DateTime timestamp = DateTime.TryParse("2017-02-03T23:54:15.123", Culture.InvariantCulture, out DateTime d) ? d : default
Quote quote = new Quote(timestamp,216.181,216.871,215.84,216.674,85273832)

string out = quote.ToStringOut();

Console.WriteLine(out);
# console output
Property   Type                 Value  Description
-------------------------------------------------------------------
Timestamp  DateTime  2024-02-03 23.54  Gets the date/time of the record.
Open       Decimal             216.18  Aggregate bar's first tick price
High       Decimal             216.87  Aggregate bar's highest tick price
Low        Decimal             215.84  Aggregate bar's lowest tick price
Close      Decimal             216.67  Aggregate bar's last tick price
Volume     Decimal           85273832  Aggregate bar's tick volume
@DaveSkender DaveSkender added the enhancement New feature or request label Dec 21, 2024
@DaveSkender DaveSkender self-assigned this Dec 21, 2024
@DaveSkender DaveSkender linked a pull request Dec 22, 2024 that will close this issue
10 tasks
@DaveSkender DaveSkender moved this from Maybe to In Review in Stock Indicators for .NET Dec 23, 2024
@github-project-automation github-project-automation bot moved this from In Review to Done in Stock Indicators for .NET Dec 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant