开云体育

ctrl + shift + ? for shortcuts
© 2025 开云体育
Date

Re: Long on the stock, want to exit but: Order rejected The contract is not available for short sale

 

A,? If it's in your paper account, welcome to IB..

If it's production, check that the contractID is the same, and the exchange is right (SMART, or whatever came on the Position record itself). If IB were to think it was a different security, your sell would be from a basis of 0 making it a short.

Otherwise report it IB, and send in your logs.

-Peter


Re: Long on the stock, want to exit but: Order rejected The contract is not available for short sale

 

No, it tried to sell half the position.
A


Re: Long on the stock, want to exit but: Order rejected The contract is not available for short sale

 

Is your algorithm trying to sell more shares than what the position holds? Maybe the fill quantity was slightly smaller than what the algorithm had ordered?

JR


On Thu, Apr 29, 2021 at 09:02 PM, Ace wrote:
Hi,

My algo took a long position on a stock and when target was reached and wanted to exit I got this message:
201 Order rejected - reason:The contract is not available for short sale.

I'm aware of? this message if I want to go short on a stock.
But if I bought and own the shares why does this happen?

The algo runs in paper trading account so is it related?
Can this really happen live?

Thanks
A


Long on the stock, want to exit but: Order rejected The contract is not available for short sale

 

Hi,

My algo took a long position on a stock and when target was reached and wanted to exit I got this message:
201 Order rejected - reason:The contract is not available for short sale.

I'm aware of? this message if I want to go short on a stock.
But if I bought and own the shares why does this happen?

The algo runs in paper trading account so is it related?
Can this really happen live?

Thanks
A


Re: Custom Scanners?

 

Patrick,

Re: "we cannot pull our already made scanners in TWS into Python?"
No, we can not, but we can look inside the already made scanner?to get all the associated attributes names etc.
Click on the floppy-disk icon in the top-right corner of the TWS classic scanner window and choose "Save template":

image.png

and store the file, then look inside that file and you'll see "internals" of your custom scanner:

image.png

Another place to have a sneak-peek inside your TWS scanners is to analyze TWS log lines around the time when you sent the scanner request. It will be serialized to one loong string with all the parameters and their values.

Cheers,
Dmitry Shevkoplyas


On Thu, Apr 29, 2021 at 3:14 PM hymagik via <hymagik=[email protected]> wrote:
On Thu, Apr 29, 2021 at 07:08 AM, Despair wrote:

LOW_OPEN_GAP, HIGH_OPEN_GAP,

Look what you look for.
As stated below also if you make a call to reqScannerParameters()?
You will get back an XML with some specifics related to each classe of instruments
But I suspect that you do not need theses (while they can be helpfull by allowing finer screening based on corporate key factors like DIVYIELD, PRICE_2_SALES, PERATIO

In case you consider it, the answer is something like a series or entries alike this single one below (for STK)

Sorry the "Past" remove some '>' and '<' but you should get the idea.

?? ???? <Instrument
?? ???? ??? <name US Stocks /name>
?? ???? ??? <type STK /type>
?? ???? ??? <filters AFTERHRSCHANGEPERC,AVGOPTVOLUME,AVGPRICETARGET,AVGRATING,AVGTARGET2PRICERATIO,AVGVOLUME,AVGVOLUME_USD,CHANGEOPENPERC,CHANGEPERC,EMA_20,EMA_50,EMA_100,EMA_200,PRICE_VS_EMA_20,PRICE_VS_EMA_50,PRICE_VS_EMA_100,PRICE_VS_EMA_200,DIVIB,DIVYIELD,DIVYIELDIB,FEERATE,FIRSTTRADEDATE,GROWTHRATE,HALTED,HASOPTIONS,HISTDIVIB,HISTDIVYIELDIB,IMBALANCE,IMBALANCEADVRATIOPERC,IMPVOLAT,IMPVOLATOVERHIST,INSIDEROFFLOATPERC,INSTITUTIONALOFFLOATPERC,MACD,MACD_SIGNAL,MACD_HISTOGRAM,MKTCAP,MKTCAP_USD,NEXTDIVAMOUNT,NEXTDIVDATE,NUMPRICETARGETS,NUMRATINGS,NUMSHARESINSIDER,NUMSHARESINSTITUTIONAL,OPENGAPPERC,OPTVOLUME,OPTVOLUMEPCRATIO,PERATIO,PPO,PPO_SIGNAL,PPO_HISTOGRAM,PRICE,PRICE2BK,PRICE2TANBK,PRICERANGE,PRICE_USD,QUICKRATIO,REBATERATE,REGIMBALANCE,REGIMBALANCEADVRATIOPERC,RETEQUITY,SHORTABLESHARES,SHORTSALERESTRICTED,SIC,ISSUER_COUNTRY_CODE,SOCSACT,SOCSNET,STKTYPE,STVOLUME_3MIN,STVOLUME_5MIN,STVOLUME_10MIN,TRADECOUNT,TRADERATE,UNSHORTABLE,VOLUME,VOLUMERATE,VOLUME_USD,RCGLTCLASS,RCGLTENDDATE,RCGLTIVALUE,RCGLTTRADE,RCGITCLASS,RCGITENDDATE,RCGITIVALUE,RCGITTRADE,RCGSTCLASS,RCGSTENDDATE,RCGSTIVALUE,RCGSTTRADE,ESG_SCORE,ESG_COMBINED_SCORE,ESG_CONTROVERSIES_SCORE,ESG_RESOURCE_USE_SCORE,ESG_EMISSIONS_SCORE,ESG_ENV_INNOVATION_SCORE,ESG_WORKFORCE_SCORE,ESG_HUMAN_RIGHTS_SCORE,ESG_COMMUNITY_SCORE,ESG_PRODUCT_RESPONSIBILITY_SCORE,ESG_MANAGEMENT_SCORE,ESG_SHAREHOLDERS_SCORE,ESG_CSR_STRATEGY_SCORE,ESG_ENV_PILLAR_SCORE,ESG_SOCIAL_PILLAR_SCORE,ESG_CORP_GOV_PILLAR_SCORE,IV_RANK13,IV_RANK26,IV_RANK52,IV_PERCENTILE13,IV_PERCENTILE26,IV_PERCENTILE52,HV_RANK13,HV_RANK26,HV_RANK52,HV_PERCENTILE13,HV_PERCENTILE26,HV_PERCENTILE52,PRICE_2_SALES,EQUITY_PER_SHARE,UTILIZATION,SSCORE,SCHANGE,SVSCORE,SVCHANGE /filters>
?? ???? ??? <group STK.GLOBAL /group>
?? ???? ??? <shortName US /shortName>
?? ???? ??? <cloudScanNotSupported false /cloudScanNotSupported>
?? ???? </Instrument>


Re: Reporting Script Code, I think its awesome, you might like it too!

 

Here's a photo of sample output. Just saw the Mark To Market is wrong, should say $2,680 with $378 in Commissions. It's a pretty neat output. You're going to have to go into the code and change that lol.?


code/script in API to close/shutdown TWS

 

Hi Josh/Group,

Please pardon if ever disclosed. Does anyone know if there exists corresponding code/script in API to close/shutdown TWS from within java, i.e. from within an IDE?? Reboot/refresh purposes.?? Please advise. ?


Thank you,
Rv


Re: CANNOT COMPILE C++ CODE WITH VISUAL STUDIO 2017

 

The project come with default SDK /Plateform settings (generally Win 8.1)
This is your responsibility as the owner or teh compiler to setup/reset the proper setting according to your Microsoft SDK setup
Go in project setting and adjust the "Windows SDK version" to something that is suggest By VS because already installed.

Like below



Check also


Which are specifics to my MS VS Studio setting
And it work like a charm with basic projet setup


Re: Do I need to create a GUI for using the IBAPI sample program TestCppClient. Thanks.

 

Yes!

In case you want to dig UI like, run the C# version (if you have VS STudio), it have some UI that may give a seed for something assuming you know or will master a little of C#
But I suspect that as Richard explained it, you need to master the UI yourself, or see

Not sure how official is this shell


Re: Custom Scanners?

 

On Thu, Apr 29, 2021 at 07:08 AM, Despair wrote:

LOW_OPEN_GAP, HIGH_OPEN_GAP,

Look what you look for.
As stated below also if you make a call to reqScannerParameters()?
You will get back an XML with some specifics related to each classe of instruments
But I suspect that you do not need theses (while they can be helpfull by allowing finer screening based on corporate key factors like DIVYIELD, PRICE_2_SALES, PERATIO

In case you consider it, the answer is something like a series or entries alike this single one below (for STK)

Sorry the "Past" remove some '>' and '<' but you should get the idea.

?? ???? <Instrument
?? ???? ??? <name US Stocks /name>
?? ???? ??? <type STK /type>
?? ???? ??? <filters AFTERHRSCHANGEPERC,AVGOPTVOLUME,AVGPRICETARGET,AVGRATING,AVGTARGET2PRICERATIO,AVGVOLUME,AVGVOLUME_USD,CHANGEOPENPERC,CHANGEPERC,EMA_20,EMA_50,EMA_100,EMA_200,PRICE_VS_EMA_20,PRICE_VS_EMA_50,PRICE_VS_EMA_100,PRICE_VS_EMA_200,DIVIB,DIVYIELD,DIVYIELDIB,FEERATE,FIRSTTRADEDATE,GROWTHRATE,HALTED,HASOPTIONS,HISTDIVIB,HISTDIVYIELDIB,IMBALANCE,IMBALANCEADVRATIOPERC,IMPVOLAT,IMPVOLATOVERHIST,INSIDEROFFLOATPERC,INSTITUTIONALOFFLOATPERC,MACD,MACD_SIGNAL,MACD_HISTOGRAM,MKTCAP,MKTCAP_USD,NEXTDIVAMOUNT,NEXTDIVDATE,NUMPRICETARGETS,NUMRATINGS,NUMSHARESINSIDER,NUMSHARESINSTITUTIONAL,OPENGAPPERC,OPTVOLUME,OPTVOLUMEPCRATIO,PERATIO,PPO,PPO_SIGNAL,PPO_HISTOGRAM,PRICE,PRICE2BK,PRICE2TANBK,PRICERANGE,PRICE_USD,QUICKRATIO,REBATERATE,REGIMBALANCE,REGIMBALANCEADVRATIOPERC,RETEQUITY,SHORTABLESHARES,SHORTSALERESTRICTED,SIC,ISSUER_COUNTRY_CODE,SOCSACT,SOCSNET,STKTYPE,STVOLUME_3MIN,STVOLUME_5MIN,STVOLUME_10MIN,TRADECOUNT,TRADERATE,UNSHORTABLE,VOLUME,VOLUMERATE,VOLUME_USD,RCGLTCLASS,RCGLTENDDATE,RCGLTIVALUE,RCGLTTRADE,RCGITCLASS,RCGITENDDATE,RCGITIVALUE,RCGITTRADE,RCGSTCLASS,RCGSTENDDATE,RCGSTIVALUE,RCGSTTRADE,ESG_SCORE,ESG_COMBINED_SCORE,ESG_CONTROVERSIES_SCORE,ESG_RESOURCE_USE_SCORE,ESG_EMISSIONS_SCORE,ESG_ENV_INNOVATION_SCORE,ESG_WORKFORCE_SCORE,ESG_HUMAN_RIGHTS_SCORE,ESG_COMMUNITY_SCORE,ESG_PRODUCT_RESPONSIBILITY_SCORE,ESG_MANAGEMENT_SCORE,ESG_SHAREHOLDERS_SCORE,ESG_CSR_STRATEGY_SCORE,ESG_ENV_PILLAR_SCORE,ESG_SOCIAL_PILLAR_SCORE,ESG_CORP_GOV_PILLAR_SCORE,IV_RANK13,IV_RANK26,IV_RANK52,IV_PERCENTILE13,IV_PERCENTILE26,IV_PERCENTILE52,HV_RANK13,HV_RANK26,HV_RANK52,HV_PERCENTILE13,HV_PERCENTILE26,HV_PERCENTILE52,PRICE_2_SALES,EQUITY_PER_SHARE,UTILIZATION,SSCORE,SCHANGE,SVSCORE,SVCHANGE /filters>
?? ???? ??? <group STK.GLOBAL /group>
?? ???? ??? <shortName US /shortName>
?? ???? ??? <cloudScanNotSupported false /cloudScanNotSupported>
?? ???? </Instrument>


Re: Can a bracket order have two take profit orders to exit a position at two different profit levels?

 

Yeah, AFAIK it's not possible to set different sizes in a simple bracket order so it's pretty perplexing that IB support would suggest that. It is possible with the pair-trade variety of the bracket order but even then the sizes are not set independently but using a beta-ratio.


Re: Model Portfolios functionality in TWS API

 

Is this possible using the TWS API?


Re: Custom Scanners?

 

In addition here are the some specific filters:

ScannerSubscription scannerSubsctiption = new ScannerSubscription();
?
scannerSubsctiption.numberOfRows(scannerResultRows);
scannerSubsctiption.scanCode("HOT_BY_PRICE");
scannerSubsctiption.instrument("STK");
scannerSubsctiption.locationCode("STK.US.MAJOR");
scannerSubsctiption.stockTypeFilter("ALL");
scannerSubsctiption.abovePrice(abovePrice);
scannerSubsctiption.belowPrice(belowPrice);

? ? ? ? ? ? ? ? List<TagValue> scannerTagValues?= Arrays.asList(new TagValue("volumeRateAbove", "2000"));

? ? ? ? ? ? ? ? socket.reqScannerSubscription(scannerId, scannerSubsctiption, null,? scannerTagValues);



Re: Can a bracket order have two take profit orders to exit a position at two different profit levels?

 

Forgot to attached a couple screen grabs.

First the five orders. Please note that 23.1 was placed with a quantity of 500.via the API.



Attempt to change quantity of 23.1 via API fails without error and TWS quanitty field is greyed out.


Re: Can a bracket order have two take profit orders to exit a position at two different profit levels?

 

I actually tried that (and slight variations) when I saw your original post last night, but it did not work for me.

What happens is that IB automatically sets the quantity for #3 to the same full amount of #1. I guess the basic idea is that the profit and stop legs of a bracket order should protect the entire position.

If you just place orders #1, #3, and #4 (no stop loss orders in the brackets) you can actually adjust quantities to Full/Half/Half right after the three orders are placed. Both via API or TWS. But once #1 was filled, IB again adjusted quantity of? #3 to the actually filled quantity. Again it was possible to adjust the quantity of #3 (the now active order) to Half via API or TWS.

When placing all five orders, quantity changes failed via API and the fields were greyed out in TWS.

JR


On Thu, Apr 29, 2021 at 10:22 AM, Levente wrote:
Unfortunately I did not have the luxury (time) to try this out myself, so a BIG thank you to Richard.
However, I managed to call IB API support and was suggested the following:

Create 5 (!!!) orders
1. Position opening order (assume ID is 1)
2. Stop loss order for the full amount (assume ID is 2) + set parent to 1
3. Take profit order for HALF of the amount?(assume ID is 3) + set parent to 1
4. Take profit order for HALF of the amount at the other price level (assume ID is 4)? + set parent to 3
5. Stop loss order for HALF of the amount (assume ID is 5) + set parent to 3

When position opening order fills, orders with ID 2 and 3 will get activated.
If stop loss order 2 fills, the take profit 3 will get cancelled and orders 4 and 5 will never activate.
If take profit order 3 fills, the stop loss order 2 will get cancelled, and orders 4 and 5 will get activated and will belong to a NEW OCA group.

I will try this out and will post my findings.


Re: Can a bracket order have two take profit orders to exit a position at two different profit levels?

Nick
 

Ruh roh, the forum may have gotten pwned by IP support.

On 4/29/2021 11:22 AM, Levente wrote:
However, I managed to call IB API support and was suggested the following:


Re: Can a bracket order have two take profit orders to exit a position at two different profit levels?

 

Unfortunately I did not have the luxury (time) to try this out myself, so a BIG thank you to Richard.
However, I managed to call IB API support and was suggested the following:

Create 5 (!!!) orders
1. Position opening order (assume ID is 1)
2. Stop loss order for the full amount (assume ID is 2) + set parent to 1
3. Take profit order for HALF of the amount?(assume ID is 3) + set parent to 1
4. Take profit order for HALF of the amount at the other price level (assume ID is 4)? + set parent to 3
5. Stop loss order for HALF of the amount (assume ID is 5) + set parent to 3

When position opening order fills, orders with ID 2 and 3 will get activated.
If stop loss order 2 fills, the take profit 3 will get cancelled and orders 4 and 5 will never activate.
If take profit order 3 fills, the stop loss order 2 will get cancelled, and orders 4 and 5 will get activated and will belong to a NEW OCA group.

I will try this out and will post my findings.


Re: Custom Scanners?

 

Here is a list of available scancodes. I don't know if there are more.

TOP_PERC_GAIN,
? TOP_PERC_LOSE,
? MOST_ACTIVE,
? ALL_SYMBOLS_ASC,
? ALL_SYMBOLS_DESC,
? BOND_CUSIP_AZ,
? BOND_CUSIP_ZA,
? FAR_MATURITY_DATE,
? HALTED,
? HIGH_BOND_ASK_CURRENT_YIELD_ALL,
? HIGH_BOND_ASK_YIELD_ALL,
? HIGH_BOND_DEBT_2_BOOK_RATIO,
? HIGH_BOND_DEBT_2_EQUITY_RATIO,
? HIGH_BOND_DEBT_2_TAN_BOOK_RATIO,
? HIGH_BOND_EQUITY_2_BOOK_RATIO,
? HIGH_BOND_EQUITY_2_TAN_BOOK_RATIO,
? HIGH_BOND_NET_ASK_CURRENT_YIELD_ALL,
? HIGH_BOND_NET_ASK_YIELD_ALL,
? HIGH_BOND_NET_SPREAD_ALL,
? HIGH_BOND_SPREAD_ALL,
? HIGH_COUPON_RATE,
? HIGH_DIVIDEND_YIELD,
? HIGH_DIVIDEND_YIELD_IB,
? HIGHEST_SLB_BID,
? HIGH_GROWTH_RATE,
? HIGH_MOODY_RATING_ALL,
? HIGH_OPEN_GAP,
? HIGH_OPT_IMP_VOLAT,
? HIGH_OPT_IMP_VOLAT_OVER_HIST,
? HIGH_OPT_OPEN_INTEREST_PUT_CALL_RATIO,
? HIGH_OPT_VOLUME_PUT_CALL_RATIO,
? HIGH_PE_RATIO,
? HIGH_PRICE_2_BOOK_RATIO,
? HIGH_PRICE_2_TAN_BOOK_RATIO,
? HIGH_QUICK_RATIO,
? HIGH_RETURN_ON_EQUITY,
? HIGH_SYNTH_BID_REV_NAT_YIELD,
? HIGH_VS_13W_HL,
? HIGH_VS_26W_HL,
? HIGH_VS_52W_HL,
? HOT_BY_OPT_VOLUME,
? HOT_BY_PRICE,
? HOT_BY_PRICE_RANGE,
? HOT_BY_VOLUME,
? LIMIT_UP_DOWN,
? LOW_BOND_BID_CURRENT_YIELD_ALL,
? LOW_BOND_BID_YIELD_ALL,
? LOW_BOND_DEBT_2_BOOK_RATIO,
? LOW_BOND_DEBT_2_EQUITY_RATIO,
? LOW_BOND_DEBT_2_TAN_BOOK_RATIO,
? LOW_BOND_EQUITY_2_BOOK_RATIO,
? LOW_BOND_EQUITY_2_TAN_BOOK_RATIO,
? LOW_BOND_NET_BID_CURRENT_YIELD_ALL,
? LOW_BOND_NET_BID_YIELD_ALL,
? LOW_BOND_NET_SPREAD_ALL,
? LOW_BOND_SPREAD_ALL,
? LOW_COUPON_RATE,
? LOWEST_SLB_ASK,
? LOW_GROWTH_RATE,
? LOW_MOODY_RATING_ALL,
? LOW_OPEN_GAP,
? LOW_OPT_IMP_VOLAT,
? LOW_OPT_IMP_VOLAT_OVER_HIST,
? LOW_OPT_OPEN_INTEREST_PUT_CALL_RATIO,
? LOW_OPT_VOLUME_PUT_CALL_RATIO,
? LOW_PE_RATIO,
? LOW_PRICE_2_BOOK_RATIO,
? LOW_PRICE_2_TAN_BOOK_RATIO,
? LOW_QUICK_RATIO,
? LOW_RETURN_ON_EQUITY,
? LOW_SYNTH_ASK_REV_NAT_YIELD,
? LOW_VS_13W_HL,
? LOW_VS_26W_HL,
? LOW_VS_52W_HL,
? LOW_WAR_REL_IMP_VOLAT,
? MARKET_CAP_USD_ASC,
? MARKET_CAP_USD_DESC,
? MOST_ACTIVE_AVG_USD,
? MOST_ACTIVE_USD,
? NEAR_MATURITY_DATE,
? NOT_OPEN,
? OPT_OPEN_INTEREST_MOST_ACTIVE,
? OPT_VOLUME_MOST_ACTIVE,
? PMONITOR_AVAIL_CONTRACTS,
? PMONITOR_CTT,
? PMONITOR_IBOND,
? PMONITOR_RFQ,
? TOP_OPEN_PERC_GAIN,
? TOP_OPEN_PERC_LOSE,
? TOP_OPT_IMP_VOLAT_GAIN,
? TOP_OPT_IMP_VOLAT_LOSE,
? TOP_PRICE_RANGE,
? TOP_STOCK_BUY_IMBALANCE_ADV_RATIO,
? TOP_STOCK_SELL_IMBALANCE_ADV_RATIO,
? TOP_TRADE_COUNT,
? TOP_TRADE_RATE,
? TOP_VOLUME_RATE,
? WSH_NEXT_ANALYST_MEETING,
? WSH_NEXT_EARNINGS,
? WSH_NEXT_EVENT,
? WSH_NEXT_MAJOR_EVENT,
? WSH_PREV_ANALYST_MEETING,
? WSH_PREV_EARNINGS,
? WSH_PREV_EVENT
?


Re: Can a bracket order have two take profit orders to exit a position at two different profit levels?

 

I recommend that you create two sets of orders with size N/2. Each set includes a parent order and the bracket order (stop loss and target limit).

--


Re: Can a bracket order have two take profit orders to exit a position at two different profit levels?

Nick
 

I don't know the commission impact or if it fits with your strategy but perhaps you could place two brackets each for N/2 shares. This would leave you always protected and you wouldn't have to deal with possible outages.

There's no perfect solution so it's a matter of picking the least evil alternative.

On 4/28/2021 5:47 PM, Levente wrote:
I would like to know if there is a mechanism that would allow me to place a position opening order for N contracts, together with two take profit orders, each of size N/2 but at different price levels.