如何使用python向代理发送FIXML消息?

2024-09-29 00:14:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在制作一个python应用程序,它将通过API向代理应用程序发送消息。 我在文档中有这样一个信息:消息应该是XML格式的:

<FIXML v="5.0" r="20080317" s="20080314">
<UserReq UserReqID="0" UserReqTyp="1" Username="1234" Password="1234"/>
</FIXML>
  1. 你能告诉我如何用python语言发送它吗
  2. 如何连接到该API,我有以下信息:
In order to connect to the API, use the following registers:
HKEY_CURRENT_USER/Software/COMARCH S.A./NOL3/7/Settings:
• nca_pasync – port value for an asynchronous channel (default value: 24445),
• nca_psync – port value for a synchronous channel (default value: 24444),
• ncaset_pasync – flag informing whether the value in nca_pasync is active (1 - active, 0 -
inactive),
• ncaset_psync - a flag indicating whether the value in nca_psync is active (1 - active, 0 - inactive).

Tags: thetoapi信息应用程序消息forvalue
1条回答
网友
1楼 · 发布于 2024-09-29 00:14:31

我已经弄明白了。一般来说,你需要手工做每件事

import socket
import sys

HOST = '127.0.0.1'  # Standard loopback interface address (localhost)
PORT = 24444        # nca_psync – port value for a synchronous channel (default value: 24444) you need to check your registery for correct value.

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
    sock.connect((HOST, PORT))
    message = '<FIXML v="5.0" r="20080317" s="20080314"><UserReq UserReqID="0" UserReqTyp="1" Username="YOUR_LOGIN" Password="YOUR_PASS"/></FIXML>'
    try:        
        # Send data
        enc = message.encode()
        sock.send(bytes([len(enc)]))
        sock.send(message.encode())


    finally:
        sock.close()

使用此代码,我可以登录。请记住,您必须先登录到您的代理,然后才能使用nol3应用程序

相关问题 更多 >