TWS API error: Invalid side field was entered

Hello,
When I testing auto trade with paper account, I got below error:

Invalid side field was entered

image
image

Any one experience the same error?

Below is my auto-execution code:


/*
=============================================
AUTO TRADING PART
==============================================
*/

if (Status("action") == actionExplore)
{
Symbol = Name();
PercentageOfAvailableFunds = 100; //% of Available Funds

if (LastValue(Buy) || LastValue(Sell) || LastValue(Short) || LastValue(Cover)) {
ibc = GetTradingInterface( "IB" );
if (ibc.IsConnected() ) {
pos = ibc.GetPositionSize(symbol);


// ################ Sell #################
if (LastValue(Sell)) {
if (pos > 0) {
orderID = ibc.PlaceOrder( symbol, "Sell", pos, "LMT", LastValue(C), 0, "GTC", True );
_TRACE("Sell "+symbol+", orderID "+orderID);
}
}

// ################ Buy #################
else if (LastValue(Buy)) {
if (pos == 0) {
CashBalance = StrToNum(ibc.GetAccountValue("CashBalance"));
Quantity =  CashBalance * PercentageOfAvailableFunds/100/LastValue(C);
_TRACE("CashBalance "+CashBalance+", Closing price "+LastValue(C)+", Quantity "+Quantity);
Quantity = Max(1, round(Quantity));
orderID = ibc.PlaceOrder( symbol, "Buy", Quantity, "LMT", LastValue(C), 0, "GTC", True );
_TRACE("Buy "+symbol+", orderID "+orderID);
}
else {
_TRACE("Order for "+symbol+" already exists!");
}
}


// ################ Cover #################
if (LastValue(Cover)) {
if (pos > 0) {
orderID = ibc.PlaceOrder( symbol, "Cover", pos, "LMT", LastValue(C), 0, "GTC", True );
_TRACE("Cover "+symbol+", orderID "+orderID);
}
}


// ################ Short #################
else if (LastValue(Short)) {
if (pos == 0 ) {
CashBalance = StrToNum(ibc.GetAccountValue("CashBalance"));
Quantity =  CashBalance * PercentageOfAvailableFunds/100/LastValue(C);
_TRACE("CashBalance "+CashBalance+", Closing price "+LastValue(C)+", Quantity "+Quantity);
Quantity = Max(1, round(Quantity));
orderID = ibc.PlaceOrder( symbol, "Short", Quantity, "LMT", LastValue(C), 0, "GTC", True );
_TRACE("Short "+symbol+", orderID "+orderID);
}
else {
_TRACE("Order for "+symbol+" already exists!");
}
}

}

// ################ Not Connected #################
else {
Error("IB Controller Interface is not connected");
}
}
}



Hi @Tomasz, could you please have look?

All messages that are shown in the "Messages" tab are NOT created by AmiBroker.
They are generated by TWS (Traders Workstation).

They are listed on IB web site:
https://interactivebrokers.github.io/tws-api/message_codes.html

If you don't understand those messages, you need to ask IB support because these are THEIR messages generated by THEIR software and they have access to your account logs and can take a look.

I don't have that access because I do not work for Interactive Brokers.

1 Like

i meant maybe my code is wrong

You're either going to "Buy" or "Sell". There is no "Cover" side in the Interactive Brokers API. You "Buy" a short to close it with a "LMT" order. So change your "Cover" to "Buy".

2 Likes

Thank you! You saved me!

Recommended reading is the DOCUMENTATION.
http://www.amibroker.com/at/

It is clearly stated what allowed values of Action parameter are in the PlaceOrder/ModifyOrder.

One note about the Action parameter. Current IB API documentation advises retail traders not to use "SSHORT". According to them, it's intended for institutional trading use.

"SSHORT is only supported for institutional account configured with Long/Short account segments or clearing with a separate account."

https://interactivebrokers.github.io/tws-api/classIBApi_1_1Order.html

1 Like

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.