@backtest-kit/mongo 0.0.1
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/README.md +150 -0
- package/build/index.cjs +2255 -0
- package/build/index.mjs +2247 -0
- package/package.json +89 -0
- package/types.d.ts +114 -0
package/package.json
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@backtest-kit/mongo",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "MongoDB + Redis persistence adapter for backtest-kit. Replaces the default file-based storage with a production-grade backend — O(1) reads via Redis, atomic writes via Mongoose.",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Petr Tripolsky",
|
|
7
|
+
"email": "tripolskypetr@gmail.com",
|
|
8
|
+
"url": "https://github.com/tripolskypetr"
|
|
9
|
+
},
|
|
10
|
+
"funding": {
|
|
11
|
+
"type": "individual",
|
|
12
|
+
"url": "http://paypal.me/tripolskypetr"
|
|
13
|
+
},
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"homepage": "https://backtest-kit.github.io/documents/article_07_ai_news_trading_signals.html",
|
|
16
|
+
"keywords": [
|
|
17
|
+
"backtest",
|
|
18
|
+
"backtesting",
|
|
19
|
+
"trading",
|
|
20
|
+
"crypto",
|
|
21
|
+
"cryptocurrency",
|
|
22
|
+
"algorithmic-trading",
|
|
23
|
+
"trading-bot",
|
|
24
|
+
"mongodb",
|
|
25
|
+
"mongoose",
|
|
26
|
+
"redis",
|
|
27
|
+
"ioredis",
|
|
28
|
+
"persistence",
|
|
29
|
+
"storage"
|
|
30
|
+
],
|
|
31
|
+
"files": [
|
|
32
|
+
"build",
|
|
33
|
+
"types.d.ts",
|
|
34
|
+
"README.md"
|
|
35
|
+
],
|
|
36
|
+
"repository": {
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "https://github.com/tripolskypetr/backtest-kit",
|
|
39
|
+
"documentation": "https://github.com/tripolskypetr/backtest-kit/tree/master/docs"
|
|
40
|
+
},
|
|
41
|
+
"bugs": {
|
|
42
|
+
"url": "https://github.com/tripolskypetr/backtest-kit/issues"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "rollup -c"
|
|
46
|
+
},
|
|
47
|
+
"main": "build/index.cjs",
|
|
48
|
+
"module": "build/index.mjs",
|
|
49
|
+
"source": "src/index.ts",
|
|
50
|
+
"types": "./types.d.ts",
|
|
51
|
+
"exports": {
|
|
52
|
+
"require": "./build/index.cjs",
|
|
53
|
+
"types": "./types.d.ts",
|
|
54
|
+
"import": "./build/index.mjs",
|
|
55
|
+
"default": "./build/index.cjs"
|
|
56
|
+
},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"@rollup/plugin-typescript": "11.1.6",
|
|
59
|
+
"@types/node": "22.9.0",
|
|
60
|
+
"glob": "11.0.1",
|
|
61
|
+
"rimraf": "6.0.1",
|
|
62
|
+
"rollup": "3.29.5",
|
|
63
|
+
"rollup-plugin-dts": "6.1.1",
|
|
64
|
+
"rollup-plugin-peer-deps-external": "2.2.4",
|
|
65
|
+
"ts-morph": "27.0.2",
|
|
66
|
+
"tslib": "2.7.0",
|
|
67
|
+
"typedoc": "0.27.9",
|
|
68
|
+
"backtest-kit": "9.1.0",
|
|
69
|
+
"mongoose": "8.23.0",
|
|
70
|
+
"ioredis": "5.6.1",
|
|
71
|
+
"worker-testbed": "2.0.0"
|
|
72
|
+
},
|
|
73
|
+
"peerDependencies": {
|
|
74
|
+
"backtest-kit": "^9.1.0",
|
|
75
|
+
"mongoose": "^8.23.0",
|
|
76
|
+
"ioredis": "^5.6.1",
|
|
77
|
+
"typescript": "^5.0.0"
|
|
78
|
+
},
|
|
79
|
+
"dependencies": {
|
|
80
|
+
"di-kit": "^1.1.1",
|
|
81
|
+
"di-factory": "^1.0.9",
|
|
82
|
+
"di-scoped": "^1.0.21",
|
|
83
|
+
"functools-kit": "^2.3.0",
|
|
84
|
+
"get-moment-stamp": "^1.1.2"
|
|
85
|
+
},
|
|
86
|
+
"publishConfig": {
|
|
87
|
+
"access": "public"
|
|
88
|
+
}
|
|
89
|
+
}
|
package/types.d.ts
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import * as functools_kit from 'functools-kit';
|
|
2
|
+
import mongoose from 'mongoose';
|
|
3
|
+
import { Redis } from 'ioredis';
|
|
4
|
+
|
|
5
|
+
declare const GLOBAL_CONFIG: {
|
|
6
|
+
CC_REDIS_HOST: string;
|
|
7
|
+
CC_REDIS_PORT: number;
|
|
8
|
+
CC_REDIS_USER: string;
|
|
9
|
+
CC_REDIS_PASSWORD: string;
|
|
10
|
+
CC_MONGO_CONNECTION_STRING: string;
|
|
11
|
+
};
|
|
12
|
+
type Config = typeof GLOBAL_CONFIG;
|
|
13
|
+
declare const getConfig: () => {
|
|
14
|
+
CC_REDIS_HOST: string;
|
|
15
|
+
CC_REDIS_PORT: number;
|
|
16
|
+
CC_REDIS_USER: string;
|
|
17
|
+
CC_REDIS_PASSWORD: string;
|
|
18
|
+
CC_MONGO_CONNECTION_STRING: string;
|
|
19
|
+
};
|
|
20
|
+
declare const setConfig: (config: Partial<Config>) => void;
|
|
21
|
+
|
|
22
|
+
interface ILogger {
|
|
23
|
+
log(topic: string, ...args: any[]): void;
|
|
24
|
+
debug(topic: string, ...args: any[]): void;
|
|
25
|
+
info(topic: string, ...args: any[]): void;
|
|
26
|
+
warn(topic: string, ...args: any[]): void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Initializes the `@backtest-kit/mongo` package: applies user-provided configuration
|
|
31
|
+
* and registers all MongoDB/Redis persistence adapters into the global `backtest-kit` registries.
|
|
32
|
+
*
|
|
33
|
+
* Should be called **once** at application startup — before any trading data operations.
|
|
34
|
+
* Internally calls {@link setConfig} followed by {@link install}.
|
|
35
|
+
*
|
|
36
|
+
* @param config - Connection parameters. If omitted, {@link DEFAULT_CONFIG} is used,
|
|
37
|
+
* which reads values from environment variables:
|
|
38
|
+
* - `CC_MONGO_CONNECTION_STRING` — MongoDB connection string (default: `mongodb://localhost:27017/backtest-kit`)
|
|
39
|
+
* - `CC_REDIS_HOST` — Redis host (default: `127.0.0.1`)
|
|
40
|
+
* - `CC_REDIS_PORT` — Redis port (default: `6379`)
|
|
41
|
+
* - `CC_REDIS_USER` — Redis username (default: empty string)
|
|
42
|
+
* - `CC_REDIS_PASSWORD` — Redis password (default: empty string)
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* // Minimal — everything is read from env variables
|
|
46
|
+
* setup();
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* // Explicit configuration
|
|
50
|
+
* setup({
|
|
51
|
+
* CC_MONGO_CONNECTION_STRING: "mongodb://mongo:27017/mydb",
|
|
52
|
+
* CC_REDIS_HOST: "redis",
|
|
53
|
+
* CC_REDIS_PORT: 6379,
|
|
54
|
+
* CC_REDIS_USER: "",
|
|
55
|
+
* CC_REDIS_PASSWORD: "secret",
|
|
56
|
+
* });
|
|
57
|
+
*/
|
|
58
|
+
declare function setup(config?: Partial<Config>): void;
|
|
59
|
+
/**
|
|
60
|
+
* Registers MongoDB implementations of all `backtest-kit` persistence adapters
|
|
61
|
+
* without modifying the global connection configuration.
|
|
62
|
+
*
|
|
63
|
+
* Use directly when the configuration has already been applied via {@link setConfig}
|
|
64
|
+
* or is provided through environment variables and does not need to be overridden.
|
|
65
|
+
* In the typical scenario, calling {@link setup} is sufficient — it calls `install` internally.
|
|
66
|
+
*
|
|
67
|
+
* Registered adapters:
|
|
68
|
+
* - **Candle** — OHLCV candle data (`PersistCandleAdapter`)
|
|
69
|
+
* - **Signal** — strategy signals (`PersistSignalAdapter`)
|
|
70
|
+
* - **Risk** — risk manager positions (`PersistRiskAdapter`)
|
|
71
|
+
* - **Schedule** — deferred signals (`PersistScheduleAdapter`)
|
|
72
|
+
* - **Partial** — partial close data (`PersistPartialAdapter`)
|
|
73
|
+
* - **Breakeven** — breakeven data (`PersistBreakevenAdapter`)
|
|
74
|
+
* - **Storage** — general signal storage (`PersistStorageAdapter`)
|
|
75
|
+
* - **Notification** — notifications (`PersistNotificationAdapter`)
|
|
76
|
+
* - **Log** — log entries (`PersistLogAdapter`)
|
|
77
|
+
* - **Measure** — arbitrary metrics keyed by bucket/key (`PersistMeasureAdapter`)
|
|
78
|
+
* - **Interval** — interval task data (`PersistIntervalAdapter`)
|
|
79
|
+
* - **Memory** — long-term signal memory (`PersistMemoryAdapter`)
|
|
80
|
+
* - **Recent** — latest strategy frame result (`PersistRecentAdapter`)
|
|
81
|
+
* - **State** — signal state (`PersistStateAdapter`)
|
|
82
|
+
* - **Session** — strategy session data (`PersistSessionAdapter`)
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* // Configuration is provided via env variables, adapters are installed manually
|
|
86
|
+
* install();
|
|
87
|
+
*/
|
|
88
|
+
declare function install(): void;
|
|
89
|
+
/**
|
|
90
|
+
* Attaches a custom logger to the internal `LoggerService`.
|
|
91
|
+
*
|
|
92
|
+
* By default the package logs to `console`. Pass your own {@link ILogger} implementation
|
|
93
|
+
* to redirect output to an external logging system (Winston, Pino, Datadog, etc.).
|
|
94
|
+
*
|
|
95
|
+
* @param logger - Object with `log`, `debug`, `info`, and `warn` methods.
|
|
96
|
+
* Each method receives a string topic followed by arbitrary arguments.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* import winston from "winston";
|
|
100
|
+
*
|
|
101
|
+
* setLogger({
|
|
102
|
+
* log: (topic, ...args) => winston.verbose(topic, ...args),
|
|
103
|
+
* debug: (topic, ...args) => winston.debug(topic, ...args),
|
|
104
|
+
* info: (topic, ...args) => winston.info(topic, ...args),
|
|
105
|
+
* warn: (topic, ...args) => winston.warn(topic, ...args),
|
|
106
|
+
* });
|
|
107
|
+
*/
|
|
108
|
+
declare function setLogger(logger: ILogger): void;
|
|
109
|
+
|
|
110
|
+
declare const getMongo: (() => Promise<typeof mongoose>) & functools_kit.ISingleshotClearable<() => Promise<typeof mongoose>>;
|
|
111
|
+
|
|
112
|
+
declare const getRedis: (() => Redis) & functools_kit.ISingleshotClearable<() => Redis>;
|
|
113
|
+
|
|
114
|
+
export { getConfig, getMongo, getRedis, install, setConfig, setLogger, setup };
|