资源简介

最近学习量化, 看到Python数据接口库TuShare还不错, 因自己C#做的多, 也不想通过IronPython等去调用, 便翻译搞了个纯C#版. 包含示例代码, 需.NET 4.0. 对量化套利感兴趣的可以参考, 或者自己建数据库, 下载数据进行个性化分析;

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

using NTuShare;
using NTuShare.Core;
using NTuShare.Attributes;

namespace NTuShareConsoleDemo
{
    class Program
    {
        const string ABOUT_STRING = @“TuShare是一个Python开源证券数据接口库 NTuShare是个人制作的C#版本; 问题反馈 技术交流 以及量化数据接口的定制等问题请联系作者 QQ:541956267 电话:13485049661。“;
        const string HELP_FORMAT = 
@“help or ?: this content;
{0}about: 关于信息
quit: 退出“;
        const string DEMO_STRING =
@“
Example:
mc.get_gdp_pull回车
sb.shibor_data回车
“;
        const string QUIT_HINT = @“输入 ‘quit‘ 退出...“;
        static List shareTypes;

        static void Main(string[] args)
        {
            WriteAbout();
            InitCommands();
            WriteHelp();
            Console.WriteLine(DEMO_STRING);
            WriteQuitHint();
            while (true)
            {
                WritePrompt();
                string commandLine = Console.ReadLine().Trim();
                if (!string.IsNullOrEmpty(commandLine))
                {
                    string[] commandParameters;
                    string commandName = ParseCommandLine(commandLine out commandParameters);
                    if (commandName == “quit“)
                        break;
                    Execute(commandName commandParameters);
                }
            }
        }

        static void WritePrompt()
        {
            Console.Write(“nts:>“);
        }

        static void WriteAbout()
        {
            Console.WriteLine(ABOUT_STRING);
        }

        private static string getParametersText(ShareMethod sm)
        {
            return string.Join(“ “ sm.MethodInfo.GetParameters().Select(p => string.Format(“[{0}:{1}]“p.Name p.ParameterType.Name)));
        }

        static void WriteHelp()
        {
            Console.WriteLine(string.Format(HELP_FORMAT string.Join(Environment.NewLine
                shareTypes.Select(st=>string.Format(“{1}{0}{2}“
                Environment.NewLine st.TypeName+“|“+st.NameAbbreviation +“\t“ + st.Description
                string.Join(Environment.NewLine
                st.Methods.Select(sm=>string.Format(“  {1} {2}  -{3}“Environment.NewLine sm.MethodNamegetParametersText(sm) sm.Description))))))));
        }

        static void WriteQuitHint()
        {
            Console.WriteLine(QUIT_HINT);
        }

        static string ParseCommandLine(string commandLine out string[] commandParameters)
        {
            //  special commands include: help([methodname]) ?([methodname]) about quit
            string[] tags = commandLine.SplitQuotes();
            string commandName = tags[0].ToLower();
            commandParameters = tags.Skip(1).ToArray();
            return commandName;
        }

        static void Execute(string commandName string[] commandParameters)
        {
            switch (

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2016-05-17 22:40  NTuShare\
     目录           0  2016-05-17 22:40  NTuShare\NTuShareConsoleDemo\
     文件        2771  2016-05-17 22:45  NTuShare\NTuShareConsoleDemo\NTuShareConsoleDemo.csproj
     文件        8436  2016-05-17 22:34  NTuShare\NTuShareConsoleDemo\Program.cs
     目录           0  2016-05-17 22:40  NTuShare\NTuShareConsoleDemo\Properties\
     文件        1474  2016-05-12 21:52  NTuShare\NTuShareConsoleDemo\Properties\AssemblyInfo.cs
     文件        2138  2016-05-17 20:56  NTuShare\NTuShareConsoleDemo\StrExt.cs
     文件         144  2016-05-14 14:33  NTuShare\NTuShareConsoleDemo\app.config
     目录           0  2016-05-17 22:40  NTuShare\NTuShareConsoleDemo\bin\
     目录           0  2016-05-17 22:40  NTuShare\NTuShareConsoleDemo\bin\Debug\
     文件      149504  2016-04-05 22:56  NTuShare\NTuShareConsoleDemo\bin\Debug\HtmlAgilityPack.dll
     文件      341504  2016-04-05 22:56  NTuShare\NTuShareConsoleDemo\bin\Debug\HtmlAgilityPack.pdb
     文件      122991  2016-04-05 22:56  NTuShare\NTuShareConsoleDemo\bin\Debug\HtmlAgilityPack.xml
     文件       55296  2016-05-12 00:30  NTuShare\NTuShareConsoleDemo\bin\Debug\LinqToExcel.dll
     文件      116224  2016-05-12 00:30  NTuShare\NTuShareConsoleDemo\bin\Debug\LinqToExcel.pdb
     文件       45828  2016-05-12 00:30  NTuShare\NTuShareConsoleDemo\bin\Debug\LinqToExcel.xml
     文件      620032  2016-05-17 22:28  NTuShare\NTuShareConsoleDemo\bin\Debug\NTuShare.dll
     文件      912896  2016-05-17 22:28  NTuShare\NTuShareConsoleDemo\bin\Debug\NTuShare.pdb
     文件       13312  2016-05-17 22:32  NTuShare\NTuShareConsoleDemo\bin\Debug\NTuShareConsoleDemo.exe
     文件         144  2016-05-14 14:33  NTuShare\NTuShareConsoleDemo\bin\Debug\NTuShareConsoleDemo.exe.config
     文件       28160  2016-05-17 22:32  NTuShare\NTuShareConsoleDemo\bin\Debug\NTuShareConsoleDemo.pdb
     文件         144  2016-05-14 14:33  NTuShare\NTuShareConsoleDemo\bin\Debug\NTuShareConsoleDemo.vshost.exe.config
     文件         490  2009-08-31 00:40  NTuShare\NTuShareConsoleDemo\bin\Debug\NTuShareConsoleDemo.vshost.exe.manifest
     文件      168960  2015-04-07 20:18  NTuShare\NTuShareConsoleDemo\bin\Debug\Remotion.Data.Linq.dll
     目录           0  2016-05-17 22:40  NTuShare\NTuShareConsoleDemo\obj\
     目录           0  2016-05-17 22:40  NTuShare\NTuShareConsoleDemo\obj\x86\
     目录           0  2016-05-17 22:40  NTuShare\NTuShareConsoleDemo\obj\x86\Debug\
     文件        5707  2016-05-17 22:45  NTuShare\NTuShareConsoleDemo\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     文件        1847  2016-05-17 22:45  NTuShare\NTuShareConsoleDemo\obj\x86\Debug\NTuShareConsoleDemo.csproj.FileListAbsolute.txt
     文件       13312  2016-05-17 22:45  NTuShare\NTuShareConsoleDemo\obj\x86\Debug\NTuShareConsoleDemo.exe
     文件       28160  2016-05-17 22:45  NTuShare\NTuShareConsoleDemo\obj\x86\Debug\NTuShareConsoleDemo.pdb
............此处省略175个文件信息

评论

共有 条评论