English
5. Web API
5.1 About Web API
  1. Data stored in shared memory and database can be retrieved or updated from external systems.
  2. According to different summary conditions, group and aggregate by positions to create report.
  3. Only CGI programs are provided. You need to build an Apache HTTP server and configure settings related to CGI applications.
  4. There is no authentication function. Please set up Basic authentication, Digest authentication or client authentication on HTTP server as needed.
5.2 Protocol
ItemDescription
ProtocolHTTP / HTTPS
URL/fxService.cgi
MethodPOST
Content-Typetext/plain
RequestXML
ResponseJSON
5.3 Settings
Please add the following settings into the HTTP server conf file.
  • SetEnv MYSQL_DB scm_fxtrade
  • SetEnv MYSQL_HOST localhost
  • SetEnv MYSQL_USER fxtrade
  • SetEnv MYSQL_PWD fxtrade
  • SetEnv MAX_CONTENT_LENGTH 65536
  • SetEnv SHM_SEL_DB 1
5.4 API Specification
5.4.1 Common specification
•Response Format
{
  "status":∼,    return value [0(succeeded), 1(failed)]
  "data":{∼}
}
5.4.2 Get the account information
•Request
Source: shared memory → DB
<fxservice>
  <method>getAccount</method>
  <params>
    <accountid>∼</accountid>    account ID [necessary] [multiple are available]
    ...
  </params>
</fxservice>
•Response
Format: [{"status":∼, "data":{∼}}, ...]
{
  "AccountID": "∼",
  "Balance": ∼,
  "Equity": ∼,
  "DayPL": ∼,
  "UsedMargin": ∼,
  "UsableMargin": ∼,
  "GrossPL": ∼,
  "Hedging": "∼"
}
5.4.3 Get the market data
•Request
Source: shared memory→DB
<fxservice>
  <method>getOffer</method>
  <params>
    <symbol>∼</symbol>    symbol [optional] [multiple are available]
    ...
  </params>
</fxservice>
•Response
Format: {"status":∼, "data":[{∼}, ...]}
{
  "OfferID": "∼",
  "Symbol": "∼",
  "Bid": ∼,
  "Ask": ∼,
  "High": ∼,
  "Low": ∼,
  "PipCost": ∼,
  "PointSize": ∼,
  "Time": "∼"
}
5.4.4 Get the opened positions
•Request
Source: shared memory→DB
<fxservice>
  <method>getOpenTrade</method>
  <params>
    <accountid>∼</accountid>    account ID [necessary]
  </params>
</fxservice>
•Response
Format: {"status":∼, "data":[{∼}, ...]}
{
  "TradeID": "∼",
  "Symbol": "∼",
  "Amount": ∼,
  "BS": "∼",
  "Open": ∼,
  "Close": ∼,
  "Stop": ∼,
  "Limit": ∼,
  "High": ∼,
  "Low": ∼,
  "PL": ∼,
  "GrossPL": ∼,
  "OpenTime": "∼",
  "CloseTime": "∼",
  "MaxSumPL": ∼,
  "MaxSumPLCount": ∼,
  "MaxSumPLTime": "∼",
  "CurSumPL": ∼,
  "CurSumPLCount": ∼
}
5.4.5 Get the closed positions
•Request
Source: DB
<fxservice>
  <method>getClosedTrade</method>
  <params>
    <accountid>∼</accountid>    account ID [necessary]
    <startdate>∼</startdate>    Open Time ≥ ∼ [optional]
    <enddate>∼</enddate>        Closed Time ≤ ∼ [optional]
  </params>
</fxservice>
•Response
Format: [{∼}, ...]
{
  "TradeID": "∼",
  "Symbol": "∼",
  "Amount": ∼,
  "BS": "∼",
  "Open": ∼,
  "Close": ∼,
  "Stop": ∼,
  "Limit": ∼,
  "High": ∼,
  "Low": ∼,
  "PL": ∼,
  "GrossPL": ∼,
  "OpenTime": "∼",
  "CloseTime": "∼",
  "MaxSumPL": ∼,
  "MaxSumPLCount": ∼,
  "MaxSumPLTime": "∼",
  "CurSumPL": ∼,
  "CurSumPLCount": ∼
}
5.4.6 Get the historical data
•Request
Source: shared memory
<fxservice>
  <method>getPriceBar</method>
  <params>
    <symbol>∼</symbol>    symbol [necessary]
    <period>∼</period>    period [necessary]
  </params>
</fxservice>
•Response
Format: {"status":∼, "data":[{∼}, ...]}
{
  "Symbol": "∼",
  "StartDate": "∼",
  "Period": "∼",
  "AskClose": ∼,
  "AskHigh": ∼,
  "AskLow": ∼,
  "AskOpen": ∼,
  "BidClose": ∼,
  "BidHigh": ∼,
  "BidLow": ∼,
  "BidOpen": ∼
}
5.4.7 Create the report
•Request
Source: DB
<fxservice>
  <method>getReport</method>
  <params>
    <rpttype>∼</rpttype>    report type [necessary] [Possible values: 1(summary), 2(details)]
    <accountid>∼</accountid>account ID [necessary]
    <symbol>∼</symbol>      symbol [optional]
    <method>∼</method>      trade method [optional]
    <startdate>∼</startdate>open time ≥ ∼ [optional]
    <enddate>∼</enddate>    open time ≤ ∼ [optional]
    <frompl>∼</frompl>      P/L ≥ ∼ [optional]
    <topl>∼</topl>          P/L ≤ ∼ [optional]
    <grouping>
      <key>∼</key>          grouping key [optional] [multiple are available]
                            [Possible values 1(Symbol), 2(Method), 3(Year), 4(Month), 5(Week)]
      ...
    </grouping>
    <maxcounts>∼</maxcounts>maximum number [optional] [default:200]
  </params>
</fxservice>
•Response
Format: [{∼}, ...]
1:summary
{
  "Symbol": "∼",
  "TradeMethodName": "∼",
  "_year": ∼,
  "_month": ∼,
  "_week": ∼,
  "PL": ∼,
  "GrossPL": ∼,
  "Counts": ∼
}
2:details
{
  "TradeID": "∼",
  "Symbol": "∼",
  "Amount": ∼,
  "BS": "∼",
  "Open": ∼,
  "Close": ∼,
  "Stop": ∼,
  "Limit": ∼,
  "High": ∼,
  "Low": ∼,
  "PL": ∼,
  "GrossPL": ∼,
  "OpenTime": "∼",
  "CloseTime": "∼",
  "MaxSumPL": ∼,
  "MaxSumPLCount": ∼,
  "MaxSumPLTime": "∼",
  "CurSumPL": ∼,
  "CurSumPLCount": ∼,
  "TradeMethodPeriod": "∼",
  "TradeMethodName": "∼",
  "TrailStopPeriod": "∼",
  "TrailStopName": "∼",
  "TrailMoveTsName": "∼"
}
5.4.8 Get the execution plans
•Request
Source: DB
<fxservice>
  <method>getImplPlan</method>
  <params>
    <accountid>∼</accountid>    account ID [necessary]
  </params>
</fxservice>
•Response
Format: [{∼}, ...]
{
  "Symbol": "∼",
  "IP1": "∼",
  "IP2": "∼",
  "IP3": "∼",
  ...
  "IP20": "∼"
}
5.4.9 Update the execution plans
•Request
Destination: DB
<fxservice>
  <method>setImplPlan</method>
  <params>
    <accountid>∼</accountid>    account ID [necessary]
    <param>
      <symbol>∼</symbol>        symbol [necessary]
      <ip1>∼</ip1>              plan1 [optional]
      ...
      <ip20>∼</ip20>            plan20 [optional]
      <loginid>∼</loginid>      login ID [optional]
    </param>
  </params>
</fxservice>
•Response
"ok"(succeeded), ""(failed)