@kkkermit/trading212.js 0.1.0 → 0.1.2
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/CHANGELOG.md +12 -0
- package/README.md +5 -0
- package/dist/chunk-AVOYEH6N.js +2661 -0
- package/dist/chunk-K766TWIM.cjs +2700 -0
- package/dist/cli.js +2804 -0
- package/dist/client-BSQXqdxj.d.cts +1684 -0
- package/dist/client-BSQXqdxj.d.ts +1684 -0
- package/dist/csv.cjs +54 -0
- package/dist/csv.d.cts +21 -0
- package/dist/csv.d.ts +21 -0
- package/dist/csv.js +50 -0
- package/dist/index.cjs +154 -0
- package/dist/index.d.cts +35 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.js +1 -0
- package/dist/testing.cjs +651 -0
- package/dist/testing.d.cts +159 -0
- package/dist/testing.d.ts +159 -0
- package/dist/testing.js +642 -0
- package/package.json +4 -4
package/dist/csv.cjs
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/csv/index.ts
|
|
4
|
+
function parseCsvRows(text) {
|
|
5
|
+
const rows = [];
|
|
6
|
+
let row = [];
|
|
7
|
+
let field = "";
|
|
8
|
+
let quoted = false;
|
|
9
|
+
let index = text.charCodeAt(0) === 65279 ? 1 : 0;
|
|
10
|
+
for (; index < text.length; index++) {
|
|
11
|
+
const char = text.charAt(index);
|
|
12
|
+
if (quoted) {
|
|
13
|
+
if (char === '"') {
|
|
14
|
+
if (text[index + 1] === '"') {
|
|
15
|
+
field += '"';
|
|
16
|
+
index++;
|
|
17
|
+
} else quoted = false;
|
|
18
|
+
} else field += char;
|
|
19
|
+
} else if (char === '"' && field === "") quoted = true;
|
|
20
|
+
else if (char === ",") {
|
|
21
|
+
row.push(field);
|
|
22
|
+
field = "";
|
|
23
|
+
} else if (char === "\n" || char === "\r") {
|
|
24
|
+
if (char === "\r" && text[index + 1] === "\n") index++;
|
|
25
|
+
row.push(field);
|
|
26
|
+
rows.push(row);
|
|
27
|
+
row = [];
|
|
28
|
+
field = "";
|
|
29
|
+
} else field += char;
|
|
30
|
+
}
|
|
31
|
+
if (field !== "" || row.length > 0) {
|
|
32
|
+
row.push(field);
|
|
33
|
+
rows.push(row);
|
|
34
|
+
}
|
|
35
|
+
return rows;
|
|
36
|
+
}
|
|
37
|
+
function parseCsv(text) {
|
|
38
|
+
const [header, ...rows] = parseCsvRows(text);
|
|
39
|
+
if (!header) return [];
|
|
40
|
+
return rows.filter((row) => !(row.length === 1 && row[0] === "")).map((row) => Object.fromEntries(header.map((name, column) => [name, row[column] ?? ""])));
|
|
41
|
+
}
|
|
42
|
+
var DECIMAL = /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i;
|
|
43
|
+
var GROUPED = /^[+-]?[1-9]\d{0,2}(?:,\d{3})+(?:\.\d+)?$/;
|
|
44
|
+
function csvNumber(value) {
|
|
45
|
+
const trimmed = value?.trim() ?? "";
|
|
46
|
+
const plain = GROUPED.test(trimmed) ? trimmed.replaceAll(",", "") : trimmed;
|
|
47
|
+
if (!DECIMAL.test(plain)) return void 0;
|
|
48
|
+
const number = Number(plain);
|
|
49
|
+
return Number.isFinite(number) ? number : void 0;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
exports.csvNumber = csvNumber;
|
|
53
|
+
exports.parseCsv = parseCsv;
|
|
54
|
+
exports.parseCsvRows = parseCsvRows;
|
package/dist/csv.d.cts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A small RFC 4180 CSV parser for Trading 212's report exports: quoted fields, doubled quotes, commas and newlines
|
|
3
|
+
* inside quotes, CRLF or LF line ends, and a leading byte-order mark. Values stay strings.
|
|
4
|
+
*/
|
|
5
|
+
declare function parseCsvRows(text: string): string[][];
|
|
6
|
+
/**
|
|
7
|
+
* Parses CSV with a header row into one object per line, keyed by column name.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* import { parseCsv } from "@kkkermit/trading212.js/csv";
|
|
11
|
+
* const { csv } = await t212.reports.export({ from: "2026-01-01", to: "2026-06-30" });
|
|
12
|
+
* for (const row of parseCsv(csv)) console.log(row.Action, row.Ticker, row["Total"]);
|
|
13
|
+
*/
|
|
14
|
+
declare function parseCsv(text: string): Record<string, string>[];
|
|
15
|
+
/**
|
|
16
|
+
* Reads a number from a CSV cell, such as `1234.56`, `1,234.56` or `-0.5`, or returns `undefined` for anything else.
|
|
17
|
+
* Trading 212 writes decimals with a full stop, so a comma is accepted only between groups of three digits.
|
|
18
|
+
*/
|
|
19
|
+
declare function csvNumber(value: string | undefined): number | undefined;
|
|
20
|
+
|
|
21
|
+
export { csvNumber, parseCsv, parseCsvRows };
|
package/dist/csv.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A small RFC 4180 CSV parser for Trading 212's report exports: quoted fields, doubled quotes, commas and newlines
|
|
3
|
+
* inside quotes, CRLF or LF line ends, and a leading byte-order mark. Values stay strings.
|
|
4
|
+
*/
|
|
5
|
+
declare function parseCsvRows(text: string): string[][];
|
|
6
|
+
/**
|
|
7
|
+
* Parses CSV with a header row into one object per line, keyed by column name.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* import { parseCsv } from "@kkkermit/trading212.js/csv";
|
|
11
|
+
* const { csv } = await t212.reports.export({ from: "2026-01-01", to: "2026-06-30" });
|
|
12
|
+
* for (const row of parseCsv(csv)) console.log(row.Action, row.Ticker, row["Total"]);
|
|
13
|
+
*/
|
|
14
|
+
declare function parseCsv(text: string): Record<string, string>[];
|
|
15
|
+
/**
|
|
16
|
+
* Reads a number from a CSV cell, such as `1234.56`, `1,234.56` or `-0.5`, or returns `undefined` for anything else.
|
|
17
|
+
* Trading 212 writes decimals with a full stop, so a comma is accepted only between groups of three digits.
|
|
18
|
+
*/
|
|
19
|
+
declare function csvNumber(value: string | undefined): number | undefined;
|
|
20
|
+
|
|
21
|
+
export { csvNumber, parseCsv, parseCsvRows };
|
package/dist/csv.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// src/csv/index.ts
|
|
2
|
+
function parseCsvRows(text) {
|
|
3
|
+
const rows = [];
|
|
4
|
+
let row = [];
|
|
5
|
+
let field = "";
|
|
6
|
+
let quoted = false;
|
|
7
|
+
let index = text.charCodeAt(0) === 65279 ? 1 : 0;
|
|
8
|
+
for (; index < text.length; index++) {
|
|
9
|
+
const char = text.charAt(index);
|
|
10
|
+
if (quoted) {
|
|
11
|
+
if (char === '"') {
|
|
12
|
+
if (text[index + 1] === '"') {
|
|
13
|
+
field += '"';
|
|
14
|
+
index++;
|
|
15
|
+
} else quoted = false;
|
|
16
|
+
} else field += char;
|
|
17
|
+
} else if (char === '"' && field === "") quoted = true;
|
|
18
|
+
else if (char === ",") {
|
|
19
|
+
row.push(field);
|
|
20
|
+
field = "";
|
|
21
|
+
} else if (char === "\n" || char === "\r") {
|
|
22
|
+
if (char === "\r" && text[index + 1] === "\n") index++;
|
|
23
|
+
row.push(field);
|
|
24
|
+
rows.push(row);
|
|
25
|
+
row = [];
|
|
26
|
+
field = "";
|
|
27
|
+
} else field += char;
|
|
28
|
+
}
|
|
29
|
+
if (field !== "" || row.length > 0) {
|
|
30
|
+
row.push(field);
|
|
31
|
+
rows.push(row);
|
|
32
|
+
}
|
|
33
|
+
return rows;
|
|
34
|
+
}
|
|
35
|
+
function parseCsv(text) {
|
|
36
|
+
const [header, ...rows] = parseCsvRows(text);
|
|
37
|
+
if (!header) return [];
|
|
38
|
+
return rows.filter((row) => !(row.length === 1 && row[0] === "")).map((row) => Object.fromEntries(header.map((name, column) => [name, row[column] ?? ""])));
|
|
39
|
+
}
|
|
40
|
+
var DECIMAL = /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i;
|
|
41
|
+
var GROUPED = /^[+-]?[1-9]\d{0,2}(?:,\d{3})+(?:\.\d+)?$/;
|
|
42
|
+
function csvNumber(value) {
|
|
43
|
+
const trimmed = value?.trim() ?? "";
|
|
44
|
+
const plain = GROUPED.test(trimmed) ? trimmed.replaceAll(",", "") : trimmed;
|
|
45
|
+
if (!DECIMAL.test(plain)) return void 0;
|
|
46
|
+
const number = Number(plain);
|
|
47
|
+
return Number.isFinite(number) ? number : void 0;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export { csvNumber, parseCsv, parseCsvRows };
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkK766TWIM_cjs = require('./chunk-K766TWIM.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
Object.defineProperty(exports, "AuthenticationError", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () { return chunkK766TWIM_cjs.AuthenticationError; }
|
|
10
|
+
});
|
|
11
|
+
Object.defineProperty(exports, "BASE_URLS", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function () { return chunkK766TWIM_cjs.BASE_URLS; }
|
|
14
|
+
});
|
|
15
|
+
Object.defineProperty(exports, "ConfigurationError", {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function () { return chunkK766TWIM_cjs.ConfigurationError; }
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports, "ENDPOINTS", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function () { return chunkK766TWIM_cjs.ENDPOINTS; }
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports, "FINAL_ORDER_STATUSES", {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
get: function () { return chunkK766TWIM_cjs.FINAL_ORDER_STATUSES; }
|
|
26
|
+
});
|
|
27
|
+
Object.defineProperty(exports, "HttpError", {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
get: function () { return chunkK766TWIM_cjs.HttpError; }
|
|
30
|
+
});
|
|
31
|
+
Object.defineProperty(exports, "InstrumentNotFoundError", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
get: function () { return chunkK766TWIM_cjs.InstrumentNotFoundError; }
|
|
34
|
+
});
|
|
35
|
+
Object.defineProperty(exports, "MemoryCache", {
|
|
36
|
+
enumerable: true,
|
|
37
|
+
get: function () { return chunkK766TWIM_cjs.MemoryCache; }
|
|
38
|
+
});
|
|
39
|
+
Object.defineProperty(exports, "MissingScopeError", {
|
|
40
|
+
enumerable: true,
|
|
41
|
+
get: function () { return chunkK766TWIM_cjs.MissingScopeError; }
|
|
42
|
+
});
|
|
43
|
+
Object.defineProperty(exports, "NetworkError", {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get: function () { return chunkK766TWIM_cjs.NetworkError; }
|
|
46
|
+
});
|
|
47
|
+
Object.defineProperty(exports, "NotAvailableInDemoError", {
|
|
48
|
+
enumerable: true,
|
|
49
|
+
get: function () { return chunkK766TWIM_cjs.NotAvailableInDemoError; }
|
|
50
|
+
});
|
|
51
|
+
Object.defineProperty(exports, "NotFoundError", {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
get: function () { return chunkK766TWIM_cjs.NotFoundError; }
|
|
54
|
+
});
|
|
55
|
+
Object.defineProperty(exports, "OrderOutcomeUnknownError", {
|
|
56
|
+
enumerable: true,
|
|
57
|
+
get: function () { return chunkK766TWIM_cjs.OrderOutcomeUnknownError; }
|
|
58
|
+
});
|
|
59
|
+
Object.defineProperty(exports, "OrderRejectedError", {
|
|
60
|
+
enumerable: true,
|
|
61
|
+
get: function () { return chunkK766TWIM_cjs.OrderRejectedError; }
|
|
62
|
+
});
|
|
63
|
+
Object.defineProperty(exports, "PermissionError", {
|
|
64
|
+
enumerable: true,
|
|
65
|
+
get: function () { return chunkK766TWIM_cjs.PermissionError; }
|
|
66
|
+
});
|
|
67
|
+
Object.defineProperty(exports, "QUANTITY_DECIMALS", {
|
|
68
|
+
enumerable: true,
|
|
69
|
+
get: function () { return chunkK766TWIM_cjs.QUANTITY_DECIMALS; }
|
|
70
|
+
});
|
|
71
|
+
Object.defineProperty(exports, "RateLimitError", {
|
|
72
|
+
enumerable: true,
|
|
73
|
+
get: function () { return chunkK766TWIM_cjs.RateLimitError; }
|
|
74
|
+
});
|
|
75
|
+
Object.defineProperty(exports, "SPEC_VERSION", {
|
|
76
|
+
enumerable: true,
|
|
77
|
+
get: function () { return chunkK766TWIM_cjs.SPEC_VERSION; }
|
|
78
|
+
});
|
|
79
|
+
Object.defineProperty(exports, "ServerError", {
|
|
80
|
+
enumerable: true,
|
|
81
|
+
get: function () { return chunkK766TWIM_cjs.ServerError; }
|
|
82
|
+
});
|
|
83
|
+
Object.defineProperty(exports, "TIME_VALIDITIES", {
|
|
84
|
+
enumerable: true,
|
|
85
|
+
get: function () { return chunkK766TWIM_cjs.TIME_VALIDITIES; }
|
|
86
|
+
});
|
|
87
|
+
Object.defineProperty(exports, "TimeoutError", {
|
|
88
|
+
enumerable: true,
|
|
89
|
+
get: function () { return chunkK766TWIM_cjs.TimeoutError; }
|
|
90
|
+
});
|
|
91
|
+
Object.defineProperty(exports, "Trading212", {
|
|
92
|
+
enumerable: true,
|
|
93
|
+
get: function () { return chunkK766TWIM_cjs.Trading212; }
|
|
94
|
+
});
|
|
95
|
+
Object.defineProperty(exports, "Trading212Error", {
|
|
96
|
+
enumerable: true,
|
|
97
|
+
get: function () { return chunkK766TWIM_cjs.Trading212Error; }
|
|
98
|
+
});
|
|
99
|
+
Object.defineProperty(exports, "TradingDisabledError", {
|
|
100
|
+
enumerable: true,
|
|
101
|
+
get: function () { return chunkK766TWIM_cjs.TradingDisabledError; }
|
|
102
|
+
});
|
|
103
|
+
Object.defineProperty(exports, "UnexpectedResponseError", {
|
|
104
|
+
enumerable: true,
|
|
105
|
+
get: function () { return chunkK766TWIM_cjs.UnexpectedResponseError; }
|
|
106
|
+
});
|
|
107
|
+
Object.defineProperty(exports, "VERSION", {
|
|
108
|
+
enumerable: true,
|
|
109
|
+
get: function () { return chunkK766TWIM_cjs.VERSION; }
|
|
110
|
+
});
|
|
111
|
+
Object.defineProperty(exports, "ValidationError", {
|
|
112
|
+
enumerable: true,
|
|
113
|
+
get: function () { return chunkK766TWIM_cjs.ValidationError; }
|
|
114
|
+
});
|
|
115
|
+
Object.defineProperty(exports, "buildPortfolioSnapshot", {
|
|
116
|
+
enumerable: true,
|
|
117
|
+
get: function () { return chunkK766TWIM_cjs.buildPortfolioSnapshot; }
|
|
118
|
+
});
|
|
119
|
+
Object.defineProperty(exports, "consoleLogger", {
|
|
120
|
+
enumerable: true,
|
|
121
|
+
get: function () { return chunkK766TWIM_cjs.consoleLogger; }
|
|
122
|
+
});
|
|
123
|
+
Object.defineProperty(exports, "decimalPlaces", {
|
|
124
|
+
enumerable: true,
|
|
125
|
+
get: function () { return chunkK766TWIM_cjs.decimalPlaces; }
|
|
126
|
+
});
|
|
127
|
+
Object.defineProperty(exports, "fieldsFirst", {
|
|
128
|
+
enumerable: true,
|
|
129
|
+
get: function () { return chunkK766TWIM_cjs.fieldsFirst; }
|
|
130
|
+
});
|
|
131
|
+
Object.defineProperty(exports, "isTrading212Error", {
|
|
132
|
+
enumerable: true,
|
|
133
|
+
get: function () { return chunkK766TWIM_cjs.isTrading212Error; }
|
|
134
|
+
});
|
|
135
|
+
Object.defineProperty(exports, "isValidQuantity", {
|
|
136
|
+
enumerable: true,
|
|
137
|
+
get: function () { return chunkK766TWIM_cjs.isValidQuantity; }
|
|
138
|
+
});
|
|
139
|
+
Object.defineProperty(exports, "parseErrorBody", {
|
|
140
|
+
enumerable: true,
|
|
141
|
+
get: function () { return chunkK766TWIM_cjs.parseErrorBody; }
|
|
142
|
+
});
|
|
143
|
+
Object.defineProperty(exports, "sessionAt", {
|
|
144
|
+
enumerable: true,
|
|
145
|
+
get: function () { return chunkK766TWIM_cjs.sessionAt; }
|
|
146
|
+
});
|
|
147
|
+
Object.defineProperty(exports, "silentLogger", {
|
|
148
|
+
enumerable: true,
|
|
149
|
+
get: function () { return chunkK766TWIM_cjs.silentLogger; }
|
|
150
|
+
});
|
|
151
|
+
Object.defineProperty(exports, "truncateQuantity", {
|
|
152
|
+
enumerable: true,
|
|
153
|
+
get: function () { return chunkK766TWIM_cjs.truncateQuantity; }
|
|
154
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export { A as AccountBucketDetailedResponse, a as AccountBucketInstrumentResult, b as AccountBucketInstrumentsDetailedResponse, c as AccountBucketResultResponse, d as AccountResource, e as AccountSummary, f as AuthenticationError, B as BASE_URLS, C as CacheStore, g as CallOptions, h as Cash, i as ConfigurationError, j as ConsoleLike, D as Dividend, k as DividendDetails, l as DryRunResult, m as DuplicateBucketRequest, E as ENDPOINTS, n as EndpointBudget, o as EndpointDefinition, p as EndpointId, q as EndpointKind, r as EndpointRateLimit, s as EnqueuedReportResponse, t as EnvSource, u as Environment, v as ErrorCode, w as ErrorDetails, x as Exchange, y as ExchangesResource, z as ExportResult, F as FINAL_ORDER_STATUSES, G as FetchLike, H as FieldsFirstMethod, I as Fill, J as FillWalletImpact, K as HistoricalOrder, L as HistoryDividendItem, M as HistoryResource, N as HistoryTransactionItem, O as HoldingSnapshot, P as Hooks, Q as HttpError, R as HttpMethod, S as Instrument, T as InstrumentIssue, U as InstrumentNotFoundError, V as InstrumentSuggestion, W as InstrumentsResource, X as InvestmentResult, Y as Investments, Z as IterateOptions, _ as LimitOrderRequest, $ as LimitRequest, a0 as ListOptions, a1 as LogFields, a2 as LogLevel, a3 as Logger, a4 as MarketOrderRequest, a5 as MarketRequest, a6 as MarketSession, a7 as MarketStatus, a8 as MemoryCache, a9 as MissingScopeError, aa as NetworkError, ab as NotAvailableInDemoError, ac as NotFoundError, ad as Order, ae as OrderInput, af as OrderOutcomeUnknownError, ag as OrderRejectedError, ah as OrderRejectionReason, ai as OrderTimeValidity, aj as OrderType, ak as OrdersResource, al as Page, am as PageOptions, an as PagedList, ao as PaginatedResponseHistoricalOrder, ap as PaginatedResponseHistoryDividendItem, aq as PaginatedResponseHistoryTransactionItem, ar as PermissionError, as as Pie, at as PieDetails, au as PieInput, av as PieRequest, aw as PiesResource, ax as PlaceOptions, ay as Placed, az as PortfolioResource, aA as PortfolioSnapshot, aB as Position, aC as PositionWalletImpact, aD as PositionsResource, aE as PublicReportRequest, aF as RateLimitError, aG as RateLimitInfo, aH as RateLimitMode, aI as RateLimitWaitEvent, aJ as Report, aK as ReportDataIncluded, aL as ReportRequest, aM as ReportResponse, aN as ReportWaitOptions, aO as ReportsResource, aP as RequestDescription, aQ as RequestEvent, aR as ResolveOptions, aS as ResponseEvent, aT as RetryEvent, aU as RetryOptions, aV as SPEC_VERSION, aW as SearchOptions, aX as SellAllOptions, aY as ServerError, aZ as StopLimitOrderRequest, a_ as StopLimitRequest, a$ as StopOrderRequest, b0 as StopRequest, b1 as TIME_VALIDITIES, b2 as Tax, b3 as TimeEvent, b4 as TimeValidity, b5 as TimeoutError, b6 as TradableInstrument, b7 as Trading212, b8 as Trading212Error, b9 as Trading212Options, ba as TradingDisabledError, bb as Transaction, bc as UnexpectedResponseError, bd as ValidationError, be as ValidationIssue, bf as VerifyResult, bg as WaitOptions, bh as WorkingSchedule, bi as buildPortfolioSnapshot, bj as consoleLogger, bk as fieldsFirst, bl as isTrading212Error, bm as sessionAt, bn as silentLogger } from './client-BSQXqdxj.cjs';
|
|
2
|
+
|
|
3
|
+
interface ParsedErrorBody {
|
|
4
|
+
/** Trading 212's own code, from `code`, or the last part of a problem-details `type`. */
|
|
5
|
+
readonly apiCode?: string;
|
|
6
|
+
/** The most human sentence the body offered. */
|
|
7
|
+
readonly message?: string;
|
|
8
|
+
/** Trading 212's reference for the request, from `traceId`. */
|
|
9
|
+
readonly traceId?: string;
|
|
10
|
+
/** The body as parsed JSON, or its text when it was not JSON. */
|
|
11
|
+
readonly body?: unknown;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Reads every error body shape Trading 212 is known to send: problem details (`type`, `title`, `detail`, `traceId`),
|
|
15
|
+
* the older `{ code, errorMessage }` it uses for a 429, `{ code, clarification }`, plain text, and nothing at all.
|
|
16
|
+
*/
|
|
17
|
+
declare function parseErrorBody(text: string): ParsedErrorBody;
|
|
18
|
+
|
|
19
|
+
/** The most decimal places Trading 212 accepts in an order quantity. Positions can hold more. */
|
|
20
|
+
declare const QUANTITY_DECIMALS = 4;
|
|
21
|
+
/** How many decimal places a number has, as written. */
|
|
22
|
+
declare function decimalPlaces(value: number): number;
|
|
23
|
+
/**
|
|
24
|
+
* Cuts a quantity to `decimals` places, always towards zero, so selling a whole 12.09032128-share position sends
|
|
25
|
+
* 12.0903 and never more than you hold. Works on the number's exact text, not floating-point arithmetic.
|
|
26
|
+
*/
|
|
27
|
+
declare function truncateQuantity(value: number, decimals?: number): number;
|
|
28
|
+
/** True when Trading 212 will accept the number as an order quantity: finite, not zero, at most 4 decimal places. */
|
|
29
|
+
declare function isValidQuantity(value: number): boolean;
|
|
30
|
+
|
|
31
|
+
/** This package's version, replaced at build time. */
|
|
32
|
+
declare const VERSION: string;
|
|
33
|
+
|
|
34
|
+
export { QUANTITY_DECIMALS, VERSION, decimalPlaces, isValidQuantity, parseErrorBody, truncateQuantity };
|
|
35
|
+
export type { ParsedErrorBody };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export { A as AccountBucketDetailedResponse, a as AccountBucketInstrumentResult, b as AccountBucketInstrumentsDetailedResponse, c as AccountBucketResultResponse, d as AccountResource, e as AccountSummary, f as AuthenticationError, B as BASE_URLS, C as CacheStore, g as CallOptions, h as Cash, i as ConfigurationError, j as ConsoleLike, D as Dividend, k as DividendDetails, l as DryRunResult, m as DuplicateBucketRequest, E as ENDPOINTS, n as EndpointBudget, o as EndpointDefinition, p as EndpointId, q as EndpointKind, r as EndpointRateLimit, s as EnqueuedReportResponse, t as EnvSource, u as Environment, v as ErrorCode, w as ErrorDetails, x as Exchange, y as ExchangesResource, z as ExportResult, F as FINAL_ORDER_STATUSES, G as FetchLike, H as FieldsFirstMethod, I as Fill, J as FillWalletImpact, K as HistoricalOrder, L as HistoryDividendItem, M as HistoryResource, N as HistoryTransactionItem, O as HoldingSnapshot, P as Hooks, Q as HttpError, R as HttpMethod, S as Instrument, T as InstrumentIssue, U as InstrumentNotFoundError, V as InstrumentSuggestion, W as InstrumentsResource, X as InvestmentResult, Y as Investments, Z as IterateOptions, _ as LimitOrderRequest, $ as LimitRequest, a0 as ListOptions, a1 as LogFields, a2 as LogLevel, a3 as Logger, a4 as MarketOrderRequest, a5 as MarketRequest, a6 as MarketSession, a7 as MarketStatus, a8 as MemoryCache, a9 as MissingScopeError, aa as NetworkError, ab as NotAvailableInDemoError, ac as NotFoundError, ad as Order, ae as OrderInput, af as OrderOutcomeUnknownError, ag as OrderRejectedError, ah as OrderRejectionReason, ai as OrderTimeValidity, aj as OrderType, ak as OrdersResource, al as Page, am as PageOptions, an as PagedList, ao as PaginatedResponseHistoricalOrder, ap as PaginatedResponseHistoryDividendItem, aq as PaginatedResponseHistoryTransactionItem, ar as PermissionError, as as Pie, at as PieDetails, au as PieInput, av as PieRequest, aw as PiesResource, ax as PlaceOptions, ay as Placed, az as PortfolioResource, aA as PortfolioSnapshot, aB as Position, aC as PositionWalletImpact, aD as PositionsResource, aE as PublicReportRequest, aF as RateLimitError, aG as RateLimitInfo, aH as RateLimitMode, aI as RateLimitWaitEvent, aJ as Report, aK as ReportDataIncluded, aL as ReportRequest, aM as ReportResponse, aN as ReportWaitOptions, aO as ReportsResource, aP as RequestDescription, aQ as RequestEvent, aR as ResolveOptions, aS as ResponseEvent, aT as RetryEvent, aU as RetryOptions, aV as SPEC_VERSION, aW as SearchOptions, aX as SellAllOptions, aY as ServerError, aZ as StopLimitOrderRequest, a_ as StopLimitRequest, a$ as StopOrderRequest, b0 as StopRequest, b1 as TIME_VALIDITIES, b2 as Tax, b3 as TimeEvent, b4 as TimeValidity, b5 as TimeoutError, b6 as TradableInstrument, b7 as Trading212, b8 as Trading212Error, b9 as Trading212Options, ba as TradingDisabledError, bb as Transaction, bc as UnexpectedResponseError, bd as ValidationError, be as ValidationIssue, bf as VerifyResult, bg as WaitOptions, bh as WorkingSchedule, bi as buildPortfolioSnapshot, bj as consoleLogger, bk as fieldsFirst, bl as isTrading212Error, bm as sessionAt, bn as silentLogger } from './client-BSQXqdxj.js';
|
|
2
|
+
|
|
3
|
+
interface ParsedErrorBody {
|
|
4
|
+
/** Trading 212's own code, from `code`, or the last part of a problem-details `type`. */
|
|
5
|
+
readonly apiCode?: string;
|
|
6
|
+
/** The most human sentence the body offered. */
|
|
7
|
+
readonly message?: string;
|
|
8
|
+
/** Trading 212's reference for the request, from `traceId`. */
|
|
9
|
+
readonly traceId?: string;
|
|
10
|
+
/** The body as parsed JSON, or its text when it was not JSON. */
|
|
11
|
+
readonly body?: unknown;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Reads every error body shape Trading 212 is known to send: problem details (`type`, `title`, `detail`, `traceId`),
|
|
15
|
+
* the older `{ code, errorMessage }` it uses for a 429, `{ code, clarification }`, plain text, and nothing at all.
|
|
16
|
+
*/
|
|
17
|
+
declare function parseErrorBody(text: string): ParsedErrorBody;
|
|
18
|
+
|
|
19
|
+
/** The most decimal places Trading 212 accepts in an order quantity. Positions can hold more. */
|
|
20
|
+
declare const QUANTITY_DECIMALS = 4;
|
|
21
|
+
/** How many decimal places a number has, as written. */
|
|
22
|
+
declare function decimalPlaces(value: number): number;
|
|
23
|
+
/**
|
|
24
|
+
* Cuts a quantity to `decimals` places, always towards zero, so selling a whole 12.09032128-share position sends
|
|
25
|
+
* 12.0903 and never more than you hold. Works on the number's exact text, not floating-point arithmetic.
|
|
26
|
+
*/
|
|
27
|
+
declare function truncateQuantity(value: number, decimals?: number): number;
|
|
28
|
+
/** True when Trading 212 will accept the number as an order quantity: finite, not zero, at most 4 decimal places. */
|
|
29
|
+
declare function isValidQuantity(value: number): boolean;
|
|
30
|
+
|
|
31
|
+
/** This package's version, replaced at build time. */
|
|
32
|
+
declare const VERSION: string;
|
|
33
|
+
|
|
34
|
+
export { QUANTITY_DECIMALS, VERSION, decimalPlaces, isValidQuantity, parseErrorBody, truncateQuantity };
|
|
35
|
+
export type { ParsedErrorBody };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { AuthenticationError, BASE_URLS, ConfigurationError, ENDPOINTS, FINAL_ORDER_STATUSES, HttpError, InstrumentNotFoundError, MemoryCache, MissingScopeError, NetworkError, NotAvailableInDemoError, NotFoundError, OrderOutcomeUnknownError, OrderRejectedError, PermissionError, QUANTITY_DECIMALS, RateLimitError, SPEC_VERSION, ServerError, TIME_VALIDITIES, TimeoutError, Trading212, Trading212Error, TradingDisabledError, UnexpectedResponseError, VERSION, ValidationError, buildPortfolioSnapshot, consoleLogger, decimalPlaces, fieldsFirst, isTrading212Error, isValidQuantity, parseErrorBody, sessionAt, silentLogger, truncateQuantity } from './chunk-AVOYEH6N.js';
|