Code Monkey home page Code Monkey logo

napi-ctp's Introduction

napi-ctp

NPM Version Platform

Node API for CTP

napi-ctp's People

Contributors

dependabot[bot] avatar shixiongfei avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

napi-ctp's Issues

Throw an error when call td.reqUserLogin(...) on Mac(Sonoma 14.1.1)

......

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

It seems ReqOrderInsert will not trigger `rsp-order-insert` and `err-rtn-order-insert` events

  1. I tried the ReqOrderInsert API, and whether it succeeded or failed, it would not trigger the rsp-order-insert, which is not expected.
  2. When the failure occurred (such as CTP: 平今仓位不足), the err-rtn-order-insert was not triggered, but the rsp-error was triggered, which seems not expected.
  3. When succeed, the rtn-order event was triggered, which is expected.

I'm not sure if 1 and 2 perform the same as the CTP C++ API.

md.reqUserLogin cause an error

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.

Throw error when calling `reqQryTrade`

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 reqQryQuotereqQryInvestorPositionDetail have same issue.

Can all parameters of the callback be passed?

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:

  1. Some callbacks may be called multiple times consecutively with different values of bIsLast, perhaps the user only wants to do some logical processing when bIsLast is true.
  2. If users want to develop a program that supports multiple trading accounts, 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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.