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

No ability to request last stock price #66

Closed eladkatz closed 3 years ago

eladkatz commented 4 years ago

I've written a very basic method and added it to the AlpacaAPI.java file on my local machine, but I wonder if you can add it to the official api. My code:

/**
 * The Last Quote API provides last quote details for a symbol.
 * @param symbol the symbol for which you'd like to get a quote
 * @return The last stock price in a Json format like:
 * {
 *   "status": "success",
 *   "symbol": "SPY",
 *   "last": {
 *     "askprice": 279.1,
 *     "asksize": 1,
 *     "askexchange": 15,
 *     "bidprice": 287.05,
 *     "bidsize": 10,
 *     "bidexchange": 17,
 *     "timestamp": 1588770424970329400
 *   }
 * }
 */
public JsonElement getLastQuote(String symbol){

    AlpacaRequestBuilder urlBuilder = new AlpacaRequestBuilder(baseDataUrl, AlpacaConstants.VERSION_1_ENDPOINT,
        AlpacaConstants.LASTQUOTE_ENDPOINT+ "/" + AlpacaConstants.STOCKS + "/" + symbol);

    HttpResponse<InputStream> response = alpacaRequest.invokeGet(urlBuilder);

    return alpacaRequest.getResponseJSON(response);
}

it's ugly, I know, but it works - I'd love to change it if it means that it will now be exposed...

Thanks, Elad

Petersoj commented 4 years ago

See my comment about this here. I started working on this PR, but then my summer job started to take priority. Feel free to contribute via the instructions in the aforementioned link. You can also see I added these endpoints on this commit on my fork. The only thing that's left is the streaming of Alpaca websocket data which has been started as seen in the latest commit on my fork.

Petersoj commented 3 years ago

The WIP PR for this is now available here. Should be done soon.

Petersoj commented 3 years ago

71 is now completed and will be integrated sometime this week which adds functionality for the new market data API.