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

Refine parsing candles for dYdX #2148

Merged
merged 2 commits into from
Dec 30, 2024
Merged

Refine parsing candles for dYdX #2148

merged 2 commits into from
Dec 30, 2024

Conversation

davidsblom
Copy link
Member

Pull Request

Refine parsing candles for dYdX

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How has this change been tested?

Unit tests

Copy link

codspeed-hq bot commented Dec 29, 2024

CodSpeed Performance Report

Merging #2148 will degrade performances by 36.48%

Comparing dydx-candles (f558a64) with develop (7392f06)

Summary

⚡ 1 improvements
❌ 1 regressions
✅ 50 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark develop dydx-candles Change
test_order_denied_to_dict 42.3 µs 33.6 µs +25.88%
test_is_limit_filled 16.2 µs 25.5 µs -36.48%

@@ -98,15 +98,14 @@ def parse_to_bar(
high_price = Price(Decimal(self.high), price_precision)
low_price = Price(Decimal(self.low), price_precision)
close_price = Price(Decimal(self.close), price_precision)
avg_price = Decimal("0.25") * (open_price + high_price + low_price + close_price)
volume = Decimal(self.usdVolume) / avg_price
volume = Quantity(Decimal(self.baseTokenVolume), size_precision)
Copy link
Member

Choose a reason for hiding this comment

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

This is an interesting choice, because most crypto API's give you both base and quote volumes - but our bar type only has one volume.

After looking around a bit, for spot markets the base volume is common, equities use units of shares, futures is contracts, derivatives markets are often notional value (in quote currency).

I'm still happy to merge this in if you find the base volume more useful in practice on dYdX, or do we want to consider further? I'm thinking a configuration, or per asset class choice - and specify in docs.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hi Chris, don't have a preference here. What do the other adapters use?

In develop branch, it is also using base volume by converting from quote to base. So I thought to simplify that. If derivatives markets use notional value, we could do that too but it would be a breaking change.

Copy link
Member Author

Choose a reason for hiding this comment

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

Making it configurable is indeed preferred I guess. I'll add that then and keep the current default base volume?

Copy link
Member

Choose a reason for hiding this comment

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

I see, looking closer there is that / avg_price.

I think yet another config option is a nice to have - I'm happy to merge as is for now?

Copy link
Member Author

@davidsblom davidsblom Dec 30, 2024

Choose a reason for hiding this comment

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

Sure, feel free to merge if you're happy with the change.

@cjdsellers cjdsellers merged commit f326782 into develop Dec 30, 2024
16 checks passed
@cjdsellers cjdsellers deleted the dydx-candles branch December 30, 2024 05:54
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