brk-client 0.1.4 → 0.1.6

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.
Files changed (2) hide show
  1. package/index.js +91 -1
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -191,6 +191,44 @@
191
191
  *
192
192
  * @typedef {CentsUnsigned} Close
193
193
  */
194
+ /**
195
+ * Cohort identifier for cost basis distribution.
196
+ *
197
+ * @typedef {string} Cohort
198
+ */
199
+ /**
200
+ * Bucket type for cost basis aggregation.
201
+ * Options: raw (no aggregation), lin200/lin500/lin1000 (linear $200/$500/$1000),
202
+ * log10/log50/log100 (logarithmic with 10/50/100 buckets per decade).
203
+ *
204
+ * @typedef {("raw"|"lin200"|"lin500"|"lin1000"|"log10"|"log50"|"log100")} CostBasisBucket
205
+ */
206
+ /**
207
+ * Path parameters for cost basis dates endpoint.
208
+ *
209
+ * @typedef {Object} CostBasisCohortParam
210
+ * @property {Cohort} cohort
211
+ */
212
+ /**
213
+ * Path parameters for cost basis distribution endpoint.
214
+ *
215
+ * @typedef {Object} CostBasisParams
216
+ * @property {Cohort} cohort
217
+ * @property {string} date
218
+ */
219
+ /**
220
+ * Query parameters for cost basis distribution endpoint.
221
+ *
222
+ * @typedef {Object} CostBasisQuery
223
+ * @property {CostBasisBucket=} bucket - Bucket type for aggregation. Default: raw (no aggregation).
224
+ * @property {CostBasisValue=} value - Value type to return. Default: supply.
225
+ */
226
+ /**
227
+ * Value type for cost basis distribution.
228
+ * Options: supply (BTC), realized (USD, price × supply), unrealized (USD, spot × supply).
229
+ *
230
+ * @typedef {("supply"|"realized"|"unrealized")} CostBasisValue
231
+ */
194
232
  /**
195
233
  * Data range with output format for API query parameters
196
234
  *
@@ -4938,7 +4976,7 @@ function createRatioPattern2(client, acc) {
4938
4976
  * @extends BrkClientBase
4939
4977
  */
4940
4978
  class BrkClient extends BrkClientBase {
4941
- VERSION = "v0.1.4";
4979
+ VERSION = "v0.1.6";
4942
4980
 
4943
4981
  INDEXES = /** @type {const} */ ([
4944
4982
  "dateindex",
@@ -7385,6 +7423,58 @@ class BrkClient extends BrkClientBase {
7385
7423
  return this.getJson(path);
7386
7424
  }
7387
7425
 
7426
+ /**
7427
+ * Available cost basis cohorts
7428
+ *
7429
+ * List available cohorts for cost basis distribution.
7430
+ *
7431
+ * Endpoint: `GET /api/metrics/cost-basis`
7432
+ * @returns {Promise<string[]>}
7433
+ */
7434
+ async getCostBasisCohorts() {
7435
+ return this.getJson(`/api/metrics/cost-basis`);
7436
+ }
7437
+
7438
+ /**
7439
+ * Available cost basis dates
7440
+ *
7441
+ * List available dates for a cohort's cost basis distribution.
7442
+ *
7443
+ * Endpoint: `GET /api/metrics/cost-basis/{cohort}/dates`
7444
+ *
7445
+ * @param {Cohort} cohort
7446
+ * @returns {Promise<Date[]>}
7447
+ */
7448
+ async getCostBasisDates(cohort) {
7449
+ return this.getJson(`/api/metrics/cost-basis/${cohort}/dates`);
7450
+ }
7451
+
7452
+ /**
7453
+ * Cost basis distribution
7454
+ *
7455
+ * Get the cost basis distribution for a cohort on a specific date.
7456
+ *
7457
+ * Query params:
7458
+ * - `bucket`: raw (default), lin200, lin500, lin1000, log10, log50, log100
7459
+ * - `value`: supply (default, in BTC), realized (USD), unrealized (USD)
7460
+ *
7461
+ * Endpoint: `GET /api/metrics/cost-basis/{cohort}/{date}`
7462
+ *
7463
+ * @param {Cohort} cohort
7464
+ * @param {string} date
7465
+ * @param {CostBasisBucket=} [bucket] - Bucket type for aggregation. Default: raw (no aggregation).
7466
+ * @param {CostBasisValue=} [value] - Value type to return. Default: supply.
7467
+ * @returns {Promise<Object>}
7468
+ */
7469
+ async getCostBasis(cohort, date, bucket, value) {
7470
+ const params = new URLSearchParams();
7471
+ if (bucket !== undefined) params.set('bucket', String(bucket));
7472
+ if (value !== undefined) params.set('value', String(value));
7473
+ const query = params.toString();
7474
+ const path = `/api/metrics/cost-basis/${cohort}/${date}${query ? '?' + query : ''}`;
7475
+ return this.getJson(path);
7476
+ }
7477
+
7388
7478
  /**
7389
7479
  * Metric count
7390
7480
  *
package/package.json CHANGED
@@ -34,5 +34,5 @@
34
34
  "url": "git+https://github.com/bitcoinresearchkit/brk.git"
35
35
  },
36
36
  "type": "module",
37
- "version": "0.1.4"
37
+ "version": "0.1.6"
38
38
  }