GithubHelp home page GithubHelp logo

memoryfraction / tigerbroker.sdk.net Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 0.0 294 KB

A library that helps users to get account info from Tiger Broker. e.g. balance, currency type etc.

License: Creative Commons Zero v1.0 Universal

C# 100.00%

tigerbroker.sdk.net's Introduction

TigerBrokerLib

Introduction

This kind of library can be used to communicate with Tiger Securities and automatically obtain the market value information of users' accounts.

Dependency

Features

  • Cross-platform: Windows, Linux, Mac

Preparatory Work

Get developer information

Use the

register as a developer. And be sure to get the following information

RSA Public Key: Save as PublicKey.txt

RSA Private Key: Save as PrivateKey.txt

account: It is used to distinguish the account type of the user, and the user can select the corresponding account type when trading

tigerId: Used to uniquely identify a developer. This parameter is required when requesting an API interface

It is recommended to use client-secret. json to store private information in the following format

{
   "account": "XXXXX",
   "tiger_id": "XXX"
}

Steps

TigerBrokerLib Installation

  • Self compilation

Download SRC, install Visual Studio, compile the source code and get TigerBrokerLibrary.dll, then you can use it.

Install-Package TigerBrokerLibrary -Version 1.0.0

client-secrets.json usage

Json file relative path: "Data/ client-secret. json"

// Definition
var config = new ConfigurationBuilder()
                .AddJsonFile("Data/client-secrets.json")
                .Build();
// Usage
var tiger_id = config["tiger_id"];

Method to get TigerBroker Method

        //1 Generate Dictionary
        //  Convert time zone to the one in Chinese
        var chinaZone = TimeZoneInfo.FindSystemTimeZoneById("China Standard Time");
        var dtChina = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow.Date, chinaZone);
        var timeStamp = dtChina.ToString("yyyy-MM-dd HH:mm:ss");

        var url = "https://openapi.itiger.com/gateway";
        var account = config["account"];
        var charset = "UTF-8";
        var method = "assets";
        var sign_type = "RSA";
        var tiger_id = config["tiger_id"];
        var version = "1.0";
        var paramsDic = _tigerBrokerService.GetTigerBrokerRequestDictionary(
            timeStampString: timeStamp, 
            account: account, 
            charset: charset, 
            method: method,
            sign_type : sign_type,
            tiger_id : tiger_id, 
            version : version);

        //2 Generate Sign
        //2.1 generate content to be signed
        var contentTobeSigned = _tigerBrokerService.GetContentTobeSigned(paramsDic);

        // 2.2 Sign
        var privateKey = File.ReadAllText(@"Data\TigerBrokerPrivateKey.txt");
        var sign = _tigerBrokerService.Sign(contentTobeSigned, privateKey);
        
        //3 Generate Request
        var tigerBrokerRequest = _tigerBrokerService.GetTigerAssetsRequest(
            account: account,
            tiger_id: tiger_id,
            timeStamp: timeStamp,
            sign: sign,
            method: method,
            charset: charset,
            sign_type:sign_type,
            version:version
            ); 

        //4 Send Request and get Response
        var tigerResponse = await _tigerBrokerService.GetTigerBrokerAssetsModelAsync(url,tigerBrokerRequest);
        var tigerAssets = _tigerBrokerService.ConverToTigerAssetsFromTigerAssetsResponse(tigerResponse);

Client (unit test) project file structure diagram

Image

Expectation Result

Image

Support

If this project is helpful to you, please click Star in the upper right corner and forward it to friends who need it.

You can also buy me a cup of coffee at the link below


简介: 使用该类库可以与老虎证券通信,自动获得用户的账户市值信息。

依赖项

特点

跨平台可用, 比如: windows, Linux, Mac

准备工作

  • 获取开发者信息

    进入老虎量化开发者页面,按照页面提示,注册成为开发者。并确保获取如下信息

    RSA公钥:比如存为PublicKey.txt

    RSA私钥:比如存为PrivateKey.txt

    account: 用来区分用户的账户类型,用户交易时选择对应的账户类型即可

    tigerId: 用来唯一标识一个开发者,在请求API接口时需要该参数

    建议使用client-secrets.json存储私密信息, 格式如下

    {
       "account": "XXXXX",
       "tiger_id": "XXX"
    }

使用方法

TigerBrokerLib安装方法

  • 自行编译

下载src, 安装Visual Studio,编译源码并获取TigerBrokerLibrary.dll, 然后可以使用。

Install-Package TigerBrokerLibrary -Version 1.0.0

client-secrets.json使用方法

假定client-secrets.json文件相对路径: "Data/client-secrets.json"

// 定义
var config = new ConfigurationBuilder()
                .AddJsonFile("Data/client-secrets.json")
                .Build();
// 使用
var tiger_id = config["tiger_id"];

获取老虎证券账户信息的方法

            //1 Generate Dictionary
            //  Convert time zone to the one in Chinese
            var chinaZone = TimeZoneInfo.FindSystemTimeZoneById("China Standard Time");
            var dtChina = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow.Date, chinaZone);
            var timeStamp = dtChina.ToString("yyyy-MM-dd HH:mm:ss");

            var url = "https://openapi.itiger.com/gateway";
            var account = config["account"];
            var charset = "UTF-8";
            var method = "assets";
            var sign_type = "RSA";
            var tiger_id = config["tiger_id"];
            var version = "1.0";
            var paramsDic = _tigerBrokerService.GetTigerBrokerRequestDictionary(
                timeStampString: timeStamp, 
                account: account, 
                charset: charset, 
                method: method,
                sign_type : sign_type,
                tiger_id : tiger_id, 
                version : version);
    
            //2 Generate Sign
            //2.1 generate content to be signed
            var contentTobeSigned = _tigerBrokerService.GetContentTobeSigned(paramsDic);
    
            // 2.2 Sign
            var privateKey = File.ReadAllText(@"Data\TigerBrokerPrivateKey.txt");
            var sign = _tigerBrokerService.Sign(contentTobeSigned, privateKey);


            //3 Generate Request
            var tigerBrokerRequest = _tigerBrokerService.GetTigerAssetsRequest(
                account: account,
                tiger_id: tiger_id,
                timeStamp: timeStamp,
                sign: sign,
                method: method,
                charset: charset,
                sign_type:sign_type,
                version:version
                ); 
    
            //4 Send Request and get Response
            var tigerResponse = await _tigerBrokerService.GetTigerBrokerAssetsModelAsync(url,tigerBrokerRequest);
            var tigerAssets = _tigerBrokerService.ConverToTigerAssetsFromTigerAssetsResponse(tigerResponse);

客户端(单元测试)项目文件结构图

Image

预期结果

Image

声明

如有问题, 欢迎在Issue区提出。

捐赠与支持

如果本项目对您有帮助,请点击右上角Star并转发给需要的好友。 您也可以通过下方链接请我喝杯咖啡

tigerbroker.sdk.net's People

Contributors

memoryfraction avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.