private void PrepareConnection() { if (_broker != null) { _broker.StreamingEventReceived -= Broker_StreamingEventReceived; _broker.Dispose(); } _sandbox = ConnectionFactory.GetSandboxConnection(TiApiToken); _broker = ConnectionFactory.GetConnection(TiApiToken); _broker.StreamingEventReceived += Broker_StreamingEventReceived; }
public async Task ClearTest() { var handler = new HttpMessageHandlerStub(HttpStatusCode.OK, "{\"trackingId\":\"QBASTAN\",\"status\":\"OK\",\"payload\":{}}"); var connection = new SandboxConnection(BaseUri, WebSocketBaseUri, Token, new HttpClient(handler)); var context = connection.Context; await context.ClearAsync(); Assert.NotNull(handler.RequestMessage); Assert.Equal(HttpMethod.Post, handler.RequestMessage.Method); Assert.Equal(new Uri($"{BaseUri}sandbox/clear"), handler.RequestMessage.RequestUri); Assert.Null(handler.RequestMessage.Content); }
public async Task SetPositionBalanceTest() { var handler = new HttpMessageHandlerStub(HttpStatusCode.OK, "{\"trackingId\":\"QBASTAN\",\"status\":\"OK\",\"payload\":{}}"); var connection = new SandboxConnection(BaseUri, WebSocketBaseUri, Token, new HttpClient(handler)); var context = connection.Context; await context.SetPositionBalanceAsync("BBG000CL9VN6", 100.7m); Assert.NotNull(handler.RequestMessage); Assert.Equal(HttpMethod.Post, handler.RequestMessage.Method); Assert.Equal(new Uri($"{BaseUri}sandbox/positions/balance"), handler.RequestMessage.RequestUri); Assert.NotNull(handler.RequestMessage.Content); var content = await handler.RequestMessage.Content.ReadAsStringAsync(); Assert.Equal("{\"figi\":\"BBG000CL9VN6\",\"balance\":100.7}", content); }
public MarketStore(string token, bool isSandbox, IUnitOfWork unitOfWork, IMessageService messageService, IFinancialModelingPrepService financialModelingPrepService) { _unitOfWork = unitOfWork; _financialModelingPrepService = financialModelingPrepService; if (isSandbox) { SandboxConnection connection = ConnectionFactory.GetSandboxConnection(token); _context = connection.Context; } else { Connection connection = ConnectionFactory.GetConnection(token); _context = connection.Context; } _context.WebSocketException += (sender, exception) => { messageService.ShowMessage(exception.Message); }; }
/// <summary> /// Creates a new sandbox connection. /// </summary> public static ISandboxConnection CreateSandboxConnection(bool isInTestMode) { ISandboxConnection sandboxConnection; if (OperatingSystemHelper.IsLinuxOS) { sandboxConnection = new SandboxConnectionLinuxDetours(FailureCallback, isInTestMode: isInTestMode); } else if (OperatingSystemHelper.IsMacOS) { var kind = ReadSandboxKindFromEnvVars(); if (kind == SandboxKind.MacOsKext) { sandboxConnection = new SandboxConnectionKext( skipDisposingForTests: true, config: new SandboxConnectionKext.Config { MeasureCpuTimes = true, FailureCallback = FailureCallback, KextConfig = new KextConfig { EnableCatalinaDataPartitionFiltering = OperatingSystemHelper.IsMacWithoutKernelExtensionSupport } }); } else { sandboxConnection = new SandboxConnection(kind, isInTestMode: isInTestMode, measureCpuTimes: true); } } else { sandboxConnection = null; } return(sandboxConnection); }
public ContextTests() { _handler = new MockHttpMessageHandler(); _handler.Fallback.Throw(); _context = new SandboxConnection(BaseUri, WebSocketBaseUri, Token, _handler.ToHttpClient()).Context; }
public ContextProvider() { _connection = ConnectionFactory.GetSandboxConnection(ApiData.TokenSandbox); _context = _connection.Context; Init(); }