Node API for CTP
shixiongfei / napi-ctp Goto Github PK
View Code? Open in Web Editor NEWNode API for CTP
Home Page: https://www.npmjs.com/package/napi-ctp
License: Apache License 2.0
Node API for CTP
Home Page: https://www.npmjs.com/package/napi-ctp
License: Apache License 2.0
......
td.on('front-connected', (...args) => {
logger.info(`td front-connected, ${JSON.stringify(args)}`);
td.reqAuthenticate({
BrokerID: 'aaaa', // replace with broker id
UserID: 'xxx', // replace with user id
AuthCode: 'yyy', // replace with auth code
AppID: 'zzz' // replace with app id
});
})
.on('rsp-authenticate', (...args) => {
logger.info(`td rsp-authenticate, ${JSON.stringify(args)}`);
td.reqUserLogin({
BrokerID: 'aaaa', // replace with broker id
UserID: 'xxx', // replace with user id
Password: 'yyy' // replace with password
});
})
It works well on windows, but throws an error when call td.reqUserLogin(...)
on Mac(Sonoma 14.1.1):
$ td front-connected, [null,{"timestamp":1715606512687}]
$ td rsp-authenticate, [{"kind":"CThostFtdcRspAuthenticateField","BrokerID":"aaaa","UserID":"xxx","UserProductInfo":"","AppID":"zzz","AppType":"1"},{"requestId":2,"isLast":true,"timestamp":1715606513152}]
$ Failed
$ zsh: segmentation fault
ReqOrderInsert
API, and whether it succeeded or failed, it would not trigger the rsp-order-insert
, which is not expected.CTP: 平今仓位不足
), the err-rtn-order-insert
was not triggered, but the rsp-error
was triggered, which seems not expected.rtn-order
event was triggered, which is expected.I'm not sure if 1 and 2 perform the same as the CTP C++ API.
code as below:
md.on('front-connected', (...args) => {
console.log('FrontConnected', ...args);
md.reqUserLogin({
BrokerID: "****",
UserID: "****",
Password: "****",
});
});
console output:
$ node test.js
v6.6.7_20220613 14:52:04.1708
v6.6.7_20220613 14:52:04.1708
Connect to 180.166.103.21:55205
Session 1759117313 Connected
FrontConnected undefined
Segmentation fault
Thanks your good job on the ctp node wrapper!
Can you help to take a look at the issue? I am not sure why occurs the Segmentation fault
, but what is certain is that it is caused by md.reqUserLogin
.
Code:
...
logger.info(`reqQryTrade', ${td.reqQryTrade()}`);
Console output:
packages/node-test test:ctp: [2024-06-03T09:35:17.132] [info] - reqQryTrade', 0
packages/node-test test:ctp: Failed
zsh: segmentation fault pnpm test:ctp
Some other functions such as reqQryQuote
、reqQryInvestorPositionDetail
have same issue.
hi @shixiongfei , I have a suggestion for the library.
Let's use the following code as an example:
void MdSpi::OnRspSubMarketData(CThostFtdcSpecificInstrumentField *pSpecificInstrument, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {
if (checkErrorRspInfo(pRspInfo, nRequestID, bIsLast))
return;
_msgq.push(EM_RSPSUBMARKETDATA, copyData(pSpecificInstrument));
}
The nRequestID
and bIsLast
are omitted, but they maybe useful in certain scenarios.
Such as:
bIsLast
, perhaps the user only wants to do some logical processing when bIsLast
is true.nRequestID
may be very useful (if users can set nRequestID
themselves when calling some APIs).If this library could encapsulate c++ interfaces one-on-one as javascript interfaces without adding any other processing logic, it would be even better, which would bring more flexibility and selectivity to developers.
as title described.
env: mb pro, Ventura 13.5.1.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.