@databolsa/sdk 1.0.9 → 1.0.11
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/dist/client.d.ts +73 -1
- package/dist/http-client.d.ts +39 -1
- package/dist/index.js +165 -2
- package/dist/schema.d.ts +3049 -1102
- package/dist/types.d.ts +92 -0
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CorporateEventsResponse, CryptoQuotesResponse, DividendsResponse, DocumentsResponse, EtfListResponse, EtfProfile, ExpectationsResponse, Fii, FiiDistributionsResponse, FiiIndicatorsResponse, FiiReportsResponse, FiiScreenResponse, FundHoldersResponse, FundHoldingsResponse, FundListResponse, FundProfile, FundQuotesResponse, FundScreenerResponse, HealthResponse, IngestHealthResponse, IndexCompositionResponse, IndexMeta, IndexQuotesResponse, IndicatorHistoryResponse, IntradaySeriesResponse, LiveQuotesResponse, BdrListResponse, BdrProfile, BdrQuotesResponse, InsiderResponse, InvestorFlowMonthlyResponse, InvestorFlowResponse, MacroGearsResponse, OfferingsResponse, OptionExpiriesResponse, OptionsChainResponse, OptionsQuotesResponse, DocumentSearchResponse, PortfolioResponse, Query, QuotesResponse, RangeParams, RegimeSnapshot, ScreenStocksResponse, SearchDocumentsParams, SearchResult, SeriesResponse, Stock, StockIndicatorsResponse, SuitabilityResponse, TesouroBondsResponse, TradeStatsResponse, YieldCurveResponse } from "./types";
|
|
1
|
+
import type { CorporateEventsResponse, CryptoQuotesResponse, DividendsResponse, DocumentsResponse, EtfListResponse, EtfProfile, ExpectationsResponse, Fii, FiiDistributionsResponse, FiiIndicatorsResponse, FiiReportsResponse, FiiScreenResponse, FundHoldersResponse, FundHoldingsResponse, FundListResponse, FundProfile, FundQuotesResponse, FundScreenerResponse, HealthResponse, IngestHealthResponse, IndexCompositionResponse, IndexMeta, IndexQuotesResponse, IndicatorHistoryResponse, IntradaySeriesResponse, LiveQuotesResponse, BdrListResponse, BdrProfile, BdrQuotesResponse, InsiderResponse, InvestorFlowMonthlyResponse, InvestorFlowResponse, MacroGearsResponse, OfferingsResponse, OptionExpiriesResponse, OptionsChainResponse, OptionsQuotesResponse, DocumentSearchResponse, PortfolioResponse, CommunityBotsResponse, CommunityBotPostInput, CommunityBotPostResponse, CommunityBotReplyResponse, CommunityFeedParams, CommunityFeedResponse, CommunityPostResponse, RegisterCommunityBotInput, RegisterCommunityBotResponse, Query, QuotesResponse, RangeParams, RegimeSnapshot, ScreenStocksResponse, SearchDocumentsParams, SearchResult, SeriesResponse, Stock, StockIndicatorsResponse, SuitabilityResponse, TesouroBondsResponse, TradeStatsResponse, YieldCurveResponse, AddPortfolioTransactionResponse, CreatePortfolioResponse, PortfolioAssetRef, PortfolioDetail, PortfolioHistoryResponse, PortfolioImportInput, PortfolioImportRowsResponse, PortfolioImportsResponse, PortfolioImportSummary, PortfolioPatch, PortfolioRfContract, PortfolioTransaction, PortfolioTransactionInput, PortfolioTransactionPatch, PortfoliosResponse, PortfolioTransactionsResponse } from "./types";
|
|
2
2
|
/** Filtros do screener de ações — derivados de `GET /v1/screener/stocks`. */
|
|
3
3
|
export type ScreenStocksParams = Query<"screenStocks">;
|
|
4
4
|
/**
|
|
@@ -192,13 +192,85 @@ export interface DataBolsaClient {
|
|
|
192
192
|
* Escopada ao dono da chave de API (a mesma da conta) — passe sua chave por usuário.
|
|
193
193
|
*/
|
|
194
194
|
getPortfolio(): Promise<PortfolioResponse>;
|
|
195
|
+
/** Histórico mensal consolidado da carteira (patrimônio × aporte × proventos × realizado). */
|
|
196
|
+
getPortfolioHistory(): Promise<PortfolioHistoryResponse>;
|
|
195
197
|
/** Seu perfil de investidor (suitability). `profile` é nulo se ainda não definido. */
|
|
196
198
|
getSuitability(): Promise<SuitabilityResponse>;
|
|
199
|
+
/** Lista as suas carteiras (id, nome, nº de ativos). */
|
|
200
|
+
listPortfolios(): Promise<PortfoliosResponse>;
|
|
201
|
+
/** Cria uma carteira. O número de carteiras depende do plano (erro 402 no teto). */
|
|
202
|
+
createPortfolio(name: string, visibility?: "private" | "unlisted" | "public"): Promise<CreatePortfolioResponse>;
|
|
203
|
+
/** Uma carteira computada: posições, preço médio, P&L, alocação. */
|
|
204
|
+
getPortfolioDetail(id: string): Promise<PortfolioDetail>;
|
|
205
|
+
/** Renomeia, muda visibilidade e/ou marca como simulação. */
|
|
206
|
+
updatePortfolio(id: string, patch: PortfolioPatch): Promise<unknown>;
|
|
207
|
+
/** APAGA a carteira com todos os ativos e transações (irreversível). */
|
|
208
|
+
deletePortfolio(id: string): Promise<{
|
|
209
|
+
deleted?: boolean;
|
|
210
|
+
}>;
|
|
211
|
+
/** Histórico mensal de UMA carteira. */
|
|
212
|
+
getPortfolioHistoryById(id: string): Promise<PortfolioHistoryResponse>;
|
|
213
|
+
/** Adiciona um ativo à carteira (idempotente; sem transações = watchlist). */
|
|
214
|
+
addPortfolioAsset(id: string, asset: PortfolioAssetRef): Promise<unknown>;
|
|
215
|
+
/** Remove um ativo da carteira, APAGANDO o ledger dele nela (irreversível). */
|
|
216
|
+
removePortfolioAsset(id: string, asset: PortfolioAssetRef): Promise<unknown>;
|
|
217
|
+
/** Define a taxa contratada de uma posição de renda fixa (indexer "none" limpa). */
|
|
218
|
+
updatePortfolioAsset(id: string, asset: PortfolioAssetRef, rf: PortfolioRfContract): Promise<unknown>;
|
|
219
|
+
/** Ledger (transações) de um ativo da carteira. */
|
|
220
|
+
listPortfolioTransactions(id: string, asset: PortfolioAssetRef): Promise<PortfolioTransactionsResponse>;
|
|
221
|
+
/** Lança uma transação; o ativo é adicionado automaticamente se preciso. */
|
|
222
|
+
addPortfolioTransaction(id: string, asset: PortfolioAssetRef, tx: PortfolioTransactionInput): Promise<AddPortfolioTransactionResponse>;
|
|
223
|
+
/** Edita uma transação (patch parcial). */
|
|
224
|
+
updatePortfolioTransaction(id: string, txId: string, patch: PortfolioTransactionPatch): Promise<PortfolioTransaction>;
|
|
225
|
+
/** Remove uma transação do ledger (irreversível). */
|
|
226
|
+
deletePortfolioTransaction(id: string, txId: string): Promise<{
|
|
227
|
+
deleted?: boolean;
|
|
228
|
+
}>;
|
|
229
|
+
/**
|
|
230
|
+
* Importa uma planilha (Negociação/Movimentação da B3 em .xlsx, ou o template
|
|
231
|
+
* manual em .csv/.xlsx) para a carteira. Idempotente: reenviar o mesmo arquivo
|
|
232
|
+
* não duplica lançamentos. Retorna o resumo (importadas/duplicadas/avisos).
|
|
233
|
+
*/
|
|
234
|
+
importPortfolioFile(id: string, input: PortfolioImportInput): Promise<PortfolioImportSummary>;
|
|
235
|
+
/** Histórico de imports da carteira. */
|
|
236
|
+
listPortfolioImports(id: string): Promise<PortfolioImportsResponse>;
|
|
237
|
+
/** Linhas de um import, com status (imported/ignored/duplicate/error) e motivo. */
|
|
238
|
+
listPortfolioImportRows(id: string, importId: string, params?: {
|
|
239
|
+
status?: "imported" | "ignored" | "duplicate" | "error";
|
|
240
|
+
limit?: number;
|
|
241
|
+
offset?: number;
|
|
242
|
+
}): Promise<PortfolioImportRowsResponse>;
|
|
243
|
+
/** Template CSV do import manual (texto). */
|
|
244
|
+
getPortfolioImportTemplate(): Promise<string>;
|
|
245
|
+
/** Reconcilia a posição de um ativo à quantidade declarada pela B3 (ajuste idempotente). */
|
|
246
|
+
reconcilePortfolioAsset(id: string, asset: PortfolioAssetRef, targetQty: number, asOf: string): Promise<unknown>;
|
|
197
247
|
/**
|
|
198
248
|
* Busca semântica no texto de documentos CVM/B3 (fatos relevantes, releases,
|
|
199
249
|
* balanços, relatórios de FII, atas). Filtre por papel/categoria/ano quando souber.
|
|
200
250
|
*/
|
|
201
251
|
searchDocuments(q: string, params?: SearchDocumentsParams): Promise<DocumentSearchResponse>;
|
|
252
|
+
/** Lista os bots de comunidade registrados pela sua conta. */
|
|
253
|
+
listCommunityBots(): Promise<CommunityBotsResponse>;
|
|
254
|
+
/**
|
|
255
|
+
* Registra um bot de comunidade (perfil público @handle que publica via API,
|
|
256
|
+
* com selo BOT). O número de bots por conta depende do plano.
|
|
257
|
+
*/
|
|
258
|
+
registerCommunityBot(input: RegisterCommunityBotInput): Promise<RegisterCommunityBotResponse>;
|
|
259
|
+
/** Desativa um bot da conta (publicações antigas permanecem, rotuladas BOT). */
|
|
260
|
+
deleteCommunityBot(handle: string): Promise<{
|
|
261
|
+
ok?: boolean;
|
|
262
|
+
}>;
|
|
263
|
+
/**
|
|
264
|
+
* Publica um post na comunidade em nome do bot (público, com selo BOT).
|
|
265
|
+
* Moderação automática: conteúdo reprovado vira erro 422 com o motivo.
|
|
266
|
+
*/
|
|
267
|
+
createCommunityBotPost(handle: string, input: CommunityBotPostInput): Promise<CommunityBotPostResponse>;
|
|
268
|
+
/** Publica uma resposta em nome do bot num post existente (mesma moderação). */
|
|
269
|
+
createCommunityBotReply(handle: string, postId: string, body: string): Promise<CommunityBotReplyResponse>;
|
|
270
|
+
/** Feed público da comunidade, paginado por cursor. */
|
|
271
|
+
getCommunityFeed(params?: CommunityFeedParams): Promise<CommunityFeedResponse>;
|
|
272
|
+
/** Um post da comunidade com a discussão completa. */
|
|
273
|
+
getCommunityPost(id: string): Promise<CommunityPostResponse>;
|
|
202
274
|
}
|
|
203
275
|
export declare class NotInPreviewError extends Error {
|
|
204
276
|
readonly entity: string;
|
package/dist/http-client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type DataBolsaClient, type LiveQuotesParams, type ScreenFiisParams, type ScreenFundsParams, type ScreenStocksParams } from "./client";
|
|
2
|
-
import type { CorporateEventsResponse, CryptoQuotesResponse, DividendsResponse, DocumentSearchResponse, DocumentsResponse, EtfListResponse, EtfProfile, ExpectationsResponse, Fii, FiiDistributionsResponse, FiiIndicatorsResponse, FiiReportsResponse, FiiScreenResponse, FundHoldersResponse, FundHoldingsResponse, FundListResponse, FundProfile, FundQuotesResponse, FundScreenerResponse, HealthResponse, IngestHealthResponse, IndexCompositionResponse, IndexMeta, IndexQuotesResponse, IndicatorHistoryResponse, IntradaySeriesResponse, LiveQuotesResponse, BdrListResponse, BdrProfile, BdrQuotesResponse, InsiderResponse, InvestorFlowMonthlyResponse, InvestorFlowResponse, MacroGearsResponse, OfferingsResponse, OptionExpiriesResponse, OptionsChainResponse, OptionsQuotesResponse, PortfolioResponse, QuotesResponse, RangeParams, RegimeSnapshot, ScreenStocksResponse, SearchDocumentsParams, SearchResult, SeriesResponse, Stock, StockIndicatorsResponse, SuitabilityResponse, TesouroBondsResponse, TradeStatsResponse, YieldCurveResponse } from "./types";
|
|
2
|
+
import type { AddPortfolioTransactionResponse, CreatePortfolioResponse, PortfolioAssetRef, PortfolioDetail, PortfolioHistoryResponse, PortfolioImportInput, PortfolioImportRowsResponse, PortfolioImportsResponse, PortfolioImportSummary, PortfolioPatch, PortfolioRfContract, PortfolioTransaction, PortfolioTransactionInput, PortfolioTransactionPatch, PortfoliosResponse, PortfolioTransactionsResponse, CorporateEventsResponse, CryptoQuotesResponse, DividendsResponse, DocumentSearchResponse, DocumentsResponse, EtfListResponse, EtfProfile, ExpectationsResponse, Fii, FiiDistributionsResponse, FiiIndicatorsResponse, FiiReportsResponse, FiiScreenResponse, FundHoldersResponse, FundHoldingsResponse, FundListResponse, FundProfile, FundQuotesResponse, FundScreenerResponse, HealthResponse, IngestHealthResponse, IndexCompositionResponse, IndexMeta, IndexQuotesResponse, IndicatorHistoryResponse, IntradaySeriesResponse, LiveQuotesResponse, BdrListResponse, BdrProfile, BdrQuotesResponse, InsiderResponse, InvestorFlowMonthlyResponse, InvestorFlowResponse, MacroGearsResponse, OfferingsResponse, OptionExpiriesResponse, OptionsChainResponse, OptionsQuotesResponse, PortfolioResponse, CommunityBotsResponse, CommunityBotPostInput, CommunityBotPostResponse, CommunityBotReplyResponse, CommunityFeedParams, CommunityFeedResponse, CommunityPostResponse, RegisterCommunityBotInput, RegisterCommunityBotResponse, QuotesResponse, RangeParams, RegimeSnapshot, ScreenStocksResponse, SearchDocumentsParams, SearchResult, SeriesResponse, Stock, StockIndicatorsResponse, SuitabilityResponse, TesouroBondsResponse, TradeStatsResponse, YieldCurveResponse } from "./types";
|
|
3
3
|
/**
|
|
4
4
|
* Cliente HTTP da Serving API do DataBolsa. Os métodos públicos espelham os
|
|
5
5
|
* operationIds do OpenAPI e retornam tipos gerados.
|
|
@@ -22,6 +22,8 @@ export declare class HttpClient implements DataBolsaClient {
|
|
|
22
22
|
private readonly getToken?;
|
|
23
23
|
constructor(baseUrl: string, opts?: HttpClientOptions);
|
|
24
24
|
private request;
|
|
25
|
+
/** Como `request`, mas p/ respostas de TEXTO (ex.: o template CSV de import). */
|
|
26
|
+
private requestText;
|
|
25
27
|
/** Extrai `detail`/`title` de um application/problem+json, se houver. */
|
|
26
28
|
private problemDetail;
|
|
27
29
|
getHealth(): Promise<HealthResponse>;
|
|
@@ -164,4 +166,40 @@ export declare class HttpClient implements DataBolsaClient {
|
|
|
164
166
|
getPortfolio(): Promise<PortfolioResponse>;
|
|
165
167
|
getSuitability(): Promise<SuitabilityResponse>;
|
|
166
168
|
searchDocuments(q: string, params?: SearchDocumentsParams): Promise<DocumentSearchResponse>;
|
|
169
|
+
listCommunityBots(): Promise<CommunityBotsResponse>;
|
|
170
|
+
registerCommunityBot(input: RegisterCommunityBotInput): Promise<RegisterCommunityBotResponse>;
|
|
171
|
+
deleteCommunityBot(handle: string): Promise<{
|
|
172
|
+
ok?: boolean;
|
|
173
|
+
}>;
|
|
174
|
+
createCommunityBotPost(handle: string, input: CommunityBotPostInput): Promise<CommunityBotPostResponse>;
|
|
175
|
+
createCommunityBotReply(handle: string, postId: string, body: string): Promise<CommunityBotReplyResponse>;
|
|
176
|
+
getCommunityFeed(params?: CommunityFeedParams): Promise<CommunityFeedResponse>;
|
|
177
|
+
getCommunityPost(id: string): Promise<CommunityPostResponse>;
|
|
178
|
+
getPortfolioHistory(): Promise<PortfolioHistoryResponse>;
|
|
179
|
+
listPortfolios(): Promise<PortfoliosResponse>;
|
|
180
|
+
createPortfolio(name: string, visibility?: "private" | "unlisted" | "public"): Promise<CreatePortfolioResponse>;
|
|
181
|
+
getPortfolioDetail(id: string): Promise<PortfolioDetail>;
|
|
182
|
+
updatePortfolio(id: string, patch: PortfolioPatch): Promise<unknown>;
|
|
183
|
+
deletePortfolio(id: string): Promise<{
|
|
184
|
+
deleted?: boolean;
|
|
185
|
+
}>;
|
|
186
|
+
getPortfolioHistoryById(id: string): Promise<PortfolioHistoryResponse>;
|
|
187
|
+
addPortfolioAsset(id: string, asset: PortfolioAssetRef): Promise<unknown>;
|
|
188
|
+
removePortfolioAsset(id: string, asset: PortfolioAssetRef): Promise<unknown>;
|
|
189
|
+
updatePortfolioAsset(id: string, asset: PortfolioAssetRef, rf: PortfolioRfContract): Promise<unknown>;
|
|
190
|
+
listPortfolioTransactions(id: string, asset: PortfolioAssetRef): Promise<PortfolioTransactionsResponse>;
|
|
191
|
+
addPortfolioTransaction(id: string, asset: PortfolioAssetRef, tx: PortfolioTransactionInput): Promise<AddPortfolioTransactionResponse>;
|
|
192
|
+
updatePortfolioTransaction(id: string, txId: string, patch: PortfolioTransactionPatch): Promise<PortfolioTransaction>;
|
|
193
|
+
deletePortfolioTransaction(id: string, txId: string): Promise<{
|
|
194
|
+
deleted?: boolean;
|
|
195
|
+
}>;
|
|
196
|
+
importPortfolioFile(id: string, input: PortfolioImportInput): Promise<PortfolioImportSummary>;
|
|
197
|
+
listPortfolioImports(id: string): Promise<PortfolioImportsResponse>;
|
|
198
|
+
listPortfolioImportRows(id: string, importId: string, params?: {
|
|
199
|
+
status?: "imported" | "ignored" | "duplicate" | "error";
|
|
200
|
+
limit?: number;
|
|
201
|
+
offset?: number;
|
|
202
|
+
}): Promise<PortfolioImportRowsResponse>;
|
|
203
|
+
getPortfolioImportTemplate(): Promise<string>;
|
|
204
|
+
reconcilePortfolioAsset(id: string, asset: PortfolioAssetRef, targetQty: number, asOf: string): Promise<unknown>;
|
|
167
205
|
}
|
package/dist/index.js
CHANGED
|
@@ -19,7 +19,7 @@ class HttpClient {
|
|
|
19
19
|
this.base = `${origin}/v1`;
|
|
20
20
|
this.getToken = opts.getToken ?? (opts.apiKey ? () => opts.apiKey : undefined);
|
|
21
21
|
}
|
|
22
|
-
async request(path, query) {
|
|
22
|
+
async request(path, query, opts) {
|
|
23
23
|
const url = new URL(this.base + path);
|
|
24
24
|
if (query) {
|
|
25
25
|
for (const [k, v] of Object.entries(query)) {
|
|
@@ -31,9 +31,15 @@ class HttpClient {
|
|
|
31
31
|
const token = this.getToken?.();
|
|
32
32
|
if (token)
|
|
33
33
|
headers.authorization = `Bearer ${token}`;
|
|
34
|
+
if (opts?.body !== undefined)
|
|
35
|
+
headers["content-type"] = "application/json";
|
|
34
36
|
let res;
|
|
35
37
|
try {
|
|
36
|
-
res = await fetch(url, {
|
|
38
|
+
res = await fetch(url, {
|
|
39
|
+
method: opts?.method ?? "GET",
|
|
40
|
+
headers,
|
|
41
|
+
...opts?.body !== undefined ? { body: JSON.stringify(opts.body) } : {}
|
|
42
|
+
});
|
|
37
43
|
} catch (cause) {
|
|
38
44
|
throw new Error(`Falha de rede ao chamar ${path}`, { cause });
|
|
39
45
|
}
|
|
@@ -45,6 +51,26 @@ class HttpClient {
|
|
|
45
51
|
const detail = await this.problemDetail(res);
|
|
46
52
|
throw new Error(`API ${res.status} em ${path}${detail ? `: ${detail}` : ""}`);
|
|
47
53
|
}
|
|
54
|
+
async requestText(path) {
|
|
55
|
+
const url = new URL(this.base + path);
|
|
56
|
+
const headers = { accept: "text/csv, text/plain" };
|
|
57
|
+
const token = this.getToken?.();
|
|
58
|
+
if (token)
|
|
59
|
+
headers.authorization = `Bearer ${token}`;
|
|
60
|
+
let res;
|
|
61
|
+
try {
|
|
62
|
+
res = await fetch(url, { headers });
|
|
63
|
+
} catch (cause) {
|
|
64
|
+
throw new Error(`Falha de rede ao chamar ${path}`, { cause });
|
|
65
|
+
}
|
|
66
|
+
if (res.ok)
|
|
67
|
+
return res.text();
|
|
68
|
+
if (res.status === 501 || res.status === 404) {
|
|
69
|
+
throw new NotInPreviewError(decodeURIComponent(path.replace(/^\//, "")));
|
|
70
|
+
}
|
|
71
|
+
const detail = await this.problemDetail(res);
|
|
72
|
+
throw new Error(`API ${res.status} em ${path}${detail ? `: ${detail}` : ""}`);
|
|
73
|
+
}
|
|
48
74
|
async problemDetail(res) {
|
|
49
75
|
try {
|
|
50
76
|
const body = await res.json();
|
|
@@ -372,6 +398,143 @@ class HttpClient {
|
|
|
372
398
|
limit: params?.limit
|
|
373
399
|
});
|
|
374
400
|
}
|
|
401
|
+
listCommunityBots() {
|
|
402
|
+
return this.request("/community/bots");
|
|
403
|
+
}
|
|
404
|
+
registerCommunityBot(input) {
|
|
405
|
+
return this.request("/community/bots", undefined, {
|
|
406
|
+
method: "POST",
|
|
407
|
+
body: { handle: input.handle, display_name: input.displayName, bio: input.bio }
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
deleteCommunityBot(handle) {
|
|
411
|
+
return this.request(`/community/bots/${enc(handle)}`, undefined, { method: "DELETE" });
|
|
412
|
+
}
|
|
413
|
+
createCommunityBotPost(handle, input) {
|
|
414
|
+
return this.request(`/community/bots/${enc(handle)}/posts`, undefined, {
|
|
415
|
+
method: "POST",
|
|
416
|
+
body: { body: input.body, title: input.title, ticker: input.ticker, asset_type: input.assetType }
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
createCommunityBotReply(handle, postId, body) {
|
|
420
|
+
return this.request(`/community/bots/${enc(handle)}/replies`, undefined, {
|
|
421
|
+
method: "POST",
|
|
422
|
+
body: { post_id: postId, body }
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
getCommunityFeed(params) {
|
|
426
|
+
return this.request("/community/feed", {
|
|
427
|
+
tab: params?.tab,
|
|
428
|
+
ticker: params?.ticker,
|
|
429
|
+
q: params?.q,
|
|
430
|
+
cursor: params?.cursor
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
getCommunityPost(id) {
|
|
434
|
+
return this.request(`/community/posts/${enc(id)}`);
|
|
435
|
+
}
|
|
436
|
+
getPortfolioHistory() {
|
|
437
|
+
return this.request("/portfolio/history");
|
|
438
|
+
}
|
|
439
|
+
listPortfolios() {
|
|
440
|
+
return this.request("/portfolios");
|
|
441
|
+
}
|
|
442
|
+
createPortfolio(name, visibility) {
|
|
443
|
+
return this.request("/portfolios", undefined, { method: "POST", body: { name, visibility } });
|
|
444
|
+
}
|
|
445
|
+
getPortfolioDetail(id) {
|
|
446
|
+
return this.request(`/portfolios/${enc(id)}`);
|
|
447
|
+
}
|
|
448
|
+
updatePortfolio(id, patch) {
|
|
449
|
+
return this.request(`/portfolios/${enc(id)}`, undefined, {
|
|
450
|
+
method: "PATCH",
|
|
451
|
+
body: { name: patch.name, visibility: patch.visibility, exclude_from_consolidated: patch.excludeFromConsolidated }
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
deletePortfolio(id) {
|
|
455
|
+
return this.request(`/portfolios/${enc(id)}`, undefined, { method: "DELETE" });
|
|
456
|
+
}
|
|
457
|
+
getPortfolioHistoryById(id) {
|
|
458
|
+
return this.request(`/portfolios/${enc(id)}/history`);
|
|
459
|
+
}
|
|
460
|
+
addPortfolioAsset(id, asset) {
|
|
461
|
+
return this.request(`/portfolios/${enc(id)}/assets`, undefined, {
|
|
462
|
+
method: "POST",
|
|
463
|
+
body: { asset_type: asset.assetType, symbol: asset.symbol }
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
removePortfolioAsset(id, asset) {
|
|
467
|
+
return this.request(`/portfolios/${enc(id)}/assets`, { asset_type: asset.assetType, symbol: asset.symbol }, { method: "DELETE" });
|
|
468
|
+
}
|
|
469
|
+
updatePortfolioAsset(id, asset, rf) {
|
|
470
|
+
return this.request(`/portfolios/${enc(id)}/assets`, { asset_type: asset.assetType, symbol: asset.symbol }, { method: "PATCH", body: { rf_indexer: rf.indexer, rf_rate: rf.rate } });
|
|
471
|
+
}
|
|
472
|
+
listPortfolioTransactions(id, asset) {
|
|
473
|
+
return this.request(`/portfolios/${enc(id)}/transactions`, {
|
|
474
|
+
asset_type: asset.assetType,
|
|
475
|
+
symbol: asset.symbol
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
addPortfolioTransaction(id, asset, tx) {
|
|
479
|
+
return this.request(`/portfolios/${enc(id)}/transactions`, undefined, {
|
|
480
|
+
method: "POST",
|
|
481
|
+
body: {
|
|
482
|
+
asset_type: asset.assetType,
|
|
483
|
+
symbol: asset.symbol,
|
|
484
|
+
kind: tx.kind,
|
|
485
|
+
trade_date: tx.tradeDate,
|
|
486
|
+
quantity: tx.quantity,
|
|
487
|
+
price: tx.price,
|
|
488
|
+
fees: tx.fees,
|
|
489
|
+
ratio: tx.ratio,
|
|
490
|
+
note: tx.note
|
|
491
|
+
}
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
updatePortfolioTransaction(id, txId, patch) {
|
|
495
|
+
return this.request(`/portfolios/${enc(id)}/transactions/${enc(txId)}`, undefined, {
|
|
496
|
+
method: "PATCH",
|
|
497
|
+
body: {
|
|
498
|
+
kind: patch.kind,
|
|
499
|
+
trade_date: patch.tradeDate,
|
|
500
|
+
quantity: patch.quantity,
|
|
501
|
+
price: patch.price,
|
|
502
|
+
fees: patch.fees,
|
|
503
|
+
ratio: patch.ratio,
|
|
504
|
+
note: patch.note
|
|
505
|
+
}
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
deletePortfolioTransaction(id, txId) {
|
|
509
|
+
return this.request(`/portfolios/${enc(id)}/transactions/${enc(txId)}`, undefined, {
|
|
510
|
+
method: "DELETE"
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
importPortfolioFile(id, input) {
|
|
514
|
+
return this.request(`/portfolios/${enc(id)}/imports`, undefined, {
|
|
515
|
+
method: "POST",
|
|
516
|
+
body: { content_base64: input.contentBase64, filename: input.filename }
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
listPortfolioImports(id) {
|
|
520
|
+
return this.request(`/portfolios/${enc(id)}/imports`);
|
|
521
|
+
}
|
|
522
|
+
listPortfolioImportRows(id, importId, params) {
|
|
523
|
+
return this.request(`/portfolios/${enc(id)}/imports/${enc(importId)}/rows`, {
|
|
524
|
+
status: params?.status,
|
|
525
|
+
limit: params?.limit,
|
|
526
|
+
offset: params?.offset
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
getPortfolioImportTemplate() {
|
|
530
|
+
return this.requestText("/portfolios/import-template");
|
|
531
|
+
}
|
|
532
|
+
reconcilePortfolioAsset(id, asset, targetQty, asOf) {
|
|
533
|
+
return this.request(`/portfolios/${enc(id)}/reconcile`, undefined, {
|
|
534
|
+
method: "POST",
|
|
535
|
+
body: { asset_type: asset.assetType, symbol: asset.symbol, target_qty: targetQty, as_of: asOf }
|
|
536
|
+
});
|
|
537
|
+
}
|
|
375
538
|
}
|
|
376
539
|
function enc(segment) {
|
|
377
540
|
return encodeURIComponent(segment);
|