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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ test-assets:
python pytestgeventwrapper.py rotkehlchen/tests/exchanges/test_kucoin.py::test_kucoin_exchange_assets_are_known
python pytestgeventwrapper.py rotkehlchen/tests/exchanges/test_poloniex.py::test_poloniex_assets_are_known
python pytestgeventwrapper.py rotkehlchen/tests/exchanges/test_gemini.py::test_gemini_all_symbols_are_known
python pytestgeventwrapper.py rotkehlchen/tests/exchanges/test_okx.py::test_assets_are_known
python pytestgeventwrapper.py rotkehlchen/tests/unit/test_assets.py::test_coingecko_identifiers_are_reachable
python pytestgeventwrapper.py rotkehlchen/tests/unit/test_assets.py::test_cryptocompare_asset_support
python pytestgeventwrapper.py rotkehlchen/tests/unit/test_aave.py::test_atoken_to_asset
Expand Down
2 changes: 1 addition & 1 deletion docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Changelog
* :bug:`-` Fixed an edge case where users would be swamped with "This socket is already used by another greenlet" errors during websocket communication between backend and frontend.
* :bug:`-` Transfers of ether between tracked accounts will now have a correct label in the UI.
* :bug:`-` Trades involving delisted bitfinex pairs will now be properly read by rotki.

* :feature:`784` Add support for OKX exchange

* :release:`1.26.3 <2022-12-30>`
* :bug:`5315` Fix issue where balance is not fully refreshed after detect tokens button pressed.
Expand Down
1 change: 1 addition & 0 deletions frontend/app/public/assets/images/exchanges/okx.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ const requiresPassphrase = computed(() => {
const { location } = get(exchange);
return (
location === SupportedExchange.COINBASEPRO ||
location === SupportedExchange.KUCOIN
location === SupportedExchange.KUCOIN ||
location === SupportedExchange.OKX
);
});

Expand Down
3 changes: 2 additions & 1 deletion frontend/app/src/types/exchanges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export enum SupportedExchange {
FTX = 'ftx',
FTXUS = 'ftxus',
INDEPENDENTRESERVE = 'independentreserve',
GEMINI = 'gemini'
GEMINI = 'gemini',
OKX = 'okx'
}

const SupportedExchangeType = z.nativeEnum(SupportedExchange);
Expand Down
7 changes: 7 additions & 0 deletions frontend/app/src/types/trades.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,13 @@ export const useTradeLocations = createSharedComposable(() => {
imageIcon: true,
exchange: true
},
{
identifier: SupportedExchange.OKX,
name: 'OKX',
icon: './assets/images/exchanges/okx.svg',
imageIcon: true,
exchange: true
},
{
identifier: EXCHANGE_SHAPESHIFT,
name: 'ShapeShift',
Expand Down
15 changes: 15 additions & 0 deletions rotkehlchen/assets/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from rotkehlchen.assets.exchanges_mappings.kraken import WORLD_TO_KRAKEN
from rotkehlchen.assets.exchanges_mappings.kucoin import WORLD_TO_KUCOIN
from rotkehlchen.assets.exchanges_mappings.nexo import WORLD_TO_NEXO
from rotkehlchen.assets.exchanges_mappings.okx import WORLD_TO_OKX
from rotkehlchen.assets.exchanges_mappings.poloniex import WORLD_TO_POLONIEX
from rotkehlchen.assets.exchanges_mappings.uphold import WORLD_TO_UPHOLD
from rotkehlchen.assets.utils import symbol_to_asset_or_token
Expand Down Expand Up @@ -792,6 +793,7 @@
BITPANDA_TO_WORLD = {v: k for k, v in WORLD_TO_BITPANDA.items()}
CRYPTOCOM_TO_WORLD = {v: k for k, v in WORLD_TO_CRYPTOCOM.items()}
BLOCKFI_TO_WORLD = {v: k for k, v in WORLD_TO_BLOCKFI.items()}
OKX_TO_WORLD = {v: k for k, v in WORLD_TO_OKX.items()}

RENAMED_BINANCE_ASSETS = {
# The old BCC in binance forked into BCHABC and BCHSV
Expand Down Expand Up @@ -1103,6 +1105,18 @@ def asset_from_cryptocom(cryptocom_name: str) -> AssetWithOracles:
return symbol_to_asset_or_token(symbol)


def asset_from_okx(okx_name: str) -> AssetWithOracles:
"""May raise:
- DeserializationError
- UnsupportedAsset
- UnknownAsset
"""
if not isinstance(okx_name, str):
raise DeserializationError(f'Got non-string type {type(okx_name)} for okx asset')
name = OKX_TO_WORLD.get(okx_name, okx_name)
return symbol_to_asset_or_token(name)


LOCATION_TO_ASSET_MAPPING: dict[Location, Callable[[str], AssetWithOracles]] = {
Location.BINANCE: asset_from_binance,
Location.CRYPTOCOM: asset_from_cryptocom,
Expand All @@ -1115,4 +1129,5 @@ def asset_from_cryptocom(cryptocom_name: str) -> AssetWithOracles:
Location.POLONIEX: asset_from_poloniex,
Location.NEXO: asset_from_nexo,
Location.KUCOIN: asset_from_kucoin,
Location.OKX: asset_from_okx,
}
59 changes: 59 additions & 0 deletions rotkehlchen/assets/exchanges_mappings/okx.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
from rotkehlchen.assets.exchanges_mappings.common import COMMON_ASSETS_MAPPINGS
from rotkehlchen.constants.resolver import strethaddress_to_identifier


WORLD_TO_OKX = COMMON_ASSETS_MAPPINGS | {
strethaddress_to_identifier('0x3301Ee63Fb29F863f2333Bd4466acb46CD8323E6'): 'AKITA', # noqa: E501
strethaddress_to_identifier('0xa1faa113cbE53436Df28FF0aEe54275c13B40975'): 'ALPHA', # noqa: E501
strethaddress_to_identifier('0xa117000000f279D81A1D3cc75430fAA017FA5A2e'): 'ANT', # noqa: E501
strethaddress_to_identifier('0x3472A5A71965499acd81997a54BBA8D852C6E53d'): 'BADGER', # noqa: E501
'ETH2': 'BETH',
strethaddress_to_identifier('0xb056c38f6b7Dc4064367403E26424CD2c60655e1'): 'CEEK', # noqa: E501
strethaddress_to_identifier('0xaaAEBE6Fe48E54f431b0C390CfaF0b017d09D42d'): 'CEL',
strethaddress_to_identifier('0x4F9254C83EB525f9FCf346490bbb3ed28a81C667'): 'CELR', # noqa: E501
strethaddress_to_identifier('0x80C62FE4487E1351b47Ba49809EBD60ED085bf52'): 'CLV',
strethaddress_to_identifier('0xc00e94Cb662C3520282E6f5717214004A7f26888'): 'COMP', # noqa: E501
strethaddress_to_identifier('0xD533a949740bb3306d119CC777fa900bA034cd52'): 'CRV',
strethaddress_to_identifier('0xa3EE21C306A700E682AbCdfe9BaA6A08F3820419'): 'CTC',
strethaddress_to_identifier('0x1A3496C18d558bd9C6C8f609E1B129f67AB08163'): 'DEP',
strethaddress_to_identifier('0xca1207647Ff814039530D7d35df0e1Dd2e91Fa84'): 'DHT',
strethaddress_to_identifier('0x84cA8bc7997272c7CfB4D0Cd3D55cd942B3c9419'): 'DIA',
strethaddress_to_identifier('0xb31eF9e52d94D4120eb44Fe1ddfDe5B4654A6515'): 'DOSE', # noqa: E501
strethaddress_to_identifier('0xf8E9F10c22840b613cdA05A0c5Fdb59A4d6cd7eF'): 'ELON', # noqa: E501
strethaddress_to_identifier('0xC581b735A1688071A1746c968e0798D642EDE491'): 'EURT', # noqa: E501
strethaddress_to_identifier('0x43f11c02439e2736800433b4594994Bd43Cd066D'): 'FLOKI', # noqa: E501
strethaddress_to_identifier('0xf8C3527CC04340b208C854E985240c02F7B7793f'): 'FRONT', # noqa: E501
strethaddress_to_identifier('0xD0352a019e9AB9d757776F532377aAEbd36Fd541'): 'FSN',
strethaddress_to_identifier('0x15D4c048F83bd7e37d49eA4C83a07267Ec4203dA'): 'GALA', # noqa: E501
strethaddress_to_identifier('0x3F382DbD960E3a9bbCeaE22651E88158d2791550'): 'GHST', # noqa: E501
strethaddress_to_identifier('0xF57e7e7C23978C3cAEC3C3548E3D615c346e79fF'): 'IMX',
strethaddress_to_identifier('0x5A98FcBEA516Cf06857215779Fd812CA3beF1B32'): 'LDO',
'LUNA-2': 'LUNA',
strethaddress_to_identifier('0xB0c7a3Ba49C7a6EaBa6cD4a96C55a1391070Ac9A'): 'MAGIC', # noqa: E501
strethaddress_to_identifier('0x69af81e73A73B40adF4f3d4223Cd9b1ECE623074'): 'MASK', # noqa: E501
strethaddress_to_identifier('0x9E32b13ce7f2E80A01932B42553652E053D6ed8e'): 'METIS', # noqa: E501
strethaddress_to_identifier('0x09a3EcAFa817268f77BE1283176B946C4ff2E608'): 'MIR',
strethaddress_to_identifier('0x3593D125a4f7849a1B059E64F4517A86Dd60c95d'): 'OM',
'ONE-2': 'ONE',
strethaddress_to_identifier('0xff56Cc6b1E6dEd347aA0B7676C85AB0B3D08B0FA'): 'ORBS', # noqa: E501
strethaddress_to_identifier('0xbC396689893D065F41bc2C6EcbeE5e0085233447'): 'PERP', # noqa: E501
strethaddress_to_identifier('0x83e6f1E41cdd28eAcEB20Cb649155049Fac3D5Aa'): 'POLS', # noqa: E501
strethaddress_to_identifier('0x362bc847A3a9637d3af6624EeC853618a43ed7D2'): 'PRQ',
strethaddress_to_identifier('0xfB5c6815cA3AC72Ce9F5006869AE67f18bF77006'): 'PSTAKE', # noqa: E501
strethaddress_to_identifier('0x557B933a7C2c45672B610F8954A3deB39a51A8Ca'): 'REVV', # noqa: E501
strethaddress_to_identifier('0xaf9f549774ecEDbD0966C52f250aCc548D3F36E5'): 'RFUEL', # noqa: E501
strethaddress_to_identifier('0x3845badAde8e6dFF049820680d1F14bD3903a5d0'): 'SAND', # noqa: E501
strethaddress_to_identifier('0xCC8Fa225D80b9c7D42F96e9570156c65D6cAAa25'): 'SLP', # noqa: E501
strethaddress_to_identifier('0xC011a73ee8576Fb46F5E1c5751cA3B9Fe0af2a6F'): 'SNX',
'SOL-2': 'SOL',
strethaddress_to_identifier('0x090185f2135308BaD17527004364eBcC2D37e5F6'): 'SPELL', # noqa: E501
strethaddress_to_identifier('0x6F87D756DAf0503d08Eb8993686c7Fc01Dc44fB1'): 'TRADE', # noqa: E501
strethaddress_to_identifier('0x88dF592F8eb5D7Bd38bFeF7dEb0fBc02cf3778a0'): 'TRB', # noqa: E501
strethaddress_to_identifier('0x0000000000085d4780B73119b644AE5ecd22b376'): 'TUSD', # noqa: E501
strethaddress_to_identifier('0xF411903cbC70a74d22900a5DE66A2dda66507255'): 'VRA', # noqa: E501
'WIN-3': 'WIN',
strethaddress_to_identifier('0x4691937a7508860F876c9c0a2a617E7d9E945D4B'): 'WOO',
strethaddress_to_identifier('0xD7EFB00d12C2c13131FD319336Fdf952525dA2af'): 'XPR',
strethaddress_to_identifier('0xcbeAEc699431857FDB4d37aDDBBdc20E132D4903'): 'YOYO', # noqa: E501
strethaddress_to_identifier('0x05f4a42e251f2d52b8ed15E9FEdAacFcEF1FAD27'): 'ZIL',
}
2 changes: 2 additions & 0 deletions rotkehlchen/db/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@
INSERT OR IGNORE INTO location(location, seq) VALUES ('c', 35);
/* FTX US */
INSERT OR IGNORE INTO location(location, seq) VALUES ('d', 36);
/* OKX */
LefterisJP marked this conversation as resolved.
Show resolved Hide resolved
INSERT OR IGNORE INTO location(location, seq) VALUES ('e', 37);
"""

# Custom enum table for AssetMovement categories (deposit/withdrawal)
Expand Down
10 changes: 9 additions & 1 deletion rotkehlchen/db/upgrades/v35_v36.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,12 @@ def _upgrade_address_book_table(write_cursor: 'DBCursor') -> None:
write_cursor.execute('ALTER TABLE address_book_new RENAME TO address_book;')


def _add_okx(write_cursor: 'DBCursor') -> None:
log.debug('Enter _add_okx')
write_cursor.execute('INSERT OR IGNORE INTO location(location, seq) VALUES ("e", 37);')
log.debug('Exit _add_okx')


def upgrade_v35_to_v36(db: 'DBHandler', progress_handler: 'DBUpgradeProgressHandler') -> None:
"""Upgrades the DB from v35 to v36

Expand All @@ -549,7 +555,7 @@ def upgrade_v35_to_v36(db: 'DBHandler', progress_handler: 'DBUpgradeProgressHand
- rename web3_nodes to rpc_nodes
"""
log.debug('Entered userdb v35->v36 upgrade')
progress_handler.set_total_steps(9)
progress_handler.set_total_steps(10)
with db.user_write() as write_cursor:
_remove_adex(write_cursor)
progress_handler.new_step()
Expand All @@ -569,5 +575,7 @@ def upgrade_v35_to_v36(db: 'DBHandler', progress_handler: 'DBUpgradeProgressHand
progress_handler.new_step()
_upgrade_address_book_table(write_cursor)
progress_handler.new_step()
_add_okx(write_cursor)
LefterisJP marked this conversation as resolved.
Show resolved Hide resolved
progress_handler.new_step()

log.debug('Finished userdb v35->v36 upgrade')
3 changes: 2 additions & 1 deletion rotkehlchen/exchanges/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
Location.FTXUS,
Location.INDEPENDENTRESERVE,
Location.POLONIEX,
Location.OKX,
]
EXCHANGES_WITH_PASSPHRASE = (Location.COINBASEPRO, Location.KUCOIN)
EXCHANGES_WITH_PASSPHRASE = (Location.COINBASEPRO, Location.KUCOIN, Location.OKX)
# Exchanges for which we allow import via CSV
ALL_SUPPORTED_EXCHANGES = SUPPORTED_EXCHANGES + EXTERNAL_EXCHANGES