TimelordUK / jspurefix

native typescript FIX engine
MIT License
58 stars 27 forks source link

Example for login #24

Open denisvolokh opened 2 years ago

denisvolokh commented 2 years ago

Hi,

Could you please show me how to log in or respond to message type A?

I have code in Python that is based on QuickFIX library and could not find any example using your library.

def toAdmin(self, message, sessionID):
        msg = message.toString().replace(__SOH__, "|")
        self.log_message("[+] To Admin: {msg}", fix_message=msg)

        message.getHeader().setField(fix.SenderSubID(self.username))
        if "A" == message.getHeader().getFieldRef(35).getString():
            message.setField(fix.Password(self.password))
        return

Thanks.

TimelordUK commented 2 years ago

hello if you check out https://github.com/TimelordUK/jspf-md-demo

this uses quick fix notation and shows how custom fields can be added and typescript interfaces created

the idea looking at src/md-client.ts is to inherit from AsciiSession which will carry out the login and maintain heartbeat etc. It will forward application messages to

  protected onApplicationMsg (msgType: string, view: MsgView): void {
    this.logger.info(`${view.toJson()}`)
  }

if for some reason AsciiSession is not suitable, you can copy the implementation into your project MyAscciSession change it and inherit from that

this is a simple complete application which sends a message to a server also included,

when login is complete the onReady is called and we can send an application message to the server at this point.

  protected onReady (view: MsgView): void {
    this.logger.info('ready')
    const logoutSeconds = 32
    this.logger.info(`will logout after ${logoutSeconds}`)
    const mdr = MDFactory.BidOfferRequest('EUR/USD')
    this.send(MsgType.MarketDataRequest, mdr)
    setTimeout(() => {
      this.done()
    }, logoutSeconds * 1000)
  }