damapi

# 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()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值