Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
441c2b8
chore: changelog
Unique-Divine Nov 4, 2025
bf1cd79
sai-trading: add first set of artifacts
Unique-Divine Nov 7, 2025
8bbf099
sai-trading: toml for build info
Unique-Divine Nov 7, 2025
0ac2a14
sai-trading: start a small program that uses a running nibid process …
Unique-Divine Nov 7, 2025
a989fee
chore: add out.txt to gitignore; add justfile comment
Unique-Divine Nov 8, 2025
1908fe2
Merge branch 'main' into ud/sai-trading-init
Unique-Divine Nov 8, 2025
9cee9d6
sai-trading: project scaffolding with script to deploy all Sai contracts
Unique-Divine Nov 8, 2025
f013071
sai-trading: get a simple test going that checks for the running netw…
Unique-Divine Nov 8, 2025
bc2f0ec
test(ci): need to install bun before running the script
Unique-Divine Nov 8, 2025
b132441
use which instead of command -v
Unique-Divine Nov 8, 2025
c1eefb7
fix array concatenation
Unique-Divine Nov 8, 2025
45b7814
make pr title lint more flexible to account for sai-trading and rever…
Unique-Divine Nov 8, 2025
ea462ec
test(.github): fix just install if statement
Unique-Divine Nov 8, 2025
ccec696
chore: linter
Unique-Divine Nov 8, 2025
2120654
fix(linter): revert the build tag issue and disable that small piece …
Unique-Divine Nov 8, 2025
c0d0cdf
Merge branch 'main' into ud/sai-trading-init
Unique-Divine Nov 10, 2025
d7ce146
Delete TODO_ANALYSIS.md
Unique-Divine Nov 10, 2025
5224eb6
evm trader
expertdicer Nov 12, 2025
aef4759
README
expertdicer Nov 12, 2025
c7646e4
merge
expertdicer Nov 12, 2025
6fa850f
adding open and close command, utilities command for querying markets…
expertdicer Nov 18, 2025
5b3ee3e
Merge branch 'main' into expertdicer/sai-trading
expertdicer Nov 20, 2025
1ab13a6
feat: add open-price flag for limit and stop orders in open command
expertdicer Nov 25, 2025
7abf185
feat: enhance trade parameters validation and open price handling
expertdicer Nov 25, 2025
1238389
feat: add TOML configuration for network settings and enhance trader …
expertdicer Dec 3, 2025
6d65dc5
feat: implement automated trading functionality with configuration su…
expertdicer Dec 5, 2025
c8cefdd
Merge branch 'main' into expertdicer/sai-trading
expertdicer Dec 5, 2025
814a043
Merge branch 'main' into expertdicer/sai-trading
expertdicer Dec 9, 2025
44f3c83
feat: add Slack notification configuration and error keyword filtering
expertdicer Dec 9, 2025
eb55d68
add .env.example file and update README for configuration instructions
expertdicer Dec 9, 2025
f662fa7
replace log calls with logError
expertdicer Dec 9, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions sai-trading/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
EVM_MNEMONIC=""
SLACK_WEBHOOK=""
SLACK_ERROR_KEYWORDS=""
62 changes: 44 additions & 18 deletions sai-trading/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,50 +46,76 @@ https://github.com/mikefarah/yq?tab=readme-ov-file#github-action

## Running the EVM Trader

### Configuration via `.env` file
### Configuration

Create a `.env` file in the root directory to configure the trader:
Create a `.env` file in the root directory (see `.env.example`):

```bash
# Account credentials (use either private key OR mnemonic)
EVM_PRIVATE_KEY=0x1234567890abcdef... # Your private key in hex format
EVM_PRIVATE_KEY=0x1234567890abcdef...
# OR
EVM_MNEMONIC="word1 word2 word3 ..." # Your BIP39 mnemonic phrase
EVM_MNEMONIC="word1 word2 word3 ..."

# Optional: Slack notifications
SLACK_WEBHOOK=""
SLACK_ERROR_KEYWORDS=""
```

### Running the trader

**Dynamic trading** (uses config parameters):
**Auto trading** :
```bash
just run-trader auto --network testnet
```

With custom parameters:
```bash
just run-trader
# or with custom parameters:
just run-trader --market-index 0 --leverage-min 5 --leverage-max 20
just run-trader auto --market-index 0 --min-leverage 5 --max-leverage 20 --blocks-before-close 20 --network testnet
```

**Static JSON file trading**:
Or use a config file:
```bash
go run ./cmd/trader auto --config auto-trader.localnet.json
```

**Manual trading**:
```bash
# Open a single position
just run-trader open --trade-type trade --market-index 0 --long false --trade-size 1 --network testnet

# Using JSON file
just run-trader --trade-json sample_txs/open_trade.json
```

### Available flags

- `--network`: Network mode (`localnet`, `testnet`, `mainnet`)
**Root flags (shared across all commands):**
- `--network`: Network mode (`localnet`, `testnet`, `mainnet`) (default: `localnet`)
- `--evm-rpc`: EVM RPC URL (overrides network mode default)
- `--networks-toml`: Path to networks TOML configuration file (default: `networks.toml`)
- `--contracts-env`: Path to contracts env file (legacy, overrides networks.toml)
- `--private-key`: Private key in hex format (overrides `EVM_PRIVATE_KEY` env var)
- `--mnemonic`: BIP39 mnemonic phrase (overrides `EVM_MNEMONIC` env var)
- `--contracts-env`: Path to contracts env file (defaults to `.cache/localnet_contracts.env`)
- `--trade-json`: Path to JSON file with trade parameters (overrides dynamic trading)

**Auto command flags:**
- `--config`: Path to JSON config file (optional)
- `--market-index`: Market index to trade (default: 0)
- `--collateral-index`: Collateral token index (default: 1)
- `--leverage-min`: Minimum leverage (default: 5)
- `--leverage-max`: Maximum leverage (default: 20)
- `--trade-size-min`: Minimum trade size in smallest units (default: 10000)
- `--trade-size-max`: Maximum trade size in smallest units (default: 50000)
- `--enable-limit-order`: Enable limit order trading (default: false)
- `--collateral-index`: Collateral token index (default: 0, uses market's quote token)
- `--min-trade-size`: Minimum trade size in smallest units (default: 1000000)
- `--max-trade-size`: Maximum trade size in smallest units (default: 5000000)
- `--min-leverage`: Minimum leverage (default: 1, e.g., 1 for 1x)
- `--max-leverage`: Maximum leverage (default: 10, e.g., 10 for 10x)
- `--blocks-before-close`: Number of blocks to wait before closing a position (default: 20)
- `--max-open-positions`: Maximum number of positions to keep open at once (default: 5)
- `--loop-delay`: Delay in seconds between each loop iteration (default: 5)

### Example `.env` file

```bash
# Account
EVM_MNEMONIC="guard cream sadness conduct invite crumble clock pudding hole grit liar hotel maid produce squeeze return argue turtle know drive eight casino maze host"
SLACK_WEBHOOK=""
SLACK_ERROR_KEYWORDS=""
```

**Note**: The `.env` file is automatically loaded if present. You can also pass values via command-line flags, which take precedence over environment variables.
Expand Down
20 changes: 20 additions & 0 deletions sai-trading/auto-trader.localnet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"network": {
"mode": "localnet",
"evm_rpc_url": "http://localhost:8545",
"networks_toml": "networks.toml"
},
"trading": {
"market_index": 0,
"collateral_index": 1,
"min_trade_size": 10000,
"max_trade_size": 50000,
"min_leverage": 2,
"max_leverage": 8
},
"bot": {
"blocks_before_close": 20,
"max_open_positions": 3,
"loop_delay_seconds": 5
}
}
19 changes: 19 additions & 0 deletions sai-trading/auto-trader.testnet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"network": {
"mode": "testnet",
"networks_toml": "networks.toml"
},
"trading": {
"market_index": 0,
"collateral_index": 3,
"min_trade_size": 10000,
"max_trade_size": 100000,
"min_leverage": 1,
"max_leverage": 5
},
"bot": {
"blocks_before_close": 10,
"max_open_positions": 2,
"loop_delay_seconds": 10
}
}
Loading