API Support Forum
OEC API > API Support > How to get current PositionList()?
Author Topic: How to get current PositionList()?
(4 messages, Page 1 of 1)
Moderators: VPfau
JGagnon
Posts: 95
Joined: Apr 11, 2011


Posted: Jun 21, 2012 @ 11:37 AM             Msg. 1 of 4
I am trying to iterate through the current list of positions to close out positions at end of market day. I am sure I am doing something simple that is wrong, the first line below that attempts to get the new PositionList() is returning an empty list.

private void button2_Click(object sender, EventArgs e)
{
var posList = new PositionList();

foreach (OEC.API.Position pos in posList)
{
NewOrderDraft draft = OECClient.Global.CreateDraft();
draft.Account = pos.Account;
draft.Side = (pos.Net.Volume < 0) ? OrderSide.Buy : OrderSide.Sell;
draft.Contract = pos.PositionContract;
draft.Quantity = Math.Abs(pos.Net.Volume);
draft.Type = OrderType.Market;
if (draft.Quantity == 0)
return;// nothing to close

OECClient.Global.SendOrder(draft);
}
}

John Gagnon
JGagnon
Posts: 95
Joined: Apr 11, 2011


Posted: Jun 22, 2012 @ 08:46 AM             Msg. 2 of 4
bump

John Gagnon
JGagnon
Posts: 95
Joined: Apr 11, 2011


Posted: Jun 27, 2012 @ 04:45 PM             Msg. 3 of 4
1 week bump, anyone there?

John Gagnon
VictorV
Posts: 746
Joined: May 08, 2007


Posted: Jun 27, 2012 @ 05:08 PM             Msg. 4 of 4
Actually, "new PositionList()" creates a new empty list. You need to use http://www.openecry.com/api/api/OEC.API.Account.AvgPositions.html to access the current positions

Victor Vins
Lead Software Developer