我正在制作一个python应用程序,它将通过API向broker应用程序发送消息。我在文档信息中有消息应该是XML格式的:
<FIXML v="5.0" r="20080317" s="20080314">
<UserReq UserReqID="0" UserReqTyp="1" Username="1234" Password="1234"/>
</FIXML>
- 你能告诉我如何用python语言发送吗
- 如何连接到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).
我已经想通了。总的来说,每件事你都需要手动完成。
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应用程序。