Skip to content

place_order is failing #83

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jbaron opened this issue Mar 27, 2025 · 10 comments
Closed

place_order is failing #83

jbaron opened this issue Mar 27, 2025 · 10 comments

Comments

@jbaron
Copy link

jbaron commented Mar 27, 2025

When I try to place an order I get an exception:

:: 400 :: Bad Request :: {"error":"orders request includes parameter with incorrect type"}

The reason I figured out through some trial and error is that we send the conid as a string and it expects it to be an int. This simple snippet is working:

 msg = {'orders': [{'conid': 80986742, 'side': 'BUY', 'quantity': 1, 'orderType': 'LMT', 'price': 46, 'tif': 'GTC'}]}
 client.post(f"iserver/account/{account_id}/orders", msg)
@salsasepp
Copy link

Hi, thank you for reporting. I didn't run into this yet. Would you be able to share a minimal code example that demonstrates the issue?

@jbaron
Copy link
Author

jbaron commented Mar 28, 2025

Sure no problem. Right now away from my computer, but will later create a few lines that can recreate the problem.

Not sure relevant, but using a paper trade account for now with oauth and my broker is IBKR Ireland

@Voyz
Copy link
Owner

Voyz commented Mar 28, 2025

hey @jbaron thanks for reporting 👍

IBind should send conid as either str or int, depending on what you provide. Can you share the code you use to place orders? Are you placing it with a string conid?

@jbaron
Copy link
Author

jbaron commented Mar 28, 2025

from time import sleep
from dotenv import load_dotenv

load_dotenv()

from ibind import IbkrClient, OrderRequest


def main():
    client = IbkrClient(use_oauth=True, use_session=True)
    ok = client.check_health()
    assert ok, "health not ok"
    sleep(1)
    
    accounts = {}
    while not accounts:
        accounts = client.receive_brokerage_accounts().data
        sleep(1)

    account_id = accounts["accounts"][0]  # type: ignore
    client.account_id = account_id

    conid = '80986742'
    req = OrderRequest(conid=conid, side="BUY", quantity=1, order_type="MKT", acct_id=str(client.account_id)) # type: ignore
    result = client.place_order(req, {})
    print(result)



if __name__ == "__main__":
    main()

The above will fail. If I change the conid to an int it will work. So the parameter type should be int only (or a conversion to an int needs to take place within the method body).

@salsasepp
Copy link

@Voyz Not sure how to proceed with this. Does conid as a str make sense under certain circumstances? If not, I believe it should be int only as suggested by @jbaron . I noticed that conid is returned by the WebAPI sometimes as an int, sometimes as a str, maybe not even IBKR knows what it should be.

@Voyz
Copy link
Owner

Voyz commented Apr 1, 2025

I agree, we should cast to int here. Indeed IBKR sometimes works with one, sometimes the other. I'll change the conid field in OrderRequest to be only int. Thanks for your example @jbaron 👍

@Voyz
Copy link
Owner

Voyz commented Apr 6, 2025

hey @jbaron please try pip install ibind==0.1.14 with the fix and let me know if it works 👍

@jbaron
Copy link
Author

jbaron commented Apr 6, 2025

Thanks !!! Seems to be fixed, although outside trading hours some of my test fail due to unexpected responses. So will try it a bit more tomorrow.

@jbaron
Copy link
Author

jbaron commented Apr 11, 2025

Last few days it is working great. Thanks for this creating this nice library.

@jbaron jbaron closed this as completed Apr 14, 2025
@Voyz
Copy link
Owner

Voyz commented Apr 14, 2025

hey @jbaron great news! Thanks for your patience and for reporting this 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants