Skip to content

test: add end-to-end trading integration script#4

Merged
juntao merged 20 commits intomainfrom
test/e2e-trading-script
Feb 27, 2026
Merged

test: add end-to-end trading integration script#4
juntao merged 20 commits intomainfrom
test/e2e-trading-script

Conversation

@juntao
Copy link
Copy Markdown
Member

@juntao juntao commented Feb 26, 2026

Summary

  • Add tests/e2e_trading.sh — a bash script that exercises a full real-money trading workflow across Hyperliquid and Coinbase

Test flow

  1. Build fintool locally
  2. Deposit $10 USDC from Base mainnet → Hyperliquid (via Across bridge)
  3. Quote SILVER perp, buy $1 perp position
  4. Monitor SILVER price every 30s for up to 10 minutes
  5. Sell when price rises above entry (or on timeout)
  6. Withdraw USDC proceeds back to Base wallet
  7. Buy $1 ETH spot on Hyperliquid
  8. Withdraw ETH to Ethereum mainnet (via HyperUnit)
  9. Buy $1 TSLA on Coinbase

Prerequisites

  • ~/.fintool/config.toml with Hyperliquid wallet (>= $10 USDC on Base) and Coinbase API keys
  • jq installed

Test plan

  • bash -n tests/e2e_trading.sh — syntax check passes
  • Manual run with funded wallet

🤖 Generated with Claude Code

juntao and others added 20 commits February 25, 2026 18:19
Bash script that exercises a full trading workflow:
- Deposit USDC from Base → Hyperliquid
- Quote and buy SILVER perp, monitor price for up to 10 min
- Sell SILVER perp when price rises above entry (or on timeout)
- Withdraw USDC back to Base
- Buy ETH spot on Hyperliquid, withdraw to Ethereum mainnet
- Buy TSLA on Coinbase

Requires funded wallet with >= $10 USDC on Base and Coinbase keys.

Signed-off-by: Michael Yuan <michael@secondstate.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add informative before/after messages for each step showing key JSON
response data — prices, funding rates, position sizes, PnL estimates,
bridge TX hashes, and color-coded price monitoring output.

Signed-off-by: Michael Yuan <michael@secondstate.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace run_fintool() || true pattern that silently swallowed all errors.
New approach captures stdout/stderr/exit-code separately via temp files.
check_fail() helper prints the full error output (colored red) and calls
fail() whenever a command returns non-zero. Each step now:

- Gates on prior step success (e.g., skip sell if buy failed)
- Prints fintool's stderr progress messages in gray on success, red on failure
- Shows the exact error text from fintool on failure
- Tracks pass/fail counts accurately in the summary

Signed-off-by: Michael Yuan <michael@secondstate.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Deposit is a prerequisite for all subsequent trading steps. Stop
immediately instead of continuing with steps that are guaranteed to fail.

Signed-off-by: Michael Yuan <michael@secondstate.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Before executing the USDC bridge, check ETH balances on both the source
chain and Arbitrum. If Arbitrum has insufficient ETH for the final HL
Bridge2 deposit tx, automatically bridge 0.001 ETH from the source chain
via Across Protocol. Bail early with a clear error if the source chain
lacks enough ETH to cover gas + the ETH bridge amount.

Signed-off-by: Michael Yuan <michael@secondstate.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Michael Yuan <michael@secondstate.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Michael Yuan <michael@secondstate.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Use 0x0 as outputToken in the Across API to receive native ETH on
Arbitrum instead of WETH. This avoids the chicken-and-egg problem where
unwrapping WETH requires native ETH for gas but there is none.

Flow: wrap ETH→WETH on Base → Across bridge → native ETH on Arbitrum.

Also removes the WETH balance check and unwrap logic that is no longer
needed.

Signed-off-by: Michael Yuan <michael@secondstate.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…P-3 dex names

- Remove "Unit" from exchange list (it's a bridge, not trading exchange)
- Split Balance/Positions in capability matrix (Positions doesn't support Coinbase)
- Fix perp quote: Hyperliquid only, not Binance (--exchange flag not wired through)
- Replace nonexistent "abcd" dex with actual dexes (km, flx)
- Remove EWY from cash dex auto-resolved assets (requires cash: prefix)
- Fix withdraw.sh: skip ETH withdrawal when amount is 0, default ETH to 0

Signed-off-by: Michael Yuan <michael@secondstate.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…st scripts

- Fix HIP-3 order signing: use SDK-compatible float_to_string_for_hashing
  (8 decimal places, strip trailing zeros) for correct msgpack/EIP-712 digest
- Fix price_to_wire: round to 5 sig figs (tick size) before formatting
- Fix size_to_wire: truncate to szDecimals before formatting
- Add get_dex_collateral_token() for dynamic collateral lookup per HIP-3 dex
  (cash dex uses USDT0, not USDC)
- Fix sendAsset destination and set_abstraction to use wallet-derived address
- Add get_wallet_address() helper, update fintool address command
- Add perp leverage command (Hyperliquid + HIP-3 + Binance)
- Add perp set-mode command (unified/standard/disabled account abstraction)
- Add transfer command (perp/spot/HIP-3 dex transfers)
- Add 50% gas price buffer for Arbitrum withdrawal transactions
- Replace blind sleep with polling loop for Arbitrum USDC arrival
- Add Coinbase support for balance, orders, cancel commands
- Add Binance support for balance, positions, orders, cancel, leverage
- Add test scripts: helpers, deposit, buy/sell eth/hype/silver/tsla,
  show_status, e2e_trading (rewritten as clean fintool command list)

Signed-off-by: Michael Yuan <michael@secondstate.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Michael Yuan <michael@secondstate.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Michael Yuan <michael@secondstate.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Michael Yuan <michael@secondstate.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Fix formatting issues in hyperliquid.md
Added command examples for checking Hyperliquid status.
…tions

- Remove Options workflow (not supported yet)
- Add Step 6 to perp workflow: close position with --close (reduce-only)
- Remove options references from description, capability table, setup check
- Renumber workflows 4-6 → 3-5

Signed-off-by: Michael Yuan <michael@secondstate.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add step-by-step workflow guides for:
- Deposit funds (Base → Hyperliquid via Across bridge)
- Withdraw funds (Hyperliquid → Base/Ethereum/Arbitrum)
- Price quotes, news, and SEC filings
- Spot buy and sell (with exchange routing)
- Open and close perp positions (with --close)
- Commodity perp on HIP-3 (USDT0 conversion workflow)

Signed-off-by: Michael Yuan <michael@secondstate.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@juntao juntao merged commit 8bd2e28 into main Feb 27, 2026
2 checks passed
@juntao juntao deleted the test/e2e-trading-script branch February 27, 2026 07:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant