
Show HN: Trade stocks from the command line with no commission - anegri
https://gitlab.com/aenegri/toro
======
srazzaque
(Disclaimer that I'm working on an open source FIX engine in Lisp.)

This is a really cool project! But alas I couldn't use it as I'm not in the
US, and I don't trade with Alpaca. And I feel like this plays into a negative
trend I'm seeing.

The retail brokerage market right now is treading on similar 'mistakes' in
institutional markets 15ish years ago. Proprietary APIs were prolific, and
therefore increased switching costs and lock-in (looking at you, Reuters and
Bloomberg).

On the one hand, retail brokers need to support popular programming languages
and paradigms to gain traction. So, they are releasing http-based APIs, or
popular language-specific libraries/bindings for their proprietary APIs. But,
they are doing this instead of pushing well-publicised battle-tested standards
such as FIX[1], that would normalise the playing field across brokers. So my
gut feel is that they are banking on users coding against their APIs and
having some lock-in effects. Notable exception is that any broker that
supports cTrader will have a FIX API, because cTrader provides that for them.

The problem is: if I write a bunch of code to work against Alpaca, TD
Ameritrade, or whoever, that code will likely need to be revisited for some
other broker like Robinhood. Granted, market connectivity code _should_ be
well abstracted from my model if I'm following good design principles. But at
least with FIX, the core concepts, fields, and messages remain the same across
most FIX endpoints (NOS, ExecRpt, etc), allowing for a more uniform code
holistically.

[1] [https://www.fixtrading.org](https://www.fixtrading.org)

~~~
klohto
Since you’re not from US, what trading platforms do you use? I haven’t found
any with free commissions and public APIs in the EU. Well, except for
Interactive Brokers.

~~~
markvdb
You probably won't ever see an EU broker offer free trades. The EU market is
more regulated to avoid anything that smells of front running. There was a
somewhat revealing interview by the people behind Flatex, a big discount
broker from Germany [0].

Dutch source, do use a translator [https://www.tijd.be/markten-
live/nieuws/algemeen/nieuwe-eige...](https://www.tijd.be/markten-
live/nieuws/algemeen/nieuwe-eige..).

"Is it easier for a pan European company to keep big US competition like Robin
Hood and Ameritrade out?

Niehage: 'The companies you name are very badly positioned for Europe. Their
economic model is based on two pillars. Firstly, they want to offer everything
for free. But if you offer all services for free, you have to earn money with
the capital in the investors' accounts. That is possible in the US, where you
can still get 2% of interest. In Europe, with zero interest rates, that's very
different.'

And the second pillar of their economic model?

Niehage: 'That's the high frequency traders. As far as I know, Robin Hood
sells its customer orders to this kind of parties. They are prepared to pay
good money for that. According to the European MiFID II-regulation, that is
illegal. Those two examples show that the US and EU markets are totally
different. That's why American brokers have difficulties breaking into the EU
market.' "

~~~
OJFord
> You probably won't ever see an EU broker offer free trades.

Freetrade, Trading212, both registered in the UK. (And I don't think
'transition period' would make a difference, but they're both years older than
that.)

~~~
poooogles
>Freetrade

Freetrade are now charging £3 a month for ISAs (tax free wrapped accounts) so
it might be free but it's not completely free.

~~~
OJFord
It also has fee-less non-ISA accounts (not tax free).

------
optymizer
Beginner question on a related topic for those of you more knowledgeable than
me:

Is there a way to get access to the order books on Nasdaq or other exchanges?

I'm working on a script that can run stock trading algorithms (and hopefully
see some profit).

My first trading experience was with crypto on GDAX (now Coinbase Pro). The
order book on GDAX is basically available via their API. I've been looking at
various stock trading APIs (Alpaca looks interesting as well) and it seems
like the only thing that's available are broker APIs that don't share the
order book.

Is the order book on Nasdaq and other exchanges unavailable to regular folks
like me? Is it hidden, available to institutions only, or to some sort of
registered brokers?

Having first dealt with GDAX and now looking at stocks, it all seems so
ambiguous and hidden behind 3rd parties, unclear order execution, etc. (not
that gdax was perfect - it has its issues), so I'm just generally confused as
to how things work.

~~~
hendzen
You have to buy the feed, the market data isn’t free. Depending on your usage
the fees can get fairly steep [0]. And that’s just the market data, you need
to pay for colocation, cross connects, and order entry sessions. Of course
Nasdaq is only one US equity market - there are 14+ with more coming online in
recent years.

[0] -
[http://www.nasdaqtrader.com/Trader.aspx?id=DPUSdata](http://www.nasdaqtrader.com/Trader.aspx?id=DPUSdata)

~~~
speedgoose
I need to create and operate a market place.

------
anegri
Heard about alpaca a while back, so I made this as a small fun side project.
The main features are buying, selling, and viewing stocks. In the future I may
add additional features if I find something I want to add (or others want to
add).

The code is just Go, using the cobra library.

------
bwood
Alpaca is great! As far as brokerage APIs go, theirs is top notch and a breeze
to code for. The founders are also really responsive and helpful.

I know this because I wrote an app that connects to Alpaca accounts (as well
as other brokerages) to help people build their own custom index funds [0]. It
only took a few weeks to build our Alpaca integration, whereas other
brokerages often take months/years just to get access to their APIs.

[0] [https://getpassiv.com/](https://getpassiv.com/)

~~~
giorgioz
how does Alpaca make money?

~~~
throwaway888abc
Guesing, they are selling order flow. Same like Robin Hood

[https://www.cnbc.com/2019/04/18/a-controversial-part-of-
robi...](https://www.cnbc.com/2019/04/18/a-controversial-part-of-robinhoods-
business-tripled-in-sales-thanks-to-high-frequency-trading-firms.html)

~~~
TeMPOraL
So Robin Hood is taking from the rich, giving to the poor, and then turning
around and selling the poor out?

~~~
psanford
Selling order flow isn't "selling the poor out". Reg NMS literally requires
brokerages to route your orders to where they will get the best execution
price. In general you as a retail investor get better execution prices because
of how this works (why? because retail investors generally don't have new
information that will move the price so they are "safe" trades for liquidity
providers).

Now robin hood _did_ get fined for "not perform[ing] systematic best execution
reviews of several order types". If that's what you were referring to then
fine. But if your complaint is just about selling order flow you should better
understand what that means. Maybe start with patio11's How Brokerages Make
Money[0].

[0]: [https://www.kalzumeus.com/2019/6/26/how-brokerages-make-
mone...](https://www.kalzumeus.com/2019/6/26/how-brokerages-make-money/)

~~~
TeMPOraL
Yeah, I misunderstood what "selling order flow" means; I was under impression
this is something closer to front-running. Thanks for the link!

------
vijucat
FYI: "With no commission" is a bug, not a feature. Typically, when you pay
commission, you get better prices. Let's say you buy 100 shares of SPY at
Interactive Brokers. You pay $1 commission and get it for 268.28. At a free-
of-commissions broker, you might get your 100 shares for 268.30. That's $1
more than the trade at IB. TNSTAAFL.

It's exactly like how duck typing took over programming in the last decade or
so with, "Whee, see, less typing!!", and we lost the value of having static
types ("strong typing"). Why are we tempted so easily? Now we have the horror
of Javascript everywhere. Even the Node.js founders recoil from their own
creation and are going a step in the right direction with Deno.

~~~
admax88q
Are you saying that alpaca charges a commission on trades by inflating the
price and taking a cut?

Or through what mechanism do commissioned trades get lower prices?

~~~
selectodude
Free brokerages generally don’t execute orders as quickly in order to sell
order flow which allows HFT firms to front-run your trade. If you’re a buy and
hold investor, the fractions of a cent you’re losing don’t matter much over
the long run but the issue is still there. Generally when you pay for
something, it means that somebody is beholden to you if there’s issues.
Robinhood et. al. are free because they suck.

[https://www.cnbc.com/2020/03/09/robinhood-app-down-again-
dur...](https://www.cnbc.com/2020/03/09/robinhood-app-down-again-during-
another-historic-trading-day.html)

~~~
mrep
No, they sell order flow because market makers know discount brokerage users
are uninformed and thus less risky to buy and sell from. However, they
actually give you better prices than the public market offers and they have to
or else the SEC would fine them [0]. Your link is just about robinhoods shitty
infra that couldn't handle their user load and has nothing to do with order
flow.

[0]: [https://www.kalzumeus.com/2019/6/26/how-brokerages-make-
mone...](https://www.kalzumeus.com/2019/6/26/how-brokerages-make-money/)

------
encyclopedia
Would be interesting to tie it into what Elastic published about trading
baskets of pharma companies related to drug development (COVID-19 included):

Generating and visualizing alpha with Vectorspace AI datasets and Canvas
[https://www.elastic.co/blog/generating-and-visualizing-
alpha...](https://www.elastic.co/blog/generating-and-visualizing-alpha-with-
vectorspace-ai-datasets-and-canvas)

Generating Alpha from Information Arbitrage in the Financial Markets with NLP
Datasets: 水涨船高 [https://medium.com/hackernoon/profiting-from-information-
arb...](https://medium.com/hackernoon/profiting-from-information-arbitrage-in-
the-financial-markets-3abfca9806d8)

algo guys take
[https://www.reddit.com/r/algotrading/comments/gkrb6f/generat...](https://www.reddit.com/r/algotrading/comments/gkrb6f/generating_alpha_in_a_down_market_with_nlp/)

------
LethargicStud
My main FUD with alpaca.markets is the ability to transfer assets in/out. It
doesn't look like they offer ACATS transfers (although there's not much info
on this!).

Using them for anything beyond entertainment budget is very scary - you may
incur substantial tax liability if e.g. they ever go out of business or you
choose to use a different brokerage.

Any insight here? Am I missing something? Is there any way to transfer
holdings out without incurring the cap gains?

~~~
whb07
as far as i know the "actual" backend data is standardized, ie same instrument
names and dates etc. Adding to that, by playing in the US markets the SEC and
FINRA, have that stipulation of being able to move between institutions in a
standardized and regulated way.

long story short, they all have to implement a system to move out and in (well
they all want your assets so this part is obvious).

------
smabie
What's really cool about Alpaca is the integration with zipline via
pylivetrader. This means that you can take your backtested factor models and
easily convert them to live trading. Also, they have pretty lax margin
requirements. You can borrow 2x the cash you have, 4x for intraday if you're a
pattern day trader, and the maintenance requirement is only 25%. And with zero
commissions, suddenly it's possible for the average joe retail investor to
actually run a legit factor strat. If you're only trading highly liquid
securities, it could even make sense to run a intraday only strat at 4x
leverage. Lets say you're trading stuff that has spreads around 4 bips, your
lost returns are going to be around 10% per year from trading costs. That's
certainly a lot and you'll need a kick-ass strategy, but that 4x leverage
might let you get there.

~~~
tosylate
Do you have any reference on `legit factor stats`? I do not understand how
leverage will be beneficial. Leverage will also multiply the potential
downside risk after all? I would like to understand more how the trading cost
would make up for it on average.

~~~
pedrosorio
> I do not understand how leverage will be beneficial.

Same here, if I understood the grandparent they were saying you lose 0.04% on
every trade (from spread) and "in a year" that is 10% (250 trades?).

If you have a strategy that has expected returns of x bips per trade then you
make an expected x-4 and with leverage 4 * (x - 4). Both have the same "sign",
so if x-4 is expected positive, leverage just makes it higher risk-reward.

In fact with leverage you also have to pay interest on the loan, which seems
to be at least ~18 bips (or 3/4 of that since the returns are on 4 * cash and
interest is on 3 * cash) for a single day loan (far exceeding the "spread
cost"):
[https://www.schwab.com/public/schwab/investing/accounts_prod...](https://www.schwab.com/public/schwab/investing/accounts_products/investment/margin_accounts)

It seems the only way leverage would help is if there were fixed costs to
trading (which I assume there are but the GP does not mention).

~~~
smabie
Well you have 504 trades approx, but you're buying in and selling out, so
you're paying the cost of spread once per day (252 trading days in a year).

Let's say you have have a strategy that has 7% return and 3% volatility.
That's a pretty fucking amazing strategy. So you lever up to 4x and now you
have 28% return and 12% vol. With your spread tax, you now have 18% return and
12% vol. Using their 2x leverage, you'll have a 14% and a 6% vol. So while
your Sharpe ratio will be lower, your max return will be higher. And since you
can't eat risk-adjusted returns, the tradeoff could very well be worth it.

------
tutfbhuf
You may also like
[https://github.com/madnight/wallstreet](https://github.com/madnight/wallstreet)
just to get the charts and quotes

------
monkeydust
What's closest to Alpaca for UK based traders?

~~~
dharma1
Not seen anything with both free trades and an API in the UK. I would like to
do this to implement simple strategies - for instance mirror indices but with
user defined filters (S&P500 minus hospitality, airlines and oil, as an
example).

Freetrade, 212 Trading and soon Robinhood offer commission free traedes in the
UK but no API

------
kyriakos
Alpaca is US-residents only unfortunately

------
BenderV
Does anyone know why they are US only? Is it because the market is different
abroad, because there are no European/Worldwide legal framework or simply
because it's easier to start with?

~~~
asmosoinio
Looks like this is the answer:

[https://news.ycombinator.com/item?id=23210385](https://news.ycombinator.com/item?id=23210385)

Different market and laws.

------
posedge
I don't get it. How does Alpaca offer free broker services?

~~~
shoo
[https://www.bloomberg.com/opinion/articles/2019-10-02/the-
tr...](https://www.bloomberg.com/opinion/articles/2019-10-02/the-trades-will-
be-free-now)

[https://www.kalzumeus.com/2019/6/26/how-brokerages-make-
mone...](https://www.kalzumeus.com/2019/6/26/how-brokerages-make-money/)

------
dose
Coincidentally I've also just released a command line client for Alpaca [0]
written in Rust along with a library backing it [1].

Interesting timing :-)

[0] [https://github.com/d-e-s-o/apcacli](https://github.com/d-e-s-o/apcacli)

[1] [https://github.com/d-e-s-o/apca](https://github.com/d-e-s-o/apca)

------
vfg1234
This is a terrible use-case for the command-line.

~~~
anegri
Could you elaborate? I understand it's pretty niche, but not sure why it is
terrible to have a cli for it?

------
anthony_r
What are you folks using this kind of stuff for? The best I can come up with
is carefully studying issuers' financial reports and reaching some not very
good but close enough conclusion about the state of businesses. At which point
paying a few $$ or even $100 in commissions is really irrelevant given how
much effort I had to put in ...

------
supernova87a
You should know in general, though, that no one trades "for free" despite what
brokerages say.

Your order gets routed, delayed, placed differently, and while you may not
immediately see it, your trades are getting a different result than if you
explicitly paid a brokerage who charges a commission on it.

Learn about "payment for order flow".

~~~
tom_mellior
I don't know why others downvoted you, I didn't. But as general feedback:
"learn about X" without linking to some resource about X is really lazy
soapboxing.

~~~
kasey_junk
I downvoted it because it’s mostly factually wrong.

First paying a commission is not correlated with participation in order flow
payment. Commissioned brokers also get paid for order flow.

Second if you interact with an internalizer your order will execute faster not
slower. And you will usually be getting better price execution than if you try
to route manually.

Third all brokerages have routing tiers that involve self matching/dark
pools/contractual discounts etc. Most of them will let you pay for the
privilege of using the same router the non-premium orders go through.

At the end of the day if your trade is that sensitive to execution you are not
a retail customer and should not be using a retail brokerage.

------
xvilka
Would be nice if the author will add more popular Interactive Brokers[1]
support. Alpaca is US bounded and seems not going to change this.

[1] [https://www.interactivebrokers.com/](https://www.interactivebrokers.com/)

------
lawrenceyan
Ok, but what's going to be your business model if you don't charge commission?

~~~
ciarannolan
Who is this question directed at? OP is linking free software.

If you mean brokerages that advertise no fees to trade, they make money by
loaning the cash in customers' accounts.

[https://www.bloomberg.com/news/articles/2019-10-10/brokers-p...](https://www.bloomberg.com/news/articles/2019-10-10/brokers-
profit-from-you-even-if-they-don-t-charge-for-trading)

~~~
toohotatopic
And by loaning out shares to short sellers [1]

Which to me begs the question: do you actually own the shares when you buy
them with those brokers? What happens if supply is limited and the loaned
shares actually have to be sold?

[1]
[https://www.investopedia.com/ask/answers/05/shortsalebenefit...](https://www.investopedia.com/ask/answers/05/shortsalebenefit.asp)

~~~
renewiltord
Ownership doesn't really matter that much so long as you meet the tax criteria
for it. As for the rest, everyone else playing in this space is likely to have
assets that are in the range of SIPC insurance so just make sure your stuff is
insured and don't sweat the small stuff.

~~~
toohotatopic
One reason people invest in stocks at the moment is hedging against a falling
dollar. In a great market turn, it could be that those $500,000 are the price
for a cup of coffee. If you lose access to your shares at that moment, it
doesn't help if you are rewarded with money.

*edit: Apart from that: is that actually an event covered by SIPC? Essentially it is a bad investment decision. You agreed to lend out those shares so you have to bear the consequences.

------
matiasb
Alpaca is very interesting, I've been following them since the beginning. The
sad thing is that I'm not from the US and it's still not available for
residents of my country (Paraguay in South America).

------
noloblo
go install doesn't work @anegri # github.com/keybase/go-keychain cgo-gcc-
prolog:203:11: warning: 'SecTrustedApplicationCreateFromPath' is deprecated:
first deprecated in macOS 10.15 - No longer supported [-Wdeprecated-
declarations]
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Security.framework/Headers/SecTrustedApplication.h:59:10:
note: 'SecTrustedApplicationCreateFromPath' has been explicitly marked
deprecated here

~~~
anegri
What os and version are you running? I have been having trouble with Mac
because of one of my dependencies

------
proverbialbunny
A problem I've bumped into with Alpaca compared to other services is my bot
needs 1 second bars, and I believe Alpaca goes down to 1min bars and nothing
smaller.

~~~
larrykubin
Did you try the Alpaca Market Data (streaming) they just released? You should
be able to get real-time data now that is aggregated from multiple exchanges.

~~~
proverbialbunny
That's the 1 min bars I was talking about.

[https://alpaca.markets/docs/api-
documentation/api-v2/market-...](https://alpaca.markets/docs/api-
documentation/api-v2/market-data/streaming/)

>Trades, quotes and minute bars are supported.

------
badrabbit
Thanks for sharing. Didn't know alpacca was a thing.

------
mylons
with a record number of investors in the stock market and tools like this, i’m
happy to be in all cash.

------
totetsu
This makes me wonder if there are any old school, ASCII or DOS era stock
trading games out there..

------
sdan
*using a service called Alpaca

~~~
ilrwbwrkhv
Is that service available outside USA?

~~~
smabie
No.

------
xwdv
Can this do OCO orders and sequences? If it can’t then it’s kind of useless.

------
ISL
Is there a reason that the repo size should be 10 MB? Seems odd.

~~~
anegri
Oh didn't realize that! Thanks for pointing that out

~~~
smabie
Maybe just remove it from the commit history? People are still going to pay
the cost even if you removed it in the most recent commit.

~~~
anegri
Took it out now, seems there is a bit of a lag for the filesize to update
unfortunately

------
moneywoes
How is the alpaca API, are there any limits? Is it fast?

------
m3kw9
File it under:New ways to lose money

------
axaxs
FYI - You're supposed to fill out the license info. I see empties in at least
two files in the main repo.

------
larrykubin
Shameless plug: I started a YouTube channel on this topic that covers a lot of
commission free trading API's, including Alpaca (got featured in their docs),
Robinhood Private API, TD Ameritrade, Tradier, and more. I'm seeing a huge
growth in interest in developing automated trading bots and algos. With
commissions dropping to zero, there is a huge wave of day/swing traders that
want to learn Python, so am creating as many tutorials as possible.

[https://youtube.com/parttimelarry](https://youtube.com/parttimelarry)

~~~
teruakohatu
I have subscribed to your channel. Do you know of any services that allow non
US residents to join? I am in New Zealand.

~~~
gunn
There's [https://hellostake.com/](https://hellostake.com/) for NZ and AU. They
don't have an API yet but would like to in the future - see comment here:
[https://old.reddit.com/r/PersonalFinanceNZ/comments/fnbmlx/x...](https://old.reddit.com/r/PersonalFinanceNZ/comments/fnbmlx/x/fletz3i/)

As mentioned, Sharesies plan to allow US market access:
[https://app.sharesies.nz/us-equities-register](https://app.sharesies.nz/us-
equities-register) They do seem to have a private API at least:
[https://app.sharesies.nz/api/fund/list](https://app.sharesies.nz/api/fund/list)

[https://www.revolut.com/en-NZ](https://www.revolut.com/en-NZ) have plans to
expand to NZ, I don't know much about their services though.

~~~
gunn
I also just found [https://hatchinvest.nz/](https://hatchinvest.nz/) \- has US
market access, I don't know about an API

------
vfg1234
This is a terrible use-case for the command-line. One of the worst ideas I
have come across.

