Attributes position in Strategy - how to set value correctly?
-
I made my class broker, orders are sent and executed - ok.
But, how to set the value of attributes position correctly?
i see several methods:- using notify_trade, and thus set the value attributes position
- using self.data[0], and thus set the value attributes position
But how do it right in the broker class?
-
Addition, notify_trade sending only after call order.execute method. Its correctly.
How correctly setting self.position (upopened, size ... etc)?
I'm still :) looking in source ... -
@dmitry-prokopiev said in Attributes position in Strategy - how to set value correctly?:
how to set the value of attributes position correctly
Having a hard time understanding your question. Could you clarify what you are trying to accomplish with
value of attributes position
?Thanks.
-
@run-out thnx the answer :)
In documentation for the Strategy class, section Member Attributes has:
....
position: actually a property which gives the current position for data0.
Methods to retrieve all possitions are available (see the reference)This attribute, instance of class Position.
When the broker (class broker) receives an order to open a position, this attribute must be correctly set. -
@dmitry-prokopiev said in Attributes position in Strategy - how to set value correctly?:
position: actually a property
Position size does not need to be set. It is tracked in the
Position
class here. You can obtain the current position for a line using:getposition(data=None, broker=None)
Returns the current position for a given data in a given broker.
If both are None, the main data and the default broker will be used
A property position is also available -
@run-out How to tracking position - understandable.
But, if implemented broker class is, how to correctly set position (size, upclosed, upopened)?
-
@run-out in github, i searched and found an example (https://github.com/bartosh/backtrader/blob/ccxt/backtrader/brokers/ccxtbroker.py)
def _submit(self, owner, data, exectype, side, amount, price, params): order_type = self.order_types.get(exectype) _order = self.store.create_order(symbol=data.symbol, order_type=order_type, side=side, amount=amount, price=price, params=params) order = CCXTOrder(owner, data, amount, _order) self.notify(order) return order
Why is the order being re-created?
-
@run-out thnx, I understand
i misunderstood the order creation and interaction with a broker class