@xtp-smart/sdk
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

xtp-smart 组件sdk api, 提供TypeScript语言定义。

使用TS语言,能够得到更好的开发体验。

具体API使用方法可以参考组件API文档

安装

npm install --save @xtp-smart/sdk

说明

该npm包没有默认导出,需要指定具体引入对象名。

// 错误示例
import smart from "@xtp-smart/sdk";

// 正确示例
import { smart } from "@xtp-smart/sdk";

该npm包会导出两种类型的对象,一类是变量,一类是类型声明

变量是实际的js对象,可以参与具体的TS运算, 类型声明仅是TS语言概念,是为了约束TS的写法。

具体可使用的导出如下

变量

  • smart - 组件的核心对象,所有组件api都来自于此对象
  • Event - 各种事件名称集合,smart.Event对象的简单写法
  • Type - 各种枚举类型与内部数据结构,smart.Type对象的简单写法
  • Utils - 各种工具类集合,smart.utils对象的简单写法
  • Cache - 持久化缓存对象,smart.cache对象的简单写法
  • Logger - 日志记录对象,smart.logger对象的简单写法

类型声明

各类枚举值

  • Source
  • AccountType
  • Exchange
  • InstrumentType
  • PriceType
  • Side
  • Offset
  • Direction
  • VolumeCondition
  • TimeCondition
  • OrderStatus
  • StrategyPlatformType
  • StrategyStatus

SDK中的各类数据结构

  • Account
  • Order
  • Trade
  • Position
  • Assets
  • Instrument
  • IPO
  • Quote
  • Strategy
  • Book
  • Round

示例

// 导入类型声明
import { Account, Strategy, Position, Order, Quote, Book, PriceType, OrderStatus, StrategyStatus, StrategyPlatformType } from "@xtp-smart/sdk";

// 导入变量声明
import { smart, Type, Utils, Event } from "@xtp-smart/sdk";

namespace demo {

    console.log("Event", Event);

    class Plugin {
        account: Account;
        strategies: {
            [propName: string]: Strategy
        };

        constructor() {
            this.account = smart.current_account;
            this.strategies = this.account.strategy_map; //策略列表

            this.start();
        }

        async start() {
            
        }
    }

    smart.on(Event.ON_INIT, () => {
        console.log("ON_INIT");
        new Plugin();
    });
}

问题反馈

如果使用组件时遇到了任何BUG,可以在smart客户端的主项目中反馈问题。

QQ 交流群: 659577632

Readme

Keywords

Package Sidebar

Install

npm i @xtp-smart/sdk

Weekly Downloads

3

Version

1.2.0

License

UNLICENSED

Unpacked Size

139 kB

Total Files

20

Last publish

Collaborators

  • zhaolei198908
  • zhengweiyi
  • shaozilee
  • yuye7xing