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

feat: add SubscribeTickers func to providers #592

Merged
merged 17 commits into from
Mar 2, 2022

Conversation

RafilxTenfen
Copy link
Contributor

@RafilxTenfen RafilxTenfen commented Mar 1, 2022

Description

  • Add SubscribeTickers function to the following providers: (Okx, Huobi, Kraken, Binance)
// SubscribeTickers subscribe all currency pairs into ticker and candle channels.
func (p *provider) SubscribeTickers(cps ...types.CurrencyPair) error {
....
}

ref: #181


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title
  • added appropriate labels to the PR
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

@RafilxTenfen RafilxTenfen marked this pull request as draft March 1, 2022 19:13
@RafilxTenfen RafilxTenfen marked this pull request as ready for review March 2, 2022 01:21
@alexanderbez
Copy link
Contributor

@RafilxTenfen does #597 need to be merged first before this?

Comment on lines 102 to 103
// SubscribeTickers subscribe to all currency pairs and
// add the new ones into the provider subscribed pairs.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: try to be consistent and wrap godocs at 80 chars :)

price-feeder/oracle/provider/binance.go Show resolved Hide resolved
@RafilxTenfen
Copy link
Contributor Author

@RafilxTenfen does #597 need to be merged first before this?

@alexanderbez I don't think it is necessary

Copy link
Contributor

@alexanderbez alexanderbez left a comment

Choose a reason for hiding this comment

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

Nice! @adamewozniak & @toteki you wanna give this a view before we merge?

Comment on lines +108 to +113
for _, cp := range cps {
pairs[iterator] = currencyPairToBinanceTickerPair(cp)
iterator++
pairs[iterator] = currencyPairToBinanceCandlePair(cp)
iterator++
}
Copy link
Member

@toteki toteki Mar 2, 2022

Choose a reason for hiding this comment

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

is cps guaranteed to be an alternating list of Ticker, Candle, Ticker, Candle, etc?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

for the moment, yes

  • maybe after tvwap implemented we could only use candles

Copy link
Contributor

Choose a reason for hiding this comment

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

oooo I didn't realize this. I'm not really a fan of that approach. It's too brittle IMO. Could we remove that assumption? Maybe just pass two args in instead?

Copy link
Collaborator

Choose a reason for hiding this comment

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

After tvwap gets merged can we put these back as separate functions?

Candle & Ticker pairs should generally be considered separate, especially since candles can not always be used immediately (you can't calculate tvwap if the only candle you have is one that closed at that exact moment) - sorry I didn't realize this before. Would make this less brittle too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, these pairs are used only to subscribe to those channels. We could have 2 lists of subscribed pairs and separate them one for each type (Ticker, Candle).

The logic to subscribe in both of those channels was the same. So, in my idea made sense to only iterate through cps ...types.CurrencyPair once

@adamewozniak @toteki @alexanderbez

Copy link
Contributor

Choose a reason for hiding this comment

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

Would rather iterate twice and keep the code clean and legible 🙏

These aren't big lists anyway

Copy link
Collaborator

@adamewozniak adamewozniak left a comment

Choose a reason for hiding this comment

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

LGTM!
Will definitely have some merge conflicts for tvwap lol, I'll probably just open up a new PR

Copy link
Member

@toteki toteki left a comment

Choose a reason for hiding this comment

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

No problems detected

@RafilxTenfen RafilxTenfen merged commit 380ec49 into main Mar 2, 2022
@RafilxTenfen RafilxTenfen deleted the rafilx/providers-subscribe branch March 2, 2022 23:04
mergify bot pushed a commit that referenced this pull request Mar 2, 2022
* feat: add SubscribeTickers to binance provider

* feat: add SubscribeTickers to huobi provider

* feat: add SubscribeTickers to huobi provider

* feat: add SubscribeTickers to Okx provider

* add subscribe tickers func to changelog

* removed unused method

* fix: set right amount of topics on reconnect

* chore: update godocs

* chore: update godocs

* chore: update godocs

* chore: update godocs

Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
(cherry picked from commit 380ec49)
@toteki toteki mentioned this pull request Mar 3, 2022
18 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants