一个MT4跟单系统,功能有:绑定账号,开户,入金,出金,下单等常规操作;可以查看本人的持仓、挂单和历史单。
跟单方案:顾问正常操作,客户可以查看顾问的订单以往交易情况,跟单后,会自动跟随按倍数下单;被跟单订单挂关闭或修改时也需要作相应动作。
智投方案:类似于跟单,但是添加了EA标识,只有该EA产生的订单下单、关闭或修改,才会有相应动作,顾问的其它订单修改,不会触发智投。
系统采用c++编写dll用于调用mtmanapi.dll【或mtmanapi64.dll】【函数参考头文件MT4ManagerAPI.h】,生成dll以备java调用。
java调用c++产生的dll完成对应操作,需要区分direct和pump模式,并应用连接池提高效率。
MT4ManagerAPI.h 关键函数:
class CManagerInterface
{
public:
//--- dummy methods for delphi
virtual int __stdcall QueryInterface(REFIID riid,LPVOID* obj)=0;
virtual int __stdcall AddRef() =0;
//--- release
virtual int __stdcall Release()=0;
//--- service methods
virtual void __stdcall MemFree(void* ptr) =0;
virtual LPCSTR __stdcall ErrorDescription(const int code)=0;
virtual void __stdcall WorkingDirectory(LPCSTR path) =0;
//--- connection
virtual int __stdcall Connect(LPCSTR server) =0;
virtual int __stdcall Disconnect() =0;
virtual int __stdcall IsConnected() =0;
virtual int __stdcall Login(const int login,LPCSTR password)=0;
virtual int __stdcall LoginSecured(LPCSTR key_path) =0;
virtual int __stdcall KeysSend(LPCSTR key_path) =0;
virtual int __stdcall Ping() =0;
virtual int __stdcall PasswordChange(LPCSTR pass,const int is_investor)=0;
virtual int __stdcall ManagerRights(ConManager *man) =0;
//--- server administration commands
virtual int __stdcall SrvRestart() =0;
virtual int __stdcall SrvChartsSync() =0;
virtual int __stdcall SrvLiveUpdateStart()=0;
virtual int __stdcall SrvFeedsRestart() =0;
//--- server configuration
//--- configuration request
virtual int __stdcall CfgRequestCommon(ConCommon *cfg)=0;
virtual int __stdcall CfgRequestTime(ConTime *cfg) =0;
virtual int __stdcall CfgRequestBackup(ConBackup *cfg)=0;
virtual int __stdcall CfgRequestSymbolGroup(ConSymbolGroup *cfg)=0;
virtual ConAccess* __stdcall CfgRequestAccess(int *total) =0;
virtual ConDataServer* __stdcall CfgRequestDataServer(int *total)=0;
virtual ConHoliday* __stdcall CfgRequestHoliday(int *total) =0;
virtual ConSymbol* __stdcall CfgRequestSymbol(int *total) =0;
virtual ConGroup* __stdcall CfgRequestGroup(int *total) =0;
virtual ConManager* __stdcall CfgRequestManager(int *total) =0;
virtual ConFeeder* __stdcall CfgRequestFeeder(int *total) =0;
virtual ConLiveUpdate* __stdcall CfgRequestLiveUpdate(int *total)=0;
virtual ConSync* __stdcall CfgRequestSync(int *total) =0;
virtual ConPluginParam* __stdcall CfgRequestPlugin(int *total) =0;
//--- configuration update
virtual int __stdcall CfgUpdateCommon(const ConCommon* cfg) =0;
virtual int __stdcall CfgUpdateAccess(const ConAccess* cfg,const int pos) =0;
virtual int __stdcall CfgUpdateDataServer(const ConDataServer *cfg,const int pos) =0;
virtual int __stdcall CfgUpdateTime(const ConTime *cfg) =0;
virtual int __stdcall CfgUpdateHoliday(const ConHoliday *cfg,const int pos) =0;
virtual int __stdcall CfgUpdateSymbol(const ConSymbol *cfg) =0;
virtual int __stdcall CfgUpdateSymbolGroup(const ConSymbolGroup *cfg,const int pos)=0;
virtual int __stdcall CfgUpdateGroup(const ConGroup *cfg) =0;
virtual int __stdcall CfgUpdateManager(const ConManager *cfg) =0;
virtual int __stdcall CfgUpdateFeeder(const ConFeeder *cfg) =0;
virtual int __stdcall CfgUpdateBackup(const ConBackup *cfg) =0;
virtual int __stdcall CfgUpdateLiveUpdate(const ConLiveUpdate *cfg) =0;
virtual int __stdcall CfgUpdateSync(const ConSync *cfg) =0;
virtual int __stdcall CfgUpdatePlugin(const ConPlugin *cfg,const PluginCfg *parupd,const int total)=0;
//--- configuration delete
virtual int __stdcall CfgDeleteAccess(const int pos) =0;
virtual int __stdcall CfgDeleteDataServer(const int pos)=0;
virtual int __stdcall CfgDeleteHoliday(const int pos) =0;
virtual int __stdcall CfgDeleteSymbol(const int pos) =0;
virtual int __stdcall CfgDeleteGroup(const int pos) =0;
virtual int __stdcall CfgDeleteManager(const int pos) =0;
virtual int __stdcall CfgDeleteFeeder(const int pos) =0;
virtual int __stdcall CfgDeleteLiveUpdate(const int pos)=0;
virtual int __stdcall CfgDeleteSync(const int pos) =0;
//--- configuration shift
virtual int __stdcall CfgShiftAccess(const int pos,const int shift) =0;
virtual int __stdcall CfgShiftDataServer(const int pos,const int shift)=0;
virtual int __stdcall CfgShiftHoliday(const int pos,const int shift) =0;
virtual int __stdcall CfgShiftSymbol(const int pos,const int shift) =0;
virtual int __stdcall CfgShiftGroup(const int pos,const int shift) =0;
virtual int __stdcall CfgShiftManager(const int pos,const int shift) =0;
virtual int __stdcall CfgShiftFeeder(const int pos,const int shift) =0;
virtual int __stdcall CfgShiftLiveUpdate(const int pos,const int shift)=0;
virtual int __stdcall CfgShiftSync(const int pos,const int shift) =0;
virtual int __stdcall CfgShiftPlugin(const int pos,const int shift) =0;
//--- server feeders
virtual ServerFeed* __stdcall SrvFeeders(int *total) =0;
virtual LPSTR __stdcall SrvFeederLog(LPCSTR name,int *len)=0;
//--- chart bases
virtual RateInfoOld* __stdcall ChartRequestObsolete(const ChartInfo *chart,__time32_t *timesign,int *total) =0;
virtual int __stdcall ChartAddObsolete(LPCSTR symbol,const int period,const RateInfoOld* rates,int *count) =0;
virtual int __stdcall ChartUpdateObsolete(LPCSTR symbol,const int period,const RateInfoOld* rates,int *count)=0;
virtual int __stdcall ChartDeleteObsolete(LPCSTR symbol,const int period,const RateInfoOld* rates,int *count)=0;
//--- performance info
virtual PerformanceInfo* __stdcall PerformaneRequest(__time32_t from,int *total)=0;
//--- users/trades backups
virtual BackupInfo* __stdcall BackupInfoUsers(const int mode,int *total) =0;
virtual BackupInfo* __stdcall BackupInfoOrders(const int mode,int *total)=0;
virtual UserRecord* __stdcall BackupRequestUsers(LPCSTR file,LPCSTR request,int *total) =0;
virtual TradeRecord* __stdcall BackupRequestOrders(LPCSTR file,LPCSTR request,int *total)=0;
virtual int __stdcall BackupRestoreUsers(const UserRecord *users,const int total) =0;
virtual TradeRestoreResult* __stdcall BackupRestoreOrders(const TradeRecord *trades,int *total)=0;
//--- administrator databases commands
virtual UserRecord* __stdcall AdmUsersRequest(LPCSTR group,int *total) =0;
virtual TradeRecord* __stdcall AdmTradesRequest(LPCSTR group,const int open_only,int *total)=0;
virtual int __stdcall AdmBalanceCheckObsolete(int *logins,int *total) =0;
virtual int __stdcall AdmBalanceFix(const int *logins,const int total) =0;
virtual int __stdcall AdmTradesDelete(const int *orders,const int total)=0;
virtual int __stdcall AdmTradeRecordModify(const TradeRecord *trade) =0;
//--- symbols
virtual int __stdcall SymbolsRefresh() =0;
virtual ConSymbol* __stdcall SymbolsGetAll(int *total) =0;
virtual int __stdcall SymbolGet(LPCSTR symbol,ConSymbol *cs) =0;
virtual int __stdcall SymbolInfoGet(LPCSTR symbol,SymbolInfo *si)=0;
virtual int __stdcall SymbolAdd(LPCSTR symbol) =0;
virtual int __stdcall SymbolHide(LPCSTR symbol) =0;
//--- symbol commands
virtual int __stdcall SymbolChangeObsolete(const SymbolPropertiesOld *prop)=0;
virtual int __stdcall SymbolSendTick(LPCSTR symbol,const double bid,const double ask)=0;
//--- manager commands
virtual ConGroup* __stdcall GroupsRequest(int *total) =0;
virtual int __stdcall MailSend(const MailBox* mail,const int *logins)=0;
virtual int __stdcall NewsSend(const NewsTopic *news) =0;
//--- journal
virtual ServerLog* __stdcall JournalRequest(const int mode,const __time32_t from,const __time32_t to,LPCSTR filter,int *total)=0;
//--- databases: direct request to the server
//--- users
virtual UserRecord* __stdcall UsersRequest(int *total) =0;
virtual UserRecord* __stdcall UserRecordsRequest(const int *logins,int *total)=0;
virtual int __stdcall UserRecordNew(UserRecord *user) =0;
virtual int __stdcall UserRecordUpdate(const UserRecord *user) =0;
virtual int __stdcall UsersGroupOp(const GroupCommandInfo *info,const int *logins)=0;
virtual int __stdcall UserPasswordCheck(const int login,LPCSTR password)=0;
virtual int __stdcall UserPasswordSet(const int login,LPCSTR password,const int change_investor,const int clean_pubkey)=0;
virtual OnlineRecord* __stdcall OnlineRequest(int *total) =0;
//--- orders
virtual int __stdcall TradeTransaction(TradeTransInfo *info) =0;
virtual TradeRecord* __stdcall TradesRequest(int *total) =0;
virtual TradeRecord* __stdcall TradeRecordsRequest(const int *orders,int *total)=0;
virtual TradeRecord* __stdcall TradesUserHistory(const int login,const __time32_t from,const __time32_t to,int *total)=0;
virtual int __stdcall TradeCheckStops(const TradeTransInfo *trade,const double price)=0;
//--- reports
virtual TradeRecord* __stdcall ReportsRequest(const ReportGroupRequest *req,const int *logins,int *total) =0;
virtual DailyReport* __stdcall DailyReportsRequest(const DailyGroupRequest *req,const int *logins,int *total)=0;
//--- external command
virtual int __stdcall ExternalCommand(LPCSTR data_in,const int size_in,LPSTR *data_out,int *size_out)=0;
//--- plugins
virtual int __stdcall PluginUpdate(const ConPluginParam *plugin)=0;
//--- pumping
virtual int __stdcall PumpingSwitch(MTAPI_NOTIFY_FUNC pfnFunc,const HWND destwnd,const UINT eventmsg,const int flags)=0;
virtual ConGroup* __stdcall GroupsGet(int *total) =0;
virtual int __stdcall GroupRecordGet(LPCSTR name,ConGroup *group) =0;
virtual int __stdcall SymbolInfoUpdated(SymbolInfo *si,const int max_info) =0;
virtual UserRecord* __stdcall UsersGet(int *total) =0;
virtual int __stdcall UserRecordGet(const int login,UserRecord *user) =0;
virtual OnlineRecord* __stdcall OnlineGet(int *total) =0;
virtual int __stdcall OnlineRecordGet(const int login,OnlineRecord *user) =0;
virtual TradeRecord* __stdcall TradesGet(int *total) =0;
virtual TradeRecord* __stdcall TradesGetBySymbol(LPCSTR symbol,int *total) =0;
virtual TradeRecord* __stdcall TradesGetByLogin(const int login,LPCSTR group,int *total)=0;
virtual TradeRecord* __stdcall TradesGetByMarket(int *total) =0;
virtual int __stdcall TradeRecordGet(const int order,TradeRecord *trade) =0;
virtual int __stdcall TradeClearRollback(const int order) =0;
virtual MarginLevel* __stdcall MarginsGet(int *total) =0;
virtual int __stdcall MarginLevelGet(const int login,LPCSTR group,MarginLevel *margin)=0;
virtual RequestInfo* __stdcall RequestsGet(int *total) =0;
virtual int __stdcall RequestInfoGet(const int pos,RequestInfo *info) =0;
virtual ConPlugin* __stdcall PluginsGet(int *total) =0;
virtual int __stdcall PluginParamGet(const int pos,ConPluginParam *plugin) =0;
virtual int __stdcall MailLast(LPSTR path,int *length) =0;
virtual NewsTopic* __stdcall NewsGet(int *total) =0;
virtual int __stdcall NewsTotal() =0;
virtual int __stdcall NewsTopicGet(const int pos,NewsTopic *news) =0;
virtual void __stdcall NewsBodyRequest(const int key) =0;
virtual LPSTR __stdcall NewsBodyGet(const int key) =0;
//--- dealing
virtual int __stdcall DealerSwitch(MTAPI_NOTIFY_FUNC pfnFunc,const HWND destwnd,const UINT eventmsg)=0;
virtual int __stdcall DealerRequestGet(RequestInfo *info) =0;
virtual int __stdcall DealerSend(const RequestInfo *info,const int requote,const int mode)=0;
virtual int __stdcall DealerReject(const int id) =0;
virtual int __stdcall DealerReset(const int id) =0;
//---
virtual TickInfo* __stdcall TickInfoLast(LPCSTR symbol,int *total)=0;
virtual int __stdcall SymbolsGroupsGet(ConSymbolGroup *grp) =0;
virtual __time32_t __stdcall ServerTime() =0;
virtual MailBox* __stdcall MailsRequest(int *total) =0;
//--- risk management
virtual SymbolSummary* __stdcall SummaryGetAll(int *total) =0;
virtual int __stdcall SummaryGet(LPCSTR symbol,SymbolSummary *info) =0;
virtual int __stdcall SummaryGetByCount(const int symbol,SymbolSummary *info)=0;
virtual int __stdcall SummaryGetByType(const int sectype,SymbolSummary *info)=0;
virtual int __stdcall SummaryCurrency(LPSTR cur,const int maxchars) =0;
virtual ExposureValue* __stdcall ExposureGet(int *total) =0;
virtual int __stdcall ExposureValueGet(LPCSTR cur,ExposureValue *info) =0;
//---
virtual int __stdcall MarginLevelRequest(const int login,MarginLevel *level) =0;
virtual int __stdcall HistoryCorrect(LPCSTR symbol,int *updated) =0;
//--- new chart bases
virtual RateInfo * __stdcall ChartRequest(const ChartInfo *chart,__time32_t *timesign,int *total) =0;
virtual int __stdcall ChartAdd(LPCSTR symbol,const int period,const RateInfo *rates,int *count) =0;
virtual int __stdcall ChartUpdate(LPCSTR symbol,const int period,const RateInfo *rates,int *count)=0;
virtual int __stdcall ChartDelete(LPCSTR symbol,const int period,const RateInfo *rates,int *count)=0;
//--- ticks base
virtual TickRecord* __stdcall TicksRequest(const TickRequest *request,int *total)=0;
//--- internal methods
virtual int __stdcall PumpingSwitchEx(MTAPI_NOTIFY_FUNC_EX pfnFunc,const int flags,void *param)=0;
virtual int __stdcall UsersSyncStart(const __time32_t timestamp)=0;
virtual UserRecord* __stdcall UsersSyncRead(int* users_total)=0;
virtual int* __stdcall UsersSnapshot(int* users_total)=0;
virtual int __stdcall TradesSyncStart(const __time32_t timestamp)=0;
virtual TradeRecord* __stdcall TradesSyncRead(int* trades_total)=0;
virtual int* __stdcall TradesSnapshot(int* trades_total)=0;
virtual int __stdcall DailySyncStart(const __time32_t timestamp)=0;
virtual DailyReport* __stdcall DailySyncRead(int* daily_total)=0;
//--- profit recalculation
virtual int __stdcall TradeCalcProfit(TradeRecord *trade)=0;
//--- new symbol commands
virtual int __stdcall SymbolChange(const SymbolProperties *prop) =0;
//--- network statistics
virtual int __stdcall BytesSent()=0;
virtual int __stdcall BytesReceived()=0;
//---
virtual int __stdcall ManagerCommon(ConCommon *common)=0;
//--- log access
virtual void __stdcall LogsOut(const int code,LPCSTR source,LPCSTR msg)=0;
virtual void __stdcall LogsMode(const int mode)=0;
//--- check license
virtual int __stdcall LicenseCheck(LPCSTR license_name)=0;
//--- gateway configs
virtual ConGatewayAccount* __stdcall CfgRequestGatewayAccount(int *total)=0;
virtual ConGatewayMarkup* __stdcall CfgRequestGatewayMarkup(int *total)=0;
virtual ConGatewayRule* __stdcall CfgRequestGatewayRule(int *total)=0;
//--- configuration update
virtual int __stdcall CfgUpdateGatewayAccount(const ConGatewayAccount* cfg)=0;
virtual int __stdcall CfgUpdateGatewayMarkup(const ConGatewayMarkup* cfg)=0;
virtual int __stdcall CfgUpdateGatewayRule(const ConGatewayRule *cfg)=0;
//--- configuration delete
virtual int __stdcall CfgDeleteGatewayAccount(const int pos)=0;
virtual int __stdcall CfgDeleteGatewayMarkup(const int pos)=0;
virtual int __stdcall CfgDeleteGatewayRule(const int pos)=0;
//--- configuration shift
virtual int __stdcall CfgShiftGatewayAccount(const int pos,const int shift)=0;
virtual int __stdcall CfgShiftGatewayMarkup(const int pos,const int shift)=0;
virtual int __stdcall CfgShiftGatewayRule(const int pos,const int shift)=0;
//--- administrator databases commands
virtual BalanceDiff* __stdcall AdmBalanceCheck(int *logins,int *total)=0;
//--- notifications
virtual int __stdcall NotificationsSend(LPWSTR metaquotes_ids,LPCWSTR message)=0;
virtual int __stdcall NotificationsSend(const int* logins,const UINT logins_total,LPCWSTR message)=0;
};
//+------------------------------------------------------------------+
//| Functions |
//+------------------------------------------------------------------+
typedef int (*MtManVersion_t)(void);
typedef int (*MtManCreate_t)(int version,CManagerInterface **man);
//+------------------------------------------------------------------+
JNI java代码:
/**
* Manager接口
* @author
* @time 下午2:14:52
*/
public class ManagerAPI {
//manager的指针地址
protected long ptr;
public ManagerAPI() {
ptr = Init();
if(ptr < 0){
throw new RuntimeException("Manager API Init fail.");
}
}
/**
* 销毁
* @author
* @time 下午2:37:14
*/
public boolean release() {
int release = Release(ptr);
return release == ResultCode.RET_OK.getValue();
}
//===========================动态库方法:开始===============================
/**
* lib:Init
* @return 返回CManagerInterface实例的地址
*/
protected native long Init();
/**
* lib:winsock startup
* @author
* @time 下午2:15:55
*/
protected static native void WinsockStartup();
/**
* lib:winsock cleanup
* @author
* @time 下午2:15:55
*/
protected native void WinsockCleanup();
//===========================动态库方法:开始===============================
/**
* API:release
* @param ptr
* @return
*/
protected native int Release(long ptr);
/**
* API:service methods
* 释放指针内存
* @param ptr
* @param targetPtr:待释放指针
* @return
*/
protected native void MemFree(long ptr, long targetPtr);
/**
* API:service methods
* 返回结果描述
* @param ptr
* @param code
* @return
*/
protected native String ErrorDescription(long ptr, int code);
/**
* API:service methods
* 设置工作目录
* @param ptr
* @param code
* @return 成功返回设置描述,否则返回null <br/>
* The specified directory must exist, the function does not create directories
*/
protected native void WorkingDirectory(long ptr, String path);
/**
* API:connection
* 连接到服务端
* @param ptr
* @param server
* @return
*/
protected native int Connect(long ptr,String server);
/**
* API:connection
* 断开链接
* @param ptr
* @return
*/
protected native int Disconnect(long ptr);
/**
* API:connection
* 是否连接
* @param ptr
* @return
*/
protected native int IsConnected(long ptr);
/**
* API:connection
* 登录
* @param ptr
* @param uid
* @param password
* @return
*/
protected native int Login(long ptr, int uid, String password);
/**
* API:connection
* 测试连通
* @param ptr
* @return
*/
protected native int Ping(long ptr);
/**
* API:connection
* 修改密码
* @param ptr
* @param pass
* @param is_investor 默认主密码(0)
* @return
*/
protected native int PasswordChange(long ptr, String pass, int is_investor);
/**
* API:connection
* Manager权限
* @param ptr
* @return
*/
protected native ConManager ManagerRights(long ptr);
/**
* API:server configuration:configuration request
* 品种组
* @return
*/
protected native ConSymbolGroup[] CfgRequestSymbolGroup(long ptr);
/**
* API:server configuration:configuration request
* 节假日
* @return
*/
protected native ConHoliday[] CfgRequestHoliday(long ptr);
/**
* API:server configuration:configuration request
* 品种对
* @return
*/
protected native ConSymbol[] CfgRequestSymbol(long ptr);
/**
* API:server configuration:configuration request
* 用户组
* @return
*/
protected native ConGroup[] CfgRequestGroup(long ptr);
/**
* API:server configuration:configuration request
* 管理员
* @return
*/
protected native ConManager[] CfgRequestManager(long ptr);
/**
* API:server configuration:configuration request
* 数据源
* @return
*/
protected native ConFeeder[] CfgRequestFeeder(