()
| 102 | return f"{float(default):.2f}" |
| 103 | |
| 104 | async def test_offline_hyperliquid(): |
| 105 | def parse_args(): |
| 106 | parser = argparse.ArgumentParser(description='Offline Trading Agent Example') |
| 107 | parser.add_argument("--config", default=os.path.join(root, "configs", "offline_trading_agent.py"), help="config file path") |
| 108 | |
| 109 | parser.add_argument( |
| 110 | '--cfg-options', |
| 111 | nargs='+', |
| 112 | action=DictAction, |
| 113 | help='override some settings in the used config, the key-value pair ' |
| 114 | 'in xxx=yyy format will be merged into config file. If the value to ' |
| 115 | 'be overwritten is a list, it should be like key="[a,b]" or key=a,b ' |
| 116 | 'It also allows nested list/tuple values, e.g. key="[(a,b),(c,d)]" ' |
| 117 | 'Note that the quotation marks are necessary and that no white space ' |
| 118 | 'is allowed.') |
| 119 | args = parser.parse_args() |
| 120 | return args |
| 121 | |
| 122 | args = parse_args() |
| 123 | |
| 124 | # Initialize configuration |
| 125 | config.init_config(args.config, args) |
| 126 | logger.init_logger(config) |
| 127 | logger.info(f"| Config: {config.pretty_text}") |
| 128 | |
| 129 | # Initialize Hyperliquid service |
| 130 | logger.info("| 🔧 Initializing Hyperliquid service...") |
| 131 | accounts = get_env("HYPERLIQUID_ACCOUNTS").get_secret_value() |
| 132 | if accounts: |
| 133 | accounts = json.loads(accounts) |
| 134 | config.hyperliquid_service.update(dict(accounts=accounts)) |
| 135 | hyperliquid_service = OfflineHyperliquidService(**config.hyperliquid_service) |
| 136 | await hyperliquid_service.initialize() |
| 137 | for env_name in config.env_names: |
| 138 | env_config = config.get(f"{env_name}_environment", None) |
| 139 | env_config.update(dict(hyperliquid_service=hyperliquid_service)) |
| 140 | logger.info(f"| ✅ Hyperliquid service initialized.") |
| 141 | |
| 142 | # Initialize environments |
| 143 | logger.info("| 🎮 Initializing environments...") |
| 144 | await ecp.initialize(config.env_names) |
| 145 | logger.info(f"| ✅ Environments initialized: {ecp.list()}") |
| 146 | |
| 147 | # Test Hyperliquid service |
| 148 | logger.info("| 🧪 Testing Hyperliquid service...") |
| 149 | # 1. Get exchange info |
| 150 | exchange_info= await hyperliquid_service.get_exchange_info(GetExchangeInfoRequest()) |
| 151 | logger.info(f"| 📝 Exchange info: {exchange_info}") |
| 152 | |
| 153 | # 2. Get account |
| 154 | account= await hyperliquid_service.get_account(GetAccountRequest(account_name="account1")) |
| 155 | logger.info(f"| 📝 Account: {account}") |
| 156 | |
| 157 | # 3. Get positions |
| 158 | positions= await hyperliquid_service.get_positions(GetPositionsRequest(account_name="account1")) |
| 159 | logger.info(f"| 📝 Positions: {positions}") |
| 160 | |
| 161 | # 4. Get orders |
no test coverage detected