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

alpacaAPI.getBars() not working as implemented #96

Closed hudsonbl closed 3 years ago

hudsonbl commented 3 years ago

The implementation of getBars(symbol, start, end, limit, ....). The method works but the start and end dates are switched. In the alpaca documentation, start implies the earliest date and the end date is the more recent to date. Instantiating the function that way resolves in a error "start cannot be after end". By switching the two, getBars(symbol, end, start, limit, ....), the function works as intended.

Petersoj commented 3 years ago

The following code snippet works as expected for me on alpaca-java 7.2.1:

BarsResponse appleBarsResponse = alpacaAPI.getBars(
                    "AAPL",
                    ZonedDateTime.of(2021, 2, 22, 9, 30, 0, 0, ZoneId.of("America/New_York")),
                    ZonedDateTime.of(2021, 2, 24, 12 + 4, 0, 0, 0, ZoneId.of("America/New_York")),
                    null,
                    null,
                    BarsTimeFrame.MINUTE);
            appleBarsResponse.getBars().forEach(System.out::println);

The method signature has the second argument as the 'start' and the third argument as the 'end' with 'start' as the earliest date and 'end' as the more recent to date. So everything is working as expected. Do you have a code snippet you could share?

hudsonbl commented 3 years ago

Ok it is behaving as expected. I confused the grammar in my own code.