hood-traders 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +214 -0
- package/dashboard/app.js +215 -0
- package/dashboard/index.html +44 -0
- package/dashboard/style.css +309 -0
- package/dist/chunk-NXL2F7EP.js +1371 -0
- package/dist/chunk-NXL2F7EP.js.map +1 -0
- package/dist/index.d.ts +697 -0
- package/dist/index.js +30 -0
- package/dist/index.js.map +1 -0
- package/dist/main.js +59 -0
- package/dist/main.js.map +1 -0
- package/package.json +75 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the
|
|
44
|
+
purposes of this License, Derivative Works shall not include works
|
|
45
|
+
that remain separable from, or merely link (or bind by name) to the
|
|
46
|
+
interfaces of, the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including the
|
|
49
|
+
original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 nirholas
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
# hood-traders
|
|
2
|
+
|
|
3
|
+
Autonomous trading agents for **Robinhood Chain** — a live fleet that trades memecoins on NOXA
|
|
4
|
+
and The Odyssey, and watches Stock Token premium/discount against Chainlink, with real signed
|
|
5
|
+
swaps, hard risk caps, and a live decision-journal dashboard.
|
|
6
|
+
|
|
7
|
+
> ## ⚠ Risk disclaimer
|
|
8
|
+
> This software can autonomously sign and broadcast **real transactions with real funds** when
|
|
9
|
+
> run in live mode. Trading is risky. Strategies here are honestly documented, not guaranteed —
|
|
10
|
+
> **most new memecoin launches go to zero**, thin Stock Token pools can move against you, and
|
|
11
|
+
> software has bugs. Read the [strategy failure modes](#strategies) before funding a wallet.
|
|
12
|
+
> **Paper mode is the default and does not touch real funds.** Live mode requires you to set
|
|
13
|
+
> `HOOD_TRADERS_LIVE=1` **and** provide a funded private key — never enabled by accident. There
|
|
14
|
+
> are no guarantees, no warranty, and no recovery for funds lost to a bug, a bad market, or a
|
|
15
|
+
> misconfigured risk cap. Start in paper mode. Use a wallet you can afford to lose. You are
|
|
16
|
+
> responsible for every transaction this software signs on your behalf.
|
|
17
|
+
|
|
18
|
+
Built on [`hoodchain`](../robinhood-chain-sdk) — the Robinhood Chain (chain ID 4663) TypeScript
|
|
19
|
+
SDK for Stock Tokens, Chainlink quotes, Uniswap v3 swaps, USDG, and launchpad watchers.
|
|
20
|
+
`hoodkit`/`hood-js` (the wave-2 convenience wrappers) had not shipped at the time this package
|
|
21
|
+
was built, so `hood-traders` talks to `hoodchain` directly — swapping in a wrapper later is a
|
|
22
|
+
drop-in change confined to `src/framework/market.ts`.
|
|
23
|
+
|
|
24
|
+
## What it does
|
|
25
|
+
|
|
26
|
+
- **Framework** (`src/framework/`): agent = strategy + wallet + risk budget + journal. Every tick
|
|
27
|
+
runs observe → decide → simulate (a real Uniswap v3 `eth_call`) → risk-check (fail-closed) →
|
|
28
|
+
execute → journal.
|
|
29
|
+
- **Three strategies** (`src/strategies/`): `launch-sniper`, `momentum`, `premium-watch` — each
|
|
30
|
+
with an honestly documented edge hypothesis and failure modes (see [Strategies](#strategies)).
|
|
31
|
+
- **Live dashboard** (`dashboard/`): fleet overview, per-agent equity curve, open positions, the
|
|
32
|
+
full decision journal (why each trade fired — or didn't), and a kill button.
|
|
33
|
+
- **Risk layer** (`src/framework/risk.ts`): per-agent position cap, daily spend cap, fleet-wide
|
|
34
|
+
daily spend cap, slippage bound, and cooldown — every one enforced *before* execution, not
|
|
35
|
+
advisory.
|
|
36
|
+
- **Kill switch** (`src/framework/kill.ts`): SIGINT/SIGTERM, a `KILL` file, or `POST /api/kill` —
|
|
37
|
+
any of the three halts new orders across the whole fleet immediately. It never force-sells; it
|
|
38
|
+
only stops taking on new risk.
|
|
39
|
+
|
|
40
|
+
## Quickstart — paper mode in 5 minutes
|
|
41
|
+
|
|
42
|
+
Paper mode simulates fills against **live** market data (real Chainlink prices, real Uniswap v3
|
|
43
|
+
quotes) — it is a real simulation, not fake data. No wallet, no key, no config needed.
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
git clone https://github.com/nirholas/hood-traders.git
|
|
47
|
+
cd hood-traders
|
|
48
|
+
npm install
|
|
49
|
+
npm run build
|
|
50
|
+
npm run fleet
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Open **http://localhost:4670** — the dashboard is live: fleet equity, per-agent P&L, open
|
|
54
|
+
positions, and the decision journal.
|
|
55
|
+
|
|
56
|
+
Or with Docker (same result, zero local Node/npm needed):
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
cd hood-traders
|
|
60
|
+
docker compose up --build
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### About `hoodchain`
|
|
64
|
+
|
|
65
|
+
`hood-traders` depends on [`hoodchain`](https://www.npmjs.com/package/hoodchain), the Robinhood
|
|
66
|
+
Chain TypeScript SDK, as a normal published npm dependency (`^0.1.1`) — `npm install` resolves it
|
|
67
|
+
from the registry like any other package. If you're developing the SDK and this fleet together,
|
|
68
|
+
clone [`robinhood-chain-sdk`](https://github.com/nirholas/robinhood-chain-sdk) as a sibling and
|
|
69
|
+
point `package.json` at `file:../robinhood-chain-sdk` for local iteration; revert to the published
|
|
70
|
+
semver before shipping.
|
|
71
|
+
|
|
72
|
+
## Going live
|
|
73
|
+
|
|
74
|
+
Live mode signs and broadcasts real transactions. It requires **both**:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
cp .env.example .env
|
|
78
|
+
# edit .env:
|
|
79
|
+
HOOD_TRADERS_LIVE=1
|
|
80
|
+
ROBINHOOD_CHAIN_PRIVATE_KEY=0x... # env var only — never hardcode a key
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Missing either one keeps the fleet in paper mode — there is no accidental-live path. Every risk
|
|
84
|
+
cap in `.env.example` applies identically in live mode; they are not paper-mode-only guardrails.
|
|
85
|
+
|
|
86
|
+
**Stock Token trading** additionally requires `HOOD_STOCK_TOKEN_ELIGIBLE=true` — an explicit
|
|
87
|
+
affirmation that you are not a US/Canada/UK/Switzerland person, per the legal restriction on
|
|
88
|
+
these tokenized debt securities (issuer: Robinhood Assets (Jersey) Ltd). Without it,
|
|
89
|
+
`premium-watch` stays alerts-only and any Stock Token swap attempt throws
|
|
90
|
+
`StockTokenEligibilityError`. Memecoin trading (`launch-sniper`, `momentum`) is never gated.
|
|
91
|
+
|
|
92
|
+
## Architecture
|
|
93
|
+
|
|
94
|
+
See [`docs/architecture.html`](docs/architecture.html) for the full observe → decide → simulate →
|
|
95
|
+
risk-check → execute → journal diagram, and how the three strategies plug into it. Short version:
|
|
96
|
+
|
|
97
|
+
```
|
|
98
|
+
Market (hoodchain SDK, live RPC)
|
|
99
|
+
│
|
|
100
|
+
▼
|
|
101
|
+
Strategy.tick(ctx) ──► Decision { intents[], alerts[] }
|
|
102
|
+
│
|
|
103
|
+
▼
|
|
104
|
+
Agent: for each intent
|
|
105
|
+
1. simulate — real QuoterV2 eth_call, no state change
|
|
106
|
+
2. price — USD notional from the simulated fill
|
|
107
|
+
3. risk gate — RiskEngine.check(...) — fails CLOSED
|
|
108
|
+
4. execute — paper: record the simulated fill
|
|
109
|
+
live: buildSwapTx → approve → sendTransaction → wait for receipt
|
|
110
|
+
5. journal — every trade AND every refusal, into SQLite
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
A strategy can never bypass the risk gate — it proposes intents, the agent enforces every cap
|
|
114
|
+
before anything executes, paper or live.
|
|
115
|
+
|
|
116
|
+
## Strategies
|
|
117
|
+
|
|
118
|
+
Full docs with live examples: [`docs/strategies.html`](docs/strategies.html). Summary:
|
|
119
|
+
|
|
120
|
+
| Strategy | Edge hypothesis (short) | Primary failure mode |
|
|
121
|
+
|---|---|---|
|
|
122
|
+
| `launch-sniper` | Opening-minutes volatility on new launches is real; discipline (round-trip + deployer-concentration filters, mechanical exits) harvests a slice of it. | Most new launches go to zero — the stop loss fires often; this is negative-carry unless winners cover losers. |
|
|
123
|
+
| `momentum` | Tokens that survive to graduation and then break out on price reflect real demand, not launch-day noise. | Breakouts on thin pools are trivially fakeable by one wallet; price-only signal has no depth check. |
|
|
124
|
+
| `premium-watch` | Stock Token pools are thin and drift from the Chainlink oracle; buying the discount captures reversion. **Alerts-only by default** — trading requires explicit eligibility + opt-in. | A premium/discount can be *correct* (DEX reacting to news the ≤24h Chainlink heartbeat hasn't caught yet); fading it loses on purpose. No shorting primitive exists. |
|
|
125
|
+
|
|
126
|
+
Every strategy exposes its `meta.edge` / `meta.failureModes` at runtime (`strategy.meta`) — the
|
|
127
|
+
dashboard and docs pull the live values, not a stale copy.
|
|
128
|
+
|
|
129
|
+
## Configuration
|
|
130
|
+
|
|
131
|
+
All of `.env.example` is optional for paper mode. Key knobs:
|
|
132
|
+
|
|
133
|
+
| Var | Default | Meaning |
|
|
134
|
+
|---|---|---|
|
|
135
|
+
| `HOOD_NETWORK` | `mainnet` | `mainnet` (4663) or `testnet` (46630) |
|
|
136
|
+
| `HOOD_RPC_URL` | *(viem's public RPC)* | Optional paid RPC (Alchemy recommended for live trading) |
|
|
137
|
+
| `HOOD_TRADERS_LIVE` | `0` | Must be `1` (+ a valid key) to trade real funds |
|
|
138
|
+
| `HOOD_STOCK_TOKEN_ELIGIBLE` | `false` | Non-US-person affirmation gating Stock Token acquisition |
|
|
139
|
+
| `FLEET_MAX_DAILY_SPEND_USDG` | `250` | Hard ceiling across the whole fleet, USD/day |
|
|
140
|
+
| `AGENT_MAX_POSITION_USDG` | `50` | Per-agent, per-token position cap |
|
|
141
|
+
| `AGENT_MAX_DAILY_SPEND_USDG` | `100` | Per-agent daily spend cap |
|
|
142
|
+
| `AGENT_MAX_SLIPPAGE_BPS` | `100` | Per-agent slippage bound (1%) |
|
|
143
|
+
| `AGENT_COOLDOWN_SECONDS` | `60` | Minimum gap between an agent's trades |
|
|
144
|
+
| `KILL_FILE` | `./KILL` | Drop a file here to halt the fleet immediately |
|
|
145
|
+
| `DASHBOARD_PORT` | `4670` | Dashboard + API port |
|
|
146
|
+
|
|
147
|
+
## Kill switch
|
|
148
|
+
|
|
149
|
+
Three independent triggers, all wired the same way — any one halts new orders across every agent:
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
# 1. Ctrl-C the process (SIGINT), or `docker compose stop` (SIGTERM)
|
|
153
|
+
|
|
154
|
+
# 2. Drop the kill file
|
|
155
|
+
touch KILL # local
|
|
156
|
+
touch data/KILL # docker (mounted volume)
|
|
157
|
+
|
|
158
|
+
# 3. HTTP
|
|
159
|
+
curl -X POST http://localhost:4670/api/kill
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
The kill switch **never force-sells** — it stops new risk, it doesn't unwind existing positions.
|
|
163
|
+
Deciding whether to exit into whatever caused the panic is an explicit operator call.
|
|
164
|
+
|
|
165
|
+
## Development
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
npm run typecheck # tsc --noEmit
|
|
169
|
+
npm test # unit tests — risk, kill switch, journal, strategies, agent (58 tests)
|
|
170
|
+
npm run test:e2e # live-network E2E — see below
|
|
171
|
+
npm run snapshot # capture a fresh live market snapshot into tests/snapshots/
|
|
172
|
+
npm run dev # tsx watch — fleet + dashboard with hot reload
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
Unit tests never hit the network: strategy logic is tested against **real recorded market
|
|
176
|
+
snapshots** (`tests/snapshots/`, captured with `npm run snapshot`) fed through a scriptable fake
|
|
177
|
+
market, and risk/kill/journal tests are pure logic. `npm run test:e2e` is the one suite that talks
|
|
178
|
+
to live RPCs.
|
|
179
|
+
|
|
180
|
+
## Deploy
|
|
181
|
+
|
|
182
|
+
### Docker / Google Cloud Run (preferred)
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
docker build -f Dockerfile -t hood-traders .. # context = parent dir, see Dockerfile comment
|
|
186
|
+
docker run -p 4670:4670 -v hood-traders-data:/app/data hood-traders
|
|
187
|
+
|
|
188
|
+
# Cloud Run
|
|
189
|
+
gcloud run deploy hood-traders \
|
|
190
|
+
--source .. \
|
|
191
|
+
--dockerfile hood-traders/Dockerfile \
|
|
192
|
+
--region us-central1 \
|
|
193
|
+
--port 4670 \
|
|
194
|
+
--set-env-vars HOOD_NETWORK=mainnet,FLEET_MAX_DAILY_SPEND_USDG=250 \
|
|
195
|
+
--min-instances 1 --max-instances 1 # single instance — the journal is a local SQLite file
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
For live trading on Cloud Run, set `HOOD_TRADERS_LIVE` and `ROBINHOOD_CHAIN_PRIVATE_KEY` via
|
|
199
|
+
`--set-secrets` (Secret Manager), never `--set-env-vars`, and mount a persistent volume (Cloud Run
|
|
200
|
+
+ a GCS FUSE mount, or migrate the journal to Cloud SQL) so the decision journal survives restarts.
|
|
201
|
+
|
|
202
|
+
### Vercel
|
|
203
|
+
|
|
204
|
+
Vercel's serverless functions are not a fit for a long-running tick loop + stateful SQLite
|
|
205
|
+
journal — this is a **long-running process**, deploy it to Cloud Run, Fly.io, Railway, or any
|
|
206
|
+
always-on container host instead.
|
|
207
|
+
|
|
208
|
+
## License
|
|
209
|
+
|
|
210
|
+
Apache-2.0 — see [LICENSE](LICENSE).
|
|
211
|
+
|
|
212
|
+
---
|
|
213
|
+
|
|
214
|
+
Built by [nirholas](https://x.com/nichxbt) · [three.ws](https://three.ws)
|
package/dashboard/app.js
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
// hood-traders dashboard — vanilla JS, no build step, polls the fleet API.
|
|
2
|
+
|
|
3
|
+
const POLL_MS = 4000
|
|
4
|
+
const openJournals = new Set()
|
|
5
|
+
|
|
6
|
+
function fmtUsd(n) {
|
|
7
|
+
const sign = n < 0 ? '-' : ''
|
|
8
|
+
return `${sign}$${Math.abs(n).toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function fmtTime(ts) {
|
|
12
|
+
if (!ts) return '—'
|
|
13
|
+
const d = new Date(ts)
|
|
14
|
+
return d.toLocaleTimeString('en-US', { hour12: false })
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function fmtAgo(ts) {
|
|
18
|
+
if (!ts) return 'never'
|
|
19
|
+
const s = Math.floor((Date.now() - ts) / 1000)
|
|
20
|
+
if (s < 5) return 'just now'
|
|
21
|
+
if (s < 60) return `${s}s ago`
|
|
22
|
+
if (s < 3600) return `${Math.floor(s / 60)}m ago`
|
|
23
|
+
return `${Math.floor(s / 3600)}h ago`
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async function api(path, opts) {
|
|
27
|
+
const res = await fetch(path, opts)
|
|
28
|
+
if (!res.ok) throw new Error(`${path} → ${res.status}`)
|
|
29
|
+
return res.json()
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function sparkline(points) {
|
|
33
|
+
if (!points || points.length < 2) {
|
|
34
|
+
return `<div class="no-positions">not enough equity history yet</div>`
|
|
35
|
+
}
|
|
36
|
+
const vals = points.map((p) => p.equityUsd)
|
|
37
|
+
const min = Math.min(...vals)
|
|
38
|
+
const max = Math.max(...vals)
|
|
39
|
+
const range = max - min || 1
|
|
40
|
+
const w = 300
|
|
41
|
+
const h = 44
|
|
42
|
+
const step = w / (points.length - 1)
|
|
43
|
+
const coords = vals.map((v, i) => `${(i * step).toFixed(1)},${(h - ((v - min) / range) * h).toFixed(1)}`)
|
|
44
|
+
const last = vals[vals.length - 1]
|
|
45
|
+
const first = vals[0]
|
|
46
|
+
const color = last >= first ? '#34d399' : '#f87171'
|
|
47
|
+
return `<svg viewBox="0 0 ${w} ${h}" preserveAspectRatio="none">
|
|
48
|
+
<polyline fill="none" stroke="${color}" stroke-width="2" points="${coords.join(' ')}" />
|
|
49
|
+
</svg>`
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function renderSummary(summary) {
|
|
53
|
+
const el = document.getElementById('summary')
|
|
54
|
+
const tiles = [
|
|
55
|
+
['Equity', fmtUsd(summary.equityUsd), summary.equityUsd >= 0 ? 'pos' : 'neg'],
|
|
56
|
+
['Realized PnL', fmtUsd(summary.realizedUsd), summary.realizedUsd >= 0 ? 'pos' : 'neg'],
|
|
57
|
+
['Open value', fmtUsd(summary.openValueUsd), ''],
|
|
58
|
+
['Fleet spend today', `${fmtUsd(summary.fleetSpentTodayUsd)} / ${fmtUsd(summary.fleetMaxDailySpendUsdg)}`, ''],
|
|
59
|
+
['Agents', String(summary.agents), ''],
|
|
60
|
+
]
|
|
61
|
+
el.innerHTML = tiles
|
|
62
|
+
.map(
|
|
63
|
+
([label, value, cls]) => `
|
|
64
|
+
<div class="stat-tile">
|
|
65
|
+
<div class="stat-label">${label}</div>
|
|
66
|
+
<div class="stat-value ${cls}">${value}</div>
|
|
67
|
+
</div>`,
|
|
68
|
+
)
|
|
69
|
+
.join('')
|
|
70
|
+
|
|
71
|
+
document.getElementById('mode-badge').textContent = summary.mode === 'live' ? '● LIVE' : '◆ PAPER'
|
|
72
|
+
document.getElementById('mode-badge').className = `badge ${summary.mode}`
|
|
73
|
+
document.getElementById('network-label').textContent = summary.network === 'testnet' ? 'testnet 46630' : 'mainnet 4663'
|
|
74
|
+
|
|
75
|
+
const killedBadge = document.getElementById('killed-badge')
|
|
76
|
+
killedBadge.hidden = !summary.killed
|
|
77
|
+
if (summary.killed) killedBadge.textContent = `⛔ killed: ${summary.killReason ?? 'unknown'}`
|
|
78
|
+
|
|
79
|
+
const killBtn = document.getElementById('kill-btn')
|
|
80
|
+
killBtn.disabled = summary.killed
|
|
81
|
+
killBtn.textContent = summary.killed ? '⛔ Halted' : '⏻ Kill switch'
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function renderAgentCard(agent, journal, equity) {
|
|
85
|
+
const statusClass = agent.killed ? 'killed' : agent.running ? 'running' : ''
|
|
86
|
+
const isOpen = openJournals.has(agent.id)
|
|
87
|
+
|
|
88
|
+
const positionsHtml = agent.positions.length
|
|
89
|
+
? agent.positions
|
|
90
|
+
.map((p) => {
|
|
91
|
+
const pnl = p.markUsd !== null && p.investedUsd > 0 ? (p.markUsd / p.investedUsd - 1) * 100 : null
|
|
92
|
+
const pnlStr = pnl === null ? '' : ` · ${pnl >= 0 ? '+' : ''}${pnl.toFixed(1)}%`
|
|
93
|
+
return `<div class="position-row"><span>${p.tokenSymbol}</span><span>${fmtUsd(p.markUsd ?? p.investedUsd)}${pnlStr}</span></div>`
|
|
94
|
+
})
|
|
95
|
+
.join('')
|
|
96
|
+
: `<div class="no-positions">no open positions</div>`
|
|
97
|
+
|
|
98
|
+
const journalHtml = journal.length
|
|
99
|
+
? journal
|
|
100
|
+
.slice(0, 40)
|
|
101
|
+
.map(
|
|
102
|
+
(j) => `<div class="journal-row kind-${j.kind}"><span class="journal-time">${fmtTime(j.ts)}</span>${escapeHtml(j.detail)}</div>`,
|
|
103
|
+
)
|
|
104
|
+
.join('')
|
|
105
|
+
: `<div class="journal-row kind-observe">no decisions journaled yet</div>`
|
|
106
|
+
|
|
107
|
+
const errorHtml = agent.lastError
|
|
108
|
+
? `<div class="error-banner">⚠ ${escapeHtml(agent.lastError)}</div>`
|
|
109
|
+
: ''
|
|
110
|
+
|
|
111
|
+
return `
|
|
112
|
+
<div class="agent-card">
|
|
113
|
+
<div class="agent-head">
|
|
114
|
+
<span class="agent-name">${agent.id}</span>
|
|
115
|
+
<span><span class="status-dot ${statusClass} ${agent.running && !agent.killed ? 'live-pulse' : ''}"></span></span>
|
|
116
|
+
</div>
|
|
117
|
+
<div class="agent-strategy">${agent.strategy} · tick ${agent.ticks} · last ${fmtAgo(agent.lastTickAt)}</div>
|
|
118
|
+
|
|
119
|
+
<div class="mini-chart">${sparkline(equity)}</div>
|
|
120
|
+
|
|
121
|
+
<div class="agent-metrics">
|
|
122
|
+
<div class="metric"><div class="metric-label">Equity</div><div class="metric-value">${fmtUsd(agent.equityUsd)}</div></div>
|
|
123
|
+
<div class="metric"><div class="metric-label">Realized</div><div class="metric-value">${fmtUsd(agent.realizedUsd)}</div></div>
|
|
124
|
+
<div class="metric"><div class="metric-label">Spent today</div><div class="metric-value">${fmtUsd(agent.spentTodayUsd)} / ${fmtUsd(agent.limits.maxDailySpendUsdg)}</div></div>
|
|
125
|
+
<div class="metric"><div class="metric-label">Trades / refused</div><div class="metric-value">${agent.trades} / ${agent.refusals}</div></div>
|
|
126
|
+
</div>
|
|
127
|
+
|
|
128
|
+
<div class="positions-list">${positionsHtml}</div>
|
|
129
|
+
|
|
130
|
+
<button class="journal-toggle" data-agent="${agent.id}" aria-expanded="${isOpen}">
|
|
131
|
+
${isOpen ? '▾' : '▸'} Decision journal (why each trade fired)
|
|
132
|
+
</button>
|
|
133
|
+
<div class="journal-list ${isOpen ? 'open' : ''}">${journalHtml}</div>
|
|
134
|
+
${errorHtml}
|
|
135
|
+
</div>`
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function escapeHtml(s) {
|
|
139
|
+
return String(s).replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]))
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function renderFleetTrades(trades) {
|
|
143
|
+
const el = document.getElementById('fleet-trades')
|
|
144
|
+
if (!trades.length) {
|
|
145
|
+
el.innerHTML = `<div class="state-block">
|
|
146
|
+
<div class="state-icon">📭</div>
|
|
147
|
+
<div class="state-title">No trades yet</div>
|
|
148
|
+
<div class="state-detail">The fleet is observing live market data. Trades will appear here the moment a strategy's risk-checked intent executes.</div>
|
|
149
|
+
</div>`
|
|
150
|
+
return
|
|
151
|
+
}
|
|
152
|
+
el.innerHTML = `<div class="agent-card">${trades
|
|
153
|
+
.slice(0, 30)
|
|
154
|
+
.map(
|
|
155
|
+
(t) =>
|
|
156
|
+
`<div class="journal-row kind-trade"><span class="journal-time">${fmtTime(t.ts)}</span>${t.agentId} ${t.side} ${t.tokenSymbol} — ${escapeHtml(t.reason)}${t.txHash ? ` <a href="#" title="${t.txHash}">↗ tx</a>` : ' (paper)'}</div>`,
|
|
157
|
+
)
|
|
158
|
+
.join('')}</div>`
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
async function refresh() {
|
|
162
|
+
try {
|
|
163
|
+
const [summary, agents, trades] = await Promise.all([
|
|
164
|
+
api('/api/summary'),
|
|
165
|
+
api('/api/agents'),
|
|
166
|
+
api('/api/trades'),
|
|
167
|
+
])
|
|
168
|
+
renderSummary(summary)
|
|
169
|
+
|
|
170
|
+
const agentsEl = document.getElementById('agents')
|
|
171
|
+
if (!agents.length) {
|
|
172
|
+
agentsEl.innerHTML = `<div class="state-block">
|
|
173
|
+
<div class="state-icon">🤖</div>
|
|
174
|
+
<div class="state-title">No agents configured</div>
|
|
175
|
+
<div class="state-detail">Add agents in src/main.ts and restart the fleet.</div>
|
|
176
|
+
</div>`
|
|
177
|
+
} else {
|
|
178
|
+
const withDetail = await Promise.all(
|
|
179
|
+
agents.map(async (a) => {
|
|
180
|
+
const [journal, equity] = await Promise.all([
|
|
181
|
+
api(`/api/agents/${encodeURIComponent(a.id)}/journal`).catch(() => []),
|
|
182
|
+
api(`/api/agents/${encodeURIComponent(a.id)}/equity`).catch(() => []),
|
|
183
|
+
])
|
|
184
|
+
return renderAgentCard(a, journal, equity)
|
|
185
|
+
}),
|
|
186
|
+
)
|
|
187
|
+
agentsEl.innerHTML = withDetail.join('')
|
|
188
|
+
agentsEl.querySelectorAll('.journal-toggle').forEach((btn) => {
|
|
189
|
+
btn.addEventListener('click', () => {
|
|
190
|
+
const id = btn.dataset.agent
|
|
191
|
+
if (openJournals.has(id)) openJournals.delete(id)
|
|
192
|
+
else openJournals.add(id)
|
|
193
|
+
refresh()
|
|
194
|
+
})
|
|
195
|
+
})
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
renderFleetTrades(trades)
|
|
199
|
+
} catch (err) {
|
|
200
|
+
document.getElementById('summary').innerHTML = `<div class="state-block" style="grid-column: 1 / -1">
|
|
201
|
+
<div class="state-icon">⚠</div>
|
|
202
|
+
<div class="state-title">Can't reach the fleet API</div>
|
|
203
|
+
<div class="state-detail">${escapeHtml(err.message)} — is the hood-traders process running?</div>
|
|
204
|
+
</div>`
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
document.getElementById('kill-btn').addEventListener('click', async () => {
|
|
209
|
+
if (!confirm('Trip the global kill switch? This halts all new orders across every agent immediately and cannot be undone for this process.')) return
|
|
210
|
+
await api('/api/kill', { method: 'POST' })
|
|
211
|
+
refresh()
|
|
212
|
+
})
|
|
213
|
+
|
|
214
|
+
refresh()
|
|
215
|
+
setInterval(refresh, POLL_MS)
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
+
<title>hood-traders — live fleet</title>
|
|
7
|
+
<meta name="description" content="Autonomous trading agents on Robinhood Chain — live P&L, decision journal, kill switch." />
|
|
8
|
+
<link rel="icon" href="data:image/svg+xml,%3Csvg%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27%20viewBox%3D%270%200%2032%2032%27%3E%3Cdefs%3E%3ClinearGradient%20id%3D%27g%27%20x1%3D%270%27%20y1%3D%270%27%20x2%3D%271%27%20y2%3D%271%27%3E%3Cstop%20offset%3D%270%27%20stop-color%3D%27%236d5ef8%27%2F%3E%3Cstop%20offset%3D%271%27%20stop-color%3D%27%232fd0e0%27%2F%3E%3C%2FlinearGradient%3E%3C%2Fdefs%3E%3Ccircle%20cx%3D%2716%27%20cy%3D%2716%27%20r%3D%2713%27%20fill%3D%27url(%23g)%27%2F%3E%3C%2Fsvg%3E" />
|
|
9
|
+
<link rel="stylesheet" href="/style.css" />
|
|
10
|
+
</head>
|
|
11
|
+
<body>
|
|
12
|
+
<div class="wrap">
|
|
13
|
+
<header class="topbar">
|
|
14
|
+
<div class="brand">
|
|
15
|
+
<span class="dot"></span>
|
|
16
|
+
hood-traders
|
|
17
|
+
<span id="mode-badge" class="badge">…</span>
|
|
18
|
+
<span id="killed-badge" class="badge killed" hidden>⛔ killed</span>
|
|
19
|
+
</div>
|
|
20
|
+
<div class="topbar-right">
|
|
21
|
+
<span id="network-label" class="badge">…</span>
|
|
22
|
+
<button id="kill-btn" class="kill-btn" title="Trip the global kill switch — halts all new orders immediately">
|
|
23
|
+
⏻ Kill switch
|
|
24
|
+
</button>
|
|
25
|
+
</div>
|
|
26
|
+
</header>
|
|
27
|
+
|
|
28
|
+
<section id="summary" class="summary-grid" aria-label="Fleet summary"></section>
|
|
29
|
+
|
|
30
|
+
<h2 class="section-title">Agents</h2>
|
|
31
|
+
<section id="agents" class="agents-grid" aria-label="Agent fleet"></section>
|
|
32
|
+
|
|
33
|
+
<h2 class="section-title">Recent fleet trades</h2>
|
|
34
|
+
<section id="fleet-trades"></section>
|
|
35
|
+
|
|
36
|
+
<footer class="footer">
|
|
37
|
+
<span>hood-traders · Robinhood Chain (4663 / 46630) autonomous trading fleet</span>
|
|
38
|
+
<span>Built by <a href="https://x.com/nichxbt" target="_blank" rel="noopener">nirholas</a> · <a href="https://three.ws" target="_blank" rel="noopener">three.ws</a></span>
|
|
39
|
+
</footer>
|
|
40
|
+
</div>
|
|
41
|
+
|
|
42
|
+
<script src="/app.js" type="module"></script>
|
|
43
|
+
</body>
|
|
44
|
+
</html>
|