天软客户端中指定服务器节点的方式:FAQ:
Q:如何指定天软服务器进行执行命令
Python两种交互方式指定服务器
TSLPy交互方法使用参考:FAQ:
2019-05-08-应用专题-第三方交互07:天软平台和PYTHON的交互
pyTSL交互方法使用参考:FAQ:
天软pyTSL接口
1.TSLPy
说明:通过函数SetService指定
示例代码:
#获取天软行情数据
import sys
import TSLPy3 as ts
sys.path.append("C:\Program Files\Tinysoft\Analyse.NET")
ts.DefaultConnectAndLogin("sz_server")#远程登录,用自己配置的别名
ts.SetService("192.168.102.46:z:\se")#指定服务器,要和登陆的服务器地址对应
ts_str='''
echo AnsiToUtf8("本次执行服务器:"), TSAppserver(),"\r\n";
setsysparam(pn_stock(),cy_day());
mtic;
t:=select ['StockID'],['date'],['sectional_cjbs']
from markettable datekey 20220301t to 20220401t of "SZ000001" end;
echo AnsiToUtf8("执行时间:"),mtoc,"\r\n";
return length(t);
'''
dt=ts.RemoteExecute(ts_str,{})
print("数据长度:",dt[1])
打印结果:
2.pyTSL
说明:通过模型exec,call中的参数service指定,还可以使用模型server_list查询当前可用的服务器节点列表
示例代码:
#获取天软行情数据
import pyTSL
c = pyTSL.Client("user", "password", "tsl.tinysoft.com.cn", 443) #user为天软账号,password 为账号密码
c.login()
sl=c.server_list()
s=sl[2]
print("可用服务器数量:",len(sl))
print("指定服务器节点:",s)
test = '''
function get_value(stock,begt,endt);
begin
echo "本次执行服务器:", TSAppserver();
setsysparam(pn_stock(),cy_day());
mtic;
t:=select ['StockID'],['date'],['sectional_cjbs']
from markettable datekey inttodate(begt) to inttodate(endt) of stock end;
echo "执行时间:",mtoc;
return length(t);
end;
'''
r = c.call('get_value',"SZ000001",20220301,20220401,code=test,service=s)
print("数据长度",r.value())
打印结果: