Error 321. An error occurred while validating the request:-"bq"

Hi, i am new in IBController, i made a code for autotrading but when i turn on IBController show me this error, " Error 321. An error occurred while validating the request:-'bq' : cause - Invalid account code ".

I saw many topics but i didn't find the solution. I have a demo account in Interactive Brokers, it can be the reason for that?


Unfortunately your question isn't clear enough and does not provide all necessary details to give you an answer. Please follow this advice: How to ask a good question

From minimum information you provided it can be guessed that you did not set account properly.

Hello EduardoFanju,

Please try/install current 'Offline TWS Latest' Version 979.4z.

This error is not generated by IBController but by TWS.

321: Server error when validating an API client request
bq : not listed by IB API error codes, but cause => 'Invalid account code'

Please check your TWS/AB setup is working fully, your AB database is connected via IB data Plug-in, configure port 7496 and localhost
You have to configure port 7496 additional in 'TWS API' section.

I think you try something like backfill quotes/send order and it is not supported by IB with your demo account/login cerdentials through TWS, you are not authenticated correct (at)IB or your TWS/AB setup does not work.

To check out this first try to create orders direct in TWS.

To develop correct AFL code please study:

Additional you could try to get support from InteractiveBrokers direct:

regards, Peter


I try your solution, the only problem is AB dont know I have position.any solutionScreenshot_5 for that ?

Hello Muli,

TWS has to be started and configured correct...

AB IB Controller is a standalone application. On my trading pc i allowed via Windows 10 firewall rules "BrokerIB.exe" to communicate ANY within my private network.

Did you register AB IB Controller and configure your ip/port to communicate with TWS ?

  1. Register IB Controller and receive your "Unlock code"

IB Controller - File - "Enter Unlock code"


  1. Configure your ip/port settings correct, port must be the same configured in TWS API section

IB Controller - File - "Configure" := local host := your PC


  1. If your setup is correct you will be able to verify correct communication via
    IB Controller - (TAB) "Messages", you can also check your account information is correct ...


In any case of errors you will find in (TAB) "Messages" other corresponding errors with TWS API

  1. If you have errors, you have to check your TWS API settings. It is absolut necessary you enable option "Enable ActiveX and Socket Client". You will find all TWS API settings in TWS Main - Edit - "Global Configuration..."

Your settings should look like:


And YES, if everything is done correct you will see/find your current positions in AB IB Controller "Portfolio"



regards, Peter

1 Like

tnx for your reply. my problem as you can see from the pic. attach is that in the account code I got A at the end of the account that makes the problem, my question it in the TWS setting or in the account set by the web?
again tnx for your help


Clearly the account number is incorrect because you have empty cash balance.

You still don't follow advice given here How to ask a good question

Formula - missing, account type - missing, description what you did - missing, list of errors you get - missing

Hi @Muli ,
since this post is little bit old. Did you find solution to your issue? Unfortunattely I have same problem on one of my account (Account with "A" in the end). Thank you!

The solution WAS GIVEN in this very thread. Post #3 Error 321. An error occurred while validating the request:-"bq" - #3 by Pietro

Use SetInfoAccount function to switch account to correct number.