# coding:utf-8
import DmaMdApi
import subprocess
import os
import threading
import time
import logging
LOG_FORMAT = "%(asctime)s - %(levelname)s - %(message)s"
logging.basicConfig(filename='test_dma.log', level=logging.DEBUG, format=LOG_FORMAT)
class Spi(DmaMdApi.XYDDmaMdSpi):
def OnDmaConnected(self):
print("spi response:successed to connect")
def OnDmaDisconnected(self):
print("disconnected!")
def OnPackageStart(self, nTopicID, startNo):
print("nTopicID", nTopicID)
print("StartSeqNo", startNo)
logging.debug("nTopicID %s", nTopicID)
logging.debug("StartSeqNo %s", startNo)
def OnPackageEnd(self, nTopicID, endNo):
print("nTopicID", nTopicID)
print("EndSeqNo", endNo)
logging.debug("nTopicID %s", nTopicID)
logging.debug("EndSeqNo %s", endNo)
def OnRtnDepthMarketData(self, *marketdata):
print("--------hardware market data----------")
logging.debug("------------hardware market data-------------")
data = marketdata[0]
print("InstrumentID", data.InstrumentID)
logging.debug("TradingDay %s, SettlementGroupID %s, SettlementID %s, LastPrice %s, PreSettlementPrice %s,"
"PreClosePrice %s, PreOpenInterest %s, OpenPrice %s, HighestPrice %s, LowestPrice %s, Volume %s,"
"Turnover %s, OpenInterest %s, ClosePrice %s, SettlementPrice %s, UpperLimitPrice %s, "
"LowerLimitPrice %s, UpdateTime %s, UpdateMillisec %s, InstrumentID %s, BidPrice1 %s, "
"BidVolume1 %s, AskPrice1 %s, AskVolume1 %s, BidPrice2 %s, BidVolume2 %s, AskPrice2 %s,"
"AskVolume2 %s, BidPrice3 %s, BidVolume3 %s, AskPrice3 %s, AskVolume3 %s, BidPrice4 %s,"
"BidVolume4 %s, AskPrice4 %s, AskVolume4 %s, BidPrice5 %s, BidVolume5 %s, AskPrice5 %s,"
"AskVolume5 %s, ActionDay %s",
data.TradingDay, data.SettlementGroupID, data.SettlementID, data.LastPrice, data.PreSettlementPrice,
data.PreClosePrice, data.PreOpenInterest, data.OpenPrice, data.HighestPrice, data.LowestPrice,
data.Volume, data.Turnover, data.OpenInterest, data.ClosePrice, data.SettlementPrice,
data.UpperLimitPrice, data.LowerLimitPrice, data.UpdateTime, data.UpdateMillisec,
data.InstrumentID, data.BidPrice1, data.BidVolume1, data.AskPrice1, data.AskVolume1,
data.BidPrice2, data.BidVolume2, data.AskPrice2, data.AskVolume2, data.BidPrice3, data.BidVolume3,
data.AskPrice3, data.AskVolume3, data.BidPrice4, data.BidVolume4, data.AskPrice4, data.AskVolume4,
data.BidPrice5, data.BidVolume5, data.AskPrice5, data.AskVolume5, data.ActionDay)
class Mgspi(DmaMdApi.XYDDmaManagerSpi):
def OnDmaConnected(self):
print("mgspi response:successed to connect")
logging.debug("ManagerSpi response:successed to connect")
def OnDmaDisconnected(self):
print("disconnected!")
# 注册回调接口
mg = DmaMdApi.XYDDmaManager.CreateXYDDmaManager()
mgspi = Mgspi()
mg.RegisterSpi(mgspi)
api = DmaMdApi.XYDDmaMdApi.CreateXYDDmaMdApi()
spi = Spi()
api.RegisterSpi(spi)
# 获取版本号
version1 = DmaMdApi.new_intp()
version2 = DmaMdApi.new_intp()
print(api.GetVersion(version1, version2))
# 设置dpdk初始化参数
mg.RegisterArgs(15, 2, 8, 0, 0, 2, 3, True)
# 设置虚拟网卡参数
mg.RegisterNetArgs("192.168.2.111", "255.255.255.0", "192.168.2.1", "172.16.70.73", "255.255.255.0")
# 注册前置机
s = subprocess.getoutput("sudo netstat -ntp | grep '172.16.70.73:20022'")
print(s)
port1 = s.split("172.16.70.4:")[1].split()[0]
port2 = s.split("172.16.70.73:")[1].split()[0]
port = (int(port1) << 16)+int(port2)
mg.RegisterFront(0, "172.16.70.73", port)
# 设置订阅产品
print("订阅返回值", mg.RegisterProduct("agrb"))
# 初始化
mg.Init()
print("HW Init Success")
mg.Join()
08-12
1843
02-01
1万+
07-12
07-12
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交