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 OKX exchange integration #5328

Merged
merged 1 commit into from Jan 11, 2023
Merged

Add OKX exchange integration #5328

merged 1 commit into from Jan 11, 2023

Conversation

anukul
Copy link
Contributor

@anukul anukul commented Dec 31, 2022

Added integration for asset balances, trades and deposits & withdrawals

Screen.Recording.2022-12-31.at.6.50.51.AM.mov

Note:

  • Used a throwaway account for exchange fixture, since all queries must be authenticated with API credentials (including list of assets)
  • Only populated a small subset of assets (those also found in other exchange mappings), would prefer to discuss before moving further on this.

@CLAassistant
Copy link

CLAassistant commented Dec 31, 2022

CLA assistant check
All committers have signed the CLA.

@anukul anukul temporarily deployed to test December 31, 2022 13:56 — with GitHub Actions Inactive
@codecov
Copy link

codecov bot commented Dec 31, 2022

Codecov Report

Merging #5328 (bf46f35) into develop (ba336d3) will increase coverage by 0.05%.
The diff coverage is 100.00%.

@@             Coverage Diff             @@
##           develop    #5328      +/-   ##
===========================================
+ Coverage    70.96%   71.01%   +0.05%     
===========================================
  Files          980      983       +3     
  Lines        73490    74062     +572     
  Branches      9039     9170     +131     
===========================================
+ Hits         52150    52593     +443     
- Misses       19737    19866     +129     
  Partials      1603     1603              
Flag Coverage Δ
frontend_integration 60.46% <100.00%> (+0.35%) ⬆️
frontend_unit 58.90% <100.00%> (+0.16%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
.../components/settings/api-keys/ExchangeKeysForm.vue 79.16% <ø> (ø)
rotkehlchen/db/schema.py 100.00% <ø> (ø)
rotkehlchen/exchanges/constants.py 100.00% <ø> (ø)
rotkehlchen/types.py 90.42% <ø> (ø)
frontend/app/src/types/exchanges.ts 100.00% <100.00%> (ø)
frontend/app/src/types/trades.ts 98.66% <100.00%> (+0.03%) ⬆️
rotkehlchen/assets/converters.py 75.95% <100.00%> (ø)
rotkehlchen/db/upgrades/v35_v36.py 82.56% <100.00%> (ø)
frontend/app/src/composables/balances.ts 51.28% <0.00%> (-41.58%) ⬇️
frontend/app/src/store/balances/breakdown.ts 34.90% <0.00%> (-29.81%) ⬇️
... and 44 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Member

@yabirgb yabirgb left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution. I checked the backend and someone else will check the frontend. Can you also add an entry in the docs/changelog file saying that support for OKX was added? Also wrote a question in discord (priv) about the tests

rotkehlchen/assets/converters.py Outdated Show resolved Hide resolved
rotkehlchen/exchanges/okx.py Outdated Show resolved Hide resolved
rotkehlchen/exchanges/okx.py Outdated Show resolved Hide resolved
rotkehlchen/exchanges/okx.py Outdated Show resolved Hide resolved
rotkehlchen/exchanges/okx.py Outdated Show resolved Hide resolved
rotkehlchen/tests/exchanges/test_okx.py Outdated Show resolved Hide resolved
rotkehlchen/tests/exchanges/test_okx.py Show resolved Hide resolved
rotkehlchen/tests/exchanges/test_okx.py Outdated Show resolved Hide resolved
rotkehlchen/tests/exchanges/test_okx.py Outdated Show resolved Hide resolved
rotkehlchen/tests/exchanges/test_okx.py Outdated Show resolved Hide resolved
@yabirgb
Copy link
Member

yabirgb commented Dec 31, 2022

Also @anukul linting is failing. Check it before pushing

@anukul anukul requested a review from yabirgb January 1, 2023 09:34
@LefterisJP
Copy link
Member

LefterisJP commented Jan 1, 2023

Hey @anukul I am not reviewing yet but just a note. We don't merge develop back to the branch. Instead we always rebase feature branches on top of develop.

Also make commits that do one big thing, but not so small as 1 commit per lint error or suggestion aplication.

@anukul anukul temporarily deployed to test January 1, 2023 21:04 — with GitHub Actions Inactive
@lukicenturi
Copy link
Contributor

The frontend part is okay.

Copy link
Member

@yabirgb yabirgb left a comment

Choose a reason for hiding this comment

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

Thanks @anukul, left some minor comments

docs/changelog.rst Outdated Show resolved Hide resolved
rotkehlchen/exchanges/okx.py Show resolved Hide resolved
rotkehlchen/exchanges/okx.py Outdated Show resolved Hide resolved
rotkehlchen/exchanges/okx.py Outdated Show resolved Hide resolved
rotkehlchen/tests/fixtures/exchanges/okx.py Outdated Show resolved Hide resolved
@LefterisJP LefterisJP mentioned this pull request Jan 3, 2023
@anukul anukul requested a review from yabirgb January 3, 2023 12:01
@anukul anukul temporarily deployed to test January 3, 2023 14:11 — with GitHub Actions Inactive
Copy link
Member

@LefterisJP LefterisJP left a comment

Choose a reason for hiding this comment

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

Hey @anukul thanks a lot for such a nice and big PR. Left some comments/questions.

rotkehlchen/db/schema.py Show resolved Hide resolved
rotkehlchen/exchanges/okx.py Outdated Show resolved Hide resolved
Comment on lines 139 to 144
else:
raise AssertionError(f'Unexpected {self.name} endpoint type: {endpoint}')
Copy link
Member

Choose a reason for hiding this comment

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

You should remove the else branch. Turn the last elif to else. And at the start of the else code branch add an `assert endpoint == 'withdrawals', 'only case left, should be withdrawals'

Why?

  1. We use type checking for a reason
  2. assertions are fine for debugging and in production since we produce optimized code they are removed. But raise AssertionError() is not.

rotkehlchen/exchanges/okx.py Outdated Show resolved Hide resolved
rotkehlchen/exchanges/okx.py Outdated Show resolved Hide resolved
rotkehlchen/exchanges/okx.py Outdated Show resolved Hide resolved
rotkehlchen/exchanges/okx.py Show resolved Hide resolved
rotkehlchen/exchanges/okx.py Show resolved Hide resolved
rotkehlchen/exchanges/okx.py Outdated Show resolved Hide resolved
rotkehlchen/exchanges/okx.py Outdated Show resolved Hide resolved
@anukul anukul requested review from LefterisJP and removed request for yabirgb January 10, 2023 06:56
@anukul anukul temporarily deployed to test January 10, 2023 10:45 — with GitHub Actions Inactive
@anukul anukul temporarily deployed to test January 10, 2023 10:45 — with GitHub Actions Inactive
Copy link
Member

@LefterisJP LefterisJP left a comment

Choose a reason for hiding this comment

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

Left some more things that need changing

rotkehlchen/db/upgrades/v35_v36.py Show resolved Hide resolved
rotkehlchen/exchanges/okx.py Outdated Show resolved Hide resolved
rotkehlchen/exchanges/okx.py Outdated Show resolved Hide resolved
rotkehlchen/exchanges/okx.py Outdated Show resolved Hide resolved
rotkehlchen/exchanges/okx.py Outdated Show resolved Hide resolved
rotkehlchen/exchanges/okx.py Outdated Show resolved Hide resolved
rotkehlchen/exchanges/okx.py Outdated Show resolved Hide resolved
rotkehlchen/exchanges/okx.py Outdated Show resolved Hide resolved
rotkehlchen/exchanges/okx.py Outdated Show resolved Hide resolved
rotkehlchen/exchanges/okx.py Outdated Show resolved Hide resolved
Copy link
Member

@LefterisJP LefterisJP left a comment

Choose a reason for hiding this comment

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

Two more small comments

data = self._api_query_list(endpoint='balance')
try:
currencies_data = data[0]['details']
except (IndexError, KeyError, TypeError) as e:
Copy link
Member

Choose a reason for hiding this comment

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

continuing the TypeError discussion do you see the problem here?

Such a TypeError would read: "TypeError: string indices must be integers"

Which would translate to: "OKX balance API request failed due to unexpected response TypeError: string indices must be integers".

We won't have any information as to what went wrong or which attribute it is that failed for us.

I think it's much better if you check that data[0] is a dict here and if not raise a RemoteError saying that the "details" key of the OKX balances response was not a dict as expected, and even include the raw response so it can be studied in the logs.

What we usually do with this is:

  1. Put as few info as needed in the RemoteError as this is usually propagated high up, caught by the API and shown to the user.
  2. At the same time log an error, with the raw response data so that when we study the logs of the user we can see both the error and the raw response and figure out what happened.

Copy link
Member

Choose a reason for hiding this comment

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

You missed to do (2).

Logging the error containing the raw response so we, the developers, can debug it.

rotkehlchen/exchanges/okx.py Outdated Show resolved Hide resolved
Copy link
Member

@LefterisJP LefterisJP left a comment

Choose a reason for hiding this comment

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

Left a small comment you forgot, but can also be added in another PR.

Other than that looks good. So will merge.

The single failing test is timeout due to ethereum remote node query

@LefterisJP LefterisJP merged commit 1b3f1ff into rotki:develop Jan 11, 2023
@gitpoap-bot
Copy link

gitpoap-bot bot commented Jan 11, 2023

Congrats, your important contribution to this open-source project has earned you a GitPOAP!

GitPOAP: 2023 rotki Contributor:

GitPOAP: 2023 rotki Contributor GitPOAP Badge

Head to gitpoap.io & connect your GitHub account to mint!

Learn more about GitPOAPs here.

@anukul anukul deleted the okx branch January 12, 2023 10:07
@yabirgb yabirgb mentioned this pull request Jan 23, 2023
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.

None yet

5 participants