playbook/docs/tsl/syntax_book/function/05_server_interaction.md

5.1 KiB
Raw Blame History

服务器交互函数

内容

  • 服务器交互函数简介
  • ConnectServer
  • LoginServer
  • DefaultConnectAndLogin
  • INI文件配置登陆信息
  • SendExecuteAndWait
  • SendExecute
  • 实时行情订阅SendExecute
  • 异步回调函数以及实时订阅系统参数说明
  • 服务器返回信息类型
  • EndExecute
  • CheckLogined
  • CheckConnected
  • LoginedUser
  • RemoteAddress
  • RemotePort
  • DisconnectServer
  • TSTaskAdmin
  • SetComputeService
  • GetComputebitsOption
  • SetComputebitsOption
  • GetComputeService

服务器交互函数简介

服务器交互函数可以让本地执行的TSL语言与金融分析.NET服务器进行交互并递交计算请求到服务器运算。

ConnectServer

范例 http模式代理登陆

cTS := ConnectServer("tsl.tinysoft.com.cn", 443, array("Address":"192.168.0.250", "Port":808, "AuthMode":0));
lg := LoginServer("TSUser", "UserPass", msg);
if lg = 0 then
begin
    echo "登陆成功!";
    Script := 'program TS_testFunc;
    begin
        r := 1 -  > 5;
        return r;
    end.';
    if SendExecuteAndWait(Script, getSysParams(), Result, ErrMsg) = 0 then//Execute Success
    echo tostn(Result), '\r\n';
    else echo '远端执行失败!\r\n';
    DisconnectServer();
end
else echo "登陆失败,报错:(", cTS, ",", msg, ")\r\n";

打印"登陆成功!"则说明连接成功。参考DefaultConnectAndLogin LoginServer

LoginServer

参考DefaultConnectAndLogin ConnectServer

DefaultConnectAndLogin

参考ConnectServer LoginServer

INI文件配置登陆信息

第一步在plugin目录下新建ini文件文件全名为tslclient.ini

客户端用户该plugin目录在天软安装目录下一般路径为C:\Program Files\Tinysoft\Analyse.NET\Plugin

其它用户需要找到插件包中的plugin目录下添加。

第二步在tslclient.ini添加以下内容

[TSLClient Config]
;调用是登陆的别名
[test]
;本地许可
Permit=local
;用户名
LoginName=
;密码
LoginPass=
;服务器 地址
Address=tsl.tinysoft.com.cn
;端口
Port=443
;---以下为代理服务器
;代理服务器端口
ProxyPort=
;代理服务器地址
ProxyAddress=
;代理身份验证用户名
ProxyUser=
;验证密码
ProxyPass=
;代理模式 http模式设置为0 SOCKS5模式设置为5
ProxyAuthMode=

其中,[test]中的test是用户自定义的别名可用户自己设定,区分大小写,在登陆时调用。

其余项用户需要根据自己的实际情况填写。

同一个ini文档中可以配置多个配置信息使用时通过别名进行识别。

调用比如cTS:=DefaultConnectAndLogin(test,msg)

SendExecuteAndWait

参考实时行情订阅。

SendExecute

参考实时行情订阅 异步回调函数以及实时订阅系统参数说明 服务器返回信息类型。

实时行情订阅SendExecute

参考异步回调函数以及实时订阅系统参数说明 服务器返回信息类型

异步回调函数以及实时订阅系统参数说明

系统参数名 类型 说明
channel 整数 通道ID,和SendExecute返回值一致
recvtype 整数 参阅:服务器返回信息类型
errno 整数 错误号,非0错误
errmsg 字符串 错误信息
result 订阅为数组类型 结果集,订阅为推送类型

服务器返回信息类型

返回类型 说明
执行函数返回 0x0201
执行委托函数返回 0x0301
ECHO返回 0x0401
客户请求返回 0x0402
实时订阅返回 0x0501
错误信息返回 0

EndExecute

CheckLogined

CheckConnected

LoginedUser

RemoteAddress

范例

####python交互范例python代码
import sys
sys.path.append('D:\\tinysoft\\Analyse.NET\\')
import TSLPy3 as ts
data := ts.DefaultConnectAndLogin("test")
print(ts.Logined())
print("远程登录地址", ts.RemoteAddress())
print("服务器设置:", ts.GetService())
ts.SetComputeBitsOption(64) #设置计算单位
print("计算位数设置:", ts.GetComputeBitsOption())
ts.Disconnect() #断开连接

结果

RemotePort

DisconnectServer

  • 服务器交互函数简介
  • ConnectServer
  • LoginServer
  • DefaultConnectAndLogin
  • INI文件配置登陆信息
  • SendExecuteAndWait
  • SendExecute
  • 实时行情订阅SendExecute
  • 异步回调函数以及实时订阅系统参数说明
  • 服务器返回信息类型
  • EndExecute
  • CheckLogined
  • CheckConnected
  • LoginedUser
  • RemoteAddress
  • RemotePort
  • DisconnectServer
  • TSTaskAdmin
  • SetComputeService
  • GetComputebitsOption
  • SetComputebitsOption
  • GetComputeService

TSTaskAdmin

范例

rdo2 TSTaskAdmin("oa", CmdReturn, BroadCastMsg, ErrMsg, 3000, 1000);
return CmdReturn;

SetComputeService

GetComputebitsOption

SetComputebitsOption

GetComputeService