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

Accept and process multiple Candle Resolutions #266

Open
rrupesh opened this issue Jan 13, 2025 · 6 comments
Open

Accept and process multiple Candle Resolutions #266

rrupesh opened this issue Jan 13, 2025 · 6 comments

Comments

@rrupesh
Copy link

rrupesh commented Jan 13, 2025

Currently, I am streaming 1min candles from a source. If I understood correctly, the asset.snapshot only accepts 1d candles. Is there a way for the asset.snapshot to support multiple resolutions? 1m, 15m, 1h

Describe the solution you'd like
Ideally, remove the format on date.Date (in the asset.snapshot).
Introduce a new field - resolution that specifies the duration of the candle. 1m, 15m etc.,

Describe alternatives you've considered
Other solution I've considered - grok this codebase, and modify the format to support minutes in the field

Additional context
Nothing more!

@cinar
Copy link
Owner

cinar commented Jan 16, 2025

My apologies for the delayed response. The Snapshot.Date is a time.Time, allowing for any time value, not just days. My examples were a bit too focused on daily data.

The Date field is primarily used for charting and reporting, where you have full control over the date formatting. Elsewhere, the code operates on the values without explicit time knowledge. This means you should be able to use data with resolutions like 1 minute, 15 minutes, or 1 hour without issues.

I'm planning to add functionality for converting between different time resolutions. Currently, functions like Sum, Avg, and Last can downsample from high to low resolution, but upsampling is not yet supported.

To help me understand your needs better, could you provide some examples of what you're trying to achieve? This will help me guide you on how to best utilize the library and prioritize any missing features that might be beneficial.

@dbuschman7
Copy link

In the Snapshot struct

Date time.Timeformat:"2006-01-02"

The custom 'format' struct tag forces a day level field data to be stored in the CSV file format from the asset/file_system_repository.go via the csv.go class reference here.

func NewCsv[T any](hasHeader bool) (*Csv[T], error) {

func (r *FileSystemRepository) Append(name string, snapshots <-chan *Snapshot) error {

So the data in the file is stored at the day level (YYYY-MM-DD) so that class is not usable for anything other than day level candles.

I myself will be creating my own repository class anyway due to embedded nature of my internal database.

Great library!

@cinar
Copy link
Owner

cinar commented Jan 18, 2025

Great catch! Yes, that doesn't look right. Let me see if I can find a solution.

Regarding database support, I have some code that works with PostgreSQL and can be extended to support other databases and languages. If you haven't written yours yet, I can try to incorporate those into this project over the weekend.

@dbuschman7
Copy link

If you can add a passed function to convert the date -> string allowing it to be passed in that would solve the 'scale of the candle' issue.

The Snapshot, of coarse, is a candle meaning it represents a range of time and I need to save partial 'times' at the minute or hour level.

Storing at the 15 second level get even more 'interesting' :)

My needs are a bit more complicated but thanks.

@cinar
Copy link
Owner

cinar commented Jan 18, 2025

Let me take care of that quickly today. Yes, better to make that configurable.

Meanwhile, just checked in the SQL Repository base files. I'll try to find a way to add the PostgreSQL portion also. Just in case if it helps with your implementation.

cinar added a commit that referenced this issue Jan 18, 2025
# Describe Request

Added SQL repository support for assets. It does not contain any actual
implementation for a particular database. I will follow up with a
separate repo or submodule.

Related #266 

# Change Type

SQL repository.
@cinar
Copy link
Owner

cinar commented Jan 18, 2025

I removed the default date/time format from asset.Snapshot and made it configurable through the helper.Csv options. The asset.FileSystemRepository also takes these options. This way, it should now be possible to store snapshots at any time resolution supported by time.Time.

Unless you see a problem, I will go ahead and merge it.

  • asset.Snapshot.Date no longer has a date format declared as a struct tag.
  • helper.NewCsv takes options to configure headers, logger, and the default date time format.
  • asset.NewFileSystemRepository also takes CSV options to configure the CSV files.

CSV Example:

csv, err := helper.NewCsv[Row](
	helper.WithCsvDefaultDateTimeFormat[Row]("2006-01-02 15:04:05"),
)

Repository Example:

repository := asset.NewFileSystemRepository(
	"assets", 
	helper.WithCsvDefaultDateTimeFormat[Row]("2006-01-02 15:04:05"),
)

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

No branches or pull requests

3 participants