I want to help Noobs!

Hi Hitoshi:

Another important addition or improvement to the Zapier integration would be to also be able to look up all open Alpaca positions in an account to get the: symbol, number of shares and position type( long or short). The reason being is with Zapier, if we have these and we are reversing a trade going from long to short for example, this information will allow us to place a new order for the same number of shares in the opposite direction for example. With out this information, it will be very hard to do this without custom coding in Zapier, which will shrink your user audience vs if you exposed this data as a Zapier module option. I would call the drop down option in the Zapier Alpaca module: “Get Open Positions” Thoughts? GF

1 Like

@Brian_Devereaux Welcome to the community. The first place I would recommend starting would be the documentation which can be found here: https://alpaca.markets/docs/. Next, I would definitely recommend looking through the GitHub repository: https://github.com/alpacahq. You can find many examples in the repository using various languages, I would highly recommend using Python to process market data. The Slack group is another great place to learn: https://alpaca.markets/slack. I’m also on Upwork if you’d rather work with a development team to develop a trading application: https://www.upwork.com/fl/joshcogburn2.

Documentation: https://alpaca.markets/docs/
Repository: https://github.com/alpacahq
Slack: https://alpaca.markets/slack
Upwork: https://www.upwork.com/fl/joshcogburn2

Hello @GJF,

This is a great question, Hitoshi is the CTO of Alpaca and definitely has a more thorough understanding of the scope of Alpaca’s integration capabilities than I.

@hitoshi Thanks for your swift response on this topic.

1 Like

Thanks for more details. Definitely helpful. So are you flipping the position between long and short based on some other conditions?

I have pine script algos that generate Tradingview alerts. The algos are constantly changing from long to short positions to generate positive return regardless of what direction the stock price is headed. So I am constantly needing to reverse positions(long/short). I cannot do this with the correct number of shares with each trade unless i can look up in Alapca how many shares i had for example in a long positon, so I can then reverse that number of shares into a short position. By having an open position lookup with the zapier integration, I will be able to do this. Hope this clarifies. GF

Josh. Thank you for the reply. I did a 4.5 hour Python tutorial today. Amazing stuff. Thank you for the links. I’d love to find something already built and tweak it some to process trades on rules that I want… such as
if todays price at 9:30:00 (open) is lower than yesterday’s closing price…buy x shares. And immediately process a sell limit order based on the fill price.

We shall see what I can dig up.

Thanks again!

@Brian_Devereaux, That’s definitely a good place to start. Check out these projects on GitHub:

Those examples and some youtubers have helped a lot. It’s a damn good feeling when you finally get things to run and you import prices and it buys through an if statement.

Also, alpha vantage says its default return is json. After hours of trying to extract a previous day’s close price, I figured out its returning a tuple, converted that to a dict, and extracted the data I needed from the dict because that’s all I could figure out how to do.

Now I want to get the a stocks open price directly when market opens, do you have a go to source for your stock data that you enjoy working with, and returns data fast?

After I’m completely done, would you be cool with me sending you the code for a quality check? Its going to be simple and stupid execution conditions but I just want to make sure I’m writing things in an efficient way and I want to execute 2 purchases at once…I think async is what I’m referring to.



1 Like

I’m getting frustrated with this one piece.
I want to use the alpaca streamconn to listen for trade_updates off a simple market buy.

Can you show me how?

Everything I try, I get an error of loop is already running

Or… teach me a way to receive fill price data. I tried to retrieve order information but it comes back in an unsubscribable object so i havent figured a way to extract specific data from that response.

1 Like

@Brian_Devereaux As for real-time market data, I would highly recommend using the Polygon.io API. Though you would need a live trading account to or you could create an account with them separate from Alpaca. The later could be quite expensive though depending on what plan you choose. They have plans that have latencies under just a few milliseconds.

1 Like


In regards to the streamconn object, this object uses the websocket protocol instead of http. An http connection is a unidirectional connection. The life cycle of an http request ends when the server responds to the client. A websocket connection is a bidirectional will remain open until the client or server terminated the connection. This allows the both the client & server to communicate with each other perpetually. A major benefit in the case of market/trading data, is that anytime there is an update on the server, the server will send that data to the client immediately.

1 Like

If you’d like go ahead and send your code, I’ll take a look at it and give you some feedback. If you would like more clarification on streamconn, implementation of the websocket protocol, or asynchronous/non-asynchronous execution. I just let me know, I really enjoy sharing my knowledge & helping others with their code.

the main help i need at this point is
Overall goal: submit a buy order. retrieve its fill price. submit a sell limit order based off its fill price. so I figured, since the streamconn listen is giving me the devil, I would set the ‘client_order_ID’, and do a loop with list_order and that ID until ‘filled_avg_price’ is no longer == to none for that particular order… store the price that is in the ‘filled_avg_price’ and submit my sell order based off that.

so here, i am trying to get a list of my orders. I have 4 at the moment, and was playing with the [:1] to pull the first one by itself. then i want to reach inside that order and pull ‘filled_avg_price’ out of it. i thought converting it to a pandas dataframe would be easiest… but honestly i dont know much coding at all and dont know anything about pandas, just trying to find examples in other codes and apply things until it works.

if extract_open < extract_close:
#buy_order = api.submit_order(“ENPH”, 1, “buy”, “market”, “day”)
get_order = api.list_orders()
order = get_order[:2]
order = pd.DataFrame(order)


here is my printed stuff

Yesterday’s Close 36.1300
Today’s Open 34.0500
[Order({ ‘asset_class’: ‘us_equity’,
‘asset_id’: ‘b0b6dd9d-8b9b-48a9-ba46-b9d54906e415’,
‘canceled_at’: None,
‘client_order_id’: ‘5a5a6b3c-5d28-4b16-9fee-a8c2982a3f09’,
‘created_at’: ‘2020-03-30T16:11:24.27903Z’,
‘expired_at’: None,
‘extended_hours’: False,
‘failed_at’: None,
‘filled_at’: None,
‘filled_avg_price’: None,
‘filled_qty’: ‘0’,
‘id’: ‘95a88880-bfdd-42c7-99e1-d6c0742854c4’,
‘legs’: None,
‘limit_price’: ‘200’,
‘order_class’: ‘’,
‘order_type’: ‘limit’,
‘qty’: ‘1’,
‘replaced_at’: None,
‘replaced_by’: None,
‘replaces’: None,
‘side’: ‘buy’,
‘status’: ‘new’,
‘stop_price’: None,
‘submitted_at’: ‘2020-03-30T16:11:24.243821Z’,
‘symbol’: ‘AAPL’,
‘time_in_force’: ‘day’,
‘type’: ‘limit’,
‘updated_at’: ‘2020-03-30T16:11:24.370317Z’})]
0 Order({ ‘asset_class’: ‘us_equity’,\n 'as…

so i think this tells me column is labeled 0 and row is labeled 0 in the dataframe. now how do i reach inside this and extract info??

i think i uploaded things right. check that out and let me know. the comments at the bottom are kind of my framework for what I want to happen

Hi, perhaps you can help with this error…trying just to replicate a paper API script to see if it works from Pycharm IDE…but get this error…here is the code and error…thanks in advance for your help.

import requests


BASE_URL = “https://paper-api.alpaca.markets
ACCOUNT_URL = “{}/V2/account”.format(BASE_URL)



Error Message is:

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “alpaca_client.py”, line 6, in
account = api.get_account()
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/alpaca_trade_api/rest.py”, line 171, in get_account
resp = self.get(’/account’)
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/alpaca_trade_api/rest.py”, line 152, in get
return self._request(‘GET’, path, data)
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/alpaca_trade_api/rest.py”, line 115, in _request
return self._one_request(method, url, opts, retry)
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/alpaca_trade_api/rest.py”, line 144, in _one_request
raise APIError(error, http_error)
alpaca_trade_api.rest.APIError: account not found for 67527d0e-0357-4c10-b3fa-b1c2d6f825e7

Hey Josh. I deleted my Alpaca files off of github. I want to clean them up some and try my hand at figuring out the sticking point before submitting them to you.
In the past day or two, coding kind of clicked for me and I have a much better understanding of how things work. While waiting for your reply, I made a completely different program using TD Ameritrade’s API. I uploaded them https://github.com/BSDevereaux/TD-Ameritrade-OvC

I feel really good about this one, and was able to work through the same sticking points which I believe will help me with my Alpaca one. I also learned a little more about coding etiquettes and program structure. So, on to overhaul my Alpaca one. In the meantime, will you give my TDAm a look over. There’s is a little different, with authenticating before using. I know for 100% the authentication piece works…learned it from a youtube video and tried it out to submit a saved order. But the piece I’d like for you to look over is the main piece. Thanks for all you do.

@ari_de_souza, Did you previously store your keys in the environment variables?
Also, I would recommend not posting your actual keys publicly, it is a major security risk. Since you’ve posted them in this thread I would also recommend that you create another pair of keys and discontinue using the old ones.

Sure no problem, I’ll take a look & get back to you with some feedback.

thanks for the reply…no I did not store the keys in the environment,(Need to figure out how to do that as it wasn’t in the tutorial I am using). The keys I posted are not complete for security…

@joshcogburn thanks so much for creating this thread.

I am a noob, and was wondering if you could help me figure out how to get the purchase price of stock.