Petersoj / alpaca-java

A Java API for Alpaca, the commission free, algo friendly, stock trading broker. https://alpaca.markets
https://petersoj.github.io/alpaca-java/
MIT License
197 stars 82 forks source link

getBars() returns wrong daily close price, volume, etc #142

Open jan-feb-sfr opened 7 months ago

jan-feb-sfr commented 7 months ago

Hello,

I just tried to use Java API to get AAPL daily bars, but it seems to return the wrong data that is different from Alpaca python API, which returns the correct data. Wonder if it's a bug or a wrong use of API. I put the java code's output in section 2), and I also put python code's output in section 3). You can see most of close, high, low and volume data don't match. But I double checked the output from python code, which seems to be aligned with Yahoo, Tradeview data, but the data obtained from Alpaca Java API, always seems to be off a bit. Thanks for your help in advance.

1) Here is the code

        StockBarsResponse aaplBarsResponse = alpacaAPI.stockMarketData().getBars(
               "AAPL",
                ZonedDateTime.of(2021, 2, 10, 9, 30, 0, 0, ZoneId.of("America/New_York")),
                ZonedDateTime.of(2023, 11, 23, 12 + 4, 0, 0, 0, ZoneId.of("America/New_York")),
                null,
                null,
                1,
                BarTimePeriod.DAY,
                BarAdjustment.SPLIT,
                BarFeed.IEX);
        aaplBarsResponse.getBars().forEach(System.out::println);

2) Here is the response of the last 10 bars

net.jacobpeterson.alpaca.model.endpoint.marketdata.stock.historical.bar.StockBar@54c5a2ff[timestamp=2023-11-08T05:00Z,open=182.29,high=183.435,low=181.62,close=182.89,tradeCount=9599,vwap=182.625857,volume=862999] net.jacobpeterson.alpaca.model.endpoint.marketdata.stock.historical.bar.StockBar@6d4d66d2[timestamp=2023-11-09T05:00Z,open=182.93,high=184.07,low=181.82,close=182.48,tradeCount=9572,vwap=182.900363,volume=906460] net.jacobpeterson.alpaca.model.endpoint.marketdata.stock.historical.bar.StockBar@2a265ea9[timestamp=2023-11-10T05:00Z,open=183.92,high=186.555,low=183.58,close=186.335,tradeCount=16304,vwap=185.137374,volume=1769685] net.jacobpeterson.alpaca.model.endpoint.marketdata.stock.historical.bar.StockBar@11392934[timestamp=2023-11-13T05:00Z,open=185.83,high=186.015,low=184.24,close=184.76,tradeCount=9956,vwap=184.782387,volume=899630] net.jacobpeterson.alpaca.model.endpoint.marketdata.stock.historical.bar.StockBar@6892b3b6[timestamp=2023-11-14T05:00Z,open=187.63,high=188.1,low=186.34,close=187.41,tradeCount=13996,vwap=187.288773,volume=1413535] net.jacobpeterson.alpaca.model.endpoint.marketdata.stock.historical.bar.StockBar@6e6f2380[timestamp=2023-11-15T05:00Z,open=187.99,high=189.49,low=187.785,close=188.15,tradeCount=9738,vwap=188.517042,volume=816730] net.jacobpeterson.alpaca.model.endpoint.marketdata.stock.historical.bar.StockBar@76a4ebf2[timestamp=2023-11-16T05:00Z,open=189.59,high=190.945,low=188.735,close=189.8,tradeCount=12849,vwap=189.691769,volume=1032052] net.jacobpeterson.alpaca.model.endpoint.marketdata.stock.historical.bar.StockBar@2e8c1c9b[timestamp=2023-11-17T05:00Z,open=190.255,high=190.35,low=188.58,close=189.75,tradeCount=7781,vwap=189.578897,volume=591204] net.jacobpeterson.alpaca.model.endpoint.marketdata.stock.historical.bar.StockBar@53fe15ff[timestamp=2023-11-20T05:00Z,open=189.995,high=191.9,low=189.94,close=191.52,tradeCount=8736,vwap=191.30822,volume=716956] net.jacobpeterson.alpaca.model.endpoint.marketdata.stock.historical.bar.StockBar@449a4f23[timestamp=2023-11-21T05:00Z,open=191.485,high=191.485,low=189.75,close=190.66,tradeCount=7083,vwap=190.474958,volume=671770] net.jacobpeterson.alpaca.model.endpoint.marketdata.stock.historical.bar.StockBar@1530c739[timestamp=2023-11-22T05:00Z,open=191.58,high=192.93,low=190.84,close=191.31,tradeCount=7212,vwap=191.79077,volume=706624]

3) Here is the response of the last 10 bars from Python Alpaca API and seems to be correct

timestamp close high low trade_count open volume vwap 2023-11-08 05:00:00+00:00 182.890 183.4500 181.5900 542542 182.350 49345307 182.656617 2023-11-09 05:00:00+00:00 182.410 184.1200 181.8100 545850 182.960 53780415 182.911582 2023-11-10 05:00:00+00:00 186.400 186.5650 183.5300 610940 183.970 66204156 185.410765 2023-11-13 05:00:00+00:00 184.800 186.0300 184.2100 530523 185.820 43631574 184.831737 2023-11-14 05:00:00+00:00 187.440 188.1100 186.3000 609334 187.700 60113030 187.203828 2023-11-15 05:00:00+00:00 188.010 189.5000 187.7800 564663 187.845 53818016 188.420726 2023-11-16 05:00:00+00:00 189.710 190.9600 188.6500 621003 189.570 54426521 189.710967 2023-11-17 05:00:00+00:00 189.690 190.3800 188.5700 509736 190.250 50929177 189.600596 2023-11-20 05:00:00+00:00 191.450 191.9050 189.8800 554091 189.890 46543084 191.298471 2023-11-21 05:00:00+00:00 190.640 191.5200 189.7400 450941 191.410 38142232 190.510023 2023-11-22 05:00:00+00:00 191.310 192.9300 190.8250 463217 191.490 39620045 191.722436

Petersoj commented 7 months ago

Thanks for reporting this. I will look into this soon. Thanks for your patience.

Petersoj commented 3 months ago

Should be fixed in 10.0.0. Re-open if not.

jan-feb-sfr commented 1 month ago

Still it's incorrect after switching to alpacaAPI.marketData().stock().stockBars() in 10.0.1