开云体育

ctrl + shift + ? for shortcuts
© 2025 开云体育

Re: Is there generic method to format contract for reqContractDetails


 

Thank you for the explanation.?
After mentioning that contract can be "overspecified", I tried? to simplify definition instead of complicating it.?
Appeared to be that specifying only 3 fields is enough to specify the contract.?
?
  • ConId
  • SecType
  • LocalSymbol
This information is returned for all open orders and positions. Technically, ConId is not required, but without ConId, reqContractDetails can't find some contracts within 5 seconds, specifically those with options expiring daily, which is not acceptable. Final version cut down to 3 fields only, works fine for stocks, options, forex, futures, futures options.?
?
public static Contract GetContract(InstrumentModel instrument)
{
? var basis = instrument.Basis;
? var derivative = instrument.Derivative;
? var contract = new Contract
? {
? ? //Symbol = basis?.Name,
? ? LocalSymbol = instrument.Name,
? ? //Multiplier = $"{instrument.Leverage}",
? ? //Exchange = instrument.Exchange ?? "SMART",
? ? SecType = GetInstrumentType(instrument.Type),
? ? ConId = int.TryParse(instrument.Id, out var id) ? id : 0,
? ? //Currency = instrument.Currency?.Name ?? nameof(CurrencyEnum.USD)
? };
? //if (derivative is not null)
? //{
? // ?contract.Strike = derivative.Strike ?? 0;
? // ?contract.LastTradeDateOrContractMonth = $"{derivative.Expiration:yyyyMMdd}";
? // ?switch (derivative.Side)
? // ?{
? // ? ?case OptionSideEnum.Put: contract.Right = "P"; break;
? // ? ?case OptionSideEnum.Call: contract.Right = "C"; break;
? // ?}
? //}
? return contract;
}

Join [email protected] to automatically receive all group messages.