I want to help Noobs!

Can I get in a request for a video? - I’m on a Mac, trying to install pylivetrader using anaconda. If there was a video that showed how to do this from start to finish, from a beginner’s perspective, it would be very helpful for me and I’m sure for others. Thanks for offering your help around here!

@WillowTime sure no problem, it will probably take a few days before I can upload a polished video, but I’ll let you know once it’s up.


1 Like

Hey josh! Im trying to build a very basic algo but I feel like I dont even know where to start. I think i have enough knowledge to do the REST API key thing.
For algos… my knowledge is about the extent of excel if statements haha.
I’m trying to input a list of tickers… let’s just say AMZN, GOOG, and AAPL… and my rule would be… if it opens lower than the previous close then buy x amount of the stock.
Then for the sell…
Once it hits +1% from that fill price… implement a 1% trailing stop.
I feel like if I see this code… i could teach myself how to implement other rules and such and be on my way.
Can you help? Thanks

Hi Josh, I am trying to get the zapier integration with Alpaca to trade with my paper account first until It is tested, but I am not able to get teh account information from my Alpaca paper account, just my live account and I do not want trade my real money until I test it with the paper account first. Any Idea how to do that? the GF


Zapier integration currently works only with live trading. That said, it is not technically impossible to support paper trading, so please weigh your use case to help us understand the needs to support papertrading with Zapier. Thanks!

1 Like

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