-
Notifications
You must be signed in to change notification settings - Fork 12
/
test_version.js
165 lines (138 loc) · 4.19 KB
/
test_version.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
const logger=console;
//logger.log("before load SegfaultHandler");
//var SegfaultHandler = require('segfault-handler');
//logger.log("after load SegfaultHandler");
//
//SegfaultHandler.registerHandler("crash1.log"); // With no argument, SegfaultHandler will generate a generic log file name
//
//// Optionally specify a callback function for custom logging. This feature is currently only supported for Node.js >= v0.12 running on Linux.
//SegfaultHandler.registerHandler("crash2.log", function(signal, address, stack) {
// // Do what you want with the signal, address, or stack (array)
// // This callback will execute before the signal is forwarded on.
//});
//SegfaultHandler.causeSegfault();
function copy_o2o(o1,o2){for(var k in o2){o1[k]=o2[k]}return o1}
const argv2o=o=>o.reduce((r,e)=>(m=e.match(/^(\/|--?)([a-zA-Z0-9-_]*)="?(.*)"?$/))&&(r[m[2]]=m[3])&&r||r,{});
const os=require('os');
var argo={};
copy_o2o(argo,argv2o(process.argv));
//logger.log('argo=',argo);
var q_sptrader = require('./q_sptrader')();
//test if any segfault:
//const crypto=require('crypto');
var { host, port, license, app_id, user_id, password, host_id, acc_no } = argo;
if(!acc_no) acc_no = user_id;
if(!host_id) host_id=80;//Default 80
port*=1;
host_id*=1;
q_sptrader.invoke('on','Test',rt=>{
logger.log(".Test.rt=",rt);
});
q_sptrader.invoke('on','LoginReply',rt=>{
logger.log(".LoginReply.rt=",rt);
});
q_sptrader.invoke('on','ConnectedReply',function(rt){
logger.log("1:连接中,2:已连接,3:连接错误, 4:连接失败");
logger.log(".ConnectedReply.rt=",rt);
});
if(!password) throw new Error('need /password=');
var login_info = { host, port, license, app_id, user_id, password };
var is_prod_init_done=false;
/*
function GetBalance_Promise(){
var dfr=Q.defer();
var rt={STS:"OK"};
var user_id=getUserId();
Q_remoteModule
.invoke('call','SPAPI_GetAllAccBal',{user_id})
.then(rst=>{
if(rst){
rt.AllAccBal=rst.out;
}
//return rst;
return Q_remoteModule;
})
.invoke('call','SPAPI_GetAccInfo',{user_id})
.then(rst=>{
if(rst){
rt.AccInfo=rst.out;
}
return Q_remoteModule;
})
.done(rst=>{
dfr.resolve(rt);
});
return dfr.promise;
}
*/
q_sptrader
.invoke('call','SPAPI_GetDllVersion',{test:new Date()})
.then( rst =>{
logger.log('SPAPI_GetDllVersion.rst=',rst);
return q_sptrader })
.invoke('call','SPAPI_SetLoginInfo',login_info)
.then((rst)=>{
logger.log('SPAPI_SetLoginInfo.rst=',rst);
if(rst && rst.rc==0) return q_sptrader;
throw new Error("SPAPI_SetLoginInfo.rst="+rst);
})
.invoke('call','SPAPI_Login',{})
.delay(3333)
.then((rst)=>{
logger.log('SPAPI_Login.rst=',rst);
if(rst && rst.rc==0) return q_sptrader;
throw new Error("SPAPI_Login.rst="+rst);
})
.then(()=>{ return q_sptrader; })
.delay(9999)
.invoke('call','SPAPI_GetLoginStatus',{user_id,host_id})
.fail(err=>{
logger.log('fail.rst=',err);
})
.done(rst=>{
logger.log(process.versions);
logger.log('done.rst=',rst);
q_sptrader
.invoke('call','SPAPI_GetAccInfo',{user_id})
.done((rst)=>{
logger.log('SPAPI_GetAccInfo.rst=',rst);
})
q_sptrader
.invoke('call','SPAPI_GetAllAccBal',{user_id})
.done((rst)=>{
logger.log('SPAPI_GetAllAccBal.rst=',rst);
})
q_sptrader
.invoke('call','SPAPI_GetAllPos',{user_id})
.done((rst)=>{
logger.log('SPAPI_GetAllPos.rst=',rst);
})
if(!is_prod_init_done && argo.test_prod_init){
return q_sptrader
.invoke('call','SPAPI_LoadInstrumentList')
.delay(4000).then(()=>q_sptrader)
//.invoke('call','SPAPI_GetInstrument')
//.then(rst=>{
// if(rst)_tmp_log(o2s(rst.out));
//})
.invoke('call','SPAPI_LoadProductInfoListByCode',{inst_code:"HSI"})
.delay(4000).then(()=>q_sptrader)
.invoke('call','SPAPI_GetProduct')
.then(rst=>{
is_prod_init_done=true;
logger.log(rst);
//if(rst)_tmp_log(o2s(rst.out));
//return Q({STS:"OK",errmsg:"",type:"I",sleepTime:4444});
});
}
//if(rst&&rst.rc==3){
// dfr.resolve({STS:"OK"});
//}else{
// logger.log("DEBUG SPAPI_GetLoginStatus",rst);
// rst.STS='KO';
// if(!rst.errmsg) rst.errmsg="LOGIN seems failed..";
// //rst.LatestLoginStatus=LatestLoginStatus;
// dfr.resolve(rst);
//}
})
;