Skip to content

Navigation Menu

Sign in
Sign up

How do I view the current price of a stock? #117

Answered by Petersoj
AndrewC243 asked this question in Q&A
Discussion options

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!

You must be logged in to vote

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

Comment options

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 :)

You must be logged in to vote
0 replies
Answer selected by Petersoj
Comment options

Thanks a bunch!

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /