@dshtrading/watchlist 0.1.0 → 0.1.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/lib/file-store.js +30 -22
- package/package.json +2 -2
package/lib/file-store.js
CHANGED
|
@@ -52,9 +52,13 @@ function createFileWatchlistStore(filePath) {
|
|
|
52
52
|
}
|
|
53
53
|
return cache;
|
|
54
54
|
}
|
|
55
|
+
/** 仅在 enqueue 队列内调用:写盘不能二次入队(外层已持队,内层 enqueue 会自等死锁)。 */
|
|
56
|
+
function writeNow(map) {
|
|
57
|
+
return safeAtomicWrite(filePath, JSON.stringify(map, null, 2));
|
|
58
|
+
}
|
|
55
59
|
async function flush(map) {
|
|
56
60
|
return enqueue(async () => {
|
|
57
|
-
await
|
|
61
|
+
await writeNow(map);
|
|
58
62
|
});
|
|
59
63
|
}
|
|
60
64
|
return {
|
|
@@ -66,29 +70,33 @@ function createFileWatchlistStore(filePath) {
|
|
|
66
70
|
await flush(cache);
|
|
67
71
|
},
|
|
68
72
|
async add(market, instrument) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
73
|
+
return enqueue(async () => {
|
|
74
|
+
const map = await load();
|
|
75
|
+
const rows = map[market] ?? [];
|
|
76
|
+
if (rows.some((row) => row.symbol === instrument.symbol)) return false;
|
|
77
|
+
const next = {
|
|
78
|
+
...map,
|
|
79
|
+
[market]: [...rows, { ...instrument }]
|
|
80
|
+
};
|
|
81
|
+
cache = next;
|
|
82
|
+
await writeNow(next);
|
|
83
|
+
return true;
|
|
84
|
+
});
|
|
79
85
|
},
|
|
80
86
|
async remove(market, symbol) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
87
|
+
return enqueue(async () => {
|
|
88
|
+
const map = await load();
|
|
89
|
+
const rows = map[market] ?? [];
|
|
90
|
+
const nextRows = rows.filter((row) => row.symbol !== symbol);
|
|
91
|
+
if (nextRows.length === rows.length) return false;
|
|
92
|
+
const next = {
|
|
93
|
+
...map,
|
|
94
|
+
[market]: nextRows
|
|
95
|
+
};
|
|
96
|
+
cache = next;
|
|
97
|
+
await writeNow(next);
|
|
98
|
+
return true;
|
|
99
|
+
});
|
|
92
100
|
}
|
|
93
101
|
};
|
|
94
102
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dshtrading/watchlist",
|
|
3
3
|
"description": "Host-side watchlist + selection stores for dsh-trading: multi-list file store (~/.dsh/watchlists.json), selection store (~/.dsh/selection.json), and cross-market watchlist_* tools (watchlist_list/add/remove/select) on the host plane",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"types": "./lib/index.d.ts",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"dependencies": {},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"@deepseek-ai/cordis": ">=4.0.0",
|
|
26
|
-
"@deepseek-ai/dsh-tools": ">=0.1.2-
|
|
26
|
+
"@deepseek-ai/dsh-tools": ">=0.1.2-rc.1"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"tsdown": "^0.22.0",
|