API setDesiredPositions

I have a couple questions about setDesiredPositions API call:

  1. Does each call override the previous if it has not been executed?
  2. To go flat on a symbol can you just leave it out of the call or do you have to specify 0 shares?

Hi,

did you figure this out? I have the same question…

  1. Does each call override the previous if it has not been executed?

Yes.

  1. To go flat on a symbol can you just leave it out of the call or do you have to specify 0 shares?

You can either specify that you want a flat quantity or you can leave the symbol out of the call entirely. However this second choice (leaving symbol out entirely) only works if your call to setDesiredPositions contains other valid desired positions. So it’s probably a good idea to specify “0” quantities as a best practice.

One note that is not obvious from the docs: when C2 determines “current” positions (in order to synchronize with your desired positions), it includes pending but not execute market orders in the current quantities.

This is the link to the API documentation for setDesiredPositions.

Thanks!

Do you know if there is a shortcut to set a desired position to 100% of the portfolio?

Btw, I can’t find the API sandbox… is there one? Or how do you test?

Thanks for your help!

To be clear, with the setDesiredPositions API, for a given security instrument, is this the correct way to set a position to zero / flat ? You’ll notice that quant = 0 for the e-mini S&P 500 future.

“positions”: [
{
“symbol” : “@ESM5”,
“typeofsymbol” : “future”,
“quant” : “0”
},
{
“symbol” : “EURUSD”,
“typeofsymbol” : “forex”,
“quant” : “-3”
},
{
“symbol” : “AAPL”,
“typeofsymbol” : “stock”,
“quant” : “211”
}
]

Yes, that should be correct. Setting to zero means: “Please go flat.”

How should I use setDesiredPositions to facilitate a rollover in futures?

We know that Futures symbol = Root + Month Code + Last Digit of Year

To rollover a position in ES Futures, we would need to go from @ESM0 to @ESU0

For example, currently, our positions are:

“positions”: [
{
“symbol” : “@ESM0”,
“typeofsymbol” : “future”,
“quant” : “5”
},
{
“symbol” : “@NQM0”,
“typeofsymbol” : “future”,
“quant” : “3”
},
{
“symbol” : “@RTYM0”,
“typeofsymbol” : “future”,
“quant” : “1”
}
]

To do the rollover, do I pass in the next Futures symbol? In doing so, does Collective2 take care of closing the previous position with @ESM0 and opening a new position with @ESU0?

“positions”: [
{
“symbol” : “@ESU0”,
“typeofsymbol” : “future”,
“quant” : “5”
},
{
“symbol” : “@NQU0”,
“typeofsymbol” : “future”,
“quant” : “3”
},
{
“symbol” : “@RTYU0”,
“typeofsymbol” : “future”,
“quant” : “1”
}
]

You have the right idea. Just tell C2 that you want the new contract, and you can either leave out the “old” contract, or, if that offends you sense of tidiness, can specify that you want the old contract to have a quant of 0. In either case, the old contract will be removed from your holdings, and a position in the new contract will be opened.

It may offend my sense of tidiness but it does not offend my sense of efficiency :slight_smile:

Send the portfolio of symbols with desired positions and let C2 handle the lower level details.

Your implementation of setDesiredPositions is simple yet clever. Two thumbs up.

I’ve been trying to figure this out for a few days now to no avail. I’ve used the setDesiredPositions functionality through the API to get long and flat a portfolio of stocks and that seems to have worked fine. However, when I try and turn it off to send individual orders I cannot seem to do so. I’ve tried both through the API and on the website and neither way seems to work. Please advise.

On the API I sent the following for the “positions” portion of the data packet: is this correct?

“positions”: [
{
“symbol” : “off”,
“typeofsymbol” : “off”,
“quant”: 0
}
]

Hi Robert -

Replace the word ‘off’ with the word ‘stop’ and it should work for you.

Let me know if you have further trouble.

That worked! Thank you.
Please note that your documentation still states to use the symbol=off and typeofsymbol=off not stop.

On a related note, if I send a setDesiredPositions command in after hours or pre-market does it just attempt to place the positions at the open of trading?

Robert -

Sorry! Thanks for bring to my attention. I will fix that.

Regarding your question: Yes, market hours are respected.

One other question regarding setDesiredPositions. It appears that when I turn off setDesiredPositions with the command below it also forces my system to flatten all positions. This is true whether or not I include the “quant”:0 line below.

“positions”: [
{
“symbol” : “stop”,
“typeofsymbol” : “stop”,
“quant”:0 <-- Have tried with and without this line with the same result
}
]

My question is, how can I turn off setDesiredPositions to once again send individual orders but maintain my current portfolio of positions?