# API setDesiredPositions

**URL:** <https://forums.collective2.com/t/api-setdesiredpositions/11196>\
**Category:** C2 Software Development\
**Created:** [December 9, 2017, 6:12pm UTC](https://forums.collective2.com/t/api-setdesiredpositions/11196 "2017-12-09T18:12:30Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![SysTrader](https://yyz2.discourse-cdn.com/flex028/user_avatar/forums.collective2.com/systrader/32/1487_2.png) [@SysTrader](https://forums.collective2.com/u/SysTrader)\
**Post date:** [December 9, 2017, 6:12pm UTC](https://forums.collective2.com/t/api-setdesiredpositions/11196/1 "2017-12-09T18:12:30Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![chris\_a2](https://yyz2.discourse-cdn.com/flex028/user_avatar/forums.collective2.com/chris_a2/32/12306_2.png) [@chris\_a2](https://forums.collective2.com/u/chris_a2)\
**Post date:** [January 22, 2019, 12:15pm UTC](https://forums.collective2.com/t/api-setdesiredpositions/11196/2 "2019-01-22T12:15:28Z")

</div>

Hi,

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

---

<div class="post-metadata">

**Author:** ![MatthewKlein](https://yyz2.discourse-cdn.com/flex028/user_avatar/forums.collective2.com/matthewklein/32/21382_2.png) [@MatthewKlein](https://forums.collective2.com/u/MatthewKlein)\
**Post date:** [January 22, 2019, 1:46pm UTC](https://forums.collective2.com/t/api-setdesiredpositions/11196/3 "2019-01-22T13:46:23Z")

</div>

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.](https://collective2.com/api-docs/latest#setDesiredPositions)

---

<div class="post-metadata">

**Author:** ![chris\_a2](https://yyz2.discourse-cdn.com/flex028/user_avatar/forums.collective2.com/chris_a2/32/12306_2.png) [@chris\_a2](https://forums.collective2.com/u/chris_a2)\
**Post date:** [January 22, 2019, 5:00pm UTC](https://forums.collective2.com/t/api-setdesiredpositions/11196/4 "2019-01-22T17:00:46Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![MichaelBloomfield2](https://yyz2.discourse-cdn.com/flex028/user_avatar/forums.collective2.com/michaelbloomfield2/32/15438_2.png) [@MichaelBloomfield2](https://forums.collective2.com/u/MichaelBloomfield2)\
**Post date:** [July 1, 2020, 5:44pm UTC](https://forums.collective2.com/t/api-setdesiredpositions/11196/5 "2020-07-01T17:44:04Z")

</div>

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”  
}  
]

---

<div class="post-metadata">

**Author:** ![MatthewKlein](https://yyz2.discourse-cdn.com/flex028/user_avatar/forums.collective2.com/matthewklein/32/21382_2.png) [@MatthewKlein](https://forums.collective2.com/u/MatthewKlein)\
**Post date:** [July 1, 2020, 7:48pm UTC](https://forums.collective2.com/t/api-setdesiredpositions/11196/6 "2020-07-01T19:48:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![MichaelBloomfield2](https://yyz2.discourse-cdn.com/flex028/user_avatar/forums.collective2.com/michaelbloomfield2/32/15438_2.png) [@MichaelBloomfield2](https://forums.collective2.com/u/MichaelBloomfield2)\
**Post date:** [July 10, 2020, 3:31pm UTC](https://forums.collective2.com/t/api-setdesiredpositions/11196/7 "2020-07-10T15:31:14Z")

</div>

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”
}
]
```

---

<div class="post-metadata">

**Author:** ![MatthewKlein](https://yyz2.discourse-cdn.com/flex028/user_avatar/forums.collective2.com/matthewklein/32/21382_2.png) [@MatthewKlein](https://forums.collective2.com/u/MatthewKlein)\
**Post date:** [July 10, 2020, 5:24pm UTC](https://forums.collective2.com/t/api-setdesiredpositions/11196/8 "2020-07-10T17:24:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![MichaelBloomfield2](https://yyz2.discourse-cdn.com/flex028/user_avatar/forums.collective2.com/michaelbloomfield2/32/15438_2.png) [@MichaelBloomfield2](https://forums.collective2.com/u/MichaelBloomfield2)\
**Post date:** [July 11, 2020, 12:48am UTC](https://forums.collective2.com/t/api-setdesiredpositions/11196/9 "2020-07-11T00:48:04Z")

</div>

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

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.

---

<div class="post-metadata">

**Author:** ![RobertGlass](https://yyz2.discourse-cdn.com/flex028/user_avatar/forums.collective2.com/robertglass/32/13320_2.png) [@RobertGlass](https://forums.collective2.com/u/RobertGlass)\
**Post date:** [July 15, 2020, 12:50am UTC](https://forums.collective2.com/t/api-setdesiredpositions/11196/10 "2020-07-15T00:50:23Z")

</div>

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  
}  
]

---

<div class="post-metadata">

**Author:** ![MatthewKlein](https://yyz2.discourse-cdn.com/flex028/user_avatar/forums.collective2.com/matthewklein/32/21382_2.png) [@MatthewKlein](https://forums.collective2.com/u/MatthewKlein)\
**Post date:** [July 15, 2020, 1:55am UTC](https://forums.collective2.com/t/api-setdesiredpositions/11196/11 "2020-07-15T01:55:17Z")

</div>

Hi Robert -

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

Let me know if you have further trouble.

---

<div class="post-metadata">

**Author:** ![RobertGlass](https://yyz2.discourse-cdn.com/flex028/user_avatar/forums.collective2.com/robertglass/32/13320_2.png) [@RobertGlass](https://forums.collective2.com/u/RobertGlass)\
**Post date:** [July 15, 2020, 5:04am UTC](https://forums.collective2.com/t/api-setdesiredpositions/11196/12 "2020-07-15T05:04:50Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![MatthewKlein](https://yyz2.discourse-cdn.com/flex028/user_avatar/forums.collective2.com/matthewklein/32/21382_2.png) [@MatthewKlein](https://forums.collective2.com/u/MatthewKlein)\
**Post date:** [July 15, 2020, 3:01pm UTC](https://forums.collective2.com/t/api-setdesiredpositions/11196/13 "2020-07-15T15:01:02Z")

</div>

Robert -

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

Regarding your question: Yes, market hours are respected.

---

<div class="post-metadata">

**Author:** ![BeckyHammond](https://yyz2.discourse-cdn.com/flex028/user_avatar/forums.collective2.com/beckyhammond/32/13320_2.png) [@BeckyHammond](https://forums.collective2.com/u/BeckyHammond)\
**Post date:** [September 30, 2020, 5:15pm UTC](https://forums.collective2.com/t/api-setdesiredpositions/11196/14 "2020-09-30T17:15:33Z")

</div>

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?
