- ago
I installed and configured the extension for Fidelity. All works good. Except one major issue. It takes 30-50 seconds to place an auto trade.
I used Streaming Chart with IQFeed.

How to make it faster to place orders within 1-5 seconds?


CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Data; using WealthLab.Indicators; using System.Collections.Generic; using System.Transactions; namespace WealthScript3 { public class MyStrategy : UserStrategyBase { //create indicators and other objects here, this is executed prior to the main trading loop public override void Initialize(BarHistory bars) {          StartIndex = 10; } //execute the strategy rules here, this is executed once for each bar in the backtest history public override void Execute(BarHistory bars, int idx) { if (!HasOpenPosition(bars, PositionType.Long)) { if(idx == (bars.Count -1))                   {                Transaction transaction = PlaceTrade(bars, TransactionType.Buy, OrderType.Market);                transaction.Quantity = 1;                } } else { //code your sell conditions here } } //declare private variables below } }
0
366
Solved
22 Replies

Reply

Bookmark

Sort
Glitch8
 ( 11.81% )
- ago
#1
Please see the last item in the help,”Lag”.

Spoilers - it’s probably impossible.
0
- ago
#2
QUOTE:
It takes 30-50 seconds to place an auto trade.

The really funny part is that Medved boasts about their REST API being asynchronous....

QUOTE:
[Our] API is asynchronous and very versatile.

And then they add a 40 second delay. I think they are trying to test our sense of humor.... And it's working. :-)

UPDATE: I stand corrected. See Post #3.
0
Glitch8
 ( 11.81% )
- ago
#3
Their API is asynchronous. Some integration points within WL8, specifically placing orders from the Signals tab, are synchronous in WL8.
1
- ago
#4
Experiencing a delay of 40 seconds might not pose a significant issue with longer time intervals, but it becomes notably problematic when dealing with one- or five-minute intervals. This discrepancy greatly affects the alignment between live trades and back-testing, detracting from the accuracy of my trading strategies. Despite utilizing a keyboard simulator that completes the process in a mere 5 seconds, I still find it unsatisfactory.

While Fidelity does offer APIs for trading, obtaining access has proven challenging as they require institutional status, even though my trading activity exceeded 5 trillion dollars last year.
0
- ago
#5
QUOTE:
While Fidelity does offer APIs for trading, obtaining access has proven challenging as they require institutional status ...

And Medved has institutional status.

UPDATE: The above was incorrect. See Post #7.

I wouldn't mind paying for a Medved subscription if it offered a data feed and some fundamental data. But I don't know if it does. I haven't studied their API.
0
- ago
#6
QUOTE:
The really funny part is that Medved boasts about their REST API being asynchronous....
That is in reference to our WebSocket API, NOT the REST API, which by definition is not asynchronous

As for Fidelity, the act of placing the order should be sub-second, not 40 seconds. HOWEVER, if you have to login first, well, that certainly would take a while. If you are already logged in, then the trades will go through right away. You can see this in the MT UI - if you open account view for example, MT will login right away. Any trades after that will go through instantly. If you then try to place trades through the API, you will see the trades both in Fidelity and in MT immediately.

NOTE: if you do not have a way to trigger the login for Fidelity via WL ahead of time (sorry, I am not familiar with WL UI and procedures), you can easily do it yourself in MT. If you open the ACCOUNT VIEW window for the account in question, then once you see the balances, it is logged in. Any API connections will get the benefit of the login as well
1
Best Answer
- ago
#7
QUOTE:
And Medved has institutional status.
We do not have institutional status with Fidelity. Though they are "friendly", they do not have a public API. We had to figure out the APIs they use ourselves.

QUOTE:
I wouldn't mind paying for a Medved subscription if it offered a data feed and some fundamental data. But I don't know if it does. I haven't studied their API.

Medved Trader does not provide any data itself. All data comes from whatever datafeed you select in MT (or via the API for that matter). We do have integration with Fidelity for Level I quotes. Also have a slew of other datafeeds and brokers (TD Ameritrade, Tradier, IB, etc). Will have Schwab and TastyWorks soon
2
- ago
#8
Thank you for those clarifications.

QUOTE:
the REST API ... by definition is not asynchronous

You are correct. REST is based on http, which employs UDP datagrams. So you are using a real asynchronous WebSocket after all. That's good to hear. (I still like REST because it's reliable and simple to use.)

QUOTE:
Medved Trader does not provide any data itself. All data comes from whatever datafeed you select in MT (or via the API for that matter). We do have integration with Fidelity for Level I quotes.

So whatever data our broker provides (including its limitations) will come through your interface. That's good to hear too. Would that include fundamental data?

Fidelity does provide very good Level I quotes. Wealth-Lab doesn't do anything with Level II data. Wealth-Lab is primarily a backtesting platform, not a "sniping" trading platform.
0
- ago
#9
QUOTE:
As for Fidelity, the act of placing the order should be sub-second, not 40 seconds. HOWEVER, if you have to login first, well, that certainly would take a while


Good to know that. I had MT open and placed 10 trades (one each minute) , and I thought I was logged into Fidelity, but I will try it again and let you know.
0
- ago
#10
Fidelity Level I - the quotes we get they update about once per second (streaming). its not like the streaming in their app which is tick by tick. Don't have their Level II.

Our API is async, but some brokers are not - so in case of Fidelity trading, we use REST. however, MT does various optimized auto updates so delays are minimized and as soon as MT has any change, that change is sent via our API to WL immediately.

QUOTE:
Good to know that. I had MT open and placed 10 trades (one each minute) , and I thought I was logged into Fidelity, but I will try it again and let you know.


Sometimes, especially if Fidelity has been logged in for many hours, it might require a re-login. However that should definitely not be a regular thing. If you still encounter the delay with orders initiated from WL, please send us the log and in the comment when sending, indicate that you encountered delay send order from Wealth-lab. If you can indicate which order was placed, it would help finding it in the log.

To send: In MT, Go to FILE / HELP => Send Log/Settings to support menu (from Dashboard or Portfolio)
1
- ago
#11
Yes. It is much faster when logged in. I made sure I am logged into Fidelity from MT and place 9 trades. All trades except the first one took exactly 7 seconds. The first took 23 seconds.


0
Glitch8
 ( 11.81% )
- ago
#12
For an end of day trader like me it’s a godsend. Even if it takes a minute it saves me keying in so many orders which is a tedious and error prone process.
2
- ago
#13
Even 7 sec seems a bit long. I daytrade Fidelity via MT and I see the order on the Level II (from another source) within a fraction of a sec. Response on Account View/transactions might be 1 sec. I am a bit curious where the 7 sec comes from. If you want, send me the log and I will check
0
- ago
#14
It could be the WL extension that iscausing the delay.

03/08/24 9:47:23 AM SPY New Order Submitted BUY 1 SPY at MARKET 1380M5C0
03/08/24 9:47:23 AM SPY Filled Filled 1 at 514.0799 : BUY 1 SPY at MARKET Day FillID: 1380M5C01278557039 1380M5C0
03/08/24 9:48:07 AM SPY New Order Submitted BUY 1 SPY at MARKET 1380RW6M
03/08/24 9:48:07 AM SPY Filled Filled 1 at 513.8797 : BUY 1 SPY at MARKET Day FillID: 1380RW6M-501174253 1380RW6M
03/08/24 9:49:07 AM SPY New Order Submitted BUY 1 SPY at MARKET 1380SK7Q
03/08/24 9:49:07 AM SPY Filled Filled 1 at 514.0367 : BUY 1 SPY at MARKET Day FillID: 1380SK7Q324148568 1380SK7Q
03/08/24 9:50:07 AM SPY New Order Submitted BUY 1 SPY at MARKET 1380MVR4
03/08/24 9:50:07 AM SPY Order Placed BUY 1 SPY at MARKET Day 1380MVR4
03/08/24 9:50:07 AM SPY Filled Filled 1 at 513.91 : BUY 1 SPY at MARKET Day FillID: 1380MVR4348322911 1380MVR4
03/08/24 9:51:07 AM SPY New Order Submitted BUY 1 SPY at MARKET 1380PWBH
03/08/24 9:51:07 AM SPY Filled Filled 1 at 513.675 : BUY 1 SPY at MARKET Day FillID: 1380PWBH1400859880 1380PWBH
03/08/24 9:52:07 AM SPY New Order Submitted BUY 1 SPY at MARKET 1380LJ6Q
03/08/24 9:52:07 AM SPY Filled Filled 1 at 513.3069 : BUY 1 SPY at MARKET Day FillID: 1380LJ6Q-606772547 1380LJ6Q
03/08/24 9:53:07 AM SPY New Order Submitted BUY 1 SPY at MARKET 1380M6BC
03/08/24 9:53:07 AM SPY Filled Filled 1 at 513.28 : BUY 1 SPY at MARKET Day FillID: 1380M6BC1861154028 1380M6BC
03/08/24 9:54:07 AM SPY New Order Submitted BUY 1 SPY at MARKET 1380NK56
0
- ago
#15
that I will leave for @Glitch
0
Glitch8
 ( 11.81% )
- ago
#16
Will certainly look but nothing is coming to mind here off the top of my head!
0
- ago
#17
@MohammadRashid - please send me the log. It will show both when API stuff is received from WL and when MT sends stuff. will make it easier to track it through.
0
- ago
#18
Just for clarification, is Post #14 saying the Windows scheduler is pacing the order submissions exactly one minute apart? But aren't these order requests going through a FIFO queue that's buffered? (And certainly the OS I/O channels are doubled buffered. For the non-Comp Sci readers, the I/O channels are what divide the application layer from the driver layer in the OS so the two can run independently. That must be running okay.)

It looks like I/O order buffering is broken somewhere in the chain. If all buffers are working, the orders should be batched together (if I'm understanding this right).
0
Glitch8
 ( 11.81% )
- ago
#19
I'm placing limit orders now into Fidelity and the response time is < 1 second in the WL8 Order Manager.
0
Glitch8
 ( 11.81% )
- ago
#20
Everything is responding super quickly now. I wonder if Fidelity just responds more sluggishly shortly after market close time which is when I usually place orders.
0
- ago
#21
QUOTE:
Just for clarification, is Post #14 saying the Windows scheduler is pacing the order submissions exactly one minute apart?

To Post #18
one minute comes from running the strategy on 1-minue interval. Has nothing to do the WL or MT (see the test Strategy at first post).
1
- ago
#22
QUOTE:
I wonder if Fidelity just responds more sluggishly shortly after market close time which is when I usually place orders.


Fido's order submission is pretty responsive throughout, including open/close. Position updates are a different matter. Plus MT sends an order notification immediately after submission, before getting order status response. And 7 seconds consistently is way too much of a coincidence. Log would show all that.
0

Reply

Bookmark

Sort