@livefolio/sdk 0.2.7 → 0.2.9
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 +74 -1
- package/dist/market/client.d.ts.map +1 -1
- package/dist/market/client.js +21 -2
- package/dist/market/client.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @livefolio/sdk
|
|
2
2
|
|
|
3
|
-
TypeScript SDK for market data, strategy evaluation, and portfolio
|
|
3
|
+
Open-source TypeScript SDK for market data, deterministic strategy evaluation and backtesting, live signal streaming, and portfolio rebalance planning.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
@@ -51,9 +51,35 @@ import { createStrategy } from '@livefolio/sdk/strategy';
|
|
|
51
51
|
|
|
52
52
|
Full method reference, arguments, return types, and usage examples: **[docs/](./docs/)**
|
|
53
53
|
|
|
54
|
+
## What The SDK Supports Today
|
|
55
|
+
|
|
56
|
+
The current public surface is strongest in four areas:
|
|
57
|
+
|
|
58
|
+
- Market data: historical daily series, quotes, trading-day lookups, and tracked ticker helpers
|
|
59
|
+
- Strategy engine: strategy retrieval, deterministic evaluation, pure evaluation helpers, live streaming updates, and rules compilation
|
|
60
|
+
- Backtesting: DB-backed historical backtests plus performance metric helpers
|
|
61
|
+
- Portfolio tooling: drift calculations, rebalance planning, and ticker-to-tradable mapping
|
|
62
|
+
|
|
63
|
+
`livefolio.auth` is intentionally lightweight, and `livefolio.portfolio` is best described today as portfolio tooling rather than a full brokerage integration layer.
|
|
64
|
+
|
|
65
|
+
## Community Contribution Areas
|
|
66
|
+
|
|
67
|
+
Good areas for community contributions:
|
|
68
|
+
|
|
69
|
+
- New indicator types and strategy primitives
|
|
70
|
+
- Additional market data adapters and quote providers
|
|
71
|
+
- Backtest realism improvements such as fees, slippage, taxes, and execution assumptions
|
|
72
|
+
- Portfolio and rebalancing logic, including tradable mappings and execution planning
|
|
73
|
+
- Broker and custodian adapters
|
|
74
|
+
- Examples, docs, notebooks, and app integrations
|
|
75
|
+
- Performance, caching, and test coverage improvements
|
|
76
|
+
|
|
77
|
+
If you are evaluating where to contribute first, the highest-leverage work is usually in `market/`, `strategy/`, `portfolio/rebalance`, and the docs/examples around those modules.
|
|
78
|
+
|
|
54
79
|
## Development
|
|
55
80
|
|
|
56
81
|
```bash
|
|
82
|
+
npm install
|
|
57
83
|
npm run build # compile TypeScript → dist/
|
|
58
84
|
npm test # run tests
|
|
59
85
|
npm run ingest:init # backfill price_observations from Yahoo
|
|
@@ -61,6 +87,53 @@ npm run ingest:daily # refresh latest daily bars
|
|
|
61
87
|
npm run backtest:smoke -- --linkId <strategy-link-id>
|
|
62
88
|
```
|
|
63
89
|
|
|
90
|
+
## Contributing Locally
|
|
91
|
+
|
|
92
|
+
Most contributors only need the default local workflow:
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
git clone https://github.com/livefolio/sdk.git
|
|
96
|
+
cd sdk
|
|
97
|
+
npm install
|
|
98
|
+
npm run build
|
|
99
|
+
npm test
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
The test suite mocks Supabase at the boundary, so most SDK work does not require a running backend.
|
|
103
|
+
|
|
104
|
+
If you are working on market ingestion, DB-backed backtests, or cache-through evaluation flows, set local Supabase credentials first:
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
export SUPABASE_URL=http://127.0.0.1:54321
|
|
108
|
+
export SUPABASE_ANON_KEY=<local-anon-key>
|
|
109
|
+
export SUPABASE_SERVICE_ROLE_KEY=<local-service-role-key>
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Then you can run the data-backed workflows:
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
npm run ingest:init
|
|
116
|
+
npm run ingest:daily
|
|
117
|
+
npm run backtest:smoke -- --linkId <strategy-link-id>
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Contributor expectations:
|
|
121
|
+
|
|
122
|
+
- Run `npm run build` and `npm test` before opening a PR
|
|
123
|
+
- Add unit tests for new exported behavior
|
|
124
|
+
- Update `docs/` when adding or changing public module methods
|
|
125
|
+
- Prefer narrow deterministic tests over large integration-only coverage
|
|
126
|
+
|
|
127
|
+
## Open Source Scope
|
|
128
|
+
|
|
129
|
+
The SDK is intended for developers building transparent, rules-based investing software. Community maintainers can use it to:
|
|
130
|
+
|
|
131
|
+
- Fetch market data and trading calendars
|
|
132
|
+
- Define, compile, evaluate, and stream rule-based strategies
|
|
133
|
+
- Run deterministic backtests over historical data
|
|
134
|
+
- Compute portfolio drift and generate rebalance plans
|
|
135
|
+
- Integrate Livefolio-compatible strategy definitions into custom apps and research workflows
|
|
136
|
+
|
|
64
137
|
PRs to `main` run build + tests and enforce a version bump. Merges auto-publish to npm.
|
|
65
138
|
|
|
66
139
|
## License
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/market/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AACpD,OAAO,KAAK,EAA2B,YAAY,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/market/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AACpD,OAAO,KAAK,EAA2B,YAAY,EAAE,MAAM,SAAS,CAAC;AAqBrE,wBAAgB,YAAY,CAAC,MAAM,EAAE,mBAAmB,GAAG,YAAY,CA0GtE"}
|
package/dist/market/client.js
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createMarket = createMarket;
|
|
4
|
+
function requireTradingDayClose(tradingDayByDate, row) {
|
|
5
|
+
const close = tradingDayByDate.get(row.date);
|
|
6
|
+
if (typeof close !== 'string' || close.length === 0) {
|
|
7
|
+
throw new Error(`Missing trading_days.post for ${row.symbol} on ${row.date}.`);
|
|
8
|
+
}
|
|
9
|
+
if (!Number.isFinite(new Date(close).getTime())) {
|
|
10
|
+
throw new Error(`Invalid trading_days.post for ${row.symbol} on ${row.date}: ${close}`);
|
|
11
|
+
}
|
|
12
|
+
return close;
|
|
13
|
+
}
|
|
4
14
|
function createMarket(client) {
|
|
5
15
|
return {
|
|
6
16
|
async getBatchSeries(symbols) {
|
|
@@ -19,19 +29,28 @@ function createMarket(client) {
|
|
|
19
29
|
return out;
|
|
20
30
|
const { data, error } = await client
|
|
21
31
|
.from('price_observations')
|
|
22
|
-
.select('symbol, date, price_400pm_et
|
|
32
|
+
.select('symbol, date, price_400pm_et')
|
|
23
33
|
.in('symbol', symbols)
|
|
24
34
|
.gte('date', startDate)
|
|
25
35
|
.lte('date', endDate)
|
|
26
36
|
.order('date', { ascending: true });
|
|
27
37
|
if (error)
|
|
28
38
|
throw new Error(`Failed to fetch price observations: ${error.message}`);
|
|
39
|
+
const { data: tradingDays, error: tradingDaysError } = await client
|
|
40
|
+
.from('trading_days')
|
|
41
|
+
.select('date, post')
|
|
42
|
+
.gte('date', startDate)
|
|
43
|
+
.lte('date', endDate)
|
|
44
|
+
.order('date', { ascending: true });
|
|
45
|
+
if (tradingDaysError)
|
|
46
|
+
throw new Error(`Failed to fetch trading days: ${tradingDaysError.message}`);
|
|
47
|
+
const tradingDayByDate = new Map((tradingDays ?? []).map((row) => [row.date, row.post]));
|
|
29
48
|
for (const row of data ?? []) {
|
|
30
49
|
const symbol = row.symbol;
|
|
31
50
|
if (!out[symbol])
|
|
32
51
|
out[symbol] = [];
|
|
33
52
|
out[symbol].push({
|
|
34
|
-
timestamp:
|
|
53
|
+
timestamp: requireTradingDayClose(tradingDayByDate, row),
|
|
35
54
|
value: row.price_400pm_et,
|
|
36
55
|
});
|
|
37
56
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/market/client.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/market/client.ts"],"names":[],"mappings":";;AAsBA,oCA0GC;AA7HD,SAAS,sBAAsB,CAC7B,gBAAqC,EACrC,GAGC;IAED,MAAM,KAAK,GAAG,gBAAgB,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC7C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACpD,MAAM,IAAI,KAAK,CAAC,iCAAiC,GAAG,CAAC,MAAM,OAAO,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC;IACjF,CAAC;IAED,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC;QAChD,MAAM,IAAI,KAAK,CAAC,iCAAiC,GAAG,CAAC,MAAM,OAAO,GAAG,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC,CAAC;IAC1F,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAgB,YAAY,CAAC,MAA2B;IACtD,OAAO;QACL,KAAK,CAAC,cAAc,CAAC,OAAiB;YACpC,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC;YACvF,IAAI,KAAK;gBAAE,MAAM,KAAK,CAAC;YACvB,OAAO,IAAqC,CAAC;QAC/C,CAAC;QAED,KAAK,CAAC,SAAS,CAAC,MAAc;YAC5B,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;YACnD,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC;QACxB,CAAC;QAED,KAAK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