API Support Forum
OEC API > API Support > GetInvalidParts always false when using allocationBlock
Author Topic: GetInvalidParts always false when using allocationBlock
(8 messages, Page 1 of 1)
Moderators: VPfau
JBerrojalbiz381
Posts: 9
Joined: Apr 06, 2011


Posted: Nov 11, 2015 @ 10:10 AM             Msg. 1 of 8
When i try to create an order using allocationblock instead of account, always receive an error when calling GetInvalidParts of the NewOrderDraft object, in my opinion is a generic problem because NewOrderDraft.CreateDraft sets OECClient to null and that implies that (!this.Client.Accounts.ContainsKey(allocationBlockItem.Account.ID)) this condition return an error.

could you please help me with this error

Jon Berrojalbiz
VPfau
Moderator
Posts: 164
Joined:


Posted: Nov 11, 2015 @ 11:52 AM             Msg. 2 of 8
Jon,

It is hard to understand what happened based on your description. Can you please provide a code example?

Vitaliy Pfau
VPfau
Moderator
Posts: 164
Joined:


Posted: Nov 11, 2015 @ 12:10 PM             Msg. 3 of 8
BW, we have a good OECAPI examples which could help you https://github.com/oecapi

See how we setup an allocation block in Advanced Example:
https://github.com/oecapi/AdvancedExample/blob/master/Globals.cs#L49

Vitaliy Pfau
JBerrojalbiz381
Posts: 9
Joined: Apr 06, 2011


Posted: Nov 12, 2015 @ 04:14 AM             Msg. 4 of 8

OEC.API.NewOrderDraft draft = OecApiClient.CreateDraft();
draft.Account = null;
foreach (var ab in OecApiClient.AllocationBlocks)
{
if (ab.Name == allocationBlock)
{
draft.AllocationBlock = ab;
}
}

OrderParts res = draft.GetInvalidParts();

if (res != OEC.API.OrderParts.None)
throw new Exception(string.Format("Invalid values in {0}", res));


And the method GetInvalidParts gives this error:
AllocationBlock
I've decompiled the api and in this method in NewOrderDraft (derived from OrderDraft), i see this code in the api:
public NewOrderDraft CreateDraft()
{
return new NewOrderDraft((OECClient) null);
}

internal NewOrderDraft(OECClient client = null)
: base(client)
{
this.Order = new Order(-1);
this.Version = new Version(this.Order);
}


That´s why i think when in the method GetInvalidParts :
if (this.AllocationBlock != null)
{
if (this.Account != null && this.Client.WashAccounts[this.Account.ID] == null)
orderParts |= OrderParts.AllocationBlock;
else if (this.AllocationBlock.Items.Count <= 0)
{
orderParts |= OrderParts.AllocationBlock;
}
else
{
foreach (AllocationBlockItem allocationBlockItem in this.AllocationBlock.Items)
{
if (!this.Client.Accounts.ContainsKey(allocationBlockItem.Account.ID))
{
orderParts |= OrderParts.AllocationBlock;
break;
}
}
if (this.Quantity > this.AllocationBlock.TotalLots && this.Quantity % this.AllocationBlock.TotalLots != 0)
orderParts |= OrderParts.Quantity | OrderParts.AllocationBlock;
}
}

give me this error :
AllocationBlock, because the client is null.

Jon Berrojalbiz
VPfau
Moderator
Posts: 164
Joined:


Posted: Nov 12, 2015 @ 12:17 PM             Msg. 5 of 8
Jon,

I see the issue now. This is not because we setup client to null but because we use OECClient.Global in Draft to check your allocation blocks. OECClient.Global holds the most recent instance of OECClient.

Only a last created client will work with Allocation blocks; We will fix this in future releases

So far here are two recommendations: use only one OECClient in your application OR OECClient which are going to send orders with allocation block should be created after all other instances.

Thank you!

Here is test which replicates an issue: https://gist.github.com/oecapi/e5c0f6f4bfd83f8613be

Vitaliy Pfau
CMicciche902
Posts: 367
Joined:


Posted: Nov 24, 2015 @ 03:30 PM             Msg. 6 of 8
Jon,

We rolled out a fix this past weekend. Can you re-test?

Chris M
JBerrojalbiz381
Posts: 9
Joined: Apr 06, 2011


Posted: Nov 25, 2015 @ 10:40 AM             Msg. 7 of 8
Sorry Chris where could i find this new release? in nuget i don't see this new version.

thanks in advance


Jon Berrojalbiz
Edited by JBerrojalbiz381 on Nov 26, 2015 at 08:34:23
VPfau
Moderator
Posts: 164
Joined:


Posted: Nov 27, 2015 @ 02:22 PM             Msg. 8 of 8
Jon,

you can update OECAPI from Trader application installation (dev environment)
http://api.openecry.com/WebPrev/Sections/Misc/DownloadFile.aspx?ClientUpdate=0_0_1&NoCache=d6ff63c9-ed24-4508-8966-d28625e56541

Vitaliy Pfau