Hello all. I’m new to Python and Alpaca (but learning quickly with your help, thanks in advance).
I’m looking for a Python code snippet that will:
- Check for a stock price (I can’t find documentation on this but I’ve read that I can’t get live price data in Paper trading)
- Submit buy order with appropriate parameters including “client_order_id” (I already know how to do this)
- Listen for order to be filled (I’ve read about streams with “account_updates” and “trade_updates” but don’t know how to implement this within this scenario)
- Once order is filled check for price again
- Then submit sell order
- Loop back and repeat
So it would look something like this:
If stock price is less than xx.xx
---- Then submit buy order_abc
-------- Listen for order_abc to be filled
------------ If order_abc is filled
---------------- and if stock price is greater than xx.xx
-------------------- then submit sell order_xyz
Go back to start of loop (to buy again)
The prices would be hardcoded so no need to make them variables. I would need the snippet to be repeated several times for different price points so I can have an independent snippet/algo for different price segments for the same stock (hence I would name each buy order with a unique client_order_id).
I can’t find info on getting price data. I have read about streams and already know how to submit an order. I just can’t seem to put it all together.
EDIT: I also just realized that if it repeats I need to append something to the “client_order_id” to make it unique for the next round (or else I’d be submitting the same “client_order_id” to buy again.)
Any help would be greatly appreciated. And if there is someone out there who is willing to tutor me, I wouldn’t mind compensating them for their time to do even more complex algorithms.