position problem:how to get order Index?(when I print position show “Opened: 0.01” )
-
I'm a beginner,My English is not good.Please forgive me.
I buy(size=0.01) 3 times in different price. such as: orderA,orderB,orderC
in notify_order,print(self.getposition(self.data)) last time show:--- Position Begin
- Size: 0.03
- Price: 1.0755933333333332
- Price orig: 1.0759599999999998
- Closed: 0
- Opened: 0.01
- Adjbase: 1.07323
--- Position End
I think:
Size: 0.03 = orderA.size+orderB.size+orderC.size
Opened: 0.01=orderC.sizeproblem:
1.how can I get orderA,orderB,orderC Index? I want to see their cost(order.executed.value)
2.how can I close orderB only? I want to close order by order.refmy English is not good, I use translation software, so the translation is not accurate.
it's hard to understand the document.
Can you write a demo for me?
Thank you very much. -
@magieva said in position problem:how to get order Index?(when I print position show “Opened: 0.01” ):
1.how can I get orderA,orderB,orderC Index? I want to see their cost(order.executed.value)
In the
notify_order()
printorder.executed.value
. So in case of N order, the script will printorder.executed.value
N times.2.how can I close orderB only? I want to close order by order.ref
Order can't be closed. It can be issued, accepted and executed. After the execution of the order the position size is increasing or decreasing.
-
@magieva said in position problem:how to get order Index?(when I print position show “Opened: 0.01” ):
1.how can I get orderA,orderB,orderC Index? I want to see their cost(order.executed.value)
Use
notify_order
, method ofStrategy
to receive the notifications for each order.@magieva said in position problem:how to get order Index?(when I print position show “Opened: 0.01” ):
2.how can I close orderB only? I want to close order by order.ref
That's an impossible. Here and in real life. Let me say it loud and clear: ORDERS ARE NOT POSITIONS, because an order is not open or closed. An order can be pending execution, partially executed, cancelled, rejected, but IT IS NOT YOUR POSITION in the market. The exchange does not keep track of which orders opened your position. Your orders are instructions to do something.
You can use
tradeid
to simulate trades which logically group orders. But you have to remember, that the EXCHANGE won't do that for you. -
Thank you for your answer.
I am used to MT4. The operation habit of order affects my understanding.
After understanding, I can think of an application: Calculate used margin
if order.status in [order.Completed]: # marginUsed for bit in order.executed.exbits: self.marginUsed += bit.openedvalue - bit.closedvalue
If this is not right, please give me suggestions and thank you again for your reply