文华财经赢顺外盘期货行情数据API接口开放代码
怎么才能获取到外盘期货行情数据API接口呢?不少朋友就会考虑到文华财经行情API接口,本身文华财经就是一个软件提供商,提供行情API接口也无可厚非。但是由于市场上外盘行情API接口都是收费的,所以软件商提供行情API接口不太合理。文华财经在我国软件提供方已经存在了23年。期货交易员90%以上都在用文华财经,可见其客户群体是非常庞大的,为什么要外盘数据收费?很显然就是为了赚钱,但是也是最近两年,文华财经不光是外盘数据收费,包括模拟交易,实盘手机端也收费了。无可厚非,一个企业如果没有利润,还怎么存活下去?。文化财经已经免费服务了20多年,客户群体非常庞大,也就是流量吧。其实你说的不光是外盘数据收费,上海黄金交易市场也收费。解决的办法有两个:第一你可以交费使用;第二,你可以选择其他的软件,比如BIGI行情、博易大师等都有免费的。
BIGI行情非常全面行情数据API接口,提供国内期货、国际期货、贵金属、全球股指、外汇、期权、现货、股票、数字货币等实时行情数据,不限制频率和次数;并且拥有推送接口socket websocket http和获取接口http post get等满足各层次的需求。BIGI行情价格实惠、数据实时、稳定获得业内好评。
下面介绍一下websocket接入外盘期货行情数据API接口开放代码
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("连接服务器成功!");
}
}
}
同学们,看懂了吗?如有疑惑向BIGI行情进行咨询。