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 script to print candle time boundaries #1126

Merged
merged 2 commits into from
Mar 1, 2024
Merged

Add script to print candle time boundaries #1126

merged 2 commits into from
Mar 1, 2024

Conversation

dydxwill
Copy link
Contributor

@dydxwill dydxwill commented Mar 1, 2024

Changelist

Add script to print candle time boundaries

Test Plan

Ran locally

Author/Reviewer Checklist

  • If this PR has changes that result in a different app state given the same prior state and transaction list, manually add the state-breaking label.
  • If the PR has breaking postgres changes to the indexer add the indexer-postgres-breaking label.
  • If this PR isn't state-breaking but has changes that modify behavior in PrepareProposal or ProcessProposal, manually add the label proposal-breaking.
  • If this PR is one of many that implement a specific feature, manually label them all feature:[feature-name].
  • If you wish to for mergify-bot to automatically create a PR to backport your change to a release branch, manually add the label backport/[branch-name].
  • Manually add any of the following labels: refactor, chore, bug.

Copy link
Contributor

coderabbitai bot commented Mar 1, 2024

Walkthrough

The recent update introduces a new feature to the script service, enabling it to calculate and display the start and end times of trading candles at various resolutions based on a specified timestamp. This enhancement is aimed at improving the utility and flexibility of the service by providing users with precise time boundaries for their data analysis tasks.

Changes

File Path Change Summary
.../scripts/README.md Added instructions for executing print-candle-time-boundaries with specific timestamp inputs.
.../scripts/src/print-candle-time-boundaries.ts Introduced a script to compute and output normalized candle start and end times for given resolutions.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 4

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 7fd1d4f and 5404b6e.
Files ignored due to path filters (1)
  • indexer/services/scripts/package.json is excluded by: !**/*.json
Files selected for processing (2)
  • indexer/services/scripts/README.md (1 hunks)
  • indexer/services/scripts/src/print-candle-time-boundaries.ts (1 hunks)

Comment on lines +23 to +24
SERVICE_NAME=script pnpm run print-candle-time-boundaries -- \
--t 2024-02-28T10:01:36.17+00:00
Copy link
Contributor

Choose a reason for hiding this comment

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

The command addition for print-candle-time-boundaries is clear and follows the documentation's structure well. However, for consistency with other examples in the documentation, consider adding a brief description above this command to explain its purpose or when it might be used. This can help users understand the context and utility of the script more quickly.

Comment on lines +5 to +14
export function calculateNormalizedCandleStartTime(
time: DateTime,
resolution: CandleResolution,
): DateTime {
const epochSeconds: number = Math.floor(time.toUTC().toSeconds());
const normalizedTimeSeconds: number = epochSeconds - (
epochSeconds % NUM_SECONDS_IN_CANDLE_RESOLUTIONS[resolution]
);

return DateTime.fromSeconds(normalizedTimeSeconds).toUTC();
Copy link
Contributor

Choose a reason for hiding this comment

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

The calculateNormalizedCandleStartTime function correctly calculates the normalized start time for a given resolution. It uses Luxon's DateTime for time manipulation, which is a good choice for handling time zones and formatting. However, consider adding error handling for cases where resolution might not be in NUM_SECONDS_IN_CANDLE_RESOLUTIONS, to prevent potential runtime errors.

Comment on lines +18 to +27
function getNormalizedBoundaries(time: string, resolutions: CandleResolution[]): void {
const date = DateTime.fromISO(time);

resolutions.forEach((resolution: CandleResolution) => {
const startTime = calculateNormalizedCandleStartTime(date, resolution);
const endTime = startTime.plus({ seconds: NUM_SECONDS_IN_CANDLE_RESOLUTIONS[resolution] });

console.log(`Resolution: ${resolution}, Start Time: ${startTime.toISO()}, End Time: ${endTime.toISO()}`);
});
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The getNormalizedBoundaries function effectively iterates over resolutions, calculates start and end times, and logs them. This function is clear and concise. However, it's important to ensure that the input time string is in a valid ISO format before converting it with DateTime.fromISO. Consider adding a validation step or try-catch block to handle parsing errors gracefully.

Comment on lines +39 to +48
const args = yargs.options({
time: {
type: 'string',
alias: 't',
description: 'Time to compute normalized boundaries for, e.g. 2024-02-28T10:01:36.17+00:00',
required: true,
},
}).argv;

getNormalizedBoundaries(args.time, resolutions);
Copy link
Contributor

Choose a reason for hiding this comment

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

The script uses yargs for command-line argument parsing, which is a robust choice for Node.js CLI applications. The time argument is correctly marked as required and has a clear description. To enhance user experience, consider adding an example usage of the script in the help text or documentation, demonstrating how to format the time argument correctly.

@dydxwill dydxwill merged commit 9850cb4 into main Mar 1, 2024
11 checks passed
@dydxwill dydxwill deleted the wl/add_s branch March 1, 2024 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

2 participants