SmartEA Restful API (1.0.0)

Download OpenAPI specification:Download

SmartEA Restful API是一个允许通过HTTP协议与MetaTrader 5交易终端进行交互的接口。 它提供了一系列功能,包括获取账户信息、下单交易、管理持仓和挂单、获取市场数据等。 默认社区版的ex5文件,只支持端口的调整,其它的参数都不可调整,在MT5终端的设置中, 可以设置Server端口,默认是9000,加载了之后就能通过外部访问了。

社区版 :只有ex5文件,直接可以手动调用这些暴露的API,自行参考文档使用。
专业版 :除了ex5文件外,还能调整里面的参数,如对应的API参数,包括链接数等,同时配套SaaS平台订阅使用,有限制的使用。
团队版 :除了专业版功能外,还能部署自己的私有化平台配套使用,包括高级功能,如回测、策略编排、策略定制等,没有任何限制。
定制版 :除了团队版功能外,还能根据客户要求,定制开发,满足特殊需求。

账户相关接口

包含当前账户所有的信息,如余额、净值、持仓、挂单、历史成交等

获取账户信息

获取当前交易账户的详细信息

Responses

Response samples

Content type
application/json
{
  • "code": "10000",
  • "msg": "SUCCESS",
  • "data": {
    • "account": {
      • "balance": 10000,
      • "equity": 10050.25,
      • "margin": 1000,
      • "freeMargin": 9050.25,
      • "profit": 50.25,
      • "currency": "USD",
      • "leverage": 100,
      • "marginLevel": 1005.03,
      • "server": "MetaQuotes-Demo",
      • "name": "John Doe",
      • "company": "MetaQuotes Software Corp."
      }
    }
}

订单相关的接口

挂单相关接口,包括开仓、平仓、修改、取消等

开仓下单

创建新的挂单

Request Body schema: application/json

订单参数

symbol
required
string

交易品种

lotSize
required
number <double>

交易手数

openOrder
required
number <double>

开仓价格

winOrder
required
number <double>

止盈价格

lowOrder
required
number <double>

止损价格

Direction
required
integer
Enum: 0 1

交易方向(1:买入, 0:卖出)

Responses

Request samples

Content type
application/json
{
  • "symbol": "EURUSD",
  • "lotSize": 0.1,
  • "openOrder": 1.085,
  • "winOrder": 1.09,
  • "lowOrder": 1.08,
  • "Direction": 1
}

Response samples

Content type
application/json
{
  • "code": "10000",
  • "msg": "SUCCESS",
  • "data": {
    • "orderTicket": 123456,
    • "symbol": "EURUSD",
    • "type": "BUY",
    • "volume": 0.1,
    • "openPrice": 1.085,
    • "stopLoss": 1.08,
    • "takeProfit": 1.09
    }
}

获取挂单列表

获取当前所有未成交的挂单

query Parameters
page
integer
Default: 1

页码

pageSize
integer <= 100
Default: 20

每页显示数量

Responses

Response samples

Content type
application/json
{
  • "code": "10000",
  • "msg": "SUCCESS",
  • "data": {
    • "orders": [
      • {
        • "ticket": 123456,
        • "symbol": "EURUSD",
        • "type": "BUY_LIMIT",
        • "volume": 0.1,
        • "openPrice": 1.082,
        • "stopLoss": 1.077,
        • "takeProfit": 1.087,
        • "createTime": "2023-05-20 10:30:15",
        • "expireTime": "2023-05-21 10:30:15",
        • "magicNumber": 20250513,
        • "comment": "Web API"
        }
      ],
    • "pagination": {
      • "total": 25,
      • "page": 1,
      • "pageSize": 20,
      • "pages": 2
      }
    }
}

取消挂单

取消指定的挂单

Request Body schema: application/json

挂单参数

ticket
required
integer

票据号

Responses

Request samples

Content type
application/json
{
  • "ticket": 123456
}

Response samples

Content type
application/json
{
  • "code": "10000",
  • "msg": "SUCCESS",
  • "data": {
    • "ticket": 123456,
    • "message": "挂单已成功取消"
    }
}

持仓相关的接口

持仓相关接口,包括获取、关闭等

获取持仓列表

获取当前所有持仓订单

query Parameters
page
integer
Default: 1

页码

pageSize
integer <= 100
Default: 20

每页显示数量

Responses

Response samples

Content type
application/json
{
  • "code": "10000",
  • "msg": "SUCCESS",
  • "data": {
    • "positions": [
      • {
        • "ticket": 123456,
        • "symbol": "EURUSD",
        • "type": "BUY",
        • "volume": 0.1,
        • "openPrice": 1.085,
        • "currentPrice": 1.0875,
        • "stopLoss": 1.08,
        • "takeProfit": 1.09,
        • "profit": 25,
        • "openTime": "2023-05-20 10:30:15",
        • "magicNumber": 20250513,
        • "comment": "Web API"
        }
      ],
    • "pagination": {
      • "total": 25,
      • "page": 1,
      • "pageSize": 20,
      • "pages": 2
      }
    }
}

关闭持仓

关闭指定的持仓单

Request Body schema: application/json

持仓单参数

ticket
required
integer

票据号

Responses

Request samples

Content type
application/json
{
  • "ticket": 123456
}

Response samples

Content type
application/json
{
  • "code": "10000",
  • "msg": "SUCCESS",
  • "data": {
    • "ticket": 123456,
    • "message": "挂单已成功取消"
    }
}

行情接口

市场数据接口,包括实时行情、K线数据等

获取实时行情

获取指定交易品种的实时行情数据

query Parameters
symbol
required
string

交易品种,如"EURUSD"

Responses

Response samples

Content type
application/json
{
  • "code": "10000",
  • "msg": "SUCCESS",
  • "data": {
    • "symbol": "EURUSD",
    • "time": "2023-05-20 10:30:15",
    • "bid": 1.0875,
    • "ask": 1.0876,
    • "last": 1.08755,
    • "volume": 325.45,
    • "spread": 1,
    • "digits": 5,
    • "point": 0.00001
    }
}

获取K线数据

获取指定交易品种和时间周期的K线数据

query Parameters
symbol
required
string

交易品种,如"EURUSD"

timeframe
string
Default: "M1"
Enum: "M1" "M5" "M15" "M30" "H1" "H4" "D1" "W1" "MN1"

时间周期

limit
integer <= 1000
Default: 100

返回K线数量

Responses

Response samples

Content type
application/json
{
  • "code": "10000",
  • "msg": "SUCCESS",
  • "data": {
    • "symbol": "EURUSD",
    • "timeframe": "H1",
    • "count": 100,
    • "candles": [
      • {
        • "time": "2023-05-20 10:00:00",
        • "open": 1.085,
        • "high": 1.086,
        • "low": 1.084,
        • "close": 1.0855,
        • "tick_volume": 3245,
        • "spread": 10,
        • "real_volume": 32450
        }
      ]
    }
}

历史数据接口

历史数据接口,包括历史成交、历史挂单等

获取历史成交订单

获取历史成交订单记录

query Parameters
page
integer
Default: 1

页码

pageSize
integer <= 100
Default: 20

每页显示数量

from
string <date>

开始日期,格式:YYYY-MM-DD

to
string <date>

结束日期,格式:YYYY-MM-DD

Responses

Response samples

Content type
application/json
{
  • "code": "10000",
  • "msg": "SUCCESS",
  • "data": {
    • "history": [
      • {
        • "ticket": 123456,
        • "orderTicket": 123450,
        • "symbol": "EURUSD",
        • "type": "BUY",
        • "entry": "ENTRY",
        • "volume": 0.1,
        • "price": 1.085,
        • "profit": 25,
        • "commission": -2,
        • "swap": -0.5,
        • "time": "2023-05-20 10:30:15",
        • "magicNumber": 20250513,
        • "comment": "Web API"
        }
      ],
    • "pagination": {
      • "total": 25,
      • "page": 1,
      • "pageSize": 20,
      • "pages": 2
      },
    • "dateRange": {
      • "from": "2023-04-20",
      • "to": "2023-05-20"
      }
    }
}

系统接口

这里主要是探针为主,一个基础的状态检查接口

健康检查

检查API服务是否正常运行

Responses

Response samples

Content type
application/json
{
  • "code": "10000",
  • "msg": "SUCCESS",
  • "data": {
    • "status": "healthy",
    • "timestamp": 1716269452,
    • "uptime": 3600
    }
}