API Support Forum
OEC API > API Support > "ContractID Invalid" error returned in Order submission
Author Topic: "ContractID Invalid" error returned in Order submission
(5 messages, Page 1 of 1)
Moderators: VPfau
RAnde
Posts: 20
Joined: Sep 05, 2017


Posted: Jun 02, 2020 @ 03:59 AM             Msg. 1 of 5
I got the error as below when calling the SendOrder api to submit an order.
"Invalid OrderDraft: ContractID (277300774, electronic) is invalid"

Note that I submit the order with symbol of ESM20. And I get the correct Contract for ESM20 after using the symbol lookup api. Also, I have tried with another symbol (such as GCLN20), but the same error returned.

Is there anyone known this error? And how should I do to solve it?
Edited by RAnde on Jun 02, 2020 04:13 AM
ETrifonov
Posts: 63
Joined:


Posted: Jun 02, 2020 @ 09:37 AM             Msg. 2 of 5
Hello RAnde,

Unfortunately it is not clear how exactly you are creating order.
If you are getting contract via api and then use it to create new order draft, you shouldn't have such issues.
Can you please provide code and GF API version.

Our sample in API documentation:
https://gainfutures.com/GFAPI/?topic=html/b7c07332-6ce9-4101-bec2-79610ad6ee7d.htm

Thank you.
Evgeny
RAnde
Posts: 20
Joined: Sep 05, 2017


Posted: Jun 02, 2020 @ 09:59 PM             Msg. 3 of 5
Hi Evgeny,

I'm getting contract by using the api of IGFCLient.Contracts.Lookup.ByCriteria. And then I use the ContractID of that contract to create the order draft for the order placing. The process is same as your example.
Please look at the code details as below

The code of symbol lookup

private void ProcessLookupSymbolRequest(RequestData requestData)
{
var symbolLookupRequestBuilder =
GainCapitalFuturesUtility.CreateSymbolLookupRequestBuilder(requestData.PostData, 50);

_clientRunner.Client.Contracts.Lookup.ByCriteria(symbolLookupRequestBuilder.Build());

GainCapitalFuturesDataStorage.AddContracts(requestData.PostData, new List());
}

private void OnSymbolLookupReceived(IGFClient client, SymbolLookupEventArgs e)
{
if (e.Contracts.Any())
{
var newContracts = e.Contracts.ToList();
GainCapitalFuturesDataStorage.AddContracts(_currentRequestData.PostData, newContracts);
}
}


Create OrderDraft

private static OrderDraft CreateNewOrderDraft(GainCapitalFuturesOrder gainFuturesOrder, AccountID accountId, IContract contract)
{
var orderDraft = new OrderDraftBuilder()
.WithAccountID(accountId)
.WithContractID(contract.ID)
.WithSide(gainFuturesOrder.Side)
.WithOrderType(gainFuturesOrder.Type)
.WithPrice(gainFuturesOrder.Price)
.WithPrice2(gainFuturesOrder.Price2)
.WithQuantity((int) gainFuturesOrder.Quantity)
.WithFlags(gainFuturesOrder.Flag);

if (gainFuturesOrder.Type != OrderType.TrailingStopLoss &&
gainFuturesOrder.Type != OrderType.TrailingStopLimit)
return orderDraft.Build();

var delta = GetTrailingStopOrderDelta(gainFuturesOrder, contract);
var referencePrice = gainFuturesOrder.Reference > 0
? gainFuturesOrder.Reference
: contract.CurrentPrice.LastPrice;
var trailingStopData = new TrailingStopData(referencePrice, delta);
orderDraft.WithTrailingStop(trailingStopData);

return orderDraft.Build();
}


Place order

private void ProcessSingleOrderSubmissionRequest(RequestData requestData)
{
var gainFuturesOrder = JsonConvert.DeserializeObject(requestData.PostData);
var orderDraft = gainFuturesOrder.ToOrderDraft(_clientRunner.Client, requestData);
var submittedOrder = _clientRunner.Client.Orders.SendOrder(orderDraft);
}


And I'm using GF API version 4.0.3.33

Thanks Evgeny for helping.
ETrifonov
Posts: 63
Joined:


Posted: Jun 03, 2020 @ 07:19 AM             Msg. 4 of 5
Thank you for details.
Can you please also provide account you used to place orders.

Also, I see that to place order you first deserialize it.
Question is - does _clientRunner.Client is the same, used for contract lookup and was it connected during whole session?
To send order, API should know about contract.
So, in case you lookup contract. build draft, serialize order draft, reconnect API, deserialize order and trying to send it - you will get that error.
After reconnect you should lookup contract again, to make sure API knows about it.

Thank you.
Evgeny
RAnde
Posts: 20
Joined: Sep 05, 2017


Posted: Jun 04, 2020 @ 03:35 AM             Msg. 5 of 5
Hi Evgeny,

You are correct. I'm using two different IGFClient objects for the processes of symbol lookup and order draft sending.
So the client in the order draft sending did not know the Contact that is from the symbol lookup.

I have moved the symbol lookup inside the order draft sending process so that they can use the same client. And the problem disappears.

Thank you very much for helping.
Edited by RAnde on Jun 04, 2020 03:36 AM