-
-
Notifications
You must be signed in to change notification settings - Fork 93
How do I view the current price of a stock? #117
Sorry if this is a dumb question, I'm a bit of a novice programmer. Basically I'm trying to make a bracket order that automatically decides the stop-loss, stop-limit, and take profit based off percentage increases or decreases from the current price of the stock, but I haven't been able to find a way to see a stock's price in any of the documentation.
Thanks!
All reactions
Hey @AndrewC243,
You'll want to take a look at some of the examples provided in the README like the StockMarketDataEndpoint (which is used for historical and current stock data) and the StockMarketDataWebsocket (which is used for real-time streamed stock data). Here is the StockMarketDataEndpoint Javadoc and here is the StockMarketDataWebsocket Javadoc. Take a look at those Javadocs and examine the various methods they offer to get a better understanding of what stock data you can use in your trading application.
Additionally, I strongly encourage you to read through the entire Alpaca Trading API documentation and the Alpaca Stock Market Data API documentation to gain an understanding of ...
Replies: 2 comments
Hey @AndrewC243,
You'll want to take a look at some of the examples provided in the README like the StockMarketDataEndpoint (which is used for historical and current stock data) and the StockMarketDataWebsocket (which is used for real-time streamed stock data). Here is the StockMarketDataEndpoint Javadoc and here is the StockMarketDataWebsocket Javadoc. Take a look at those Javadocs and examine the various methods they offer to get a better understanding of what stock data you can use in your trading application.
Additionally, I strongly encourage you to read through the entire Alpaca Trading API documentation and the Alpaca Stock Market Data API documentation to gain an understanding of all the features Alpaca has to offer.
To answer your question directly, the following code snippet shows how you can get the current/latest price of AAPL:
// Print out latest AAPL trade
Trade latestAAPLTrade = alpacaAPI.stockMarketData().getLatestTrade("AAPL").getTrade();
System.out.printf("Latest AAPL Trade: %s\n", latestAAPLTrade);
Here is the Javadoc for the OrdersEndpoint which is used to request orders. In addition to the bracket market order method signature here, you also might want to check out the trailing stop percent order method signature here.
Let me know if you have any other questions! Don't forget to star this repository :)
All reactions
Thanks a bunch!