public async void Init() { Observable.Timer(DateTimeOffset.Now, TimeSpan.FromSeconds(1)).Subscribe(x => Date.Value = DateTime.Now); try { interReactClient = await InterReactClient.BuildAsync(); } catch (Exception exception) { await SyncMessageBox.Show(exception.Message, terminate : true); return; } CoreApplication.Suspending += (x, y) => { interReactClient.Dispose(); }; // TickRedundantRealtimeVolumeFilter removes redundant messages (LastPrice, LastSize, Volume and Time ticks). // Display a message box for any errors. Write messages to the Debug window. interReactClient.Response .Subscribe(async message => { Debug.WriteLine(message.Stringify()); if (message is Alert alert && (alert.AlertType == AlertType.ConnectionLost || alert.AlertType == AlertType.ConnectionRestored)) { await SyncMessageBox.Show(alert.Message); } }, async exception => await SyncMessageBox.Show(exception.Message, terminate: true)); // Note that Symbol is an observable. Symbol.Throttle(TimeSpan.FromSeconds(1)) .DistinctUntilChanged() .Subscribe(async symbol => { try { await FindContract(symbol); } catch (Exception exception) { await SyncMessageBox.Show(exception.Message); } }); }
private void Form1_FormClosing(object sender, FormClosingEventArgs e) => client?.Dispose();
public void Dispose() => client?.Dispose();