I have recently deployed my strategy live using Tradier as my primary brokerage on a Cash account. However, when I deploy my strategy, I am getting errors regarding my buy orders
New Order Event: Time: 10/17/2023 14:19:00 OrderID: 3 EventID: 2 Symbol: SASI Status: Invalid Quantity: 10 LimitPrice: 3.79 Message: Brokerage failed to place orders: [3]
When calculating number of shares to buy for orders, I use Portfolio.Cash variable to calculate the amount of shares to buy. The issue is that variable only seems to return the the amount of cash cleared when starting the algorithm.
762
|
3:43:07
:
Cash Available: 1220.2700000000
Is there a way to get the “Available Funds” field from Tradier in QuantConnect?
Mia Alissi
QuantConnect syncs the algorithm's cash holdings with the cash holdings in your brokerage account every day at 7:45 AM Eastern Time (ET) source. However, it does not provide a direct way to access the "Available Funds" field from Tradier.
The error message you're seeing, "Brokerage failed to place orders", could be due to a variety of reasons. One common reason is not having enough margin or cash available in your account to place the order. This could be due to the fact that the Portfolio.Cash variable might not be updated in real-time and might not reflect the current available cash in your account.
To avoid this, you could consider implementing a check before placing an order to ensure you have enough cash available. Here's an example in Python:
In this example,
price
is the current price of the security you want to buy,quantity
is the number of shares you want to buy, andsymbol
is the symbol of the security.If you're still encountering issues, it might be helpful to post your question on the QuantConnect Forum where the community and QuantConnect team can provide more specific assistance.
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Clement Hill
Thank you for your answer Mia!
Though I am already implementing a similar check before placing orders, the Algorithm needs the available funds to do so. I am going to see if I can add Tradier API calls from my Algorithm directly in order to obtain that needed piece of information.
Mia Alissi
While it's possible to make direct API calls to Tradier from your algorithm, it's important to note that this might not be the best approach due to potential synchronization issues between the LEAN engine and the direct API calls.
The LEAN engine, which powers QuantConnect, is designed to manage all interactions with the brokerage, including fetching the latest cash balance. Making direct API calls could lead to a state where the LEAN engine and your algorithm have different views of the cash balance, which could lead to unexpected behavior.
If you're still encountering issues with the cash balance, I would recommend reaching out to the QuantConnect support team or posting a detailed question on the QuantConnect Forum. They might be able to provide more specific guidance based on the details of your algorithm and trading setup.
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Clement Hill
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!