public async Task<IList<IBContractDetails>> GetContractDetailsAsync(IBContract c) { var id = -1; var results = new List<IBContractDetails>(); var completed = new ProgressiveTaskCompletionSource<List<IBContractDetails>> {Value = results}; id = NextValidId; _asyncCalls.Add(id, completed); RequestContractDetails(c, id); await completed.Task; _asyncCalls.Remove(id); return results; }
public async Task<int> RequestMarketDataAsync(IBContract contract, IList<IBGenericTickType> tickList = null, bool snapshot = false) { var completion = new ProgressiveTaskCompletionSource<object>(); var id = NextValidId; _asyncCalls.Add(id, completion); RequestMarketData(contract, tickList, snapshot, id); int timeout = 1000; if (await Task.WhenAny(completion.Task, Task.Delay(timeout)) == completion.Task) { if (completion.Task.IsFaulted) throw completion.Task.Exception; } // We might be here because there was no market-data or error within the timeout // At any rate, we consider this to be a success // IB is shit, this is the best we can do _asyncCalls.Remove(id); return id; }