Skip to content

Commit c0bc8ac

Browse files
committed
feat: upload codebase
0 parents  commit c0bc8ac

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+8655
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.env
2+
/target
3+
Cargo.lock
4+
testnet
5+
src/frontend/interface/.vite

Cargo.toml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
[package]
2+
name = "hyperliquid_rust_bot"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[dependencies]
7+
hyperliquid_rust_sdk = { git = "https://github.com/0xNoSystem/hyperliquid-rust-sdk.git", branch = "master" }
8+
kwant = { git = "https://github.com/0xNoSystem/Indicators_rs.git", branch = "main" }
9+
chrono = "0.4.26"
10+
env_logger = "0.10.0"
11+
ethers = {version = "2.0.14", features = ["eip712", "abigen"]}
12+
futures-util = "0.3.28"
13+
hex = "0.4.3"
14+
http = "0.2.9"
15+
lazy_static = "1.3"
16+
log = "0.4.19"
17+
rand = "0.8.5"
18+
reqwest = "0.11.18"
19+
serde = { version = "1.0.175", features = ["derive"] }
20+
serde_json = "1.0.103"
21+
rmp-serde = "1.0.0"
22+
thiserror = "1.0.44"
23+
tokio = { version = "1.29.1", features = ["full"] }
24+
tokio-tungstenite = {version = "0.20.0", features = ["native-tls"]}
25+
uuid = {version = "1.6.1", features = ["v4"]}
26+
dotenv = "0.15.0"
27+
flume = "0.11.1"
28+
toml = "0.8.20"
29+
arraydeque = "0.5.1"
30+
rustc-hash = "2.1.1"
31+
futures = "0.3.31"
32+
hyperliquid = "0.2.4"
33+
anyhow = "1.0.98"
34+
actix = "0.13"
35+
actix-web = "4.11.0"
36+
actix-web-actors = "4"
37+
actix-cors = "0.6"
38+
39+
40+

README.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Hyperliquid Trading Bot - Rust
2+
3+
Hyperliquid trading Bot with Rust is an experimental trading system built with
4+
[`hyperliquid_rust_sdk`](https://github.com/0xTan1319/hyperliquid-rust-sdk). It manages multiple
5+
markets on the Hyperliquid exchange and places trades based on signals from
6+
user-selected indicators.
7+
8+
The repository currently ships a React/TS UI and actix server, follow the getting started steps.
9+
10+
## Contact
11+
12+
If you have any question or need more update for this, contact here: [Telegram](https://t.me/shiny0103) | [Twitter](https://x.com/0xTan1319)
13+
14+
## Features
15+
16+
- Connect to Hyperliquid mainnet, testnet or localhost.
17+
- Manage several markets concurrently with configurable margin allocation.
18+
- Customisable strategy (risk, style, stance).
19+
- Indicator engine where each indicator is bound to a timeframe.
20+
- Asynchronous design using `tokio` and `flume` channels.
21+
22+
## Getting started
23+
24+
After cloning the repo
25+
26+
1. Install a recent Rust toolchain.
27+
2. Create a `.env` file in the root directory`:
28+
29+
```env
30+
PRIVATE_KEY=<your API private key> -> https://app.hyperliquid.xyz/API
31+
AGENT_KEY=<optional agent api public key>
32+
WALLET=<public wallet address>
33+
```
34+
35+
3. Run the app:
36+
37+
```bash
38+
./run.sh
39+
```
40+
41+
## Strategy
42+
43+
The bot uses `CustomStrategy` (see `src/strategy.rs`). It combines indicators
44+
such as RSI, StochRSI, EMA crosses, ADX and ATR. Risk level (`Low`, `Normal`,
45+
`High`), trading style (`Scalp` or `Swing`) and market stance (`Bull`, `Bear` or
46+
`Neutral`) can be set. Signals are generated when multiple indicator conditions
47+
agree—for example an oversold RSI with a bullish StochRSI crossover may trigger a
48+
long trade.
49+
50+
## Indicators
51+
52+
Indicators are activated with `(IndicatorKind, TimeFrame)` pairs. Available kinds
53+
include:
54+
55+
- `Rsi(u32)`
56+
- `SmaOnRsi { periods, smoothing_length }`
57+
- `StochRsi { periods, k_smoothing, d_smoothing }`
58+
- `Adx { periods, di_length }`
59+
- `Atr(u32)`
60+
- `Ema(u32)`
61+
- `EmaCross { short, long }`
62+
- `Sma(u32)`
63+
64+
Each pair is wrapped in an `Entry` together with an `EditType` (`Add`, `Remove` or
65+
`Toggle`). The snippet below (from `enginetest.rs`) shows how a market can be
66+
created with a custom indicator configuration:
67+
68+
```rust
69+
let config = vec![
70+
(IndicatorKind::Rsi(12), TimeFrame::Min1),
71+
(IndicatorKind::EmaCross { short: 21, long: 200 }, TimeFrame::Day1),
72+
];
73+
74+
let market = AddMarketInfo {
75+
asset: "BTC".to_string(),
76+
margin_alloc: MarginAllocation::Alloc(0.1),
77+
trade_params,
78+
config: Some(config),
79+
};
80+
```
81+
82+
## Project structure
83+
84+
- `src/bot.rs` – orchestrates markets and keeps margin in sync.
85+
- `src/market.rs` – handles a single market: data feed, signal engine and order
86+
execution.
87+
- `src/signal/` – indicator trackers and strategy logic.
88+
- `src/executor.rs` – sends orders via the Hyperliquid API.
89+
- 'src/strategy.ra' - Implements strategies followed by the signal engine.
90+
- `src/trade_setup.rs` – trading parameters and trade metadata.
91+
- `config.toml` – example strategy configuration.
92+
93+
Supported trading pairs can be found in `src/assets.rs` (`MARKETS`).
94+
95+
## Disclaimer
96+
97+
This code is experimental and not audited. Use at your own risk when trading on
98+
live markets.

config.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#Three trading styles: Scalp - Swing - build_position
2+
3+
style = "Scalp"
4+
5+
#Risk: Low - Normal - High
6+
risk = "High"
7+
8+
#Stance: Bull - Neutral - Bear
9+
stance = "Neutral"
10+
11+
#Follow trend: true - false
12+
followTrend= false
13+

run.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
cargo run --release --bin load #update tradable assets list
2+
3+
4+
cargo run --release --bin kwant & #PREFIX WITH "RUST_LOG=info" for logging
5+
6+
cd ./src/frontend/interface
7+
8+
npm install
9+
npm run dev
10+
11+
12+

src/assets.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub static MARKETS: &[&str] = &["BTC", "ETH", "ATOM", "MATIC", "DYDX", "SOL", "AVAX", "BNB", "APE", "OP", "LTC", "ARB", "DOGE", "INJ", "SUI", "kPEPE", "CRV", "LDO", "LINK", "STX", "RNDR", "CFX", "FTM", "GMX", "SNX", "XRP", "BCH", "APT", "AAVE", "COMP", "MKR", "WLD", "FXS", "HPOS", "RLB", "UNIBOT", "YGG", "TRX", "kSHIB", "UNI", "SEI", "RUNE", "OX", "FRIEND", "SHIA", "CYBER", "ZRO", "BLZ", "DOT", "BANANA", "TRB", "FTT", "LOOM", "OGN", "RDNT", "ARK", "BNT", "CANTO", "REQ", "BIGTIME", "KAS", "ORBS", "BLUR", "TIA", "BSV", "ADA", "TON", "MINA", "POLYX", "GAS", "PENDLE", "STG", "FET", "STRAX", "NEAR", "MEME", "ORDI", "BADGER", "NEO", "ZEN", "FIL", "PYTH", "SUSHI", "ILV", "IMX", "kBONK", "GMT", "SUPER", "USTC", "NFTI", "JUP", "kLUNC", "RSR", "GALA", "JTO", "NTRN", "ACE", "MAV", "WIF", "CAKE", "PEOPLE", "ENS", "ETC", "XAI", "MANTA", "UMA", "ONDO", "ALT", "ZETA", "DYM", "MAVIA", "W", "PANDORA", "STRK", "PIXEL", "AI", "TAO", "AR", "MYRO", "kFLOKI", "BOME", "ETHFI", "ENA", "MNT", "TNSR", "SAGA", "MERL", "HBAR", "POPCAT", "OMNI", "EIGEN", "REZ", "NOT", "TURBO", "BRETT", "IO", "ZK", "BLAST", "LISTA", "MEW", "RENDER", "kDOGS", "POL", "CATI", "CELO", "HMSTR", "SCR", "NEIROETH", "kNEIRO", "GOAT", "MOODENG", "GRASS", "PURR", "PNUT", "XLM", "CHILLGUY", "SAND", "IOTA", "ALGO", "HYPE", "ME", "MOVE", "VIRTUAL", "PENGU", "USUAL", "FARTCOIN", "AI16Z", "AIXBT", "ZEREBRO", "BIO", "GRIFFAIN", "SPX", "S", "MORPHO", "TRUMP", "MELANIA", "ANIME", "VINE", "VVV", "JELLY", "BERA", "TST", "LAYER", "IP", "OM", "KAITO", "NIL", "PAXG", "PROMPT", "BABY", "WCT", "HYPER", "ZORA", "INIT", "DOOD", "LAUNCHCOIN", "NXPC", "SOPH", "RESOLV", "SYRUP", "PUMP", "PROVE", "YZY", "XPL", "WLFI", "LINEA"];

src/backtest.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use crate::{SignalEngine, MARKETS, IndexId};
2+
use crate::helper::{load_candles};
3+
use kwant::indicators::{Price};
4+
use crate::trade_setup::{TradeParams, TimeFrame};
5+
use crate::strategy::{Strategy, CustomStrategy, Style, Stance};
6+
use tokio::time::{sleep, Duration};
7+
use hyperliquid_rust_sdk::{InfoClient, BaseUrl};
8+
9+
pub struct BackTester{
10+
pub asset: String,
11+
pub signal_engine: SignalEngine,
12+
pub params: TradeParams,
13+
pub candle_data: Vec<Price>,
14+
}
15+
16+
17+
18+
19+
impl BackTester{
20+
21+
pub fn new(asset: &str,params: TradeParams, config: Option<Vec<IndexId>>, margin: f64) -> Self{
22+
if !MARKETS.contains(&asset){
23+
panic!("ASSET ISN'T TRADABLE, MARKET CAN'T BE INITILIAZED");
24+
}
25+
26+
BackTester{
27+
asset: asset.to_string(),
28+
signal_engine: SignalEngine::new_backtest(params.clone(), config, margin),
29+
params,
30+
candle_data: Vec::new(),
31+
}
32+
}
33+
34+
}
35+

0 commit comments

Comments
 (0)