- ago
alpaca sell order becomes a short order after I manually close the long trade.

In alpaca, I was holding spy this morning. I closed the trade manually. Then later 60 minutes macd strategy issued a sell order for spy, efa and gld. The sell order has turned to sell short because I don't hold spy ,efa gld any more. I am surprised.

0
509
37 Replies

Reply

Bookmark

Sort
- ago
#1
alpaca received a sell order, but it turn into a short position for spy, efa and gld. It is a surprise

my macd strategy only generates buy and sell order
0
Cone8
 ( 6.32% )
- ago
#2
That can be expected if you're not using any of the Portfolio Sync options in Trading Preferences.
Any of these should have prevented that from occurring. The last arrow refers to "Use Live Positions"

Edit -
"Use Live Positions" may not actually help in this scenario. When using this feature, you shouldn't manually trade out of a Auto-Traded Position.

0
Glitch8
 ( 12.10% )
- ago
#3
Hmmm the "could not find a matching position to exit" indicates use of the Block Exit order preference.

replyxfl123456, I see many CancelPending statuses, is this happening frequently in your operation? It's possible your connection to Alpaca is getting disrupted.
0
- ago
#4
yes, I have seen a lot of cancel pending, even if the order has been executed.
0
Glitch8
 ( 12.10% )
- ago
#5
Ok and no errors in the WL8 log? This is a live account, not paper, correct?
0
- ago
#6
live account. not many errors in past several days
0
- ago
#7
here is my sync setting

0
- ago
#8
i have already have block exit orders. The order shouldn't be sent to aplaca. And I don't understand you send a sell order, not a sell short order. Is this how alpaca handle sell order, if no position, it sell short? That is not a typical broker behaviour
0
- ago
#9
this is my strategy , just buy/sell, no short
0
Glitch8
 ( 12.10% )
- ago
#10
I’d recommend restarting WL8 every day. I’m not sure why you’re getting out of sync and will investigate. But yes the Alpaca API will create a short position if a sell comes in with no position.
0
Glitch8
 ( 12.10% )
- ago
#11
Alpaca has an update to the component we use to connect, I'm going to get that up to date in the next build. Let's see if this helps with the issues.
0
- ago
#12
can you please add a protection that if you can't get response of querying the positions before issue a trade, don't send the trade.
0
Glitch8
 ( 12.10% )
- ago
#13
We already have that protection in place. But it's obviously been failing for you. It leads me to believe the connection to Alpaca becomes unstable, we are not able to get correct information back from their API. I'm hoping the new middle component from Alpaca improves this.
0
- ago
#14
It seem that your order AI has no problem to send the order to alpaca, but read position API has trouble to read position. I have to click the request updata button to get positions. Is it the normal behavior or it should automatically display the account positions.
0
Glitch8
 ( 12.10% )
- ago
#15
It's API (Application Programmer Interface) not AI (Artificial Intelligence)

And yes there's some problem there.

The account positions should automatically update whenever there is a confirmed fill.
0
Cone8
 ( 6.32% )
- ago
#16
Are you connected to the Alpaca account with WealthLab on more than one machine?
0
- ago
#17
no, just one machine
0
- ago
#18
today's order, the order is already executed, but wp8 still think it is active. I have just done require update to sync with alpaca. When I restart my wp8, I need to activate it gain. How to keep the activate status?
0
Glitch8
 ( 12.10% )
- ago
#19
Do you mean, the order is already filled?

The order RWM to sell 22. Is that order already filled but WL8 thinks it is still active?
0
- ago
#20
yes, the orders are always filled. But wp WL8 can't read the account poistion back, and there is no error log message.

I have restarted wp 8 WL8
0
Glitch8
 ( 12.10% )
- ago
#21
Just to compare, this is what I'm seeing auto-trading 1 1-minute system with Alpaca.

1) I'm not seeing any CancelPendings, the orders get canceled right away and show Canceled.
2) I'm seeing Filled when a fill occurs.
3) I'm seeing an Error when it issues a Sell and I don't have a position.

It looks like your experience is very different. How's your internet connection, is it stable?

Let's see if the new Alpaca build improves things for you. I'll try to get this out within the next few days. From what I'm seeing of your experience it's currently not tradable for you.
0
Glitch8
 ( 12.10% )
- ago
#22
0
- ago
#23
my internet is stable. why I don't see error log? issue order is always successful. Reading position has trouble. but how did you issue order when you can't read position back, are you using historical data? I think there is an issue in your code. Before you issue an order, how do you verify if the position exists?
0
- ago
#24
clearly in my case, I have closed spy,efa manually. When the sell signal generated, you r code has failed to detect that there is no position for spy and efa and you issued a sell order. This sell order is executed as sell short order in alpaca which is a surprise to me.
0
Glitch8
 ( 12.10% )
- ago
#25
Are you closing the position manually in WealthLab, or in the Alpaca web site?

If you close a position manually in WealthLab then the positions will get updated automatically, please see the video as a demonstration.

>>how do you verify if the position exists?<<

We verify positions exist because we get them from the Alpaca API.

https://drive.google.com/file/d/1nGFklbSKy_2lSZ5dkaEFCq45ix9X9t6e/view?usp=sharing
0
- ago
#26
I have closed in alpaca.

next time I will close it in wp 8 WL8.

how often do you query position from alpaca
0
Glitch8
 ( 12.10% )
- ago
#27
We query whenever there is a FILL detected. That's why it's important to exit a position in WL8.
0
Cone8
 ( 6.32% )
- ago
#28
You can also hit this button on the Accounts tool to sync your positions too.

0
- ago
#29
how do you detect fill detected? I wonder if you can add more process: such as query position before send order, query position after send order, periodic poll as fallback just in case missed fill detected signal
0
Glitch8
 ( 12.10% )
- ago
#30
Alpaca already has rate limiting and we have to impose throttling. Adding that many more requests to their API would result in things shutting down sooner. If too many requests are made to Alpaca they simply stop responding.
0
- ago
#31
what is the rate limit? I think query position every 10 to 30 minutes won't be too much. or at least query position before you send order. What if you miss order fill signal, then wp8 WL8 will be forever out of sync until manual update is clicked. in my case today, order fill signals were most likely missed
0
Cone8
 ( 6.32% )
- ago
#32
Querying after 10 minutes, 5 minutes, 1 minute.. it doesn't matter. Murphy's Law guarantees you'll be out of sync at the time a new Auto-Trade is submitted.

This happens because you're Auto-Trading but interfering by not only making manual trades, but worse, not using WealthLab to do that.

Make your manual trades from WealthLab. It's a 1 button click to close positions at Market right from the Accounts tool. If you need Limit/Stop, use the Order Manager.

Incidentally, not all brokers' APIs are the same. IB, for example, will send an event anytime the account Positions change, so even manual trades outside of WealthLab will cause the account positions to update.
0
- ago
#33
manual trade in alpaca is just one reason to cause out of sync. I saw out of sync very often: trade orders are completed in alpaca, but wp8 WL8 can't receive trade complete signal and then issue cancelpending. It happens very often in my wp8 WL8. It seems send order to alpaca is reliable, but receiving order complete signal is not. I wonder if you can debug more on receiving order complete signal such as adding more log, and add polling as backup.
0
- ago
#34
for example, i didn't do any manual trading today, it is still out of sync.
0
Glitch8
 ( 12.10% )
- ago
#35
Yes, your experience is very poor.

I can't explain why it's like this, it certainly isn't at my end.

That's why I went ahead and updated our component for the next Build. I hope this provides some improvement for you.
0
- ago
#36
I am your user and also function as your tester. I wonder if you can put more log, f.e. waiting for trade confirmation, and error message ' time out waiting for trade confirmation'. After time out error, poll the position. if you can get the position, then it means connection is good, something went wrong trying to get trade confirmation, either the api has a bug or your code has a bug.
0
Glitch8
 ( 12.10% )
- ago
#37
To me it looks like you’re not getting order status updates like we are. All of your orders are sitting in CancelPending status when they should go to Cancel. I’ll add more logging 👍
0

Reply

Bookmark

Sort