Alpaca stock dashboard in OpenCode: paper trading key fix
Watch on YouTube ↗ Subscribe on YouTube ↗
Written guide: Six Agent Builds: Claude Code, Dashboards and Outreach Tools
An unfinished attempt to build a stock dashboard with Alpaca's API using OpenCode's free models. A detailed prompt from Claude Desktop scaffolds a Node.js and Express app with a WebSocket bridge, then a 401 Unauthorized error persists until Mike realizes the keys must come from the paper trading account and not the broker API. Prices then load, but the chart never renders by the end. Paper trading only, no real money, and the key is shown on screen and deleted later.
Video summary
The video covers 10 parts: Introduction to Alpaca API and project goals, Creating a detailed app prompt in Claude desktop, Setting up a free Alpaca developer account, Scaffolding the Node.js project using OpenCode, Reviewing the auto-generated project structure and files, How to generate and configure your Alpaca API keys, Running the local dev server and first dashboard test, Troubleshooting 401 Unauthorized errors with OpenCode, Fixing the Paper Trading connection and verifying data, and Adding live stock charts and console logging for debugging.
What this video covers
What you build
A local Node.js dashboard at localhost:3000 with an Alpaca client, routes for account, positions and orders, a WebSocket stream, a symbol lookup and a chart that is still not displaying.
Tools used
Key steps
- 0:44 - Write a detailed MVP prompt in Claude Desktop and paste it into OpenCode.
- 1:21 - Create a free Alpaca developer account.
- 2:18 - Let OpenCode scaffold the project with its free models.
- 5:35 - Generate API keys and enter them in the .env file.
- 7:07 - Run npm start and open the dashboard on localhost:3000.
- 8:00 - Chase the 401 error and let OpenCode read Alpaca's docs.
- 12:02 - Fix it by generating keys under the paper trading account, which gives a $100,000 test balance.
- 13:54 - Add console logging to debug the chart, which still does not render.
Not covered
- A working chart. The data arrives but nothing displays by the end of the video.
- Trading or investment advice. Only paper trading is used.
- Safe handling of API keys. A key is shown on screen and Mike says he deletes it later.
- The accuracy of the displayed prices, which Mike says he cannot confirm.
In this video
- 0:00 Introduction to Alpaca API and project goals
- 0:44 Creating a detailed app prompt in Claude desktop
- 1:21 Setting up a free Alpaca developer account
- 2:18 Scaffolding the Node.js project using OpenCode
- 3:15 Reviewing the auto-generated project structure and files
- 5:35 How to generate and configure your Alpaca API keys
- 7:07 Running the local dev server and first dashboard test
- 8:00 Troubleshooting 401 Unauthorized errors with OpenCode
- 12:02 Fixing the Paper Trading connection and verifying data
- 13:54 Adding live stock charts and console logging for debugging
Questions and answers
Why did the API return 401?
Mike had keys from the broker API, and the market data worked only after creating keys under the paper trading account.
Was real money involved?
No. The account is a sandbox or paper account with fake balances.
Which models did OpenCode use?
Free ones such as MiniMax 2.5, with Qwen and Kimi also available, per Mike.
Keep learning
Transcript
Hey there, welcome to the channel. This video tutorial is going to be slightly different than usual. I'm going to be playing around with Alpaca, which is a free API that you can use for tracking stock options and crypto. I'm going to leave a link in the description below where you can get started. It's completely free and that allows for real-time trading analysis as well. They provide the broker API, trading API.
So, in order to get started, I'm just going to scroll down here and I have the option to either choose trading or building. In this case, I'm not going to be trading real money. I just want to use the API to build a Node.js app. I'm just going to create my account, so I'll fill this out and while we're doing this, I'm also creating the detailed prompt over here in Claude Desktop. This is what I want to build, an Alpaca stock trading dashboard as an MVP.
Read the rest of the transcript
So, I want to build a minimum viable product. I'm just going to come over to OpenCode, which I've got running in terminal. I've already created a new project directory and we're just going to simply copy and paste in that entire prompt. And now we are building out the MVP essentially of a stock trading app. You can see it already has some fields in here for the API key, secret key, uh the URL and all of that stuff, but in order to get those, I will need
to create my free account. So, I'm just going to do that real quick. So, now that I've created my free account on Alpaca, I'm just going to go ahead and verify my email address on my phone. And now I just have to fill out some information here, which I'm going to do real quick. What best describes my product? Uh software as a service. We're going to put the partnership here. I'll just use technology partner. What type of investors are you targeting? Uh startup investors.
We'll enter in some information here. I'm going to skip that part and then we're just going to finish the setup. But the only thing I need now is the API key. So, we're going to come over to quick start API and we're just going to fill out some information here. And we should be able to get our API key relatively easily here. And while this is working over here, I'm also building the MVP of the app in OpenCode. This is completely free.
I'm using the free models. And as you can see, it's just building out looks like all of the CSS right now. If I want to take a look at the project directory, you can see it is in fact building out the files. And if I go ahead and open up the index.html file, we can see this is what it looks like. So, it's already been able to create this fairly detailed dashboard for the MVP in just a couple minutes using OpenCode completely for free.
So, that's pretty amazing. And right now, it's just creating the source route files. So, for market orders, positions, and account. It's going to go through and create all of those files as you can see it's doing over here. And I will need to enter in my API key soon here. So, I'm just going to go ahead and see if I can grab that real quick. Looks like it was able to generate a response here.
So, there's all of the data which we're going to need to parse. So, we're just going to go ahead and accept that. I'll go next. So, it successfully ran the request. This is going to take up to 10 minutes to generate the transaction details. So, we'll let we'll wait for this to continue running while we're building the app over here. If I go ahead and refresh my index file, you can see it is building out a fairly detailed dashboard over here.
And you can see there's the index or the stock market ticker that we want to track. Overall, I say it looks pretty good. I don't really want to use this for trading. I just want to use it for tracking different stock indexes. So, that's what we're building as an MVP. And you can see it is now finished uh all of these different things. So, it scaffolded the project structure and dependencies. It built the Alpaca client wrapper which is a JavaScript file.
It created the API routes, which I showed you earlier, implemented the web socket bridge, created Express server, it built HTML dashboard, which is what we're looking at over here, and also set up the CSS and implemented the front end as well. So, here's the project directory, which we can also see over here. It also installed a lot of the packages that it needed directly through OpenCode. So, these are all of the Node.js packages that it needs in the node modules folder.
It's also got public with the CSS and also app.js. So, if we want to see what that looks like, we can quickly and easily open it up over here. It's about a thousand lines long. I don't really know what any of this code does, but fact of the matter is I don't have to because it's just building everything for me. It's also got one called websocket.js, which is this file, and another one called alpaca.js.
So, I'm assuming this is what's in charge of pulling in the API data. Does have the API key and secret right here, which we're still trying to get through Alpaca. So, we'll see if we can just go ahead and grab that. So, we're going to wait for this to finish, and then we should be able to enter in the API key using the .env file. So, I'm just going to open that up, and you can see here's the different keys that we need to provide.
API key, secret key, base URL, and also the data URL. Uh it did take about 10 minutes to finish pulling in the request and generating a response, but now this is done. I'm just going to go next. And this is going to be the last step, hopefully right here, to pass on an order. We're just going to click on send. It'll generate the response, and then you click on next.
It says, "Now you know how to create an account, create an ACH relationship, fund an account, and place an order." Here in the dashboard, it says, "Number of active accounts, 101." So, here's all of my different account IDs, apparently, as well as different amounts. I'm assuming this is just for testing because obviously uh I haven't funded my account with any real money, but if I come over to the balance here, we can see I have $50,000 in here, which is a bit surprising.
So, if I click on that, executed, and we've got a net amount of $50,000 just for playing around. This is just a sandbox, so it's not actual real money, but you can see these are all just fake transactions, I guess. And we've got all the transfers orders over here. I'm still trying to figure out how to actually get my API key, but looks like I have now figured it out.
So, all you have to do is click on API devs, and then from here you can generate the API key. So, in this case, we're just going to use the base URL, and we're going to put the API key name right here, also the type. So, I just want to generate a client secret, and then the access controls, I'll just give it full access, and then we can go ahead and generate that API key.
I'm going to delete this later, so just know that it's not going to be available once you watch this video. I'm going to go ahead and copy and paste this. So, now you're just going to want to make sure that everything over here in the dot env file matches what is over here. So, I've got the API key, secret key, as well as the Alpaca base URL, which is this top one here.
Now that that information is entered in, we should just be able to do an npm start to run the server. I'm going to open up a new tab, and we're just going to run npm start in our project directory. So, you can see here it's started up the Alpaca trading dashboard on our localhost port 3000. If I go ahead and open that up, we can see that it is now running over here.
This looks very, very similar to the index.html file, because it is, but it's running on my server. If I enter in a stock symbol here, it should display the data. I can also refresh this as well, but it looks like it's having some issues connecting. If I want to figure out what's going on in the in the dashboard over here, I could just come over to OpenCode and say, for example, run a live test with the API key and confirm it's working.
So, we're just going to enter that in and it should be able to do a live test. Now that my server is started up over here, we can see that it has connected to the Alpaca data stream. Looks like the app disconnected from Alpaca and now it's connected again, which is happening over here in OpenCode. So, it's just going to first pull in my .env file and then test it. So, it's starting the server and it's testing the account API.
And it can just pretty much automatically go through and diagnose any issues. Now it's doing the full test. It's pulling out all my API keys and everything. It should be able to test and see what's going on over here and it will also automatically refresh. So, we should hopefully see some sort of live stock data being pulled in. The credentials are wrong, the account doesn't have paper trading enabled, or the credentials have been rotated/invalidated. So, just going to see what's going on here.
We may need to enable some other things over here inside the Alpaca dashboard, but we'll see what it says over here first. Obviously, this is a work in progress. I'm just getting started building this out and I figured why not make a tutorial while I'm doing it to share this as information with others. You can see it's relatively easy to set the set this up. Just have to go through the quick start guide over here, create your API key, and then start building.
I would recommend creating a very detailed prompt inside something like Claude to start because it's just going to give you a much better result right from the get-go, and then you can obviously fix up the app as much as you want to. This particular issue I'm having right now, uh I haven't exactly figured out what's going on, but I would like to at least see some sort of graph over here, as well as the stock data and positions and orders and all that sort of stuff
inside my dashboard. They also have a doc section over here if you hit any snags and you need help with anything, you just come over to Alpaca documentation. You can see they have uh client SDK which you can install which is just a Python package and then you can also grab your API keys, generate your API keys from the command line. And I just want to make sure that I'm using the right uh data URL.
Maybe it's this one right here, data.alpaca.markets which is what we have over here as well. So, that should be fine. So, we can come back over here and just do npm start. And we can load that up. And again, we're still not actually getting any details over here and I'm not getting logs as well. So, looks like it was able to connect to the data stream, no issue.
It looks like it is able to successfully connect to the Alpaca data stream, but then it just disconnects right away, reconnects, connected again. So, if I want to figure out what's going on with this, I could just basically copy and paste this and come on over to OpenCode and say diagnose the dev server run and then paste in the output. Normally, I'm very impressed by OpenCode, but it is having a bit of trouble with this particular one.
So now, since I still haven't been able to figure this out yet, I've just told it to read the docs over here getting started with market data API and it's going to fire up that URL and it should be able to diagnose the issue here. Says the keys are from the broker dashboard which is correct. It's going to update the code to use the broker API correctly.
So, I think it hasn't actually written the code correctly which is probably the main reason why we're not getting any data over here. It still says the API is still returning a 401 unauthorized. This confirms that the API credentials are invalid or the wrong type for this API. So, it's just going to go ahead and fix up a few things. It's going to modify the alpaca.js file and it says right here, "Found it.
The broker API uses HTTP basic authentication instead of this for headers." So, now it's going to update the code and going to update the web the websocket.js file using the data that I got from the documentation on Alpaca's website, which is pretty cool. Once this fix is in, we should be able to refresh the dev server and hopefully we'll start getting some data over here.
Aha, so after a lot of screwing around, it turns out that what I needed to do was create the API under the paper trading API account right here versus the broker API. So, in this case, I would need to switch over to this one. So, now I have a paper trading account with a balance of $100,000 for some reason. Then we can generate the new API key. So, this is the API key that I need, it turns out.
I'm just going to go ahead and copy and paste that in and then also same for the secret key. And now when it starts the server, there finally it says success true. Looks like the API is now working, which is definitely encouraging. And again, this is just a test account with $100,000 fake dollars in it. So, we're not actually using any real money. It's just a sandbox account for now. But we could see the fixes needed based on paper trading docs.
So, I went ahead and re- read the paper trading docs and I implemented the fixes. And you can see this is now verified working. It's got the account. It pulled in how much how much money I have in the account as well as positions, orders, market clock, historical bars, and the websocket. And now it says the dashboard is fully functional and I can use it at localhost:3000. Oh, there we go. We did get some data coming in. So, we have a stock ticker price over here.
If I type in Amazon, that is updating. So, we are actually able to get the stock ticker price. I'll put in AMD. And I don't know if that's the exact right price for AMD, but we are getting something over here. It just looks like it's having some issues actually loading and connecting. If I hit refresh, again, nothing happens, but it is definitely encouraging that we're getting some stock ticker prices coming in. That's a step in the right direction.
And if we want to buy anything, we can do that down here as well. We should be able to buy and sell. What I've gone ahead and done is type in OpenCode. When I enter it in a stock ticker symbol, display the graph below on the dashboard. So, what I want this to do is every time I enter in a new symbol over here, I want to see some sort of graphical representation um from Alpaca. So, we'll see if it's able to do that.
I think it's going to need to modify the alpaca.js file and maybe a couple other ones. We'll see what it actually does. So, now it's going to add comprehensive logging to the front end, which is another thing that I wanted it to do so that I know exactly what's going on so that it will print out logs. Cuz I can just come to inspect and then over to console here and now we can see all of the logs for everything that we're doing inside the app.
So, if I type in Amazon, you can see it is loading the chart for Amazon for 1 day and it's fetching the data and everything, but I'm not actually getting a display over here. So, um it looks like it is getting all of the graph data. Success. It's succeeding with getting the data, but it's just not actually displaying it.
So, that's one of the nice things about having the console logs over here is you can see exactly what it's doing when you perform actions inside the app. So, anytime that I update the stock ticker symbol over here, I want to get some sort of graph down here, obviously. So, it should be able to do that. Now, if I come over here and refresh, we should be able to hit enter.
And again, I'm still not getting any sort of graph down here, but obviously it's still work in progress. It's going to start the dev server again cuz it may have crashed. Just going to restart it. And looks like that is data. So, it's pulling in data over here. And we are getting graph data coming in. And this is just JSON, basically. Which it needs to parse. And then but it looks like it is making progress.
I'm still not getting any sort of graph display here for some reason. I've taken the console log output and I've just put it in OpenCode over here. And told it to diagnose this issue why I'm not getting any sort of graph display. And it says the chart is working, the MVP is complete, the API fetches the data for the symbol, the candlestick chart renders with 32 bars, you've got the volume histogram, EMA line, all this stuff.
And it says I just need to enter in the ticker and it should display the graph. But again, it's still not working. Although it is showing over here that it should be displaying the graph. I'm just not getting any sort of visual display over here. But keep in mind, I am using OpenCode, which is a little bit limited in terms of its capabilities.
If I were doing this in like Codex or Claude Code or Gemini or something, I'm sure it would be able to produce much better results faster. But in this case, I'm just using the free models that are built into OpenCode. And I can easily switch the models over here if I want to switch to let's say Minimax 2.5, which I'm already using, or Quin 3.6, or Kimi 2.5. I have all these different options inside OpenCode.
And again, I'm not spending any credits in order to build this app. It's basically completely free. Through OpenCode. Hopefully you enjoyed the tutorial. This is still a work in progress. Stay tuned for updates. Please subscribe to the channel if you haven't already, and let me know if you have any questions down below. With that being said, thank you so much for watching. Take care, stay safe. Peace from Thailand. I will see you in the next one. Signing off.



