2

我目前正在尝试使用 qsharp 订阅我的tickerplant,但是当我尝试获取消息数据时,我只会System.Int64[]被返回或system.object[]如下所示: 在此处输入图像描述

取自示例的 C# 代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using NetMQ;
using System.Text.RegularExpressions;
using qSharp;
namespace SubscribeToData
{
    class Program
    {
        static void Main(string[] args)
        {
            QCallbackConnection q = new QCallbackConnection("localhost", 5005);
            try
            {

                Console.WriteLine("conn: " + q + "  protocol: " + q.ProtocolVersion);
                Console.WriteLine("Press <ENTER> to close application");
                q.DataReceived += OnData;
                q.ErrorOccured += OnError;
                q.Open();
                Console.WriteLine("conn: " + q + "  protocol: " + q.ProtocolVersion);
                Console.WriteLine("Press <ENTER> to close application");
                Object response = q.Sync(".u.sub", "trade", ""); // subscribe to tick
                QTable model = (QTable)((Object[])response)[1]; // get table model
                Console.WriteLine(model);
                q.StartListener();
                Console.ReadLine();
                q.StopListener();
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Error occured: " + e);
                Console.ReadLine();
            }
            finally
            {
                q.Close();
            }



        }
        static void OnData(object sender, QMessageEvent message)
        {
            Object data = message.Message.Data;
            Console.WriteLine(sender);
            Console.WriteLine(message.Message.Data);
            Console.WriteLine("message type: " + message.Message.MessageType + " size: " + message.Message.MessageSize + " isCompressed: " + message.Message.Compressed + " endianess: " + message.Message.Endianess);
            PrintResult(message.Message.Data);
            if (data is Object[])
            {
                 Console.WriteLine("TEST");
                Console.WriteLine(message);
                // unpack upd message
                Object[] args = ((Object[])data);
                Console.WriteLine("testargs");
                Console.WriteLine(args[0].ToString());
                Console.WriteLine(args[1]);
                Console.WriteLine(args[2].GetType());
                Console.WriteLine(data);
                if (args.Length == 3 && args[0].Equals("upd") && args[2] is QTable)
                {
                    QTable table = (QTable)args[2];
                    foreach (QTable.Row row in table)
                    {
                        Console.WriteLine(row);
                    }
                }
            }
        }
        static void PrintResult(object obj)
        {
            if (obj == null)
            {
                Console.WriteLine("::");
            }
            else if (obj is QDictionary)
            {
                PrintResult(obj as QDictionary);
            }
            else
            {
                Console.WriteLine(obj);
            }
        }
        static void PrintResult(QDictionary d)
        {
            foreach (QDictionary.KeyValuePair e in d)
            {
                Console.WriteLine(e.Key + "| " + e.Value);
            }
        }
        static void OnError(object sender, QErrorEvent error)
        {
            Console.Error.WriteLine("Error received via callback: " + error.Cause.Message);
        }
    }

对于我的 q 代码:

Tickerplant:

trade:([]daytime:();instrumenttype:();symbol:();expiration:();mtype:();price:();cond:();exchange:();volume:());
quote:([]daytime:();instrumenttype:();symbol:();expiration:();mtype:();price:();cond:();exchange:();volume:());
upath:"tick/u.q";
@[system;"l ",upath;{-2"Failed to load u.q from ",x," : ",y,
                       ". Please make sure u.q is accessible.",
                       " kdb+tick can be downloaded from http://code.kx.com/wsvn/code/kx/kdb+tick";
                       exit 2}[upath]]
.u.init[]
.u.upd:insert;

我发布使用

.u.pub[`trade;2,2,2,2,2,1,1,1,1]

现在的问题是它似乎确实收到了QMessage但只是解析不正确?

4

0 回答 0