public async Task Connect() { OpenClient liveClient = null; OpenClient demoClient = null; try { liveClient = _liveClientFactory(); await liveClient.Connect(); demoClient = _demoClientFactory(); await demoClient.Connect(); } catch { if (liveClient is not null) { liveClient.Dispose(); } if (demoClient is not null) { demoClient.Dispose(); } throw; } _liveClient = liveClient; _demoClient = demoClient; IsConnected = true; }
public async void ConnectDisposedTest(string host, int port) { var client = new OpenClient(host, port, TimeSpan.FromSeconds(10)); await client.Connect(); client.Dispose(); await Assert.ThrowsAsync <ObjectDisposedException>(client.Connect); }
public Main() { _client = new OpenClient(_apiHost, _apiPort, TimeSpan.FromSeconds(10)); _client.ObserveOn(SynchronizationContext.Current).OfType <ProtoMessage>().Subscribe(OnMessage, OnError); _client.ObserveOn(SynchronizationContext.Current).OfType <ProtoOASpotEvent>().Subscribe(OnSpotMessage); _client.ObserveOn(SynchronizationContext.Current).OfType <ProtoOAExecutionEvent>().Subscribe(OnExecutionEvent); _client.ObserveOn(SynchronizationContext.Current).OfType <ProtoOAGetAccountListByAccessTokenRes>().Subscribe(OnAccountListResponse); _client.ObserveOn(SynchronizationContext.Current).OfType <ProtoOATraderRes>().Subscribe(OnTraderResponse); InitializeComponent(); }
public async void OnCompletedTest(string host, int port) { var client = new OpenClient(host, port, TimeSpan.FromSeconds(10)); bool isCompleted = false; client.Subscribe(message => { }, exception => { }, () => isCompleted = true); await client.Connect(); client.Dispose(); Assert.True(isCompleted); }
public async void DisposeTest(string host, int port) { var client = new OpenClient(host, port, TimeSpan.FromSeconds(1)); Exception exception = null; client.Subscribe(message => { }, ex => exception = ex); await client.Connect(); await Task.Delay(5000); client.Dispose(); Assert.Null(exception); }
public async void AppAuthTest(string host, int port, string appId, string appSecret) { if (string.IsNullOrWhiteSpace(appId)) { throw new ArgumentException($"'{nameof(appId)}' cannot be null or whitespace", nameof(appId)); } if (string.IsNullOrWhiteSpace(appSecret)) { throw new ArgumentException($"'{nameof(appSecret)}' cannot be null or whitespace", nameof(appSecret)); } var client = new OpenClient(host, port, TimeSpan.FromSeconds(10)); await client.Connect(); var isResponseReceived = false; Exception exception = null; client.OfType <ProtoOAApplicationAuthRes>().Subscribe(message => isResponseReceived = true, ex => exception = ex); var appAuhRequest = new ProtoOAApplicationAuthReq { ClientId = appId, ClientSecret = appSecret }; await client.SendMessage(appAuhRequest, ProtoOAPayloadType.ProtoOaApplicationAuthReq); await Task.Delay(3000); client.Dispose(); Assert.True(isResponseReceived && exception is null); }
private void openFormButton_Click(object sender, EventArgs e) { ICommand command = new OpenClient(user); command.invoke(); }
public async void ConnectTest(string host, int port) { var client = new OpenClient(host, port, TimeSpan.FromSeconds(10)); await client.Connect(); }
private static async Task Main() { Console.Write("Enter App ID: "); var appId = Console.ReadLine(); Console.Write("Enter App Secret: "); var appSecret = Console.ReadLine(); Console.Write("Enter App Redirect URL: "); var redirectUrl = Console.ReadLine(); _app = new App(appId, appSecret, redirectUrl); Console.Write("Enter Connection Mode (Live or Demo): "); var modeString = Console.ReadLine(); var mode = (Mode)Enum.Parse(typeof(Mode), modeString, true); Console.Write("Enter Scope (Trading or Accounts): "); var scopeString = Console.ReadLine(); var scope = (Scope)Enum.Parse(typeof(Scope), scopeString, true); var authUri = _app.GetAuthUri(); System.Diagnostics.Process.Start("explorer.exe", $"\"{authUri}\""); ShowDashLine(); Console.WriteLine("Follow the authentication steps on your browser, then copy the authentication code from redirect" + " URL and paste it here."); Console.WriteLine("The authentication code is at the end of redirect URL and it starts after '?code=' parameter."); ShowDashLine(); Console.Write("Enter Authentication Code: "); var authCode = Console.ReadLine(); _token = await TokenFactory.GetToken(authCode, _app); Console.WriteLine("Access token generated"); ShowDashLine(); var host = ApiInfo.GetHost(mode); _client = new OpenClient(host, ApiInfo.Port, TimeSpan.FromSeconds(10)); _disposables.Add(_client.Where(iMessage => iMessage is not ProtoHeartbeatEvent).Subscribe(OnMessageReceived, OnException)); _disposables.Add(_client.OfType <ProtoOAErrorRes>().Subscribe(OnError)); _disposables.Add(_client.OfType <ProtoOARefreshTokenRes>().Subscribe(OnRefreshTokenResponse)); Console.WriteLine("Connecting Client..."); await _client.Connect(); ShowDashLine(); Console.WriteLine("Client successfully connected"); ShowDashLine(); Console.WriteLine("Sending App Auth Req..."); Console.WriteLine("Please wait..."); ShowDashLine(); var applicationAuthReq = new ProtoOAApplicationAuthReq { ClientId = _app.ClientId, ClientSecret = _app.Secret, }; await _client.SendMessage(applicationAuthReq, ProtoOAPayloadType.ProtoOaApplicationAuthReq); await Task.Delay(5000); Console.WriteLine("You should see the application auth response message before entering any command"); Console.WriteLine("For commands list and description use 'help' command"); ShowDashLine(); GetCommand(); }