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

Refactor of _optimize_assets_for_exchange #269

Merged
merged 13 commits into from
Dec 3, 2024

Conversation

macanudo527
Copy link
Collaborator

What?

This is essentially a refactoring of _optimize_assets_for_exchange

I broke it into 6 stages and created individual functions for most of them to test them individually. This resulted in finding two bugs.

Questions

I'm not sure if I should make these individual stage functions private or extract this logic into a separate module of some kind.

@macanudo527 macanudo527 self-assigned this Nov 19, 2024
@macanudo527 macanudo527 requested a review from eprbell November 19, 2024 14:44
Comment on lines -960 to -971

# Copy over assets from previous timestamps so there are no holes in the graph
composite_optimizations: Dict[datetime, Dict[str, Dict[str, float]]] = {}
previous_timestamp: Optional[datetime] = None

for timestamp, optimization_dict in sorted_optimizations.items():
if previous_timestamp is None:
composite_optimizations[timestamp] = optimization_dict
else:
composite_optimizations[timestamp] = sorted_optimizations[previous_timestamp].copy()
composite_optimizations[timestamp].update(sorted_optimizations[timestamp])

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This code was cut out since the layering process was causing errors and unexpected behavior. It's actually not really necessary since we delete duplicates later.

Comment on lines -919 to -923
timestamp_diff: float = (child_bars[child_name][neighbor.name][0].timestamp - start_date).total_seconds()

# Find the start of the market if it is after the first transaction
if timestamp_diff > _TIME_GRANULARITY_STRING_TO_SECONDS[_ONE_WEEK]:
market_starts[child_name][neighbor.name] = child_bars[child_name][neighbor.name][0].timestamp
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was causing the no_market_padding bar to never be used, so I removed it.

@macanudo527
Copy link
Collaborator Author

@eprbell Most of the code was simply moved into individual functions except the two pieces I commented on above.

@eprbell
Copy link
Owner

eprbell commented Nov 28, 2024

@eprbell Most of the code was simply moved into individual functions except the two pieces I commented on above.

Sounds good: I'm planning to review this weekend.

Copy link
Owner

@eprbell eprbell left a comment

Choose a reason for hiding this comment

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

Very nice: this is good refactoring and I love that we can unit test the new granular functions. We should strive to do this everywhere functions are bigger than 100 lines or so.

src/dali/abstract_ccxt_pair_converter_plugin.py Outdated Show resolved Hide resolved
@macanudo527
Copy link
Collaborator Author

Very nice: this is good refactoring and I love that we can unit test the new granular functions. We should strive to do this everywhere functions are bigger than 100 lines or so.

Yeah, I'd like to do this for the core functions. It is a complicated beast and I found two bugs just in this one function.

@macanudo527 macanudo527 merged commit b475035 into eprbell:main Dec 3, 2024
19 checks passed
@macanudo527 macanudo527 deleted the pair_converters/ccxt_testing branch December 3, 2024 07:43
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

Successfully merging this pull request may close these issues.

2 participants