易盛信息9.0外盘期货行情数据API接口公共授权开发包例子代码

易盛信息9.0外盘期货行情数据API接口公共授权开发包例子代码-LMLPHP
       怎么才能获取到外盘期货行情数据API接口呢?不少朋友就会考虑到易盛9.0行情API接口,本身易盛就是一个软件提供商,提供行情API接口也无可厚非。但是由于市场上外盘行情API接口都是收费的,所以软件商提供行情API接口不太合理。实时上,不少朋友也用过易盛行情数据API接口,反馈问题不少,经常莫名其妙断了,而且得不到上游断数据原因。易盛9.0行情API不稳定性显而易见。另外易盛外盘数据也不全面,选择产品上非常受限制。
       BIGI行情非常全面行情数据API接口,提供国内期货、国际期货、贵金属、全球股指、外汇、期权、现货、A股、数字货币等实时行情数据,不限制频率和次数;并且拥有推送接口socket websocket http和获取接口http post get等满足各层次的需求。BIGI行情价格实惠、数据实时、稳定获得业内好评。
下面介绍一下C# socket和websocket开发包例子代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using TCPLibrary;
using TCPLibrary.Abstracts;
using TCPLibrary.DefaultImplements;

namespace SocketTest
{
class Program
{
static BaseClientSocket _client;
static string ip = "";
static int port = 8091;
static DateTime lastTim = DateTime.Now;
static void Main(string[] args)
{
//域名转ip
IPAddress[] IPs = Dns.GetHostAddresses("127.0.0.1");
ip = IPs[0].ToString();
_client = new BaseClientSocket();
_client.Connected += new ConnectedEventHandler(_client_Connected);
_client.DisConnected += new DisConnectedEventHandler(_client_DisConnected);
_client.MessageReceived += new MessageReceivedEventHandler(_client_MessageReceived);
_client.Connect(ip, port);
ThreadPool.QueueUserWorkItem(new WaitCallback(MonitorConnect), 1000);
while (Console.ReadLine() != "q") ;
}
static void MonitorConnect(object o)
{
while (true)
{
if ((DateTime.Now - lastTim).TotalSeconds > 40)
{
Console.WriteLine("重新连接并订阅...");
if (_client != null)
{
_client.Release();
}
_client.Connect(ip, port);
lastTim = DateTime.Now;
}
}
}
static void _client_MessageReceived(ZProxySocket proxySocket, ZMessage message)
{
lastTim = DateTime.Now;
BaseMessage msg = message as BaseMessage;
string strs = Encoding.UTF8.GetString(msg.MsgContent, 0, msg.MsgContent.Length).Trim();
if (string.IsNullOrEmpty(strs))
{
return;
}
if (strs == "ok")
{
//1.连接成功发送登陆信息
proxySocket.SendMessage(new BaseMessage(1, Encoding.UTF8.GetBytes("0=login|1=1|2=A8C7E85B958645419910F0E07F1D08F0\n"))); ;
}
else
{
Dictionary<string, string> dic = new Dictionary<string, string>();//解析数据各项
string[] groups = strs.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; groups != null && groups.Length > i; i++)
{
string[] items = groups[i].Split(new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
if (items.Length == 2 && !dic.ContainsKey(items[0]))
{
dic.Add(items[0], items[1].Trim());
}
}

if (dic["0"] == "login")
{
if (dic["1"] == "0")
{
//2.登陆成功后 订阅产品
proxySocket.SendMessage(new BaseMessage(1, Encoding.UTF8.GetBytes("0=subscribe|1=6BML,HSIML,USDJPY,CLML,HGML,ZSML,VXML,KCML,CCML,BRNML,FDAXML,A50ML,BTCML,DOWJONES,N225,PLML,NGML,SIML,ZCML,TCHZ8,METZ8,AGML,AUML,RBML,BUML,SRML,CFML,10001547,10001548,GC,CL\n")));
//2.登陆成功后 订阅产品带k线
//proxySocket.SendMessage(new BaseMessage(1, Encoding.UTF8.GetBytes("0=subscribe|1=6BML,HSIML,USDJPY,CLML,HGML,ZSML,VXML,KCML,CCML,BRNML,FDAXML,A50ML,BTCML,DOWJONES,N225,PLML,NGML,SIML,ZCML,TCHZ8,METZ8,AGML,AUML,RBML,BUML,SRML,CFML,10001547,10001548,GC,CL|2=k\n")));
}
else
{
//登陆失败
Console.WriteLine("登陆失败:" + dic["2"]);
}
}
else if (dic["0"] == "subscribe")
{
if (dic["1"] == "0")
{
//3.订阅成功返回
Console.WriteLine(dic["2"]);
}
else
{
//订阅失败
Console.WriteLine("订阅失败:" + dic["2"]);
}
}
else if (dic["0"] == "hq")
{
//开始处理行情 行情各项在 dic 中
Console.WriteLine(strs);

}
}

}

static void _client_DisConnected(ZProxySocket proxySocket)
{
Console.WriteLine("重新连接并订阅...");

if (_client != null)
{
_client.Release();
}
_client.Connect(ip, port);
}

static void _client_Connected(ZProxySocket proxySocket)
{
Console.WriteLine("连接服务器成功!");
}
}
}
朋友们,学会了吗?有疑问的话欢迎留言交流。

05-06 06:51