Skip to content

Commit b4c778f

Browse files
authored
Merge pull request #118 from Adamant-im/dev
Chore: Merge dev for v9.0.0 release
2 parents 15787b9 + 13382b4 commit b4c778f

40 files changed

Lines changed: 6490 additions & 134 deletions

.dockerignore

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
node_modules
2+
npm-debug.log
3+
.git
4+
.github
5+
.ai-tasks
6+
coverage
7+
logs
8+
config.jsonc
9+
config.*.jsonc
10+
!config.default.jsonc
11+
trade/settings/*
12+
!trade/settings/tradeParams_Default.js
13+
tests
14+
*.md
15+
!README.md
16+
.vscode
17+
.idea
18+
docker/config
19+
docker/trade-config
20+
docker/logs
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Publish Docker image
2+
3+
# Runs when a GitHub Release is published (not on every push).
4+
# The job is skipped unless the release tag points to a commit on master.
5+
on:
6+
release:
7+
types: [published]
8+
9+
permissions:
10+
contents: read
11+
packages: write
12+
13+
jobs:
14+
docker:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout release tag
18+
uses: actions/checkout@v4
19+
with:
20+
ref: ${{ github.event.release.tag_name }}
21+
fetch-depth: 0
22+
23+
- name: Verify release tag is on master
24+
run: |
25+
git fetch origin master
26+
git merge-base --is-ancestor HEAD origin/master
27+
28+
- name: Log in to GHCR
29+
uses: docker/login-action@v3
30+
with:
31+
registry: ghcr.io
32+
username: ${{ github.actor }}
33+
password: ${{ secrets.GITHUB_TOKEN }}
34+
35+
- name: Extract version tag
36+
id: meta
37+
run: |
38+
TAG="${GITHUB_REF_NAME#v}"
39+
echo "version=${TAG}" >> "$GITHUB_OUTPUT"
40+
41+
- name: Build and push
42+
uses: docker/build-push-action@v6
43+
with:
44+
context: .
45+
push: true
46+
tags: |
47+
ghcr.io/adamant-im/adamant-tradebot:latest
48+
ghcr.io/adamant-im/adamant-tradebot:${{ steps.meta.outputs.version }}

.github/workflows/publish-npm.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Publish npm package
2+
3+
# Runs when a GitHub Release is published (not on every push).
4+
# The job is skipped unless the release tag points to a commit on master.
5+
on:
6+
release:
7+
types: [published]
8+
9+
permissions:
10+
id-token: write
11+
contents: read
12+
13+
jobs:
14+
publish:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout release tag
18+
uses: actions/checkout@v4
19+
with:
20+
ref: ${{ github.event.release.tag_name }}
21+
fetch-depth: 0
22+
23+
- name: Verify release tag is on master
24+
run: |
25+
git fetch origin master
26+
git merge-base --is-ancestor HEAD origin/master
27+
28+
- name: Setup Node.js
29+
uses: actions/setup-node@v4
30+
with:
31+
node-version: 22
32+
registry-url: https://registry.npmjs.org
33+
34+
- name: Install dependencies
35+
run: npm ci
36+
37+
- name: Publish to npm with provenance
38+
run: npm publish --provenance --access public
39+
env:
40+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
node_modules/
22
logs/
3+
# Docker user data (./mm init)
4+
docker/config/
5+
docker/trade-config/
6+
docker/logs/
37
keys/
48
.vscode/*
59
!.vscode/settings.json
@@ -22,3 +26,4 @@ trade/settings/*
2226
!trade/settings/tradeParams_Default.js
2327
CLAUDE.md
2428
.ai-tasks/
29+
.ai-ignored/

Dockerfile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
FROM node:22-bookworm-slim
2+
3+
WORKDIR /app
4+
5+
RUN apt-get update \
6+
&& apt-get install -y --no-install-recommends ca-certificates \
7+
&& rm -rf /var/lib/apt/lists/*
8+
9+
COPY package.json package-lock.json .npmrc ./
10+
RUN npm ci --omit=dev
11+
12+
COPY . .
13+
14+
RUN chmod +x docker-entrypoint.sh mm bin/mm.js \
15+
&& ln -sf /app/bin/mm.js /usr/local/bin/mm
16+
17+
ENV NODE_ENV=production
18+
ENV MM_DOCKER=1
19+
20+
EXPOSE 3000
21+
22+
ENTRYPOINT ["./docker-entrypoint.sh"]
23+
CMD ["node", "app.js"]

README.md

Lines changed: 125 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,135 @@ The software is self-hosted. You keep control of the exchange account, API keys,
158158

159159
For additional management options, including Telegram, CLI, and WebUI access, request a manager.
160160

161-
### Documentation
161+
## Requirements
162+
163+
- Ubuntu 20+ or CentOS 8+ (other Linux distros may work but are not tested)
164+
- Node.js v22.2+
165+
- npm v9+
166+
- MongoDB ([installation instructions](https://www.mongodb.com/docs/manual/administration/install-community/)
167+
168+
## Setup
169+
170+
```bash
171+
su - adamant
172+
git clone https://github.com/Adamant-im/adamant-tradebot
173+
cd adamant-tradebot
174+
npm i
175+
```
176+
177+
## Pre-launch tuning
178+
179+
The bot uses `config.jsonc` if present, otherwise `config.default.jsonc`.
180+
For named configs, use `config.<name>.jsonc` and pass `<name>` as a launch argument.
181+
182+
```bash
183+
cp config.default.jsonc config.jsonc
184+
nano config.jsonc
185+
```
186+
187+
Parameter descriptions are in comments inside `config.jsonc`.
188+
189+
## Launching
190+
191+
You can start the bot with `node app.js`, but a process manager is recommended.
192+
193+
### NPM scripts
194+
195+
```bash
196+
npm start # config.default.jsonc or config.jsonc
197+
npm run start:config -- <name> # config.<name>.jsonc
198+
npm run start:dev # config.dev.jsonc
199+
npm run clear # clear DB for default config
200+
npm run clear:config -- <name> clear_db # clear DB for config.<name>.jsonc
201+
```
202+
203+
### PM2
204+
205+
```bash
206+
pm2 start app.js --name tradebot
207+
```
208+
209+
With a named config:
210+
211+
```bash
212+
pm2 start app.js --name tradebot-p2b -- p2b_mmtest
213+
```
214+
215+
Add the process to `pm2 startup` or cron so it restarts on reboot.
216+
217+
## Updating
218+
219+
```bash
220+
su - adamant
221+
cd adamant-tradebot
222+
pm2 stop tradebot
223+
git pull
224+
npm i
225+
```
226+
227+
If `config.default.jsonc` changed, merge new fields into your `config.jsonc`.
228+
229+
Then:
230+
231+
```bash
232+
pm2 restart tradebot
233+
```
234+
235+
## Quick start with `mm` CLI
236+
237+
The `mm` command simplifies install, configuration, and day-to-day operation. It works in **npm/local** mode and **Docker Compose** mode.
238+
239+
### Install via npm
240+
241+
```bash
242+
npm install -g adamant-tradebot
243+
mkdir my-bot && cd my-bot
244+
mm init
245+
mm doctor
246+
mm on
247+
mm status
248+
```
249+
250+
Both `mm` and `adamant-tradebot` are available as CLI aliases.
251+
252+
### Install via Docker Compose
253+
254+
```bash
255+
git clone https://github.com/Adamant-im/adamant-tradebot
256+
cd adamant-tradebot
257+
./mm init
258+
./mm doctor
259+
./mm on
260+
./mm status
261+
```
262+
263+
The stack runs `mm-app` and MongoDB (`mongo:8`). User data is stored in `./docker/config`, `./docker/trade-config`, and `./docker/logs` (gitignored).
264+
265+
### Command reference
266+
267+
| Command | Description |
268+
| --- | --- |
269+
| `mm init` | Interactive first-time setup wizard |
270+
| `mm on` | Start the bot (preflight `doctor`, no duplicate instance) |
271+
| `mm off` | Stop the bot (`--all` also stops MongoDB in Docker) |
272+
| `mm restart` | Restart the bot |
273+
| `mm status` | Installation, process, and health summary (`--json`, `--short`) |
274+
| `mm config` | View or change config parameters (`--edit`, `--restart`) |
275+
| `mm doctor` | Diagnose config, MongoDB, exchange API, and runtime |
276+
| `mm logs` | Show logs (`-f`, `--tail`, `--since`, `--level`, `--grep`) |
277+
| `mm update` | Update the app without touching user config (`--check`) |
278+
279+
Use `--mode npm` or `--mode docker` when auto-detection is ambiguous.
280+
281+
## Documentation
162282

163283
- [Installation and usage guide](https://marketmaking.app/cex-mm/installation/)
164284
- [Command reference](https://marketmaking.app/cex-mm/command-reference/)
165285

286+
## Tests & Developer tools
287+
288+
See [CONTRIBUTING.md — Tests](CONTRIBUTING.md#tests) for Jest suites, interactive simulators, and live exchange scripts.
289+
166290
## Contact
167291

168292
Want to try it for your token project or request exchange support?

bin/mm.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env node
2+
'use strict';
3+
4+
/**
5+
* ADAMANT Market-Making Software installer and maintenance CLI entrypoint.
6+
*
7+
* Exposed on PATH as `mm` and `adamant-tradebot` via package.json bin map.
8+
* This is intentionally separate from `bin/cli.js`, which sends trading commands
9+
* to an already running bot instance (`/balances`, `/start`, …).
10+
*
11+
* Unhandled promise rejections exit with code 3 (CLI/internal error).
12+
*
13+
* @module bin/mm
14+
* @typedef {import('types/bot/mm').MmCliModule} MmCliModule
15+
*/
16+
17+
process.env.MM_CLI = '1';
18+
19+
require('../modules/mm/silence-diagnostics').installDiagnosticSilence();
20+
21+
/** @type {MmCliModule} */
22+
const mmCli = require('../modules/mm/cli.js');
23+
24+
mmCli.main(process.argv.slice(2)).then((code) => {
25+
process.exit(typeof code === 'number' ? code : 0);
26+
}).catch((error) => {
27+
console.error(error instanceof Error ? error.message : String(error));
28+
process.exit(3);
29+
});

docker-compose.yaml

Lines changed: 0 additions & 12 deletions
This file was deleted.

docker-entrypoint.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/sh
2+
set -e
3+
4+
# Docker volumes use ./config/config.jsonc — link to the path configReader expects.
5+
if [ -f /app/config/config.jsonc ]; then
6+
ln -sfn /app/config/config.jsonc /app/config.jsonc
7+
fi
8+
9+
# Link trade-config files into trade/settings so runtime saves (WebUI, commands) persist
10+
# on the mounted volume and fs.watch sees the same path the bot reads/writes.
11+
if [ -d /app/trade-config ]; then
12+
for file in /app/trade-config/tradeParams_*.js; do
13+
[ -e "$file" ] || continue
14+
ln -sfn "$file" "/app/trade/settings/$(basename "$file")"
15+
done
16+
fi
17+
18+
if [ "$1" = "mm" ]; then
19+
shift
20+
set -- node /app/bin/mm.js "$@"
21+
fi
22+
23+
exec "$@"

docker/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# User data created by `./mm init` — never commit
2+
config/
3+
trade-config/
4+
logs/

0 commit comments

Comments
 (0)