工作中需要将MT4的数据读取并且存储到Redis数据库中去,同时MT4读取Redis当中的数据用于下单的切换账户。
MT4支持使用MQL进行开发,通过调用标准的系统DLL实现系统调用,因此技术实现并不是太难,只需要按MQL的接口要求编写相应的CPP代码
编译成DLL即可实现所需要的功能。
在Windows平台上,连接Redis的客户端选用Hiredis作为连接客户端lib。
MT4 连接Redis 头文件定义,
MT4RedisPlugin.h
MT4支持使用MQL进行开发,通过调用标准的系统DLL实现系统调用,因此技术实现并不是太难,只需要按MQL的接口要求编写相应的CPP代码
编译成DLL即可实现所需要的功能。
在Windows平台上,连接Redis的客户端选用Hiredis作为连接客户端lib。
MT4 连接Redis 头文件定义,
MT4RedisPlugin.h
#define MT4_REDIS_ERR -1 /* Error */
#define MT4_REDIS_OK 0 /* OK */
#define MT4_REDIS_ERR_IO 1 /* error in read or write */
#define MT4_REDIS_ERR_EOF 3 /* eof */
#define MT4_REDIS_ERR_PROTOCOL 4 /* protocol error */
#define MT4_REDIS_ERR_OTHER 2 /* something else */
#define MT4_REDIS_CMD_SUCCESSED 0 /* Successed */
#define MT4_REDIS_CMD_FAILED -1 /* Failed */
//---
#define MT4_EXPFUNC __declspec(dllexport)
//+------------------------------------------------------------------+
//| Test Redis if is working |
//+------------------------------------------------------------------+
MT4_EXPFUNC int __stdcall RedisTest(const char* server, const int port);
//+------------------------------------------------------------------+
//| Excute Redis Command "GET key" |
//+------------------------------------------------------------------+
MT4_EXPFUNC wchar_t* __stdcall RedisGet(const wchar_t* key);
//+------------------------------------------------------------------+
//| Excute Redis Command "GET key" |
//+------------------------------------------------------------------+
MT4_EXPFUNC wchar_t* __stdcall RedisGetWithTimeout(const wchar_t* key,int timeout);
//+------------------------------------------------------------------+
//| Excute Redis Command "SET key value" |
//+------------------------------------------------------------------+
MT4_EXPFUNC int __stdcall RedisSet(const wchar_t* key, const wchar_t* value);
//+------------------------------------------------------------------+
//| Excute Redis Command "SET key value" |
//+------------------------------------------------------------------+
MT4_EXPFUNC int __stdcall RedisSetWithTimeout(const wchar_t* key, const wchar_t* value,int timeout);
//+------------------------------------------------------------------+
//| Excute Redis Command |
//+------------------------------------------------------------------+
MT4_EXPFUNC int __stdcall RedisCommand(const wchar_t* command);
//+------------------------------------------------------------------+
//| Excute Red