4

I'm using a API called WindAPI which provided the financial data from China markets. This API provides a method call wsq() which will provide the RealTime price data to user's program through a callback function!

I write some simple codes in c#,trying to use this wsq() method, but get no results. I wonder there must be some error in codes, but just can't find it! I'm new to both C# and programming, so if it's a rookie mistake, don't laugh at me:)

Here's the codes, I'll give as much comments as possible, so you can find the misunderstanding in it quickly.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//-----------------------------
using WAPIWrapperCSharp;  //the namespace in API dll(official provided)
using WindCommon;         //the namespace to process the data formats (official provided)

namespace WSQ2String
{
    class WSQ2StringSample
    {
        static void Main()
        {
            Console.Write("Begin......");
            Console.ReadLine(); 
            //--------------------creat the new API object and log on
            WindAPI w = new WindAPI();
            Console.WriteLine("New API created!");
            w.start();
            Console.WriteLine("API log on!");
            //--------------------request for the realtime data through w.wsq() method
            int errorId = 0;
            ulong reqId = w.wsq(ref errorId, "150195.sz", "rt_date, rt_time, rt_lastest", "", myCallback);
            Console.WriteLine("errorId = {0}", errorId);
            //----adding a control line which will stop the main program and wait for myCallback function to be called
            Console.ReadLine();    //after the data arrived, the test is over, and we press a key to let the main program continue
            w.cancelRequest(reqId);
            w.stop();
            Console.Write("End......");
            Console.ReadLine();
        }
        //----
        static void myCallback(ulong reqId, WindData wd)
        {
            Console.WriteLine("wsq data gotback......");
            //----transfer the official WindData format to String, and output to the screen 
            string s = WindDataMethod.WindDataToString(wd, "wsq");   //the method is in WindCommon namespace 
            Console.Write(s);
        }
    }
}

My understanding is that, when I request the data service by using w.wsq(), when the prices change(that's the event), myCallback() will be called and export the data on screen!

The reason I add a readline() is to prevent the main program runs too fast, and end before the event(price changing). In that situation, the myCallback() would have no chance to be called!

But when I run the codes, after "errorId = 0" shows, I wait several minutes and still get no results! I confirmed that the price has changed(it usually changed within seconds).

Here is the result I get, and I can't find the reason....(I just type the lines in screen)

>>Begin......
>>New API created!
>>API log on!
>>errorId = 0

and then the prgram just paused there and nothing more happened! So I'd be very thankful if someone could explain that to me....

Thank you in advanced!


Updated: According to the comments below, I give the zip files of my solutions. Also with the API dll and it's source codes.

My solution files and dll

so, anyone help?

Saji Ren
  • 95
  • 6
  • You can use [callback](http://stackoverflow.com/questions/2139812/what-is-a-callback) link for better understanding. – Jignesh Patel Jun 25 '16 at 04:54
  • 1
    If you can point to the API Souce, then it would be helpful – cvraman Jun 25 '16 at 05:01
  • @cvraman Thank you for reply! By API Souce, I don't understand what do you mean exactly.(as you know, I am a rookie in programming). Do you mean the whole API dll files? Or just the methods I used? – Saji Ren Jun 25 '16 at 05:20
  • @cvraman I give the source codes of the API, is that helpful? – Saji Ren Jun 25 '16 at 14:12
  • 1
    What exactly is `WindCallback`? And why dont you use it? – lokusking Jun 25 '16 at 14:29
  • By API Source. I mean, the entire actual source code (or dll) or nuget. Right now there are too many unknowns for us to be able to arrive at a solution. Basically if you could post a zip of your visual studio solution, then someone might be able to help. – cvraman Jun 27 '16 at 04:08
  • After I re-considered the issue, I think maybe there're 2 mistakes in my codes: 1.I declared `myCallback` as private, should it be public? 2.After I use the `w.wsq()` method to request the data, I used the `readline()` for preventing the main program finish too early. Will this also stop the API for calling `myCallback`? @cvraman – Saji Ren Jun 28 '16 at 10:04
  • @SajiRen : Am not sure. I tried running your code but got an exception at the Constructor itself. And the documentation is not in english so I can't read :( Sorry for not being able to help much. – cvraman Jun 28 '16 at 16:35
  • @cvraman: Thank you all the same...Letting the API to work also require user to install an application. But that's too much trouble for you helpers, I really understand! Next time, I'll try to ask a more smarter question without so much unnecessary details, so anyone intend to help can point to the question at once. Thanks, again~ – Saji Ren Jun 29 '16 at 00:24

0 Answers0