当前仓库属于暂停状态,部分功能使用受限,详情请查阅 仓库状态说明
1 Star 0 Fork 6

small_fly / data_publish
暂停

forked from 海风 / data_publish
暂停
 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
PublishDepth.cs 5.27 KB
一键复制 编辑 原始数据 按行查看 历史
海风 提交于 2016-07-08 09:59 . 增加: 深度行情 5058 订阅
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using MongoDB.Bson.IO;
using NetMQ;
using NetMQ.Sockets;
using TShfeFtdcPriceType = System.Double;
using TShfeFtdcLargeVolumeType = System.Double;
using TShfeFtdcMoneyType = System.Double;
using TShfeFtdcRatioType = System.Double;
using TShfeFtdcDateType = System.String;
using TShfeFtdcInstrumentIDType = System.String;
using TShfeFtdcTimeType = System.String;
using TShfeFtdcSettlementGroupIDType = System.String;
using TShfeFtdcDirectionType = System.Char;
namespace data_publish
{
class PublishDepth
{
private string _url;
private UdpClient _listener;
PublisherSocket pub = new PublisherSocket();
ManualResetEvent _terminateEvent = new ManualResetEvent(false);
public PublishDepth(string pUrl)
{
_url = pUrl;
}
void Log(string pMsg)
{
Console.WriteLine(DateTime.Now + "\t" + pMsg);
}
public void Publish()
{
pub.Options.SendHighWatermark = 1000;
pub.Bind($"tcp://{_url}");
Log($"receive depth data from {5011}, publish server bind {_url}.");
_listener = new UdpClient(5011);
IPEndPoint groupEP = null;// new IPEndPoint(GroupAddress, pPort);
int size = Marshal.SizeOf(typeof(Level20));
byte[] buf = new byte[size];
IntPtr buffer = Marshal.AllocHGlobal(size);
while (true)
{
try
{
byte[] bytes = _listener.Receive(ref groupEP);
if (bytes.Length > 0)
{
Marshal.Copy(bytes, 0, buffer, size);
Level20 f = (Level20)Marshal.PtrToStructure(buffer, typeof(Level20));
pub.SendMoreFrame(f.Instrument).SendFrame(bytes);
}
}
catch (Exception e)
{
Log(e.Message);
}
}
}
[StructLayout(LayoutKind.Sequential)]
public struct Level20
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
public string Instrument;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)]
public double[] AskPrice;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)]
public int[] AskVolume;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)]
public double[] BidPrice;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)]
public int[] BidVolume;
}
///深度市场行情
[StructLayout(LayoutKind.Sequential)]
struct CShfeFtdcDepthMarketDataField
{
///交易日 char[9]
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 9)]
public TShfeFtdcDateType TradingDay;
///结算组代码 char[9]
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 9)]
public TShfeFtdcSettlementGroupIDType SettlementGroupID;
///结算编号 int
public int SettlementID;
///最新价 double
public TShfeFtdcPriceType LastPrice;
///昨结算
public TShfeFtdcPriceType PreSettlementPrice;
///昨收盘 double
public TShfeFtdcPriceType PreClosePrice;
///昨持仓量 double
public TShfeFtdcLargeVolumeType PreOpenInterest;
///今开盘 double
public TShfeFtdcPriceType OpenPrice;
///最高价 double
public TShfeFtdcPriceType HighestPrice;
///最低价 double
public TShfeFtdcPriceType LowestPrice;
///数量 int
public int Volume;
///成交金额 double
public TShfeFtdcMoneyType Turnover;
///持仓量 double
public TShfeFtdcLargeVolumeType OpenInterest;
///今收盘 double
public TShfeFtdcPriceType ClosePrice;
///今结算
public TShfeFtdcPriceType SettlementPrice;
///涨停板价 double
public TShfeFtdcPriceType UpperLimitPrice;
///跌停板价 double
public TShfeFtdcPriceType LowerLimitPrice;
///昨虚实度 double
public TShfeFtdcRatioType PreDelta;
///今虚实度 double
public TShfeFtdcRatioType CurrDelta;
///最后修改时间 char[9]
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 9)]
public TShfeFtdcTimeType UpdateTime;
///最后修改毫秒 int
public int UpdateMillisec;
///合约代码 char[31]
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 31)]
public TShfeFtdcInstrumentIDType InstrumentID;
///申买价一 double
public TShfeFtdcPriceType BidPrice1;
///申买量一 int
public int BidVolume1;
///申卖价一 double
public TShfeFtdcPriceType AskPrice1;
///申卖量一 int
public int AskVolume1;
///申买价二 double
public TShfeFtdcPriceType BidPrice2;
///申买量二 int
public int BidVolume2;
///申卖价二 double
public TShfeFtdcPriceType AskPrice2;
///申卖量二 int
public int AskVolume2;
///申买价三 double
public TShfeFtdcPriceType BidPrice3;
///申买量三 int
public int BidVolume3;
///申卖价三 double
public TShfeFtdcPriceType AskPrice3;
///申卖量三 int
public int AskVolume3;
///申买价四 double
public TShfeFtdcPriceType BidPrice4;
///申买量四 int
public int BidVolume4;
///申卖价四 double
public TShfeFtdcPriceType AskPrice4;
///申卖量四 int
public int AskVolume4;
///申买价五 double
public TShfeFtdcPriceType BidPrice5;
///申买量五 int
public int BidVolume5;
///申卖价五 double
public TShfeFtdcPriceType AskPrice5;
///申卖量五 int
public int AskVolume5;
///业务发生日期 char[9]
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 9)]
public TShfeFtdcDateType ActionDay;
}
}
}
C#
1
https://gitee.com/small_fly/data_publish.git
git@gitee.com:small_fly/data_publish.git
small_fly
data_publish
data_publish
master

搜索帮助