diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e4a3daa4..f3b6bbb9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -34,3 +34,11 @@ repos: entry: poetry run black --config pyproject.toml types: [python] language: system + + - repo: local + hooks: + - id: codestyle + name: codestyle + entry: make codestyle + types: [python] + language: system diff --git a/README.md b/README.md index a120996f..0cd398a6 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,12 @@ make install Codestyle

+Install pre-commit hooks which will run isort, black and codestyle on your code: + +```bash +make pre-commit-install +``` + Automatic formatting uses `pyupgrade`, `isort` and `black`. ```bash diff --git a/examples/basic_adding.py b/examples/basic_adding.py index afdc8347..7f10b7a4 100644 --- a/examples/basic_adding.py +++ b/examples/basic_adding.py @@ -4,6 +4,8 @@ import threading import time +import example_utils + from hyperliquid.exchange import Exchange from hyperliquid.info import Info from hyperliquid.utils import constants @@ -21,7 +23,6 @@ UserEventsMsg, UserEventsSubscription, ) -import example_utils # How far from the best bid and offer this strategy ideally places orders. Currently set to .3% # i.e. if the best bid is $1000, this strategy will place a resting bid at $997 diff --git a/examples/basic_agent.py b/examples/basic_agent.py index f040cfc8..ca01fd0b 100644 --- a/examples/basic_agent.py +++ b/examples/basic_agent.py @@ -1,9 +1,9 @@ import eth_account +import example_utils from eth_account.signers.local import LocalAccount from hyperliquid.exchange import Exchange from hyperliquid.utils import constants -import example_utils def main(): diff --git a/examples/basic_builder_fee.py b/examples/basic_builder_fee.py index 872e138c..4eb38ccb 100644 --- a/examples/basic_builder_fee.py +++ b/examples/basic_builder_fee.py @@ -1,6 +1,7 @@ -from hyperliquid.utils import constants import example_utils +from hyperliquid.utils import constants + def main(): address, info, exchange = example_utils.setup(constants.TESTNET_API_URL, skip_ws=True) diff --git a/examples/basic_leverage_adjustment.py b/examples/basic_leverage_adjustment.py index 993052e5..41e2772f 100644 --- a/examples/basic_leverage_adjustment.py +++ b/examples/basic_leverage_adjustment.py @@ -1,8 +1,9 @@ import json -from hyperliquid.utils import constants import example_utils +from hyperliquid.utils import constants + def main(): address, info, exchange = example_utils.setup(constants.TESTNET_API_URL, skip_ws=True) diff --git a/examples/basic_market_order.py b/examples/basic_market_order.py index 81ffbc6a..f3db2c73 100644 --- a/examples/basic_market_order.py +++ b/examples/basic_market_order.py @@ -1,8 +1,9 @@ import time -from hyperliquid.utils import constants import example_utils +from hyperliquid.utils import constants + def main(): address, info, exchange = example_utils.setup(constants.TESTNET_API_URL, skip_ws=True) diff --git a/examples/basic_order.py b/examples/basic_order.py index 5bd77aaf..e596a1cd 100644 --- a/examples/basic_order.py +++ b/examples/basic_order.py @@ -1,8 +1,9 @@ import json -from hyperliquid.utils import constants import example_utils +from hyperliquid.utils import constants + def main(): address, info, exchange = example_utils.setup(base_url=constants.TESTNET_API_URL, skip_ws=True) diff --git a/examples/basic_order_modify.py b/examples/basic_order_modify.py index 2d4f6160..f37d6d4e 100644 --- a/examples/basic_order_modify.py +++ b/examples/basic_order_modify.py @@ -1,6 +1,7 @@ +import example_utils + from hyperliquid.utils import constants from hyperliquid.utils.types import Cloid -import example_utils def main(): diff --git a/examples/basic_order_with_cloid.py b/examples/basic_order_with_cloid.py index beaf9798..31fed272 100644 --- a/examples/basic_order_with_cloid.py +++ b/examples/basic_order_with_cloid.py @@ -1,6 +1,7 @@ +import example_utils + from hyperliquid.utils import constants from hyperliquid.utils.types import Cloid -import example_utils def main(): diff --git a/examples/basic_schedule_cancel.py b/examples/basic_schedule_cancel.py index ff8db478..d46cda46 100644 --- a/examples/basic_schedule_cancel.py +++ b/examples/basic_schedule_cancel.py @@ -1,8 +1,9 @@ import time +import example_utils + from hyperliquid.utils import constants from hyperliquid.utils.signing import get_timestamp_ms -import example_utils def main(): diff --git a/examples/basic_set_referrer.py b/examples/basic_set_referrer.py index 10960258..d3f22464 100644 --- a/examples/basic_set_referrer.py +++ b/examples/basic_set_referrer.py @@ -1,6 +1,7 @@ -from hyperliquid.utils import constants import example_utils +from hyperliquid.utils import constants + def main(): address, info, exchange = example_utils.setup(constants.TESTNET_API_URL, skip_ws=True) diff --git a/examples/basic_spot_order.py b/examples/basic_spot_order.py index 6e197ae3..e312541a 100644 --- a/examples/basic_spot_order.py +++ b/examples/basic_spot_order.py @@ -1,8 +1,8 @@ import json -from hyperliquid.utils import constants import example_utils +from hyperliquid.utils import constants PURR = "PURR/USDC" OTHER_COIN = "@8" diff --git a/examples/basic_spot_to_perp.py b/examples/basic_spot_to_perp.py index c3a92cbb..0361ed88 100644 --- a/examples/basic_spot_to_perp.py +++ b/examples/basic_spot_to_perp.py @@ -1,6 +1,7 @@ -from hyperliquid.utils import constants import example_utils +from hyperliquid.utils import constants + def main(): address, info, exchange = example_utils.setup(constants.TESTNET_API_URL, skip_ws=True) diff --git a/examples/basic_spot_transfer.py b/examples/basic_spot_transfer.py index a9557974..01d4f380 100644 --- a/examples/basic_spot_transfer.py +++ b/examples/basic_spot_transfer.py @@ -1,6 +1,7 @@ -from hyperliquid.utils import constants import example_utils +from hyperliquid.utils import constants + def main(): address, info, exchange = example_utils.setup(constants.TESTNET_API_URL, skip_ws=True) diff --git a/examples/basic_sub_account.py b/examples/basic_sub_account.py index e3c8d694..d274953a 100644 --- a/examples/basic_sub_account.py +++ b/examples/basic_sub_account.py @@ -1,6 +1,7 @@ -from hyperliquid.utils import constants import example_utils +from hyperliquid.utils import constants + # This example shows how to create, query, and transfer funds to a subaccount. # To trade as a subaccount set vault_address to the subaccount's address. See basic_vault.py for an example. diff --git a/examples/basic_tpsl.py b/examples/basic_tpsl.py index 426c5391..fccb37db 100644 --- a/examples/basic_tpsl.py +++ b/examples/basic_tpsl.py @@ -1,8 +1,9 @@ import argparse -from hyperliquid.utils import constants import example_utils +from hyperliquid.utils import constants + def main(): parser = argparse.ArgumentParser(description="basic_tpsl") diff --git a/examples/basic_transfer.py b/examples/basic_transfer.py index 1d07ff9c..0df92747 100644 --- a/examples/basic_transfer.py +++ b/examples/basic_transfer.py @@ -1,6 +1,7 @@ -from hyperliquid.utils import constants import example_utils +from hyperliquid.utils import constants + def main(): address, info, exchange = example_utils.setup(constants.TESTNET_API_URL, skip_ws=True) diff --git a/examples/basic_vault.py b/examples/basic_vault.py index 5f96eb1f..6fc16a51 100644 --- a/examples/basic_vault.py +++ b/examples/basic_vault.py @@ -1,6 +1,7 @@ +import example_utils + from hyperliquid.exchange import Exchange from hyperliquid.utils import constants -import example_utils def main(): diff --git a/examples/basic_vault_transfer.py b/examples/basic_vault_transfer.py index 2f2e5ac9..d613e303 100644 --- a/examples/basic_vault_transfer.py +++ b/examples/basic_vault_transfer.py @@ -1,6 +1,7 @@ -from hyperliquid.utils import constants import example_utils +from hyperliquid.utils import constants + def main(): address, info, exchange = example_utils.setup(constants.TESTNET_API_URL, skip_ws=True) diff --git a/examples/basic_withdraw.py b/examples/basic_withdraw.py index 82cf8f30..e8cf845c 100644 --- a/examples/basic_withdraw.py +++ b/examples/basic_withdraw.py @@ -1,6 +1,7 @@ -from hyperliquid.utils import constants import example_utils +from hyperliquid.utils import constants + def main(): address, info, exchange = example_utils.setup(constants.TESTNET_API_URL, skip_ws=True) diff --git a/examples/basic_ws.py b/examples/basic_ws.py index 85357089..5c70fbbe 100644 --- a/examples/basic_ws.py +++ b/examples/basic_ws.py @@ -1,6 +1,7 @@ -from hyperliquid.utils import constants import example_utils +from hyperliquid.utils import constants + def main(): address, info, _ = example_utils.setup(constants.TESTNET_API_URL) diff --git a/examples/cancel_open_orders.py b/examples/cancel_open_orders.py index fbdb6d11..257d6b68 100644 --- a/examples/cancel_open_orders.py +++ b/examples/cancel_open_orders.py @@ -1,6 +1,7 @@ -from hyperliquid.utils import constants import example_utils +from hyperliquid.utils import constants + def main(): address, info, exchange = example_utils.setup(constants.TESTNET_API_URL, skip_ws=True) diff --git a/examples/example_utils.py b/examples/example_utils.py index 36c1cd06..40b77d96 100644 --- a/examples/example_utils.py +++ b/examples/example_utils.py @@ -1,8 +1,9 @@ -import eth_account -from eth_account.signers.local import LocalAccount import json import os +import eth_account +from eth_account.signers.local import LocalAccount + from hyperliquid.exchange import Exchange from hyperliquid.info import Info diff --git a/examples/rounding.py b/examples/rounding.py index 584c5536..b7c692ec 100644 --- a/examples/rounding.py +++ b/examples/rounding.py @@ -9,9 +9,10 @@ """ import json -from hyperliquid.utils import constants import example_utils +from hyperliquid.utils import constants + def main(): address, info, exchange = example_utils.setup(constants.TESTNET_API_URL, skip_ws=True) diff --git a/hyperliquid/exchange.py b/hyperliquid/exchange.py index d9f5f538..85c8b4a2 100644 --- a/hyperliquid/exchange.py +++ b/hyperliquid/exchange.py @@ -1,34 +1,34 @@ -import eth_account import logging import secrets +import eth_account from eth_account.signers.local import LocalAccount from hyperliquid.api import API from hyperliquid.info import Info from hyperliquid.utils.constants import MAINNET_API_URL from hyperliquid.utils.signing import ( - CancelRequest, CancelByCloidRequest, + CancelRequest, ModifyRequest, + OidOrCloid, OrderRequest, OrderType, OrderWire, - OidOrCloid, ScheduleCancelAction, float_to_usd_int, get_timestamp_ms, order_request_to_order_wire, order_wires_to_order_action, + sign_agent, sign_approve_builder_fee, sign_l1_action, + sign_spot_transfer_action, sign_usd_class_transfer_action, sign_usd_transfer_action, - sign_spot_transfer_action, sign_withdraw_from_bridge_action, - sign_agent, ) -from hyperliquid.utils.types import Any, List, Meta, SpotMeta, Optional, Tuple, Cloid, BuilderInfo +from hyperliquid.utils.types import Any, BuilderInfo, Cloid, List, Meta, Optional, SpotMeta, Tuple class Exchange(API): diff --git a/hyperliquid/info.py b/hyperliquid/info.py index 22fcc4f1..b63f2751 100644 --- a/hyperliquid/info.py +++ b/hyperliquid/info.py @@ -2,13 +2,13 @@ from hyperliquid.utils.types import ( Any, Callable, + Cloid, Meta, + Optional, SpotMeta, SpotMetaAndAssetCtxs, - Optional, Subscription, cast, - Cloid, ) from hyperliquid.websocket_manager import WebsocketManager diff --git a/hyperliquid/utils/signing.py b/hyperliquid/utils/signing.py index c0c467ab..2e063343 100644 --- a/hyperliquid/utils/signing.py +++ b/hyperliquid/utils/signing.py @@ -1,11 +1,11 @@ import time - from decimal import Decimal + +import msgpack from eth_account.messages import encode_structured_data from eth_utils import keccak, to_hex -import msgpack -from hyperliquid.utils.types import Literal, Optional, TypedDict, Union, Cloid, NotRequired +from hyperliquid.utils.types import Cloid, Literal, NotRequired, Optional, TypedDict, Union Tif = Union[Literal["Alo"], Literal["Ioc"], Literal["Gtc"]] Tpsl = Union[Literal["tp"], Literal["sl"]] diff --git a/hyperliquid/utils/types.py b/hyperliquid/utils/types.py index 1c71c279..d400453e 100644 --- a/hyperliquid/utils/types.py +++ b/hyperliquid/utils/types.py @@ -1,7 +1,7 @@ from __future__ import annotations +from typing import Any, Callable, Dict, List, Literal, NamedTuple, Optional, Tuple, TypedDict, Union, cast from typing_extensions import NotRequired -from typing import Any, Callable, Dict, List, NamedTuple, Optional, Tuple, Union, cast, Literal, TypedDict Any = Any Option = Optional diff --git a/tests/signing_test.py b/tests/signing_test.py index 1b55246e..4458290e 100644 --- a/tests/signing_test.py +++ b/tests/signing_test.py @@ -3,9 +3,9 @@ from eth_utils import to_hex from hyperliquid.utils.signing import ( - action_hash, OrderRequest, ScheduleCancelAction, + action_hash, construct_phantom_agent, float_to_int_for_hashing, order_request_to_order_wire,