Пример #1
0
            public override void OnLoginReject(ClientSession session, LoginRequestClientContext LoginRequestClientContext, LoginReject message)
            {
                var context   = (LoginAsyncContext)LoginRequestClientContext;
                var exception = new Exception(message.Message);

                context.Tcs.SetException(exception);
            }
Пример #2
0
            public override void OnSymbolsReject(ClientSession session, SymbolsRequestClientContext SymbolsRequestClientContext, QueryReject reject)
            {
                var context   = (GetSupportedSymbolsAsyncContext)SymbolsRequestClientContext;
                var exception = new Exception(reject.Message);

                context.Tcs.SetException(exception);
            }
Пример #3
0
            public override void OnBarsReject(ClientSession session, BarsRequestClientContext BarsRequestClientContext, QueryReject reject)
            {
                var context   = (QueryQuoteHistoryBarsAsyncContext)BarsRequestClientContext;
                var exception = new Exception(reject.Message);

                context.Tcs.SetException(exception);
            }
Пример #4
0
            public override void OnTicksFileReject(ClientSession session, TicksFileRequestClientContext TicksFileRequestClientContext, QueryReject reject)
            {
                var context   = (QueryQuoteHistoryTicksFilesAsyncContext)TicksFileRequestClientContext;
                var exception = new Exception(reject.Message);

                context.Tcs.SetException(exception);
            }
Пример #5
0
            public override void OnFileReport(ClientSession session, FileRequestClientContext FileRequestClientContext, FileReport report)
            {
                var context = (FileAsyncContext)FileRequestClientContext;

                context.Buffer.AddRange(report.Content);

                if (report.EndOfFile)
                {
                    context.Files.Add(context.Buffer.ToArray());
                    context.Buffer.Clear();
                    context.FileIndex++;
                    context.Tcs.SetResult(context.Files.Last());
                    if (context.FileIndex == context.Files.Count)
                    {
                        (context as BarsFileAsyncContext)?.ParentContext.Tcs.SetResult(context.Files);
                        (context as TicksFileAsyncContext)?.ParentContext.Tcs.SetResult(context.Files);
                        return;
                    }
                }

                var request = new FileRequest(0);

                request.FileId = context.FileIds[context.FileIndex];
                request.Chunk  = ++context.ChunkIndex;
                session.SendFileRequest(context, request);
            }
Пример #6
0
            public override void OnPeriodicitiesReject(ClientSession session, PeriodicitiesRequestClientContext PeriodicitiesRequestClientContext, QueryReject reject)
            {
                var context   = (GetSupportedPeriodicitiesAsyncContext)PeriodicitiesRequestClientContext;
                var exception = new Exception(reject.Message);

                context.Tcs.SetException(exception);
            }
Пример #7
0
            public override void OnLogoutReport(ClientSession session, LogoutRequestClientContext LogoutRequestClientContext, LogoutReport message)
            {
                var context = (LogoutAsyncContext)LogoutRequestClientContext;
                var result  = new LogoutInfo();

                result.Reason  = (LogoutReason)message.Reason; // values match
                result.Message = message.Message;
                context.Tcs.SetResult(result);
            }
Пример #8
0
            public override void OnFileReject(ClientSession session, FileRequestClientContext FileRequestClientContext, QueryReject reject)
            {
                var barsContext = FileRequestClientContext as BarsFileAsyncContext;

                if (barsContext != null)
                {
                    var exception = new Exception(reject.Message);
                    barsContext.Tcs.SetException(exception);
                    barsContext.ParentContext.Tcs.SetException(exception);
                }
            }
Пример #9
0
            public override void OnSymbolsReport(ClientSession session, SymbolsRequestClientContext SymbolsRequestClientContext, SymbolsReport report)
            {
                var context = (GetSupportedSymbolsAsyncContext)SymbolsRequestClientContext;
                var result  = new List <string>();

                for (int i = 0; i < report.Symbols.Length; i++)
                {
                    var symbol = report.Symbols[i];
                    result.Add(symbol);
                }
                context.Tcs.SetResult(result);
            }
Пример #10
0
            public override void OnPeriodicitiesReport(ClientSession session, PeriodicitiesRequestClientContext PeriodicitiesRequestClientContext, PeriodicitiesReport report)
            {
                var context = (GetSupportedPeriodicitiesAsyncContext)PeriodicitiesRequestClientContext;
                var result  = new List <string>();

                for (int i = 0; i < report.Periodicities.Length; i++)
                {
                    var periodicity = report.Periodicities[i];
                    result.Add(periodicity);
                }
                context.Tcs.SetResult(result);
            }
Пример #11
0
        private QuoteHistoryClient(string name, ClientSessionOptions options)
        {
            options.ConnectionType        = ConnectionType.Secure;
            options.ServerCertificateName = "TickTraderManagerService";
#if DEBUG
            options.Log.Events   = true;
            options.Log.States   = false;
            options.Log.Messages = true;
#else
            options.Log.Events   = false;
            options.Log.States   = false;
            options.Log.Messages = false;
#endif
            options.SendBufferSize = 10485760;
            _session          = new ClientSession(name, options);
            _sessionListener  = new ClientSessionListener(this);
            _session.Listener = _sessionListener;
        }
Пример #12
0
            public override void OnTicksReport(ClientSession session, TicksRequestClientContext TicksRequestClientContext, QueryTicksReport report)
            {
                var context = (QueryQuoteHistoryTicksAsyncContext)TicksRequestClientContext;
                var result  = new List <Tick>();

                for (int i = 0; i < report.Ticks.Length; i++)
                {
                    var sourceTick = report.Ticks[i];
                    var tick       = new Tick()
                    {
                        Id = new TickId
                        {
                            Time  = sourceTick.Id.Time,
                            Index = sourceTick.Id.Index
                        },
                        Level2 = new Level2Collection()
                    };

                    for (int j = 0; j < sourceTick.Level2.Bids.Length; j++)
                    {
                        var sourceBid = sourceTick.Level2.Bids[j];
                        var bid       = new Level2Value
                        {
                            Price  = (decimal)sourceBid.Price,
                            Volume = (decimal)sourceBid.Volume
                        };
                        tick.Level2.Bids.Add(bid);
                    }

                    for (int j = 0; j < sourceTick.Level2.Asks.Length; j++)
                    {
                        var sourceAsk = sourceTick.Level2.Asks[j];
                        var ask       = new Level2Value
                        {
                            Price  = (decimal)sourceAsk.Price,
                            Volume = (decimal)sourceAsk.Volume
                        };
                        tick.Level2.Asks.Add(ask);
                    }

                    result.Add(tick);
                }
                context.Tcs.SetResult(result);
            }
Пример #13
0
            public override void OnDisconnect(ClientSession clientSession, ClientContext[] contexts, string text)
            {
                string message = "Client disconnected";

                if (text != null)
                {
                    message += " : ";
                    message += text;
                }
                Exception exception = new Exception(message);

                foreach (ClientContext context in contexts)
                {
                    ((IAsyncContext)context).SetException(exception);
                }

                _client.IsConnected = false;
                _client.Disconnected?.Invoke(_client);
            }
Пример #14
0
            public override void OnBarsReport(ClientSession session, BarsRequestClientContext BarsRequestClientContext, QueryBarsReport report)
            {
                var context = (QueryQuoteHistoryBarsAsyncContext)BarsRequestClientContext;
                var result  = new List <Bar>();

                for (int i = 0; i < report.Bars.Length; i++)
                {
                    var sourceBar = report.Bars[i];
                    var bar       = new Bar
                    {
                        Time   = sourceBar.Time,
                        Open   = (decimal)sourceBar.Open,
                        High   = (decimal)sourceBar.High,
                        Low    = (decimal)sourceBar.Low,
                        Close  = (decimal)sourceBar.Close,
                        Volume = (decimal)sourceBar.Volume
                    };
                    result.Add(bar);
                }
                context.Tcs.SetResult(result);
            }
Пример #15
0
            public override void OnTicksFileReport(ClientSession session, TicksFileRequestClientContext TicksFileRequestClientContext, QueryTicksFileReport report)
            {
                var context = (QueryQuoteHistoryTicksFilesAsyncContext)TicksFileRequestClientContext;

                if (report.Files.Length > 0)
                {
                    var fileContext = new TicksFileAsyncContext(context);
                    for (int i = 0; i < report.Files.Length; i++)
                    {
                        fileContext.FileIds.Add(report.Files[i].FileId);
                    }

                    var request = new FileRequest(0);
                    request.FileId = fileContext.FileIds[0];
                    request.Chunk  = 0;
                    session.SendFileRequest(fileContext, request);
                }
                else
                {
                    context.Tcs.SetResult(new List <byte[]>());
                }
            }
Пример #16
0
 public override void OnConnectError(ClientSession clientSession, string text)
 {
     _client.IsConnected = false;
     _client.ConnectError?.Invoke(_client);
 }
Пример #17
0
            public override void OnLoginReport(ClientSession session, LoginRequestClientContext LoginRequestClientContext, LoginReport message)
            {
                var context = (LoginAsyncContext)LoginRequestClientContext;

                context.Tcs.SetResult(null);
            }
Пример #18
0
 public override void OnConnect(ClientSession clientSession, ConnectClientContext connectContext)
 {
     _client.IsConnected = true;
     _client.Connected?.Invoke(_client);
 }