コード例 #1
0
        public async Task RunSample()
        {
            var    IqClientApi = new IqOptionWebSocketClient("f3f6e297e92f17161f099cef0c6fff71");
            string requestId;

            IqClientApi.PositionChangedObservable().Subscribe(x =>
            {
                Console.WriteLine(string.Format("PortfolioChange - {0}, InstrumentId: {1}, Side: {2} {3}, Margin(Amount): {4}",
                                                x.Id,
                                                x.InstrumentId,
                                                x.PortfolioChangedEventInfo.Status,
                                                x.PortfolioChangedEventInfo.Type,
                                                x.InvestAmount));
            });

            while (true)
            {
                await Task.Delay(TimeSpan.FromSeconds(10));

                requestId = Guid.NewGuid().ToString().Replace("-", string.Empty);
                var position = await IqClientApi.PlaceDigitalOptions(requestId, ActivePair.EURUSD,
                                                                     OrderDirection.Call, DigitalOptionsExpiryDuration.M1, 1);

                Console.WriteLine($"Placed position Id: {position.Id}");
            }
        }
コード例 #2
0
 public IqOptionApiClient(IqAccount account)
 {
     Account = account;
     Client  = new IqOptionWebSocketClient(ws =>
     {
         ws.OpenSecuredSocketAsync(account.Ssid);
     });
 }
コード例 #3
0
        public async Task GetCandles()
        {
            var getCandleRequest = new GetCandleItemRequestMessage(ActivePair.EURAUD, TimeFrame.Min5, 100, DateTimeOffset.Now);
            var ws = new IqOptionWebSocketClient("ce9e2de1cb04bc4d06c8a5707976783f");

            await ws.SendMessageAsync(getCandleRequest);

            Thread.Sleep(1000);

            await ws.SendMessageAsync(getCandleRequest);

            Thread.Sleep(1000);
        }
コード例 #4
0
        public Task <bool> ConnectAsync()
        {
            connectedSubject.OnNext(false);
            IsConnected = false;

            var tcs = new TaskCompletionSource <bool>();

            try
            {
                HttpClient
                .LoginAsync()
                .ContinueWith(t =>
                {
                    if (t.Result != null && t.Result.IsSuccessful)
                    {
                        _logger.Information($"{Username} logged in success!");

                        if (WsClient != null)
                        {
                            WsClient.Dispose();
                        }
                        WsClient = new IqOptionWebSocketClient(t.Result.Data.Ssid);

                        SubscribeWebSocket();

                        IsConnected = true;
                        connectedSubject.OnNext(true);
                        tcs.TrySetResult(true);
                        return;
                    }

                    _logger.Information(
                        $"{Username} logged in failed due to {t.Result?.Errors?.GetErrorMessage()}");
                    tcs.TrySetResult(false);
                });
            }
            catch (Exception ex)
            {
                tcs.TrySetException(ex);
            }

            return(tcs.Task);
        }
コード例 #5
0
        public async Task AppendUserAsync(string email, string password)
        {
            Trader?.Dispose();

            var result = await _commandBus.PublishAsync(new IqLoginCommand(IqOptionIdentity.New, email, password), default(CancellationToken));

            if (result.IsSuccess)
            {
                _logger.LogInformation($"Traders Loged in with email {email}, succeed!");

                await _commandBus.PublishAsync(new StoreSsidCommand(IqOptionIdentity.New, email, result.Ssid), default(CancellationToken));

                MasterClient = new IqOptionWebSocketClient(ws => {
                    ws.OpenSecuredSocketAsync(result.Ssid);
                    ws.InfoDataObservable.Subscribe(x => {
                        if ((x?.Any() ?? false) && x[0].Win == "equal")
                        {
                            _infoDataSubject.OnNext(x[0]);
                        }
                    });
                });
            }
        }
コード例 #6
0
 public IqOptionApiClient([NotNull] IqAccount account)
 {
     Account = account;
     Client  = new IqOptionWebSocketClient();
 }