I was trying this basic code to check get_open_orders() functionality. But it seems like it is not returning any thing ?
Is there anything I am missing ?
I was trying this basic code to check get_open_orders() functionality. But it seems like it is not returning any thing ?
Is there anything I am missing ?
This is the snippet of the output:
2011-01-04PRINTdabd2d76e471436c9bc33e2d4349756d
2011-01-04PRINT{}
2011-01-04PRINT{}
2011-01-04PRINT{}
2011-01-04PRINT{}
2011-01-04PRINT{}
2011-01-04PRINT{}
2011-01-04PRINT{}
2011-01-04PRINT{}
2011-01-04PRINT{}
2011-01-04PRINT{}
2011-01-04PRINT{}
2011-01-04PRINT{}
2011-01-04PRINT{}
2011-01-04PRINT{}
2011-01-04PRINT{}
2011-01-04PRINT{}
Hey harsh pahel,
Great start on testing things out and you're pretty much almost there! I think what's happening is that by the first time 'if context.invested' gets triggered, the order has already been fulfilled and consequently, 'get_open_orders' returns an empty dictionary.
One way way to go about this is to move the 'get_open_orders()' directly after you order 'context.aapl' and you should see it return something like '{Security(24[...]}'
if not context.invested:
order_id = order(context.aapl, 100)
print order_id
context.invested = True
open_orders = get_open_orders()
print "printing open_orders"
print open_orders
Does that do what you were looking for?
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 Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian 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.
Hello Seong Lee, thanks for clearing my confusion.
I was thinking that get_open_orders() will return my current position what I hold.
Can you tell me if there is any function which will return my current positions ?
Thanks
You're looking for the positions object. You can read about it in the help doc, and you can see a lot of usage examples.
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 Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian 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.
I have one more question Dan,
Okay so I was going through the api docs and found out that we can place target orders and stoploss orders. I have a confusion in that:
So suppose we placed both orders for AAPL, now if my target is achieved will my stoploss order automatically get cancelled? Or vice-versa like if we hit the stoploss first will the target order get cancelled ?
There are no automatic cancellations like that. I can see the appeal and we might build such an order type in the future. For now, though, you need to do your own order management and cancel orders that are no longer relevant.
There is one exception: in live trading, orders are canceled at the end of the day. That is different from the backtester where orders stay open indefinitely. That's one of the very few differences between the backtester and live trading.
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 Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian 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.