Hacker News new | past | comments | ask | show | jobs | submit login
Show HN: Stock Trading with Insomnia REST Client and Alpaca API
71 points by shift8 on Dec 14, 2018 | hide | past | favorite | 36 comments
I've created an Insomnia workspace to make it easier to debug your stock trading code and learn the Alpaca API. You can read about how here: https://medium.com/automation-generation/using-alpacas-stock...

The actual workspace JSON for you to import into Insomnia can be found here: https://github.com/alpacahq/insomnia-workspace




I've been playing with the Alpaca streaming API's in Node to get quotes. I have it working, the next step is figure out a trading algorithm.

I am a pretty traditional long term investor, $AAPL, Berkshire, Bank of America, Ford, Amazon, AMD, $SPY, with 10+ years in the market. However with the crazy volatility, I have been toying with the idea of buying ProShares UltraPro Short $SQQQ to hedge my losses on big pre-market open down days. Today for example would have been a good day to own $SQQQ for the day (up 7.3%). Any insight on how to go about this hedge strategy using Alpaca? Can I get pre-market quotes for the Nasdaq?


Seems inherit the same limitation of RobinHood: you can't do short selling. Not sure how actually they could do a free commission order, so not sure why short selling is not supported, but it limits the use of long only strategy.


Interesting. I suppose it's a much more involved process where you need to locate shares to borrow. You need to maintain a list of easy to borrow and hard to borrow names. ETFs by definition are hard to borrow.

I used to work next to the stock loan desk at a bank. The equity markets are generally pretty tech driven these days but stock loan is still operating in a 1980s mentality.


Open question: If, for one stock, you could predict tomorrow's closing price today (with 80% accuracy within 2% of the actual price), how would you trade that stock?


It's easy to predict tomorrow's closing price with that accuracy: it will be the same as today's closing price.

For a large majority of S&P 500 stocks this prediction will be within 2% of the actual price very often (more than 80% of the days). In aggregate, the hit rate is over 80% as well.


Great, so how do you use that for a trading strategy?


You can't. What parent tries to explain is your predictions is no different than regular fluctuations, so you can't use it to get an edge.


Weekly out of the money options trades with short expires. It’s more gambling than anything else fwiw.


How far will it move if it doesn't land within the "80% accuracy"?


Try an iron condor - you’ll profit if the price of the underlying asset stays between two points


Buy call / puts (depending on the current price) near the target price, with very close expiry dates. This would maximize your convexity.


The bigger question is - what happens if you get the price 20% wrong? This might look like a winning strategy in a normal and calm market. But, it'll take only one day to wipe out all the gains.


That's an excellent question. It all depends on the strategy. How would you address that scenario?


More than 80% of stocks will close within 2% of previous day closing price.


Alpaca looks awesome, but doesn't support after hours trading. Does anyone know of a good API that does?


Yes. Narwhal. Narwhal provides commission free flat rate brokerage trading via tradier and you can trade both in pre and post market hours.


How is the access to historical data with these services?


A commission-free trading API? How does Alpaca make money?


Likely the same as similar services like RobinHood. A quick Google suggests they make most of their money on interest from cash sitting around in user's accounts that has not been invested yet.


And by selling info about customer orders to front runners. IIUC, these are high frequency traders who may place similar orders milliseconds in advance of yours then profit from the fact that you have to pay a bit more to fill your order. Full disclosure, I continue to use Robinhood despite this.


It is not front running. These HFT are called market makers. Essentially, brokers show you the NBBO - National Best Bid and Offer. When you place an order on that price, one of the many market makers will pick it up. At any given point of time they will hold multiple buys/sells. So, they make money by collecting the spreads.

Nearly all brokers tend to sell order information to one or many market makers. It is neither illegal nor harm retail customers, not unless these customers are trying to run some HFT algos on their own.


This is highly illegal and taken very seriously. Is this speculation on your part or do you know this for a fact (in which case, you should report it).


https://seekingalpha.com/article/4205379-robinhood-making-mi...

They're probably not front-running. They are almost certainly selling trade information to HFT firms.


It's been widely reported [0]. And as I said I feel like it's still a fair deal. Some HFT's get my orders and they know I purchased 2 AMZN yesterday a few seconds before it executed. In return I get to trade for free on their platform.

[0] https://www.bloomberg.com/news/articles/2018-10-15/robinhood...


Are you sure it's illegal in all cases? I was under the impression this was standard practice. https://www.cnbc.com/2014/03/30/michael-lewis-flash-boys-and...


And selling order flow


What is order flow?


I'm not familiar with it either, but this seems to provide a description https://en.wikipedia.org/wiki/Payment_for_order_flow


Seeing/selling order flow is a term of art in finance. Seeing order flow refers to the ability to trade against customer orders. Selling order flow is getting paid by someone else for the ability to trade against customer orders.

Imagine that a stock is bid at $100.00 and offered at $100.01. Assume that market makers estimate the fair price to be $100.005 unconditionally.

A customer sends a marketable buy limit order at $100.01.

If this hits the exchange then the person who's offering at $100.01 will make $0.005.

If the order flow gets sold (i.e. someone gets to see the flow before it hits the exchange) then the internalizer can fill it at $100.01 and make the $0.005 themselves instead of letting someone else on the exchange do it. It has nothing to do with front running or even information.

This is really valuable because you're not competing for speed with other market participants and you expect the customer flow to be uninformed so the trade is less likely to move against you before you trade out.

This is a problem for market structure because it discourages people from quoting on the exchange.


So the market maker who pays for order flow data takes the spread. But how are they able to trade with the buyer at $100.01 when there are limit asks on the book already at that price? Seems they need to cut the line?


That's part of thr reason that they pay for the flow. They're able to sell at $100.01 off exchange even if there was someone else who was willing to sell at $100.01 on the exchange first.

This also why I think payment for order flow is bad even if the first order effects are not bad for Robinhood customers under reasonable assumptions.


Why is this not just a spread and does RH not just have spreads to make money?


User data on what stocks they buy and sell

Except between the time the user clicks buy and when it the buy actually happens. Basically hedge funds are able to receive and parse this data, and change their orders to an advantage before the users order hits the actual exchange

Its analogous to a MITM attack

Despite my wording its not necessarily bad, but I think users should have a better understanding of it.


(any insight on why this is downvoted -4 at time of writing?)


They probably use the algorithms implemented on their platform to make better ones.


services




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: