|
1 | 1 | import datetime
|
2 | 2 | import pandas as pd
|
| 3 | +from alpaca_trade_api import polygon |
3 | 4 | from alpaca_trade_api.polygon import REST
|
4 | 5 | import pytest
|
5 | 6 | import requests_mock
|
| 7 | +from alpaca_trade_api.polygon.rest import FinancialsReportType, FinancialsSort |
6 | 8 |
|
7 | 9 |
|
8 | 10 | @pytest.fixture
|
@@ -244,6 +246,82 @@ def test_polygon(reqmock):
|
244 | 246 | ret = cli.financials(['AAPL'])
|
245 | 247 | assert ret['AAPL'][0].reportDateStr == '2018-09-01'
|
246 | 248 |
|
| 249 | + # Financials v2 |
| 250 | + reqmock.get( |
| 251 | + endpoint('/reference/financials/AAPL', api_version='v2'), |
| 252 | + text=''' |
| 253 | + { |
| 254 | + "status": "OK", |
| 255 | + "results": [ |
| 256 | + { |
| 257 | + "earningsPerBasicShare": 11.97, |
| 258 | + "payoutRatio": 0.251, |
| 259 | + "updated": "2020-05-01", |
| 260 | + "workingCapital": 57101000000, |
| 261 | + "earningsBeforeInterestTaxesDepreciationAmortizationUSD": |
| 262 | + 78284000000, |
| 263 | + "priceEarnings": 20.003, |
| 264 | + "dividendYield": 0.012, |
| 265 | + "period": "Y", |
| 266 | + "earningsBeforeInterestTaxesDepreciationAmortization": 78284000000, |
| 267 | + "earningBeforeInterestTaxesUSD": 65737000000, |
| 268 | + "preferredDividendsIncomeStatementImpact": 0, |
| 269 | + "dividendsPerBasicCommonShare": 3, |
| 270 | + "earningsBeforeTax": 65737000000, |
| 271 | + "dateKey": "2019-10-31", |
| 272 | + "earningsPerDilutedShare": 11.89, |
| 273 | + "earningsPerBasicShareUSD": 11.97, |
| 274 | + "ticker": "AAPL", |
| 275 | + "earningBeforeInterestTaxes": 65737000000 |
| 276 | + }, |
| 277 | + { |
| 278 | + "earningsPerBasicShare": 12.01, |
| 279 | + "enterpriseValueOverEBIT": 14, |
| 280 | + "workingCapital": 14473000000, |
| 281 | + "priceToBookValue": 8.928, |
| 282 | + "weightedAverageSharesDiluted": 5000109000, |
| 283 | + "period": "Y", |
| 284 | + "priceSales": 3.602, |
| 285 | + "earningsBeforeInterestTaxesDepreciationAmortization": 83806000000, |
| 286 | + "tradeAndNonTradeReceivables": 48995000000, |
| 287 | + "totalLiabilities": 258578000000, |
| 288 | + "earningsPerDilutedShare": 11.91, |
| 289 | + "calendarDate": "2018-12-31", |
| 290 | + "earningsPerBasicShareUSD": 12.01, |
| 291 | + "earningsBeforeTax": 72903000000, |
| 292 | + "priceEarnings": 16.069, |
| 293 | + "netIncomeCommonStockUSD": 59531000000, |
| 294 | + "netIncomeCommonStock": 59531000000, |
| 295 | + "enterpriseValueOverEBITDA": 12.472, |
| 296 | + "earningBeforeInterestTaxesUSD": 72903000000, |
| 297 | + "effectOfExchangeRateChangesOnCash": 0, |
| 298 | + "updated": "2020-05-01", |
| 299 | + "earningsBeforeInterestTaxesDepreciationAmortizationUSD": |
| 300 | + 83806000000, |
| 301 | + "netIncome": 59531000000, |
| 302 | + "enterpriseValue": 1045194782820, |
| 303 | + "tradeAndNonTradePayables": 55888000000, |
| 304 | + "dateKey": "2018-11-05", |
| 305 | + "ticker": "AAPL", |
| 306 | + "weightedAverageShares": 4955377000, |
| 307 | + "preferredDividendsIncomeStatementImpact": 0, |
| 308 | + "earningBeforeInterestTaxes": 72903000000 |
| 309 | + } |
| 310 | + ] |
| 311 | +} |
| 312 | + ''', |
| 313 | + ) |
| 314 | + |
| 315 | + ret = cli.financials_v2('AAPL', |
| 316 | + 2, |
| 317 | + FinancialsReportType.Y, |
| 318 | + FinancialsSort.CalendarDateDesc) |
| 319 | + |
| 320 | + assert len(ret) == 2 |
| 321 | + assert type(ret) == polygon.entity.Financials |
| 322 | + assert type(ret[0]) == polygon.entity.Financial |
| 323 | + assert ret[0].ticker == "AAPL" |
| 324 | + |
247 | 325 | # News
|
248 | 326 | reqmock.get(
|
249 | 327 | endpoint('/meta/symbols/AAPL/news'),
|
|
0 commit comments