Skip to content

Commit

Permalink
[MDAPI-42] [.NET] Implement OptionChain
Browse files Browse the repository at this point in the history
- fix after review
  • Loading branch information
Konstantin Ivaschenko committed Jul 29, 2024
1 parent 2e35650 commit f2991ee
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions samples/DXFeedOptionChain/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static async Task Main(string[] args)
if (args.Length != 5)
{
Console.WriteLine("usage: DXFeedOptionChain <address> <ipf-file> <symbol> <nStrikes> <nMonths>");
Console.WriteLine(" <ipf-file> is endpoint address");
Console.WriteLine(" <address> is endpoint address");
Console.WriteLine(" <ipf-file> is name of instrument profiles file");
Console.WriteLine(" <symbol> is the product or underlying symbol");
Console.WriteLine(" <nStrikes> number of strikes to print for each series");
Expand Down Expand Up @@ -81,7 +81,8 @@ public static async Task Main(string[] args)
}
}

await Task.WhenAll(quotes.Values);
// Ignore timeout and continue to print retrieved quotes even on timeout.
await Task.WhenAny(Task.WhenAll(quotes.Values), Task.Delay(TimeSpan.FromSeconds(1)));

Console.WriteLine("Printing option series ...");
foreach (var series in seriesList)
Expand All @@ -93,12 +94,16 @@ public static async Task Main(string[] args)
{
series.Calls.TryGetValue(strike, out var call);
series.Puts.TryGetValue(strike, out var put);
var callQuote = call != null && quotes.TryGetValue(call, out var callTask)
? callTask.Result
: new Quote();
var putQuote = put != null && quotes.TryGetValue(put, out var putTask)
? putTask.Result
: new Quote();
var callQuote = new Quote();
if (call != null && quotes.TryGetValue(call, out var callTask) && callTask.IsCompleted)
{
callQuote = callTask.Result;
}
var putQuote = new Quote();
if (put != null && quotes.TryGetValue(put, out var putTask) && putTask.IsCompleted)
{
putQuote = putTask.Result;
}
Console.WriteLine(
$"{callQuote.BidPrice,10:F3} {callQuote.AskPrice,10:F3} {strike,10:F3} {putQuote.BidPrice,10:F3} {putQuote.AskPrice,10:F3}");
}
Expand Down

0 comments on commit f2991ee

Please sign in to comment.