1

I'm working on a test algorithm using IBapi with python (IBKR native API). How can I get the prices my market orders were filled at? I looked into the official documentation but it was hard to understand.

I would be so grateful if you could help me.

  • 1
    I doubt if it is something suitable to stackoverflow, which is more to deal with technical questions. Anyway, with a quick glance, I think what you need to look into is Execution. – Adrian Shum Aug 21 '20 at 19:51
  • 1
    I’m voting to close this question because this question is related to business knowledge instead of a technical question which Stackoverflow aimed for – Adrian Shum Aug 21 '20 at 19:57
  • Thank you so much for the answer, I'll do what you suggested. – Satoshi Nakamoto Aug 21 '20 at 20:30
  • 1
    By the way, the help I was looking for is the right "code" to give the API so it is suitable to post in Stackoverflow I think. – Satoshi Nakamoto Aug 21 '20 at 20:32

1 Answers1

2

This is partial code but implement these callbacks in your wrapper impl.

def execDetails(self, reqId: int, contract: Contract, execution: Execution):
    print("ExecDetails. ReqId:", reqId, "Symbol:", contract.symbol, "SecType:", 
           contract.secType, "Currency:", contract.currency, execution)

If you look up the Execution class you'll see a field for price along with some others.

You should also impl

def orderStatus(self, orderId: OrderId, status: str, filled: float,
                remaining: float, avgFillPrice: float, permId: int,
                parentId: int, lastFillPrice: float, clientId: int,
                whyHeld: str, mktCapPrice: float):

Which will be called may times depending on the order and the avgFIllPrice will be current.

brian
  • 10,619
  • 4
  • 21
  • 79
  • Thank you so so much, I really appreciate the help. – Satoshi Nakamoto Aug 22 '20 at 08:53
  • Is it possible to use for example "execution.price" as a variable and plug it in functions later in the code? **sorry if my questions are stupid but I'm just new to all this – Satoshi Nakamoto Aug 22 '20 at 17:33
  • @Elias execution is a class and price is a field, look at the docs and source code. Maybe do some python tutorials first. I haven't seen your code but normally your wrapper class will have fields and one could be assigned to like `self.price = execution.price` for just the price. – brian Aug 22 '20 at 18:43
  • Oh okay, thank you so much again for the help. I appreciate it – Satoshi Nakamoto Aug 22 '20 at 18:57