Skip to content

Commit

Permalink
Version 0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Louis Tao committed Feb 15, 2024
1 parent 36dac26 commit b827942
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 142 deletions.
3 changes: 2 additions & 1 deletion examples/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"comments": "
Make a copy of this file and save to `config.json`
Fill in your secret key e.g. 0x0000000000000000000000000000000000000000000000000000000000000000
If you are using an Agent/API Wallet you MUST also specify the public address of your account!
If you are using an Agent/API Wallet you MUST also specify the public address of your account, not the
address of the Agent/API Wallet.
Otherwise, feel free to leave it blank and it will be automatically derived from the secret key.
",
"secret_key": "",
Expand Down
5 changes: 2 additions & 3 deletions examples/example_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ def setup(base_url=None, skip_ws=False):
if float(margin_summary["accountValue"]) == 0:
print("Not running the example because the provided account has no equity.")
url = info.base_url.split(".", 1)[1]
print(f"If you think this is a mistake, make sure that {address} has a balance on {url}.")
print("If address shown is your API wallet address, update the config to specify account_address")
raise Exception("No accountValue")
error_string = f"No accountValue:\nIf you think this is a mistake, make sure that {address} has a balance on {url}.\nIf address shown is your API wallet address, update the config to specify the address of your account, not the address of the API wallet."
raise Exception(error_string)
exchange = Exchange(account, base_url, account_address=address)
return address, info, exchange
19 changes: 19 additions & 0 deletions hyperliquid/exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,25 @@ def update_isolated_margin(self, amount: float, coin: str) -> Any:
timestamp,
)

def set_referrer(self, code: str) -> Any:
timestamp = get_timestamp_ms()
set_referrer_action = {
"type": "setReferrer",
"code": code,
}
signature = sign_l1_action(
self.wallet,
set_referrer_action,
None,
timestamp,
self.base_url == MAINNET_API_URL,
)
return self._post_action(
set_referrer_action,
signature,
timestamp,
)

def usd_transfer(self, amount: float, destination: str) -> Any:
timestamp = get_timestamp_ms()
payload = {
Expand Down
3 changes: 3 additions & 0 deletions hyperliquid/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,9 @@ def query_order_by_oid(self, user: str, oid: int) -> Any:
def query_order_by_cloid(self, user: str, cloid: Cloid) -> Any:
return self.post("/info", {"type": "orderStatus", "user": user, "oid": cloid.to_raw()})

def query_referral_state(self, user: str) -> Any:
return self.post("/info", {"type": "referral", "user": user})

def subscribe(self, subscription: Subscription, callback: Callable[[Any], None]) -> int:
if self.ws_manager is None:
raise RuntimeError("Cannot call subscribe since skip_ws was used")
Expand Down
2 changes: 1 addition & 1 deletion hyperliquid/utils/signing.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ def order_type_to_wire(order_type: OrderType) -> OrderTypeWire:
elif "trigger" in order_type:
return {
"trigger": {
"isMarket": order_type["trigger"]["isMarket"],
"triggerPx": float_to_wire(order_type["trigger"]["triggerPx"]),
"tpsl": order_type["trigger"]["tpsl"],
"isMarket": order_type["trigger"]["isMarket"],
}
}
raise ValueError("Invalid order type", order_type)
Expand Down
Loading

0 comments on commit b827942

Please sign in to comment.