Repository navigation
Expand file tree
/
Copy pathstocks.py
More file actions
2775 lines (2264 loc) · 124 KB
/
Copy pathstocks.py
File metadata and controls
2775 lines (2264 loc) · 124 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
from __future__ import annotations
from typing_extensions import Literal
import httpx
from ..._types import Body, Omit, Query, Headers, NotGiven, omit, not_given
from ..._utils import maybe_transform, async_maybe_transform
from ..._compat import cached_property
from ...types.v2 import (
stock_quote_params,
stock_profile_params,
stock_screener_params,
stock_cash_flow_params,
stock_dividends_params,
stock_historical_params,
stock_statistics_params,
stock_value_added_params,
stock_balance_sheet_params,
stock_financial_data_params,
stock_income_statement_params,
stock_insider_transactions_params,
)
from ..._resource import SyncAPIResource, AsyncAPIResource
from ..._response import (
to_raw_response_wrapper,
to_streamed_response_wrapper,
async_to_raw_response_wrapper,
async_to_streamed_response_wrapper,
)
from ..._base_client import make_request_options
from ...types.v2.stock_quote_response import StockQuoteResponse
from ...types.v2.stock_profile_response import StockProfileResponse
from ...types.v2.stock_screener_response import StockScreenerResponse
from ...types.v2.stock_cash_flow_response import StockCashFlowResponse
from ...types.v2.stock_dividends_response import StockDividendsResponse
from ...types.v2.stock_historical_response import StockHistoricalResponse
from ...types.v2.stock_statistics_response import StockStatisticsResponse
from ...types.v2.stock_value_added_response import StockValueAddedResponse
from ...types.v2.stock_balance_sheet_response import StockBalanceSheetResponse
from ...types.v2.stock_financial_data_response import StockFinancialDataResponse
from ...types.v2.stock_income_statement_response import StockIncomeStatementResponse
from ...types.v2.stock_insider_transactions_response import StockInsiderTransactionsResponse
__all__ = ["StocksResource", "AsyncStocksResource"]
class StocksResource(SyncAPIResource):
@cached_property
def with_raw_response(self) -> StocksResourceWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/brapi-dev/brapi-python#accessing-raw-response-data-eg-headers
"""
return StocksResourceWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> StocksResourceWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/brapi-dev/brapi-python#with_streaming_response
"""
return StocksResourceWithStreamingResponse(self)
def balance_sheet(
self,
*,
symbols: str,
end_date: str | Omit = omit,
period: Literal["annual", "quarterly"] | Omit = omit,
start_date: str | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> StockBalanceSheetResponse:
"""
Ativo, passivo e patrimônio líquido de empresas listadas, com base nos
demonstrativos entregues à CVM. Uma linha por período, do mais recente para o
mais antigo.
Use para analisar endividamento, liquidez e estrutura de capital.
O padrão é `period=annual`. Use `period=quarterly` para trimestres. `startDate`
e `endDate` filtram pela data de encerramento do período.
Bancos e seguradoras usam outro plano de contas. Campos que não se aplicam ao
setor vêm como `null`.
Args:
symbols: Tickers separados por vírgula. Ex.: PETR4,VALE3. `requestedSymbol` identifica o
ticker enviado e `symbol` identifica os dados retornados.
end_date: Data final no formato YYYY-MM-DD. Filtra pela data de encerramento do período.
period: Período de cada linha: anual ou trimestral.
start_date: Data inicial no formato YYYY-MM-DD. Filtra pela data de encerramento do período.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return self._get(
"/api/v2/stocks/balance-sheet",
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"symbols": symbols,
"end_date": end_date,
"period": period,
"start_date": start_date,
},
stock_balance_sheet_params.StockBalanceSheetParams,
),
),
cast_to=StockBalanceSheetResponse,
)
def cash_flow(
self,
*,
symbols: str,
end_date: str | Omit = omit,
period: Literal["annual", "quarterly"] | Omit = omit,
start_date: str | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> StockCashFlowResponse:
"""
Demonstração do fluxo de caixa de empresas listadas: caixa das atividades
operacionais, de investimento e de financiamento, com os saldos de caixa no
início e no fim do período.
Use para comparar a geração de caixa com o lucro e calcular o fluxo de caixa
livre.
O padrão é `period=annual`. Use `period=quarterly` para trimestres. `startDate`
e `endDate` filtram pela data de encerramento do período.
`freeCashFlow` soma o caixa operacional e o caixa de investimento. Ele é `null`
quando um dos dois falta.
Os trimestres usam a mesma base, consolidada ou individual, do relatório anual
do mesmo ano. Sem relatório anual, a base é a que tem o trimestre mais recente.
Em empate, a consolidada vale. Lacunas não são preenchidas com a outra base. Um
período sem os dados necessários para o cálculo retorna `null`.
Args:
symbols: Tickers separados por vírgula. Ex.: PETR4,VALE3. `requestedSymbol` identifica o
ticker enviado e `symbol` identifica os dados retornados.
end_date: Data final no formato YYYY-MM-DD. Filtra pela data de encerramento do período.
period: Período de cada linha: anual ou trimestral.
start_date: Data inicial no formato YYYY-MM-DD. Filtra pela data de encerramento do período.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return self._get(
"/api/v2/stocks/cash-flow",
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"symbols": symbols,
"end_date": end_date,
"period": period,
"start_date": start_date,
},
stock_cash_flow_params.StockCashFlowParams,
),
),
cast_to=StockCashFlowResponse,
)
def dividends(
self,
*,
symbols: str,
end_date: str | Omit = omit,
include_raw: Literal["true", "false"] | Omit = omit,
sort_by: Literal["paymentDate", "lastDatePrior", "approvedOn", "rate"] | Omit = omit,
sort_order: Literal["asc", "desc"] | Omit = omit,
start_date: str | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> StockDividendsResponse:
"""
Proventos de ações brasileiras: dividendos, JCP, bonificações, desdobramentos,
grupamentos e subscrições, com valor por ação, data-com, data ex e data de
pagamento.
Use para calcular dividend yield, montar calendários de proventos e registrar
proventos em carteiras.
Em conversões de ações, os proventos de cada classe permanecem separados. Uma
consulta por AXIA6 retorna os proventos de AXIA6 e ELET6.
Os proventos de LCAM3 e BRFS3 permanecem separados de RENT3 e MBRF3. PRGA3 usa
BRFS3. MRFG3 usa MBRF3.
Os proventos disponíveis podem ser consultados mesmo quando o ticker não tem
cotação atual.
`lastDatePrior` é a data-com, o último dia para comprar a ação e ter direito ao
provento. `exDate` é a data ex, o primeiro dia sem esse direito. `exDate` pode
ser nulo.
`startDate` e `endDate` filtram proventos em dinheiro por `paymentDate` e
eventos em ações por `lastDatePrior`.
`includeRaw=true` exige o plano Pro. Ele adiciona `rawRate`, o valor por ação na
escala dos preços sem ajuste.
FIIs não entram aqui. Um ticker de FII retorna erro 400. Use
[dividendos de FIIs](https://brapi.dev/docs/fiis/dividendos).
Args:
symbols: Tickers separados por vírgula. Ex.: PETR4,VALE3. `requestedSymbol` identifica o
ticker enviado e `symbol` identifica os dados retornados.
end_date: Data final no formato YYYY-MM-DD. Filtra proventos em dinheiro por `paymentDate`
e eventos em ações por `lastDatePrior`.
include_raw: Inclui `rawRate`, o valor por ação na escala dos preços sem ajuste. Exige o
plano Pro.
sort_by: Campo de ordenação dos eventos.
sort_order: Ordem dos eventos.
start_date: Data inicial no formato YYYY-MM-DD. Filtra proventos em dinheiro por
`paymentDate` e eventos em ações por `lastDatePrior`.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return self._get(
"/api/v2/stocks/dividends",
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"symbols": symbols,
"end_date": end_date,
"include_raw": include_raw,
"sort_by": sort_by,
"sort_order": sort_order,
"start_date": start_date,
},
stock_dividends_params.StockDividendsParams,
),
),
cast_to=StockDividendsResponse,
)
def financial_data(
self,
*,
symbols: str,
end_date: str | Omit = omit,
mode: Literal["current", "history"] | Omit = omit,
period: Literal["annual", "quarterly"] | Omit = omit,
start_date: str | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> StockFinancialDataResponse:
"""
Receita, lucro, EBITDA, margens, dívida, caixa e fluxo de caixa livre de uma
empresa, em um único objeto.
Use para ver o resumo financeiro sem ler cada demonstração.
O padrão `mode=current` traz os últimos 12 meses. `mode=history` traz a série
anual ou trimestral, conforme `period`, filtrada por `startDate` e `endDate`.
Para as linhas completas, use
[balanço patrimonial](https://brapi.dev/docs/acoes/balanco-patrimonial),
[DRE](https://brapi.dev/docs/acoes/dre) e
[fluxo de caixa](https://brapi.dev/docs/acoes/fluxo-de-caixa).
Args:
symbols: Tickers separados por vírgula. Ex.: PETR4,VALE3. `requestedSymbol` identifica o
ticker enviado e `symbol` identifica os dados retornados.
end_date: Data final no formato YYYY-MM-DD. Filtra pela data de encerramento do período.
mode: `current` traz o valor atual. `history` traz a série definida por `period`.
period: Período de cada linha: anual ou trimestral.
start_date: Data inicial no formato YYYY-MM-DD. Filtra pela data de encerramento do período.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return self._get(
"/api/v2/stocks/financial-data",
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"symbols": symbols,
"end_date": end_date,
"mode": mode,
"period": period,
"start_date": start_date,
},
stock_financial_data_params.StockFinancialDataParams,
),
),
cast_to=StockFinancialDataResponse,
)
def historical(
self,
*,
symbols: str,
end_date: str | Omit = omit,
include_raw: Literal["true", "false"] | Omit = omit,
interval: Literal["1m", "2m", "5m", "15m", "30m", "60m", "90m", "1h", "1d", "5d", "1wk", "1mo", "3mo"]
| Omit = omit,
range: Literal["1d", "2d", "5d", "7d", "1mo", "3mo", "6mo", "1y", "2y", "5y", "10y", "ytd", "max"]
| Omit = omit,
sort_order: Literal["asc", "desc"] | Omit = omit,
start_date: str | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> StockHistoricalResponse:
"""
Série de preços por pregão com abertura, máxima, mínima, fechamento, fechamento
ajustado e volume. Serve para ações, FIIs, BDRs, ETFs, units e índices com
histórico.
Use para gráficos, backtests e cálculo de retorno.
Em conversões de ações, use o ticker original para consultar o histórico daquela
classe. Por exemplo, AXIA6 mantém seu próprio histórico.
LCAM3 e BRFS3 também mantêm históricos próprios, separados de RENT3 e MBRF3.
PRGA3 usa a série de BRFS3. MRFG3 usa MBRF3.
O histórico disponível pode ser consultado mesmo quando o ticker não tem cotação
atual.
Defina a janela com `range` e `interval`, por exemplo `range=1y&interval=1d`, ou
com `startDate` e `endDate`. O padrão é `range=1mo` e `interval=1d`.
O plano define os valores aceitos em `range` e `interval` e o tamanho máximo da
janela por data. Um pedido acima do limite do plano retorna erro 400.
Em intervalos diários, `open`, `high`, `low` e `close` podem vir ajustados.
Nesses pontos, `close` coincide com `adjustedClose`. Outros pontos podem trazer
`close` sem ajuste ou `adjustedClose` nulo. Os campos `raw*`, quando
disponíveis, trazem os preços originais.
Use `adjustedClose` para calcular retorno diário. Ele considera proventos,
desdobramentos e grupamentos.
`includeRaw=true` exige o plano Pro. Em intervalos diários, ele adiciona
`rawOpen`, `rawHigh`, `rawLow` e `rawClose`, os preços originais sem ajuste.
Esses campos podem ser nulos. Intervalos intradiários não trazem campos `raw*`.
Args:
symbols: Tickers separados por vírgula. Ex.: PETR4,VALE3. `requestedSymbol` identifica o
ticker enviado e `symbol` identifica os dados retornados.
end_date: Data final no formato YYYY-MM-DD.
include_raw: Inclui os preços originais sem ajuste (`rawOpen`, `rawHigh`, `rawLow`,
`rawClose`) em intervalos diários. Exige o plano Pro.
interval: Intervalo entre os pontos. Padrão: 1d.
range: Janela relativa. Padrão: 1mo.
sort_order: Ordem dos pontos por data.
start_date: Data inicial no formato YYYY-MM-DD.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return self._get(
"/api/v2/stocks/historical",
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"symbols": symbols,
"end_date": end_date,
"include_raw": include_raw,
"interval": interval,
"range": range,
"sort_order": sort_order,
"start_date": start_date,
},
stock_historical_params.StockHistoricalParams,
),
),
cast_to=StockHistoricalResponse,
)
def income_statement(
self,
*,
symbols: str,
end_date: str | Omit = omit,
period: Literal["annual", "quarterly"] | Omit = omit,
start_date: str | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> StockIncomeStatementResponse:
"""
Demonstração de resultado de empresas listadas: receita, custos, lucro bruto,
despesas operacionais, resultado financeiro, impostos e lucro líquido. Uma linha
por período, do mais recente para o mais antigo.
Use para acompanhar resultados, margens e crescimento de lucro.
O padrão é `period=annual`. Use `period=quarterly` para trimestres. `startDate`
e `endDate` filtram pela data de encerramento do período.
Cada trimestre traz o valor do trimestre isolado, sem somar os trimestres
anteriores do ano.
Os trimestres usam a mesma base, consolidada ou individual, do relatório anual
do mesmo ano. Sem relatório anual, a base é a que tem o trimestre mais recente.
Em empate, a consolidada vale. Lacunas não são preenchidas com a outra base. Um
período sem os dados necessários para o cálculo retorna `null`.
Args:
symbols: Tickers separados por vírgula. Ex.: PETR4,VALE3. `requestedSymbol` identifica o
ticker enviado e `symbol` identifica os dados retornados.
end_date: Data final no formato YYYY-MM-DD. Filtra pela data de encerramento do período.
period: Período de cada linha: anual ou trimestral.
start_date: Data inicial no formato YYYY-MM-DD. Filtra pela data de encerramento do período.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return self._get(
"/api/v2/stocks/income-statement",
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"symbols": symbols,
"end_date": end_date,
"period": period,
"start_date": start_date,
},
stock_income_statement_params.StockIncomeStatementParams,
),
),
cast_to=StockIncomeStatementResponse,
)
def insider_transactions(
self,
*,
symbols: str,
all_versions: Literal["true", "false"] | Omit = omit,
company_relation: Literal["company", "parent", "subsidiary", "all"] | Omit = omit,
direction: Literal["credit", "debit"] | Omit = omit,
end_date: str | Omit = omit,
limit: int | Omit = omit,
movement_type: str | Omit = omit,
page: int | Omit = omit,
role_group: Literal["controller", "board", "director", "fiscalCouncil", "statutoryBody"] | Omit = omit,
start_date: str | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> StockInsiderTransactionsResponse:
"""
Movimentações de valores mobiliários por administradores, controladores e
pessoas vinculadas, por empresa e período. Os relatórios são mensais. A
atualização ocorre semanalmente.
O ticker identifica a empresa do relatório. PETR3 e PETR4 retornam os mesmos
dados. Os registros agrupam pessoas por cargo, sem identificar cada pessoa ou o
ticker negociado.
`direction` indica entrada ou saída da posição, inclusive transferências. Use
`movementType` para identificar compras e vendas.
A resposta traz as movimentações mais recentes primeiro e a última versão de
cada relatório. Use `allVersions=true` para incluir versões anteriores. Não some
essas versões, pois elas podem repetir movimentações. Saldos iniciais não entram
na lista.
Plano Pro. PETR4, MGLU3, VALE3 e ITUB4 permitem testes gratuitos, sem token.
Args:
symbols: Tickers separados por vírgula. Máximo de 20. Cada ticker identifica a empresa
que apresenta o relatório.
all_versions: Inclui versões anteriores dos relatórios. Padrão: false. Versões anteriores
podem repetir movimentações.
company_relation: Empresa que emite o valor mobiliário: a própria empresa, sua controladora ou sua
controlada.
direction: Entrada ou saída da posição. Inclui transferências e outras movimentações.
end_date: Data final da movimentação. Padrão: hoje.
limit: Máximo de movimentações por empresa e página.
movement_type: Tipo de movimentação, com o texto exato do relatório.
page: Página de cada empresa.
role_group: Grupo de cargos. Cada grupo inclui pessoas vinculadas.
start_date: Data inicial da movimentação. Padrão: 365 dias antes de endDate.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return self._get(
"/api/v2/stocks/insider-transactions",
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"symbols": symbols,
"all_versions": all_versions,
"company_relation": company_relation,
"direction": direction,
"end_date": end_date,
"limit": limit,
"movement_type": movement_type,
"page": page,
"role_group": role_group,
"start_date": start_date,
},
stock_insider_transactions_params.StockInsiderTransactionsParams,
),
),
cast_to=StockInsiderTransactionsResponse,
)
def profile(
self,
*,
symbols: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> StockProfileResponse:
"""
Dados cadastrais da empresa por trás do ticker: razão social, CNPJ, setor,
indústria, endereço, site, telefone, número de funcionários e descrição da
atividade.
Use para páginas de empresa, filtros por setor e cadastro de ativos em
carteiras.
Esses dados quase não mudam. Guarde a resposta e consulte de novo poucas vezes.
Args:
symbols: Tickers separados por vírgula. Ex.: PETR4,VALE3. `requestedSymbol` identifica o
ticker enviado e `symbol` identifica os dados retornados.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return self._get(
"/api/v2/stocks/profile",
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform({"symbols": symbols}, stock_profile_params.StockProfileParams),
),
cast_to=StockProfileResponse,
)
def quote(
self,
*,
symbols: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> StockQuoteResponse:
"""
Preço, variação, volume, market cap, máxima e mínima do dia, faixa de 52 semanas
e logo de ações, FIIs, BDRs, ETFs, units e índices brasileiros.
Use para telas de cotação, carteiras, alertas de preço e widgets.
Envie vários tickers em `symbols`, separados por vírgula. O número máximo de
tickers por chamada depende do plano.
Quando alguns tickers não existem, eles ficam fora de `results`. Se nenhum
ticker tem cotação, a resposta retorna 404.
Um ticker antigo é trocado pelo ticker atual. Nesse caso, `changed` é `true` e
`requestedSymbol` guarda o ticker enviado.
AXIA5 e AXIA6 retornam a cotação de uma ação AXIA3. Consulte a resolução de
tickers para ver a proporção de conversão.
Para a série de preços, use o
[histórico de preços](https://brapi.dev/docs/acoes/historico). Para achar
tickers válidos, use a [lista de tickers](https://brapi.dev/docs/tickers).
Args:
symbols: Tickers separados por vírgula. Ex.: PETR4,VALE3. `requestedSymbol` identifica o
ticker enviado e `symbol` identifica os dados retornados.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return self._get(
"/api/v2/stocks/quote",
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform({"symbols": symbols}, stock_quote_params.StockQuoteParams),
),
cast_to=StockQuoteResponse,
)
def screener(
self,
*,
book_value_per_share_max: float | Omit = omit,
book_value_per_share_min: float | Omit = omit,
change_percent_max: float | Omit = omit,
change_percent_min: float | Omit = omit,
current_ratio_max: float | Omit = omit,
current_ratio_min: float | Omit = omit,
debt_to_equity_max: float | Omit = omit,
debt_to_equity_min: float | Omit = omit,
dividend_yield_max: float | Omit = omit,
dividend_yield_min: float | Omit = omit,
earnings_growth_annual_max: float | Omit = omit,
earnings_growth_annual_min: float | Omit = omit,
earnings_growth_max: float | Omit = omit,
earnings_growth_min: float | Omit = omit,
earnings_per_share_max: float | Omit = omit,
earnings_per_share_min: float | Omit = omit,
ebitda_margin_max: float | Omit = omit,
ebitda_margin_min: float | Omit = omit,
ebitda_max: float | Omit = omit,
ebitda_min: float | Omit = omit,
enterprise_to_ebitda_max: float | Omit = omit,
enterprise_to_ebitda_min: float | Omit = omit,
enterprise_to_revenue_max: float | Omit = omit,
enterprise_to_revenue_min: float | Omit = omit,
enterprise_value_max: float | Omit = omit,
enterprise_value_min: float | Omit = omit,
fifty_two_week_change_max: float | Omit = omit,
fifty_two_week_change_min: float | Omit = omit,
free_cashflow_max: float | Omit = omit,
free_cashflow_min: float | Omit = omit,
gross_margin_max: float | Omit = omit,
gross_margin_min: float | Omit = omit,
last_price_max: float | Omit = omit,
last_price_min: float | Omit = omit,
limit: int | Omit = omit,
market_cap_max: float | Omit = omit,
market_cap_min: float | Omit = omit,
net_debt_to_ebitda_max: float | Omit = omit,
net_debt_to_ebitda_min: float | Omit = omit,
net_margin_max: float | Omit = omit,
net_margin_min: float | Omit = omit,
operating_margin_max: float | Omit = omit,
operating_margin_min: float | Omit = omit,
page: int | Omit = omit,
peg_ratio_max: float | Omit = omit,
peg_ratio_min: float | Omit = omit,
price_to_book_max: float | Omit = omit,
price_to_book_min: float | Omit = omit,
quick_ratio_max: float | Omit = omit,
quick_ratio_min: float | Omit = omit,
return_on_assets_max: float | Omit = omit,
return_on_assets_min: float | Omit = omit,
return_on_equity_max: float | Omit = omit,
return_on_equity_min: float | Omit = omit,
revenue_growth_annual_max: float | Omit = omit,
revenue_growth_annual_min: float | Omit = omit,
revenue_growth_max: float | Omit = omit,
revenue_growth_min: float | Omit = omit,
search: str | Omit = omit,
sector: str | Omit = omit,
sort_by: Literal[
"symbol",
"name",
"lastPrice",
"changePercent",
"volume",
"marketCap",
"trailingPE",
"priceToBook",
"enterpriseToEbitda",
"enterpriseToRevenue",
"pegRatio",
"earningsPerShare",
"bookValuePerShare",
"netMargin",
"enterpriseValue",
"fiftyTwoWeekChange",
"dividendYield",
"returnOnEquity",
"returnOnAssets",
"grossMargin",
"ebitdaMargin",
"operatingMargin",
"debtToEquity",
"netDebtToEbitda",
"currentRatio",
"quickRatio",
"revenueGrowth",
"earningsGrowth",
"revenueGrowthAnnual",
"earningsGrowthAnnual",
"totalRevenue",
"ebitda",
"freeCashflow",
"totalDebt",
"totalCash",
]
| Omit = omit,
sort_order: Literal["asc", "desc"] | Omit = omit,
subsector: str | Omit = omit,
sub_type: Literal["stock", "unit", "fii", "etf", "fi-infra", "fi-agro", "fip", "fidc", "bdr"] | Omit = omit,
total_cash_max: float | Omit = omit,
total_cash_min: float | Omit = omit,
total_debt_max: float | Omit = omit,
total_debt_min: float | Omit = omit,
total_revenue_max: float | Omit = omit,
total_revenue_min: float | Omit = omit,
trailing_pe_max: float | Omit = omit,
trailing_pe_min: float | Omit = omit,
type: Literal["stock", "fund", "bdr"] | Omit = omit,
volume_max: float | Omit = omit,
volume_min: float | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> StockScreenerResponse:
"""
Filtra e ordena ações da B3 por preço e indicadores fundamentalistas, como P/L,
P/VP, dividend yield e ROE. Uma chamada percorre todas as ações.
Cada indicador aceita `{chave}Min` e `{chave}Max`. Os limites são inclusivos e
usam a mesma unidade da resposta. Frações seguem `/api/v2/stocks/statistics` e
`/api/v2/stocks/financial-data`: 6% é `0.06`. Um filtro remove os ativos sem o
dado. Na ordenação, os nulos ficam no fim.
Exemplos:
- P/L entre 0 e 8 e dividend yield de pelo menos 6%:
`?trailingPEMin=0&trailingPEMax=8÷ndYieldMin=0.06&sortBy=dividendYield`
- ROE de pelo menos 15%, do maior para o menor:
`?returnOnEquityMin=0.15&sortBy=returnOnEquity`
Empresas com prejuízo têm P/L negativo. Para excluí-las, envie `trailingPEMin=0`
junto com `trailingPEMax`.
`quote` e `dividendYield` usam o último preço. P/L, P/VP e os outros indicadores
usam o preço da atualização diária dos fundamentos. Em units, P/L e P/VP usam o
último preço da unit. `dividendYield` soma os proventos em dinheiro dos últimos
12 meses.
Planos Startup e Pro. Os indicadores do plano Pro não vêm em `metrics` no plano
Startup. Um filtro ou uma ordenação com esses indicadores no plano Startup
retorna 403.
| Indicador | Chave | Unidade | Plano |
| ---------------------------- | ---------------------- | -------------------------- | ------------- |
| Preço | `lastPrice` | reais | Startup e Pro |
| Variação no dia | `changePercent` | porcentagem (2.81 = 2,81%) | Startup e Pro |
| Volume | `volume` | ações | Startup e Pro |
| Valor de mercado | `marketCap` | reais | Startup e Pro |
| P/L | `trailingPE` | múltiplo | Startup e Pro |
| P/VP | `priceToBook` | múltiplo | Startup e Pro |
| EV/EBITDA | `enterpriseToEbitda` | múltiplo | Startup e Pro |
| EV/Receita | `enterpriseToRevenue` | múltiplo | Startup e Pro |
| PEG | `pegRatio` | múltiplo | Startup e Pro |
| LPA | `earningsPerShare` | reais | Startup e Pro |
| VPA | `bookValuePerShare` | reais | Startup e Pro |
| Margem líquida | `netMargin` | fração (0.06 = 6%) | Startup e Pro |
| Valor da firma | `enterpriseValue` | reais | Startup e Pro |
| Variação 52 semanas | `fiftyTwoWeekChange` | fração (0.06 = 6%) | Startup e Pro |
| Dividend yield | `dividendYield` | fração (0.06 = 6%) | Startup e Pro |
| ROE | `returnOnEquity` | fração (0.06 = 6%) | Pro |
| ROA | `returnOnAssets` | fração (0.06 = 6%) | Pro |
| Margem bruta | `grossMargin` | fração (0.06 = 6%) | Pro |
| Margem EBITDA | `ebitdaMargin` | fração (0.06 = 6%) | Pro |
| Margem operacional | `operatingMargin` | fração (0.06 = 6%) | Pro |
| Dívida/PL | `debtToEquity` | múltiplo | Pro |
| Dívida líquida/EBITDA | `netDebtToEbitda` | múltiplo | Pro |
| Liquidez corrente | `currentRatio` | múltiplo | Pro |
| Liquidez seca | `quickRatio` | múltiplo | Pro |
| Crescimento da receita | `revenueGrowth` | fração (0.06 = 6%) | Pro |
| Crescimento do lucro | `earningsGrowth` | fração (0.06 = 6%) | Pro |
| Crescimento anual da receita | `revenueGrowthAnnual` | fração (0.06 = 6%) | Pro |
| Crescimento anual do lucro | `earningsGrowthAnnual` | fração (0.06 = 6%) | Pro |
| Receita | `totalRevenue` | reais | Pro |
| EBITDA | `ebitda` | reais | Pro |
| Fluxo de caixa livre | `freeCashflow` | reais | Pro |
| Dívida bruta | `totalDebt` | reais | Pro |
| Caixa | `totalCash` | reais | Pro |
Args:
book_value_per_share_max: VPA: valor máximo, inclusive. Unidade: reais. Plano Startup e Pro.
book_value_per_share_min: VPA: valor mínimo, inclusive. Unidade: reais. Plano Startup e Pro.
change_percent_max: Variação no dia: valor máximo, inclusive. Unidade: porcentagem (2.81 = 2,81%).
Plano Startup e Pro.
change_percent_min: Variação no dia: valor mínimo, inclusive. Unidade: porcentagem (2.81 = 2,81%).
Plano Startup e Pro.
current_ratio_max: Liquidez corrente: valor máximo, inclusive. Unidade: múltiplo. Plano Pro.
current_ratio_min: Liquidez corrente: valor mínimo, inclusive. Unidade: múltiplo. Plano Pro.
debt_to_equity_max: Dívida/PL: valor máximo, inclusive. Unidade: múltiplo. Plano Pro.
debt_to_equity_min: Dívida/PL: valor mínimo, inclusive. Unidade: múltiplo. Plano Pro.
dividend_yield_max: Dividend yield: valor máximo, inclusive. Unidade: fração (0.06 = 6%). Plano
Startup e Pro.
dividend_yield_min: Dividend yield: valor mínimo, inclusive. Unidade: fração (0.06 = 6%). Plano
Startup e Pro.
earnings_growth_annual_max: Crescimento anual do lucro: valor máximo, inclusive. Unidade: fração (0.06 =
6%). Plano Pro.
earnings_growth_annual_min: Crescimento anual do lucro: valor mínimo, inclusive. Unidade: fração (0.06 =
6%). Plano Pro.
earnings_growth_max: Crescimento do lucro: valor máximo, inclusive. Unidade: fração (0.06 = 6%).
Plano Pro.
earnings_growth_min: Crescimento do lucro: valor mínimo, inclusive. Unidade: fração (0.06 = 6%).
Plano Pro.
earnings_per_share_max: LPA: valor máximo, inclusive. Unidade: reais. Plano Startup e Pro.
earnings_per_share_min: LPA: valor mínimo, inclusive. Unidade: reais. Plano Startup e Pro.
ebitda_margin_max: Margem EBITDA: valor máximo, inclusive. Unidade: fração (0.06 = 6%). Plano Pro.
ebitda_margin_min: Margem EBITDA: valor mínimo, inclusive. Unidade: fração (0.06 = 6%). Plano Pro.
ebitda_max: EBITDA: valor máximo, inclusive. Unidade: reais. Plano Pro.
ebitda_min: EBITDA: valor mínimo, inclusive. Unidade: reais. Plano Pro.
enterprise_to_ebitda_max: EV/EBITDA: valor máximo, inclusive. Unidade: múltiplo. Plano Startup e Pro.
enterprise_to_ebitda_min: EV/EBITDA: valor mínimo, inclusive. Unidade: múltiplo. Plano Startup e Pro.
enterprise_to_revenue_max: EV/Receita: valor máximo, inclusive. Unidade: múltiplo. Plano Startup e Pro.
enterprise_to_revenue_min: EV/Receita: valor mínimo, inclusive. Unidade: múltiplo. Plano Startup e Pro.
enterprise_value_max: Valor da firma: valor máximo, inclusive. Unidade: reais. Plano Startup e Pro.
enterprise_value_min: Valor da firma: valor mínimo, inclusive. Unidade: reais. Plano Startup e Pro.
fifty_two_week_change_max: Variação 52 semanas: valor máximo, inclusive. Unidade: fração (0.06 = 6%). Plano
Startup e Pro.
fifty_two_week_change_min: Variação 52 semanas: valor mínimo, inclusive. Unidade: fração (0.06 = 6%). Plano
Startup e Pro.
free_cashflow_max: Fluxo de caixa livre: valor máximo, inclusive. Unidade: reais. Plano Pro.
free_cashflow_min: Fluxo de caixa livre: valor mínimo, inclusive. Unidade: reais. Plano Pro.
gross_margin_max: Margem bruta: valor máximo, inclusive. Unidade: fração (0.06 = 6%). Plano Pro.
gross_margin_min: Margem bruta: valor mínimo, inclusive. Unidade: fração (0.06 = 6%). Plano Pro.
last_price_max: Preço: valor máximo, inclusive. Unidade: reais. Plano Startup e Pro.