本程序适合跟单交易,只要在MT4或者MT5上写好跟单代码即可实现下单到期货账户
实现逻辑:
1.MtctpServer.exe 负责登录期货账户并同时开通http服务器默认80端口,
2.使用MT4或者MT5的WebRequest进行提交下单
期货账户信息在Accountlogin.json里面配置好即可,可以实现多账户操作,默认只开通了十个
启动程序后 当界面显示出来账户和总权益即表示登录成功,此时就可以提交下单了
程序免费使用,带来的任何问题自己负责,开发这个小工具纯属个人爱好,有时间也会更新功能。目前仅仅是个玩具,实现不了复杂的操作。
目前期货MT5:赫兹和MT5CTP两个平台做的比较好,本人均可代写他们的期货EA
赫兹地址:https://www.herzqt.com/?mark=YBZO4K4
期货跟单MT4MT5免费版
期货跟单MT4MT5免费版
期货跟单MT4MT5免费版
WebRequest提交链接支持浏览器直接访问
期货跟单MT4MT5免费版
以下是MT4/5的代码(需要在软件打钩允许WebRequest)
- //+------------------------------------------------------------------+
- //| ProjectName |
- //| Copyright 2018, CompanyName |
- //| http://www.companyname.net |
- //+------------------------------------------------------------------+
- #property copyright "不才编程"
- #property link "http://www.mtctp.com/"
- #property description "www.mtctp.com"
- #property description "\n业务范围 :专业MT4MT5EA指标脚本编程"
- #property description "\n联系方式 :微信:bucaiea / QQ;280726108"
- #property version "1.0"
- #property strict
- input string url="http://127.0.0.1/";
- input int 手数=1;
- input int 账号=228732;
- input bool 等待同步返回信息=true;
- input int 同步信息等待毫秒=500;//同步信息等待毫秒
- //等待时间长降低效率,时间短可能还没有返回信息。
- datetime settime;
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- int OnInit()
- {
- settime=TimeCurrent();
- EventSetMillisecondTimer(100);
- Comment(url);
- return(INIT_SUCCEEDED);
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- void OnDeinit(const int reason)
- {
- EventKillTimer();
- for(int i=ObjectsTotal(0,-1,-1)-1; i>=0; i--)
- if(StringFind(ObjectName(0,i),m_url,0)!=-1)
- ObjectDelete(0,ObjectName(0,i));
- Comment("");
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- void OnTick()
- {
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- void OnChartEvent(const int id,
- const long& lparam,
- const double& dparam,
- const string& sparam
- )
- {
- //+------------------------------------------------------------------+
- //| 下单和平仓
- //+------------------------------------------------------------------+
- Createbutton(m_url+"做多"," 做多 ...","做多",155,35+105,150,28,CORNER_RIGHT_LOWER,clrAqua,clrNavy,10);
- Createbutton(m_url+"做空"," 做空 ...","做空",155,35+70,150,28,CORNER_RIGHT_LOWER,clrCrimson,clrWhite,10);
- Createbutton(m_url+"平多"," 平多 ...","平多",155,35+35,150,28,CORNER_RIGHT_LOWER,clrSkyBlue,clrNavy,10);
- Createbutton(m_url+"平空"," 平空 ...","平空",155,35,150,28,CORNER_RIGHT_LOWER,clrLightSalmon,clrNavy,10);
- ObjectSetInteger(0,m_url+"账号",OBJPROP_STATE,0);
- if(ObjectGetInteger(0,m_url+"做多",OBJPROP_STATE)==1)
- {
- OrderSend(Symbol(),0,手数,账号);
- ObjectSetInteger(0,m_url+"做多",OBJPROP_STATE,0);
- }
- if(ObjectGetInteger(0,m_url+"做空",OBJPROP_STATE)==1)
- {
- OrderSend(Symbol(),1,手数,账号);
- ObjectSetInteger(0,m_url+"做空",OBJPROP_STATE,0);
- }
- if(ObjectGetInteger(0,m_url+"平多",OBJPROP_STATE)==1)
- {
- OrderClose(Symbol(),0,手数,账号);
- ObjectSetInteger(0,m_url+"平多",OBJPROP_STATE,0);
- }
- if(ObjectGetInteger(0,m_url+"平空",OBJPROP_STATE)==1)
- {
- OrderClose(Symbol(),1,手数,账号);
- ObjectSetInteger(0,m_url+"平空",OBJPROP_STATE,0);
- }
- //+------------------------------------------------------------------+
- //| 查询信息 如果查询返回"Querying, please try again later..."请过几秒再查询(此时请求已经提交)
- //| 这个接口是在本地查询内存记录,不涉及频率限制,但是这个数据不会自动更新 也就是返回的是最近查询的数据
- //+------------------------------------------------------------------+
- Createbutton(m_url+"查询持仓汇总"," 查询持仓汇总 ...","查询持仓汇总",155,35+105+50,150,28,CORNER_RIGHT_LOWER,clrAqua,clrNavy,10);
- Createbutton(m_url+"查询持仓明细"," 查询持仓明细 ...","查询持仓明细",155,35+105+50+50,150,28,CORNER_RIGHT_LOWER,clrAqua,clrNavy,10);
- Createbutton(m_url+"查询资金明细"," 查询资金明细 ...","查询资金明细",155,35+105+50+100,150,28,CORNER_RIGHT_LOWER,clrAqua,clrNavy,10);
- Createbutton(m_url+"查询合约"," 查询合约 ...","查询合约",155,35+105+50+100+50,150,28,CORNER_RIGHT_LOWER,clrAqua,clrNavy,10);
- Createbutton(m_url+"查询市场深度"," 查询市场深度 ...","查询市场深度",155,35+105+50+100+100,150,28,CORNER_RIGHT_LOWER,clrAqua,clrNavy,10);
- Createbutton(m_url+"账号","账号:"+string(账号),"账号:"+string(账号),155,35+105+50+100+150,150,28,CORNER_RIGHT_LOWER,clrYellow,clrNavy,10);
- if(ObjectGetInteger(0,m_url+"查询持仓汇总",OBJPROP_STATE)==1)
- {
- Print(查询持仓汇总(账号));
- ObjectSetInteger(0,m_url+"查询持仓汇总",OBJPROP_STATE,0);
- }
- if(ObjectGetInteger(0,m_url+"查询持仓明细",OBJPROP_STATE)==1)
- {
- Print(查询持仓明细(账号));
- ObjectSetInteger(0,m_url+"查询持仓明细",OBJPROP_STATE,0);
- }
- if(ObjectGetInteger(0,m_url+"查询资金明细",OBJPROP_STATE)==1)
- {
- Print(查询资金明细(账号));
- ObjectSetInteger(0,m_url+"查询资金明细",OBJPROP_STATE,0);
- }
- if(ObjectGetInteger(0,m_url+"查询合约",OBJPROP_STATE)==1)
- {
- Print(查询合约(账号,Symbol()));
- ObjectSetInteger(0,m_url+"查询合约",OBJPROP_STATE,0);
- }
- if(ObjectGetInteger(0,m_url+"查询市场深度",OBJPROP_STATE)==1)
- {
- Print(查询市场深度(账号,Symbol()));
- ObjectSetInteger(0,m_url+"查询市场深度",OBJPROP_STATE,0);
- }
- //+------------------------------------------------------------------+
- //| 主动查询信息 每次需要查询最新的信息就要先提交这个需求,然后再去使用上面的查询
- //| 这个接口是在期货CTP那边查询,不要频繁查询,防止被封号!!!
- //| 这个接口是在期货CTP那边查询,不要频繁查询,防止被封号!!!
- //| 这个接口是在期货CTP那边查询,不要频繁查询,防止被封号!!!
- //| 重要的事情说三遍
- //+------------------------------------------------------------------+
- Createbutton(m_url+"请求查询持仓汇总"," 请求 ...","请求",50+155,35+105+50,45,28,CORNER_RIGHT_LOWER,clrAqua,clrNavy,10);
- Createbutton(m_url+"请求查询持仓明细"," 请求 ...","请求",50+155,35+105+50+50,45,28,CORNER_RIGHT_LOWER,clrAqua,clrNavy,10);
- Createbutton(m_url+"请求查询资金明细"," 请求 ...","请求",50+155,35+105+50+100,45,28,CORNER_RIGHT_LOWER,clrAqua,clrNavy,10);
- Createbutton(m_url+"请求查询合约"," 请求 ...","请求",50+155,35+105+50+100+50,45,28,CORNER_RIGHT_LOWER,clrAqua,clrNavy,10);
- Createbutton(m_url+"请求查询市场深度"," 请求 ...","请求",50+155,35+105+50+100+100,45,28,CORNER_RIGHT_LOWER,clrAqua,clrNavy,10);
- if(ObjectGetInteger(0,m_url+"请求查询持仓汇总",OBJPROP_STATE)==1)
- {
- Print(查询持仓汇总(账号,"-"));
- ObjectSetInteger(0,m_url+"请求查询持仓汇总",OBJPROP_STATE,0);
- }
- if(ObjectGetInteger(0,m_url+"请求查询持仓明细",OBJPROP_STATE)==1)
- {
- Print(查询持仓明细(账号,"-"));
- ObjectSetInteger(0,m_url+"请求查询持仓明细",OBJPROP_STATE,0);
- }
- if(ObjectGetInteger(0,m_url+"请求查询资金明细",OBJPROP_STATE)==1)
- {
- Print(查询资金明细(账号,"-"));
- ObjectSetInteger(0,m_url+"请求查询资金明细",OBJPROP_STATE,0);
- }
- if(ObjectGetInteger(0,m_url+"请求查询合约",OBJPROP_STATE)==1)
- {
- Print(查询合约(账号,Symbol(),"-"));
- ObjectSetInteger(0,m_url+"请求查询合约",OBJPROP_STATE,0);
- }
- if(ObjectGetInteger(0,m_url+"请求查询市场深度",OBJPROP_STATE)==1)
- {
- Print(查询市场深度(账号,Symbol(),"-"));
- ObjectSetInteger(0,m_url+"请求查询市场深度",OBJPROP_STATE,0);
- }
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- int OrderSend(string symbol,int cmd,int volume,int account,double price=0)//价格0默认就涨跌停开单
- {
- string tmp=cmd==0?"buy":"sell";
- if(price==0)
- price=cmd==0?SymbolInfoDouble(symbol,SYMBOL_SESSION_PRICE_LIMIT_MAX):SymbolInfoDouble(symbol,SYMBOL_SESSION_PRICE_LIMIT_MIN);
- string mtctp=url+"?mode="+"0";
- mtctp=mtctp+"&symbol="+symbol;
- mtctp=mtctp+"&type="+tmp;
- mtctp=mtctp+"&lots="+IntegerToString(volume);
- mtctp=mtctp+"&price="+DoubleToString(price,int(SymbolInfoInteger(symbol,SYMBOL_DIGITS)));
- mtctp=mtctp+"&account="+string(account);
- string cookie=NULL,headers;
- char post[],result[];
- int res;
- ResetLastError();
- int timeout=2000;
- res=WebRequest("GET",mtctp,cookie,NULL,timeout,post,0,result,headers);
- if(res==-1)
- {
- Print(account," ",__FUNCTION__,"失败:"+mtctp);
- }
- else
- {
- if(等待同步返回信息)
- Print(Result(account,url+"?"+CharArrayToString(result,0,-1,CP_UTF8)));//打印同步等待的服务器处理结果
- else
- Print(account," ",__FUNCTION__,":"+CharArrayToString(result,0,-1,CP_UTF8)+">>"+mtctp);
- return 1;
- }
- return 0;
- }
- string jiemi(string in)
- {
- string keystr="ABCDEFG";
- uchar src[],dst[],key[];
- ArrayResize(dst,StringLen(in)*2);
- StringToCharArray(keystr,key);
- StringToCharArray(in,dst);
- CryptDecode(CRYPT_BASE64,dst,key,src);
- return CharArrayToString(src);
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- int OrderClose(string symbol,int cmd,int volume,int account,double price=0)//价格0默认就涨跌停平仓
- {
- string tmp=cmd==0?"closebuy":"closesell";
- if(price==0)
- price=cmd==0?SymbolInfoDouble(symbol,SYMBOL_SESSION_PRICE_LIMIT_MIN):SymbolInfoDouble(symbol,SYMBOL_SESSION_PRICE_LIMIT_MAX);
- string mtctp=url+"?mode="+"0";
- mtctp=mtctp+"&symbol="+symbol;
- mtctp=mtctp+"&type="+tmp;
- mtctp=mtctp+"&lots="+IntegerToString(volume);
- mtctp=mtctp+"&price="+DoubleToString(price,int(SymbolInfoInteger(symbol,SYMBOL_DIGITS)));
- mtctp=mtctp+"&account="+string(account);
- string cookie=NULL,headers;
- char post[],result[];
- int res;
- ResetLastError();
- int timeout=2000;
- res=WebRequest("GET",mtctp,cookie,NULL,timeout,post,0,result,headers);
- if(res==-1)
- {
- Print(account," ",__FUNCTION__,"失败:"+mtctp);
- }
- else
- {
- if(等待同步返回信息)
- Print(Result(account,url+"?"+CharArrayToString(result,0,-1,CP_UTF8)));//打印同步等待的服务器处理结果
- else
- Print(account," ",__FUNCTION__,":"+CharArrayToString(result,0,-1,CP_UTF8)+">>"+mtctp);
- return 1;
- }
- return 0;
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- string Result(int account,string _url)
- {
- Sleep(同步信息等待毫秒);
- string cookie=NULL,headers;
- char post[],result[];
- int res;
- ResetLastError();
- int timeout=2000;
- res=WebRequest("GET",_url,cookie,NULL,timeout,post,0,result,headers);
- if(res==-1)
- {
- return "false";
- }
- else
- {
- return jiemi(CharArrayToString(result,0,-1,CP_UTF8))+">>"+_url;
- }
- return "";
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- string 查询合约(int account,string symbol,string set="")
- {
- string mtctp=url+"?mode="+set+"5";
- mtctp=mtctp+"&account="+string(account);
- mtctp=mtctp+"&symbol="+symbol;
- string cookie=NULL,headers;
- char post[],result[];
- int res;
- ResetLastError();
- int timeout=2000;
- Print(mtctp);
- res=WebRequest("GET",mtctp,cookie,NULL,timeout,post,0,result,headers);
- if(res==-1)
- {
- Print(__FUNCTION__,"失败:"+mtctp);
- }
- else
- {
- return CharArrayToString(result,0,-1,CP_UTF8);
- }
- return "";
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- string 查询市场深度(int account,string symbol,string set="")
- {
- string mtctp=url+"?mode="+set+"4";
- mtctp=mtctp+"&account="+string(account);
- mtctp=mtctp+"&symbol="+symbol;
- string cookie=NULL,headers;
- char post[],result[];
- int res;
- ResetLastError();
- int timeout=2000;
- Print(mtctp);
- res=WebRequest("GET",mtctp,cookie,NULL,timeout,post,0,result,headers);
- if(res==-1)
- {
- Print(__FUNCTION__,"失败:"+mtctp);
- }
- else
- {
- return CharArrayToString(result,0,-1,CP_UTF8);
- }
- return "";
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- string 查询持仓汇总(int account,string set="")
- {
- string mtctp=url+"?mode="+set+"1";
- mtctp=mtctp+"&account="+string(account);
- string cookie=NULL,headers;
- char post[],result[];
- int res;
- ResetLastError();
- int timeout=2000;
- Print(mtctp);
- res=WebRequest("GET",mtctp,cookie,NULL,timeout,post,0,result,headers);
- if(res==-1)
- {
- Print(__FUNCTION__,"失败:"+mtctp);
- }
- else
- {
- return CharArrayToString(result,0,-1,CP_UTF8);
- }
- return "";
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- string 查询持仓明细(int account,string set="")
- {
- string mtctp=url+"?mode="+set+"2";
- mtctp=mtctp+"&account="+string(account);
- string cookie=NULL,headers;
- char post[],result[];
- int res;
- ResetLastError();
- int timeout=2000;
- Print(mtctp);
- res=WebRequest("GET",mtctp,cookie,NULL,timeout,post,0,result,headers);
- if(res==-1)
- {
- Print(__FUNCTION__,"失败:"+mtctp);
- }
- else
- {
- return CharArrayToString(result,0,-1,CP_UTF8);
- }
- return "";
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- string 查询资金明细(int account,string set="")
- {
- string mtctp=url+"?mode="+set+"3";
- mtctp=mtctp+"&account="+string(account);
- string cookie=NULL,headers;
- char post[],result[];
- int res;
- ResetLastError();
- int timeout=2000;
- Print(mtctp);
- res=WebRequest("GET",mtctp,cookie,NULL,timeout,post,0,result,headers);
- if(res==-1)
- {
- Print(__FUNCTION__,"失败:"+mtctp);
- }
- else
- {
- return CharArrayToString(result,0,-1,CP_UTF8);
- }
- return "";
- }
- //+------------------------------------------------------------------+
- void Createbutton(string name,string txt1,string txt2,int XX,int YX,int XL,int YL,int WZ,color A,color B,int size)
- {
- if(ObjectFind(0,name)==-1)
- ObjectCreate(0,name,OBJ_BUTTON,0,0,0);
- ObjectSetInteger(0,name,OBJPROP_XDISTANCE,XX);
- ObjectSetInteger(0,name,OBJPROP_YDISTANCE,YX);
- ObjectSetInteger(0,name,OBJPROP_XSIZE,XL);
- ObjectSetInteger(0,name,OBJPROP_YSIZE,YL);
- ObjectSetString(0,name,OBJPROP_FONT,"微软雅黑");
- ObjectSetInteger(0,name,OBJPROP_FONTSIZE,size);
- ObjectSetInteger(0,name,OBJPROP_CORNER,WZ);
- if(ObjectGetInteger(0,name,OBJPROP_STATE)==1)
- {
- ObjectSetInteger(0,name,OBJPROP_COLOR,A);
- ObjectSetInteger(0,name,OBJPROP_BGCOLOR,B);
- ObjectSetString(0,name,OBJPROP_TEXT,txt1);
- }
- else
- {
- ObjectSetInteger(0,name,OBJPROP_COLOR,B);
- ObjectSetInteger(0,name,OBJPROP_BGCOLOR,A);
- ObjectSetString(0,name,OBJPROP_TEXT,txt2);
- }
- }
- string m_url="mtctp";
- //+------------------------------------------------------------------+
- //| Expert tick function |
- //+------------------------------------------------------------------+
- //+------------------------------------------------------------------+
- void OnTimer()
- {
- OnTick();
- }
- //+------------------------------------------------------------------+
复制代码
下面这些文件都要下载放到同一个文件夹里面 比如随便建立一个CTP文件夹来放这些文件
运行的时候就运行EXE文件
JSON里面是设置账号密码的。
不想打包成压缩文件了。嫌麻烦
|
|