示例#1
0
 public async Task RunTimer(CancellationTokenSource _cts, int startId /*, TimeSpan _time, TimeSpan _limit, Label _descLabel, Label _titleLabel*/)
 {
     await Task.Run(async() =>
     {
         try
         {
             while (true)
             {
                 if (_cts != null)
                 {
                     _cts.Token.ThrowIfCancellationRequested();
                 }
                 Device.BeginInvokeOnMainThread(() =>
                 {
                     var message = new TickMessage();
                     Device.BeginInvokeOnMainThread(() => {
                         MessagingCenter.Send <TickMessage>(message, $"TickMessage");
                     });
                 });
                 await Task.Delay(1000);
             }
         }
         catch (Exception ex)
         {
         }
     });
 }
        public async Task RunAsync()
        {
            // *************************************

            // Step 1 - !!! Configure your credentials for IQConnect in user environment variable or app.config !!!
            //              Check the documentation for more information.

            // Step 2 - Run IQConnect launcher
            IQFeedLauncher.Start();

            // Step 3 - Use the appropriate factory to create the client
            var lookupClient = LookupClientFactory.CreateNew();

            // Step 4 - Connect it
            lookupClient.Connect();

            var tmpFilename = await lookupClient.Historical.File.GetHistoryTickDatapointsAsync(Symbol, 1000);

            // Step 5 - Make file request!

            // Step 6 - Move the file
            var basePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, DownloadBasePath);
            var fullPath = Path.Combine(basePath, $"{DateTime.Now:yyyyMMddHHmmss}-{Symbol}.csv");

            Directory.CreateDirectory(basePath);
            File.Move(tmpFilename, fullPath);

            // Step 7 - Parse TickMessages from saved file
            var ticks = TickMessage.ParseFromFile(fullPath).ToList();

            Console.WriteLine($"Saved {Symbol} ticks in {fullPath}");
        }
        public void Should_Resample_Bars_From_Ticks()
        {
            // Arrange
            var ticks     = TickMessage.ParseFromFile(TestData.TestData.GetFileName(TestDataType.Ticks, DataDirection.Oldest)).ToList();
            var intervals = IntervalMessage.ParseFromFile(TestData.TestData.GetFileName(TestDataType.Intervals_1s, DataDirection.Oldest)).ToList();

            // Act
            var bars = ticks.ToHistoricalBars(TimeSpan.FromSeconds(1), DataDirection.Oldest).ToList().ToList();

            // Assert
            Assert.IsNotEmpty(intervals);
            Assert.AreEqual(intervals.Count, bars.Count);

            for (var i = 0; i < intervals.Count; i++)
            {
                var interval = intervals[i];
                var bar      = bars[i];

                // TODO: create comparable
                if (interval.Timestamp == bar.Timestamp &&
                    interval.Open == bar.Open &&
                    interval.High == bar.High &&
                    interval.Low == bar.Low &&
                    interval.Close == bar.Close &&
                    interval.PeriodVolume == bar.PeriodVolume &&
                    interval.TotalVolume == bar.TotalVolume)
                {
                    continue;
                }

                throw new Exception();
            }
        }
        public void Should_Load_And_Parse_Protocol60_Data_From_File()
        {
            // Arrange
            var ticks = TickMessage.ParseFromFile(TestData.TestData.GetFileName(TestDataType.Ticks, DataDirection.Oldest, true)).ToList();

            // Assert
            Assert.IsNotEmpty(ticks);
        }
示例#5
0
        public void Should_TryParse_Return_False_When_Invalid_Data_Overflow()
        {
            // Act
            var parsed = TickMessage.TryParse($"2018-04-17 17:51:22.123456,96.0700,{long.MaxValue},0,0.0000,0.0000,4145784264,O,19,143A,2,17", out _);

            // Assert
            Assert.IsFalse(parsed);
        }
        public TickMessageTests()
        {
            _message = "2018-04-17 17:51:22.123456,96.0700,1061909,0,0.0000,0.0000,4145784264,O,19,143A";
            _messageWithRequestId = "XYZ,2018-04-17 17:51:22.123456,96.0700,1061909,0,0.0000,0.0000,4145784264,O,19,143A";

            var timestamp = DateTime.ParseExact("2018-04-17 17:51:22.123456", TickMessage.TickDateTimeFormat, CultureInfo.InvariantCulture);

            _expectedMessage = new TickMessage(timestamp, 96.07, 1061909, 0, 0.0, 0.0, 4145784264, 'O', 19, "143A");
        }
示例#7
0
 public void UpdateSimulation(TickMessage tickMessage)
 {
     LogProxy.Debug("ExplicitUpdate Simulation");
     lock (_queueLock)
     {
         _queuedMessages.Enqueue(tickMessage);
     }
     _messageSignal.Set();
 }
示例#8
0
        public void Should_Parse_TickMessageProtocol62_Culture_Independent(string cultureName)
        {
            // Arrange
            TestHelper.SetThreadCulture(cultureName);

            // Act
            var tickMessageParsed = TickMessage.Parse(_messageProtocol62);

            // Assert
            Assert.AreEqual(tickMessageParsed, _expectedMessageProtocol62);
        }
示例#9
0
文件: Tick.cs 项目: ktj007/mmo
        internal void OnTick(Entity entity, TickMessage tick)
        {
            // 로그아웃 한 상태에서 Tickable이 남아있는 유저는 Tick을 수행하지 않도록 한다.
            if (entity.Has <Player>() && !entity.Get <Player>().Logged)
            {
                entity.Detach <Tickable>();
                return;
            }

            if (entity.Has <Fightable>())
            {
                var fightable = entity.Get <Fightable>();
                if (fightable.IsAlive)
                {
                    if (++fightable.RecoveryCurrentTick >= fightable.RecoveryTickCount)
                    {
                        var recovery = DataCenter.Instance.GetDatum <InteractTemplate>((int)InteractTemplate.Ids.Recovery);
                        EffectSystem.Affect(entity, recovery);

                        fightable.RecoveryCurrentTick = 0;
                    }
                }
            }

            if (entity.Has <Eatable>())
            {
            }

            if (entity.Has <EntityGenerate>())
            {
                var entityGenerate = entity.Get <EntityGenerate>();
                if (entityGenerate.IsGeneratable)
                {
                    if (entityGenerate.Resource >= entityGenerate.NeededResourceToGen)
                    {
                        // generate!


                        entityGenerate.Resource -= entityGenerate.NeededResourceToGen;
                    }

                    entityGenerate.Resource += entityGenerate.IncResource;
                }
            }

            // 다음 Tick을 요청한다.
            if (entity.Has <Tickable>())
            {
                var nextMsg = new TickMessage {
                    Id = entity.Id
                };
                nextMsg.ExecuteDelayed(entity, entity.Get <Tickable>().Interval);
            }
        }
示例#10
0
        private void onTickMessage(Message message)
        {
            TickMessage tmessage = (TickMessage)message;

            foreach (AddAgentMessage aam in tmessage.agents)
            {
                this.onAddAgentMessage(aam);
            }

            AgentManagementSystem.NextTimeEvent.Set();
        }
示例#11
0
        public void Should_TryParse_Protocol62_Return_True(string cultureName)
        {
            // Arrange
            TestHelper.SetThreadCulture(cultureName);

            // Act
            var parsed = TickMessage.TryParse(_messageProtocol62, out var tickMessage);

            // Assert
            Assert.IsTrue(parsed);
            Assert.AreEqual(tickMessage, _expectedMessageProtocol62);
        }
示例#12
0
        public void Should_Convert_Csv_To_Original_MessageProtocol60(string cultureName)
        {
            // Arrange
            TestHelper.SetThreadCulture(cultureName);
            var tickMessage1 = TickMessage.Parse(_messageProtocol60);

            // Act
            var tickMessage1Csv = tickMessage1.ToCsv();
            var tickMessage2    = TickMessage.Parse(tickMessage1Csv);

            // Assert
            Assert.AreEqual(tickMessage2, tickMessage1);
        }
示例#13
0
        public void Should_Parse_TickMessage_Culture_Independent(string cultureName)
        {
            // Arrange
            TestHelper.SetThreadCulture(cultureName);
            var message = "2018-04-17 17:51:22.123456,96.0700,1061909,0,0.0000,0.0000,4145784264,O,19,143A";

            // Act
            var tickMessageParsed = TickMessage.Parse(message);

            var timestamp   = DateTime.ParseExact("2018-04-17 17:51:22.123456", TickMessage.TickDateTimeFormat, CultureInfo.InvariantCulture);
            var tickMessage = new TickMessage <double>(timestamp, 96.07d, 1061909, 0, 0.0d, 0.0d, 4145784264, 'O', 19, "143A");

            // Assert
            Assert.AreEqual(tickMessageParsed, tickMessage);
        }
        private void OnTick(TickMessage obj)
        {
            if (_currentTask != null &&
                !_currentTask.Mandelbrot.IsScaleComplete)
            {
                _whenLastActiveUtc = DateTime.UtcNow;
                _currentTask.RequestCopy();
            }

            if (AutoPlay)
            {
                if (DateTime.UtcNow - _whenLastActiveUtc > AutoPlayTimeout)
                {
                    DoRestart();
                }
            }
        }
示例#15
0
        /// <summary>
        /// Stream IQFeed TickMessages from disk to Lean Tick
        /// </summary>
        /// <param name="filename"></param>
        /// <param name="request"></param>
        /// <param name="tickFunc"></param>
        /// <param name="delete"></param>
        /// <returns>Converted Tick</returns>
        private IEnumerable <BaseData> GetDataFromTickMessages(string filename, HistoryRequest request, Func <DateTime, Symbol, TickMessage, Tick> tickFunc, bool delete)
        {
            var dataTimeZone = _marketHoursDatabase.GetDataTimeZone(request.Symbol.ID.Market, request.Symbol, request.Symbol.SecurityType);

            // We need to discard ticks which are not impacting the price, i.e those having BasisForLast = O
            // To get a better understanding how IQFeed is resampling ticks, have a look to this algorithm:
            // https://github.com/mathpaquette/IQFeed.CSharpApiClient/blob/1b33250e057dfd6cd77e5ee35fa16aebfc8fbe79/src/IQFeed.CSharpApiClient.Extensions/Lookup/Historical/Resample/TickMessageExtensions.cs#L41
            foreach (var tick in TickMessage.ParseFromFile(filename).Where(t => t.BasisForLast != 'O'))
            {
                var timestamp = tick.Timestamp.ConvertTo(TimeZones.NewYork, dataTimeZone);
                yield return(tickFunc(timestamp, request.Symbol, tick));
            }

            if (delete)
            {
                File.Delete(filename);
            }
        }
示例#16
0
        public IEnumerable <IHistoricalMessage> Parse()
        {
            ZipFile zipFile;

            using (var unzipped = Compression.Unzip(_zipPath, _zipEntry, out zipFile))
            {
                if (unzipped == null)
                {
                    yield break;
                }
                string line;
                while ((line = unzipped.ReadLine()) != null)
                {
                    yield return(TickMessage.Parse(line));
                }
            }
            zipFile.Dispose();
        }
示例#17
0
        /// <summary>
        /// Stream IQFeed TickMessages from disk to Lean Tick
        /// </summary>
        /// <param name="filename"></param>
        /// <param name="request"></param>
        /// <param name="isEquity"></param>
        /// <returns>Converted Tick</returns>
        private IEnumerable <BaseData> GetDataFromTickMessages(string filename, HistoryRequest request)
        {
            var dataTimeZone = _marketHoursDatabase.GetDataTimeZone(request.Symbol.ID.Market, request.Symbol, request.Symbol.SecurityType);

            // We need to discard ticks which are not impacting the price, i.e those having BasisForLast = O
            // To get a better understanding how IQFeed is resampling ticks, have a look to this algorithm:
            // https://github.com/mathpaquette/IQFeed.CSharpApiClient/blob/1b33250e057dfd6cd77e5ee35fa16aebfc8fbe79/src/IQFeed.CSharpApiClient.Extensions/Lookup/Historical/Resample/TickMessageExtensions.cs#L41
            foreach (var tick in TickMessage.ParseFromFile(filename).Where(t => t.BasisForLast != 'O'))
            {
                var timestamp = tick.Timestamp.ConvertTo(TimeZones.NewYork, dataTimeZone);

                // trade
                yield return(new Tick(
                                 timestamp,
                                 request.Symbol,
                                 tick.TradeConditions,
                                 tick.TradeMarketCenter.ToStringInvariant(),
                                 tick.LastSize,
                                 (decimal)tick.Last
                                 ));

                // quote
                yield return(new Tick(
                                 timestamp,
                                 request.Symbol,
                                 tick.TradeConditions,
                                 tick.TradeMarketCenter.ToStringInvariant(),
                                 0, // not provided by IQFeed on history
                                 (decimal)tick.Bid,
                                 0, // not provided by IQFeed on history
                                 (decimal)tick.Ask
                                 ));
            }

            File.Delete(filename);
        }
示例#18
0
        void HandleTick(TickMessage msg)
        {
            //sending packs
            foreach (var queue in _sendQueues)
            {
                if (!queue.Value.IsEmpty)
                {
                    List <JediumBehaviourMessage> s_msgs = new List <JediumBehaviourMessage>(50);
                    int i = 0;
                    JediumBehaviourMessage cmsg = null;
                    do
                    {
                        if (queue.Value.TryDequeue(out cmsg))
                        {
                            s_msgs.Add(cmsg);
                            i++;
                        }
                    } while (i < MAX_PACK_SIZE && !queue.Value.IsEmpty);


                    _serverConnection.WithNoReply().SendMessagePack(s_msgs.ToArray());
                }
            }
        }
示例#19
0
 private void OnTick(TickMessage obj)
 {
     Update();
 }
示例#20
0
 private void OnTick(TickMessage message)
 {
     Update();
 }
示例#21
0
文件: Tick.cs 项目: ktj007/mmo
 internal void OnTick(TickMessage msg)
 {
 }
示例#22
0
 private void OnTick(TickMessage message)
 {
     Update();
 }
示例#23
0
        private IEnumerable <HistoricalData> GetData(MarketRequest request, string filename)
        {
            switch (request.DataType)
            {
            case DataType.Tick:
                return(LookupMessageFileParser.ParseFromFile(line => new HistoricalData(TickMessage.Parse(line).Timestamp, line), filename));

            case DataType.Daily:
                return(LookupMessageFileParser.ParseFromFile(line => new HistoricalData(DailyWeeklyMonthlyMessage.Parse(line).Timestamp, line), filename));

            default:
                throw new NotSupportedException();
            }
        }
示例#24
0
 private void HandleTick(TickMessage msg)
 {
     Tick(msg.Ticks);
 }
示例#25
0
 private void ProcessMessage(TickMessage message)
 {
     Console.WriteLine("Counter tick {0}", ++_count);
 }