-
Notifications
You must be signed in to change notification settings - Fork 334
Expand file tree
/
Copy pathusd_class_transfer.py
More file actions
75 lines (66 loc) · 2.11 KB
/
usd_class_transfer.py
File metadata and controls
75 lines (66 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import argparse
from pathlib import Path
from eth_account import Account
from hyperliquid.exchange import Exchange
from hyperliquid.utils import constants
from hyperliquid.utils.types import Meta, SpotMeta
def main() -> None:
parser = argparse.ArgumentParser(
description="Transfer USDC between spot and perps balances"
)
parser.add_argument(
"--private-key-file",
required=True,
help="Path to private key file for account",
)
parser.add_argument(
"--amount",
type=float,
required=True,
help="Amount to transfer in USDC",
)
parser.add_argument(
"--to-perp",
type=bool,
required=True,
help="Transfer from spot to perp balance or vice versa (you probably want true)",
)
network = parser.add_mutually_exclusive_group(required=True)
network.add_argument(
"--testnet",
action="store_true",
help="Use testnet",
)
network.add_argument(
"--mainnet",
action="store_true",
help="Use mainnet",
)
parser.add_argument(
"--dry-run",
action="store_true",
help="Only show parameters without sending",
)
args = parser.parse_args()
network_name = "testnet" if args.testnet else "mainnet"
base_url = constants.TESTNET_API_URL if args.testnet else constants.MAINNET_API_URL
print(f"Using {network_name} URL: {base_url}")
account = Account.from_key(Path(args.private_key_file).read_text().strip())
exchange = Exchange(
wallet=account,
base_url=base_url,
meta=Meta(universe=[]),
spot_meta=SpotMeta(universe=[], tokens=[]),
)
print("address:", account.address)
print("amount:", args.amount)
print("to_perp:", args.to_perp)
if args.dry_run:
print(
f"dry run: {network_name}: would transfer {args.amount} USDC in {account.address} with to_perp={args.to_perp}"
)
else:
print("calling usdClassTransfer...")
print(exchange.usd_class_transfer(amount=args.amount, to_perp=args.to_perp))
if __name__ == "__main__":
main()