Back

How to get historical transactions from broker?

During Live trading, this is what I want to accomplish..

Periodically retrieve all new transactions from trading account at broker since the previous run of the same.  Meaning say for every hour, I want to get list of all transactions from my live trading account from OandA broker for the last hour.  That list must include new orders placed, orders filled, orders changed, and even those transactions which were executed out side of QC through other interfaces lke (MT4 or web or desktop client).  Similar to its activity tab in desktop client or Full Transaction History.

Is this even possible?  If yes, how shoud I go for that?  I think brokerage model might be able to help me out but not sure how..

Thank you for your help and guidance.

Shailesh.

Update Backtest







0

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.


Hi Shailesh,

For all transactions made to brokers through QC, self.Transactions.GetOrders(filter) will return a list of all orders that pass a certain filter. If we pass None in for our filter, we get all orders in the transaction history. Once we have our orders, we can filter them by Order.Time, which returns the utc time the order was created, and Order.LastUpdateTime, which returns the utc time the order was last updated or None if it hasn't been updated. To retrieve all orders that have been created or updated within the last hour, we can do something like this:
 

recentTransactions = [order for order in self.Transactions.GetOrders(None) if (self.UtcTime - order.Time) <= timedelta(hours = 1) or (order.LastUpdateTime != None and (self.UtcTime - order.LastUpdateTime) <= timedelta(hours = 1))]

 

0

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.


Hi Rahul,

Thank you.

I understand this.  Is there a way to get ALL transactions occured in my live trading account with oanda broker including transactions not executed through QC?   

Another query: 

Does   self.Transactions.GetOrders(filter)   return those orders/transactions which were rejected due to OandA's FIFO order execution policy?    FIFO policy dictates that any open trades with TP or SL set should have unique order size.  Meaning no two orders with TP/SL can have same unit size.  Say  you have a pverall long position with few open long trades and if you place any short/sell limit order which (potentially) may make two trades with same units/size, that new order will be rejected irrespective of order type (market or limit).  For example, if you have two trades with units 2000 and 1000 with respective TPs, any new sell order (market or limit) with TP/SL with unit size 1000 will be rejected at the time of execution as that new order will make two open trades with TP/SL of same size i.e. 1000 . 

I hope I explain my query accurately.  Please let me know if otherwise.

Thanks

Shailesh.

0

QC populates your algorithm with open orders not placed by the algo, but

the closed ones. Then GetOrders or GetOpenOrders should return the list of

the orders.



This is available after initialize()
1

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.


Is this one-time thing?   does GetOrders() return orders directly from broker or from QC copy of orders list?  Meaning if some orders are placed outside of QC and in parallal to QC Algo run,, are they reported by GetOrders()? 

Say Time T1 QC Algo started/initiated

Time T2  QC populates current open orders from broker

Time T3   some orders are placed directly to broker outside of QC

Time  T4  some direct orders get filled

Time T5  GetOrders() is called within algo

What all orders do I get when GetOrders() is called?

--  All orders which were open at Time T2 with the broker

-- All orders placed by QC between Time T2 and Time T5

??  Orders placed outside of QC at time T3 but not the filled ones at time T4

?? All Orders placed outside of QC at time T3 including the filled ones at time T4.

There may be further complexity like some (QC and/or direct) orders are changed/modified/cancelled/rejected  outside of QC algo run. 

How are they handled within QC?

How is FIFO related rejection handled in QC live algo run?

Thanks

Shailesh.

0

QC does not support interfering with the brokerage, any detected external

orders kill the algorithm immediately
0

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.


Interesting..  How does QC detect external orders?  Does it poll periodically? if yes, what frequency?   Is it interupt driven?   How has it been implemented?  

May be personal thinking, but killing algo immediately is not optimal policy decision,,

0

Imagine you have algorithms that ensure a 20% allocation to AAPL, and manual orders keep trying to sell the position. The algorithm would "go crazy" immediately rebuying the stocks, or imagine you have pending orders which are externally canceled, and internal state dependant on that order filling.. etc, There are sadly no good options to allow manual interactions other than via the algo-lab where the order is filled by the algorithm itself and state is maintained.

LEAN detects the externally filled orders as all order fills (streamed from brokerage API to LEAN). 

0

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.


There is no disagreement over complexity due to allowing external interections.  Still Killing algo is harse.

 

0

Update Backtest





0

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.


Loading...

This discussion is closed