MT4开发文档之 Server API: Hooks and Trade Functions

提示:如有疑问可留言或者私信


前言

提示:如有疑问可留言或者私信:

本文来自MT4开发文档,可自行翻译
在这里插入图片描述


提示:以下是本篇文章正文内容,下面案例可供参考

一、简介

MetaTrader 4 platform in eludes the server API. It is inten ded for developme nt of high-performa nee plug ins that work in the server process and can access the in ter nal server structures. This is the disti ncti on of kind betwee n the server API and the Man ager API: the latter one works with the server in n etwork sessi ons, and this lowers the productivity.
The server API allows expansion of logic of clients’ requests, swaps and commissions processing, filtering of quotes, report generation. Moreover, it can help in integration with the existing software.
Un fort un ately, high speed of plugi ns can be fraught with the risk of the server crash. Although all server API accesses are checked, there are no difficulties to write a code of, for example, divisi on by zero in the plug in. This is why the testi ng and plugi n code an alysis requireme nts must be strictly kept whe n the plugi n is in stalled on the live server.

二、方法列表

1.介绍

The key concepts in the development of plugins are hook and server interface.
The hook is a predefi ned plug in fun ctio n called by the server at a certa in mome nt. For example, a hook n amed MtSrvTradeRequestApply will be called every time when a client’s request is enqueued for processing. All available hooks, as funcitons described with the APIENTRY modificator, can be found in the lMT4ServerAPI.h’file.
There must be at least two hooks in a plugi n: MtSrvAbout and MtSrvStartup. Both are called whe n the server dow nl oads a plug in. The former is resp on sible for that the server receives in formati on about the plug in. The latter one serves for the plugi n global in itializati on and gets the server in terface as a parameter.
If a plug in n eeds to be dein itialized (for example, at clos ing of threads or sockets), it must in elude the hook n amed MtSrvCIea nup to be called at the server shutdow n. You must keep in mind that you will not be able to call the server in terface after you have called this hook. For example, if there is a separate thread in the plug in / it is in the MtSrvCIea nup where this thread must be stopped. You should not wait un til the plugi n is uni oaded.
The server interface is a set of fun cti ons that man age the server and access to its in ter nal structures. For example, you can throw ticks into the flow or request about the list of all traders using this in terface. The descriptio n of the CServer In terface can also be found in the ‘MT4ServerAPI.h’ file.

Trade Hooks of MetaTrader Server

The trade hooks allow interception of the most trading situations and expansion of the server logic. The hooks are listed below:

MtSrvTradeReauestFilter
MtSrvTradeReauestADDlv
MtSrvTradeTra nsactio n
MtSrvTradeStoDsFilter
MtSrvTradeStoDsADDlv
MtSrvTradePe ndin asFilter
MtSrvTradePe ndin qsAddIv
MtSrvTradeStoDoutsFilter
MtSrvTradeStoDOUtsADDlv
MtSrvTradeCommissi on
MtSrvTradeCommissi on Aae nt
MtSrvTradeRollover
MtSrvTradesAdd
MtSrvTradesAddExt
MtSrvTradesUDdate

2.方法

MtSrvTradeRequestFilter

int APIENTRY MtSrvTradeRequestFilter(RequestInfo *request,const int isdemo)

Purpose - filteri ng and modify ing of the thread of in com ing requests.
The hook should be called before the request is enqueued to be processed. This hook can be used for rejection of any requests about working with pending orders. It can also be applied, for example, if there is a need to set forecedly the order expiration date under certain conditions.
If the hook does not return RET_OK, the request will not be enqueued. The return code will be passed to the client as an error code.
Parameters:
request - the client’s request
isdemo - flag of the request execution by automated dealer of the server

MtSrvTradeRequestApply

void APIENTRY MtSrvTradeRequestApply(RequestInfo *request,const int isdemo)

MetaTrader 4 Server API: Hooks and Trade Functions - Articles - MetaQuotes Software Support Center
Purpose - impleme ntati on of automated deali ng plug ins.
The hook is called whe n the clie nt’s request is enq ueued to be processed. The request received can be processed immediately and con firmed or rejected using the methods of CServer In terface::RequestsPrices, CServer In terface::RequestsC on firm, CServer In terface:: RequestsReset, CServer In terface::RequestsRequote. If it takes some time to process a given request (for example, when connecting to an external server), the given order must be attached to the manager on behalf of which the plug in works (us ing the CServer In terface::RequestsLock method), and the n the request must be processed in a separate thread. If the plugi n leaves request untouched it will be left in request queue for processing by dealer.
Parameters:
request - the client’s request
isdemo - flag of the request execution by automated dealer of the server
Example: DealerHelper.

MtSrvTradeTransaction

int APIENTRY MtSrvTradeTransaction(TradeTransInfo* trans,const UserInfo *user,int *request id)

Purpose - additional check of trading transactions.
The hook named MtSrvTradeTransaction is called after the client’s or manager’s trading transaction (position opening or closing, order modifying, pending order triggering, etc.) has been primarily checked.
If this hook does not retur n RET_OK, the tra nsacti on will not be performed. If the operati on succeeds, the nu mber of the request that con ducted this tra nsacti on will be placed in the request_id. Otherwise, the return code will be passed to the client as an error code.
Parameters:
tra ns - tra nsacti on
user - description of the trader’s or manager’s account that performs a transaction
request_id - the request number
Example: IEInterceptor.

MtSrvTradeStopsFilter

int APIENTRY MtSrvTradeStopsFilter(const ConGroup *group,const ConSymbol *symbol,const TradeRecord *trade)

Purpose - filtering of StopLoss and TakeProfit orders processing.
The server calls this hook when a StopLoss or a TakeProfit order triggers. If this hook returns RET_OK, the order will be processed according to a standard procedure (by the server automated dealer or a huma n dealer). Otherwise, if the hook retur ns someth ing other tha n RET_OK, the plug in will no tify the server about that the former will process the order independently (or that the order will not be processed at all).
■Implementation of this hook must be optimized by time, otherwise the processing of StopLoss and TakeProfit orders may be considerably delayed.
■In side of this hook, the methods of server in terface n amed CServer In terface::MtSrvTradesAdd and CServer In terface::MtSrvTradesUpdate should not be called in order to add/remove orders with in the same group of users.
Parameters:
group - description of the group
symbol - description of the symbol
trade - trade position
Example: TradeCollector.

MtSrvTradeStopsApply

int APIENTRY MtSrvTradeStopsApply(const UserInfo *user,const ConGroup *group,const ConSymbol *symbol, TradeRecord *trade,const int isTP)

Purpose - interception of StopLoss and TakeProfit orders processing.
This hook is intended for interception and modifying of parameters of the position order to be executed (for example, the position close price). It is called after the necessary information (trade) for execution of the Stop order has been prepared.
If this hook returns RET_OK, the order is executed by the server automated dealer considering changes made by the hook. Otherwise, the order will not be processed.
■Implementation of this hook must be optimized by time, otherwise the processing of StopLoss and TakeProfit orders may be considerably delayed.
■In side of this hook, the methods of server in terface n amed CServer In terface::MtSrvTradesAdd and CServer In terface::MtSrvTradesUpdate should not be called in order to add/remove orders with in the same group of users.
Parameters:
user - description of the account
group - description of the group to which the account belongs
symbol - description of the symbol
MetaTrader 4 Server API: Hooks and Trade Functions - Articles - MetaQuotes Software Support Center
trade - position to be closed
isTP - flag showing that TakeProfit is being processed (TRUE), otherwise (FALSE) the closing is performed by StopLoss Example: TradeCollector.

MtSrvTradePendingsFilter

int APIENTRY MtSrvTradePendingsFilter(const ConGroup *group,const ConSymbol *symbol,const TradeRecord *trade)

Purpose - filtering of the pending order activation.
The server calls this hook when pending orders are activated. If this hook returns RET_OK, the order will be processed according to the standard procedure (by the server automated dealer or by a huma n dealer). Otherwise, if the hook retur ns someth ing other tha n RET_OK, the plug in no tifies the server that the plug in will process this order independently (or that the order will not be processed at all).
■Implementation of this hook must be optimized by time, otherwise the pending order activation may be considerably delayed.
■In side of this hook, the methods of server in terface n amed CServer In terface::MtSrvTradesAdd and CServer In terface::MtSrvTradesUpdate should not be called in order to add/remove orders with in the same group of users.
Parameters:
group - description of the group
symbol - description of the symbol
trade - pending order
Example: TradeCollector.

MtSrvTradePendingsApply

int APIENTRY MtSrvTradePendingsApply(const UserInfo *user,const ConGroup *group,const ConSymbol *symbol, const TradeRecord *pending,TradeRecord *trade)

Purpose - interception of the pending order activation.
This hook is intended for interception and modifying of the order to be executed (for example, the position open price) and is called after the necessary information (trade) has been prepared for activation of the initial pending order.
If this hook returns RET_OK, the order is executed by the server automated dealer considering the changes made by the hook. Otherwise, the order will not be processed.
■Implementation of this hook must be optimized by time, otherwise the pending order activation may be considerably delayed.
■In side of this hook, the methods of server in terface n amed CServer In terface::MtSrvTradesAdd and CServer In terface::MtSrvTradesUpdate should not be called in order to add/remove orders with in the same group of users.
Parameters:
user - description of the account
group - description of the group to which the account belongs
symbol - description of the symbol
pending - the initial pending order
trade - the position to be opened
Example: TradeCollector.

MtSrvTradeStopoutsFilter

int APIENTRY MtSrvTradeStopoutsFilter(const ConGroup *group,const ConSymbol *symbol,const int login, const double equity,const double margin)

Purpose - filtering of stopuots processing.
The server calls this hook when positions are being closed by stopout. If this hook returns RET_OK, the position will be closed according to the standard procedure using the server automated dealer. Otherwise (the hook retur ns someth ing other tha n RET_OK), the plug in no tifies the server that the plugi n will close the positions by stopouts independently (or the positions will not be closed at all).
■Implementation of this hook must be optimized by time, otherwise the processing of stops and pending orders may be considerably delayed.
■In side of this hook, the methods of server in terface n amed CServer In terface::MtSrvTradesAdd and CServer In terface::MtSrvTradesUpdate should not be called in order to add/remove orders with in the same group of users.
Parameters:
group - description of the group
symbol - description of the symbol
log in - the acco unt n umber
https://support.metaquotes.net/en/articles/print/45
equity - the current funds
marg in - the curre nt margi n
Example: TradeCollector.

MtSrvTradeStopoutsApply

int APIENTRY MtSrvTradeStopoutsApply(const UserInfo *user,const ConGroup *group,
const ConSymbol *symbol,TradeRecord *stopout)

Purpose - interception of position closing by stopout
This hook is intended for interception and modifying of parameters of positions closed by stopout (for example, close price or comments). It is called after the necessary information (stopout) for pending order activation has been prepared.
If this hook returns RET_OK, the position will be closed by automated dealer considering changes made by the hook. Otherwise, the position remains open.
■Implementation of this hook must be optimized by time, otherwise the processing of stops and pending orders may be considerably delayed.
■In side of this hook, the methods of server in terface n amed CServer In terface::MtSrvTradesAdd and CServer In terface::MtSrvTradesUpdate should not be called in order to add/remove orders with in the same group of users.
Parameters:
user - description of the account
group - description of the group to which the account belongs
symbol - description of the symbol
stopout - the position to be closed by stopout
Example: TradeCollector.

MtSrvTradeCommission

void APIENTRY MtSrvTradeCommission(TradeRecord *trade,const ConSymbol *symbol,const ConGroup *group)

Purpose - in tercepti on of commissi on calculatio n at ope ning of a new positi on.
This hook should be used to impleme nt your own algorithms of commissi on calculati on. Whe n this hook is called by the server, the commissi on calculated by default is set in the commission field of the trade parameter.
Parameters:
trade - the position to be opened
symbol - description of the symbol
group - description of the group to which the account belongs

MtSrvTradeCommissionAgent

int APIENTRY MtSrvTradeCommissionAgent(TradeRecord *trade,const ConSymbol * sec,const UserInfo* user);

Purpose - in tercepti on of age nt commissio n calculati on at positi on clos ing.
This hook should be used to impleme nt your own algorithms of age nt commissi on calculati on. Whe n this hook is called by the server, the commissi on value calculated by default is set in the commissi on_ age nt field of the trade parameter.
If this hook retur ns TRUE, the age nt commissi on is charged. Otherwise, the age nt commissi on is zeroed and the bala nee operatio n to an age nt’s acco unt is not performed.
Parameters:
trade - the position to be opened
sec - description of the security
user - description of a client

MtSrvTradeRollover

int APIENTRY	MtSrvTradeRollover(TradeRecord *trade,const double value,const OverNightData *data)

Purpose - interception of swaps calculation when the position rolls over the end of trading day
This hook should be used to implement your own of swap calculation algorithms. When this hook is called by the server, the swap value calculated by default is passed in the value parameter.
If this hook retur ns FALSE, the accumulated swap for a positi on (the storage field of the trade parameter) will be in creased by the value specified in the value parameter. Otherwise, the hook must update the value of the storage field.
Parameters:
trade - the trade position
value - the precalculated value of the daily swap
data - the structure of the swap calculation parameters for the given symbol
https://support.metaquotes.net/en/articles/print/45

MtSrvTradesAdd

void APIENTRY MtSrvTradesAdd(TradeRecord *trade,const UserInfo *user,const ConSymbol *symbol)

Purpose - interception of adding of the order to the database.
The hook is called immediately after the new trade record has been added to the server database. This opportunity can be used to trace the trade records on certain accounts.
Parameters:
trade - the trade record to be added
user - description of the account
symbol - description of the symbol
Example: TradeCollector.
MtSrvTradesAdd Ext

void APIENTRY MtSrvTradesAddExt(TradeRecord *trade,const UserInfo *user,const ConSymbol *symbol,const int mode)

Purpose - interception of adding of the order to the database.
The hook is called immediately after the new trade record has been successfully added to the server database. This opportunity can be used to trace the cha nges made in the trade records on certa in acco un ts. Un like the MtSrvTradesAdd, this hook additi on ally passes the mode flag that gives reas ons for which the trade record has been added.
Parameters:
trade - the record
user - flag of the account decription
symbol - flag of the symbol description
the reason why the trade record was added: OPEN_NEW - adding of a new order/position, OPEN_CLOSE - adding of the rest of a closed mode - position, OPEN_RESTORE - reopening a closed position, OPEN_API - opening of position using API, OPEN_ROLLOVER - opening of position by rollover
Example: TradeCollector.

MtSrvTradesUpdate

void APIENTRY MtSrvTradesUpdate(TradeRecord *trade,UserInfo *user,const int mode)

Purpose - interception of the trade record changes in the database.
he hook is called immediately after the new trade record has bee n successfully added to the server database. This opport unity can be used to trace the cha nges made in the trade records on certain accounts.
Parameters:
trade - the trade record to be added
user - description of the account
. the reason for update: UPDATE_NORMAL - normal 叩date, UPDATE_ACTIVATE - order activation, UPDATE_CLOSE - closing of the order,
m0Qe - UPDATE_DELETE - deletion of the order
Example: TradeCollector.
MetaTrader Server Interface Trade Functions
The trade functions listed below are intended for clients’ requests processing, adding of requests to be processed, working with orders:

■ReauestsAdd
■ReauestsGet
■ReauestsF ind
■ReauestsPrices
■ReauestsCo nfirm
■ReauestsC on firmPrice
■ReauestsReauote
■ReauestsReset
■ReauestsLock
■ReauestsFree
■OrdersAdd
■OrdersUDdate
■OrdersGet
■OrdersGetODe n
■OrdersGetClosed
■TradesCalcProfit
■TradesMara inInfo
■TradesMara in Check
■OrdersODe n
■OrdersClose
■OrdersCloseBv

RequestsAdd

int RequestsAdd(RequestInfo *request,const int isdemo,int *request_id)

Purpose - enqueuing of a request to be processed.
Returns RET_TRADE_ACCEPTED or RET_TRADE_REQUOTE (if a requote). After the request has been enqueued, the request number will be placed in the request_id.
Parameters:
request - the request
isdemo - flag of the request processing by automated dealer of the server
request_id - the request number
Example: IEInterceptor.

RequestsGet

int RequestsGet(int *key,RequestInfo *req,const int maxreq)

Purpose - receiving of the current requests list.
This method places in the req array all requests that have an id exceeding the key value, and sets the most recently received request id in the key value.
Returns the amount of requests.
Parameters:
, the key to be used in order to define adding of new requests since the most recent call of the method. The key must be initialized as 0
叭 before the first call
req - requests array
maxreq - the maximal amount of requests to be placed in the req array

RequestsFind
int RequestsFind(const int login,LPCSTR symbol,const int volume,double *prices,DWORD *ctm,int *manager)
Purpose - search for the previously con firmed price request or requote.
This method is used to find the price previously given by the dealer (when orders are executed in the Request mode, or as a result of requoting in the Instant mode) by the trade request parameters.
In case of success, it returns TRUE, otherwise it is FALSE.
Parameters:
log in - the trader’s acco unt
symbol - the symbol name
volume - the amount of lots
prices - the prices at which the request was con firmed or which were requoted. The first item corresp onds to bid, the sec ond is for ask ctm - the requesting time
man ager - the acco unt of the man ager that con firmed the price request or requoted

RequestsPrices

int RequestsPrices(const int id,const UserInfo *us,double *prices,const int in_stream)

Purpose - quoting of the client’s request.
This method is for quoting in the Request Execution mode. If the in_stream parameter does not equal to zero, the quote will be thrown into the price stream.
In case of success, it returns RET_OK.
Parameters:
id - the request number
us - description of the manager the prices are quoted by
prices - prices given to the client
in_stream - the flag that the prices to be given to the client will be thrown into the price stream
Example: TradeCollector.
Req uestsConfi rm
int RequestsConfirm(const int id,const UserInfo *us,double *prices)
MetaTrader 4 Server API: Hooks and Trade Functions - Articles - MetaQuotes Software Support Center
Purpose - confirmation of the client’s request.
This method is applied to con firm the clie nts1 requests. The prices parameter is used to specify order executio n prices in the Market executi on mode.
If succeeded, it returns RET_OK.
Parameters:
id - the request number
us - flag of the descripti on of the man ager the request is con firmed by
prices - flag of the prices at which the request is con firmed
Examples: DealerHelper, TradeCollector.

RequestsConfirmPrice

int RequestsConfirmPrice(const int id,const UserInfo *us,double price,double *prices)

Purpose - confirmation of a client request at a specified price.
The method is used to con firm clie nt requests at a specified price. Un like RequestC on firm, this method allows con firm ing market orders at a specified price both in Market and Instant Execution modes. In case of Instant execution mode, this can be used to reduce the number of requotes. For example, if a client has not specified acceptable deviati on (set to 0), while the price has moved in the clie nt’s favor, the clie nt’s request can be immediately con firmed without a requote.
Returns RET_OK if successful.
Parameters:
id - request ID
us - poin ter to the descripti on of the man ager, on whose behalf the request is con firmed
price - price, at which the clie nt’s order is con firmed and executed
pointer to the current market prices. These prices are thrown into the flow of quotes if the order is executed in Market mode and the prices mode of throwing in quotes at a dealer’s answer is enabled
Req uests Req uote
int RequestsRequote(const int id,const UserInfo *us,double *prices,const int in_stream)
Purpose - requoting of the clients’ requests in the Instant execution mode.
If succeeded, it returns RET_OK.
Parameters:
id - the request number
us - flag of the description of the manager that is requoting
prices - flag of the new prices
in_stream - the flag that the prices to be given to the client will be thrown into the price stream
Examples: MT4Connector, TradeCollector.

RequestsReset

int RequestsReset(const int id,const UserInfo *us,const char flag)

Purpose - rejection to execute the request.
If succeeded, the function returns RET_OK.
Parameters:
id - the request number
us - flag of the description of the manager that is made the rejection
flag - flag: DC_RESETED - off quotes
Examples: MT4Connector, TradeCollector.
RequestsLock
int RequestsLock(const int id,const int manager)
Purpose - flagging of the request as “requests lock”.
The order flagged in this way cannot be processed by another manager. This method is normally used from the MtSrvTradeRequestApply hook if the plugin cannot con firm the request or requote immediately. For example, it is the case whe n the requests con firmati on is supposed to be deferred.
If succeeded, it retuns TRUE, otherwise it is FALSE.
Parameters:
id - the request number
manager - the account of the manager that took the request in processing
RequestsFree

Purpose - repeated enqueueing of the request that was previously enqueued for processing, using the RequestsLock method.
This method and the RequestsLock method are the pair. The RequestsFree is used if the trade request cannot be processed automatically. In this case, the request will be returned to be processed by a dealer.
If succeeded, it returns TRUE, otherwise FALSE.
Parameters:
id - the request number
manager - the account of the manager that took the request for processing
OrdersAdd
int OrdersAdd(const TradeRecord order,UserInfo user,const ConSymbol *symbol)
Purpose - adding of a new trade record into the database.
This method allows add ing of records directly to the trade database, without any additi onal check ing (whether the symbol group is allowed, marg in requirements, etc.).
As the usage of this method without due checking can damage the integrity of MT4 databases, it is recommended to check correctness of all parameters passed.
If succeeded, it returns the ID (the number) of the added record, otherwise it returns 0.
Parameters:
order - the new trade record
user - description of the account
symbol - description of the symbol
Example: TradeCollector.

OrdersUpdate

int	OrdersUpdate(TradeRecord *order,UserInfo* user,const int mode)

Purpose - modifies the trade record (activates, closes, deletes or modifies the parameters). If succeeded, it returns TRUE, otherwise FALSE.
This method allows direct modify ing of the records in the trade database, without any additi onal check ing (whether the symbol group is allowed, marg in requirements, etc.).
As the usage of this method without due checking can damage the integrity of MT4 databases, it is recommended to check correctness of all parameters passed.
Parameters:
order - the trade record to be updated
user - description of the account
. updating mode: UPDATE_NORMAL - normal modification, UPDATE_ACTIVATE - activation, UPDATE_CLOSE - closing, UPDATE_DELETE -
r i iouc —
deleti on
Example: TradeCollector.

OrdersGet

int	OrdersGet(const int ticket,TradeRecord *order)

Purpose - receiving of the trade record from the database by ticket.
If succeeded, it returns TRUE and fills the order with the order description. Otherwise returns FALSE.
Parameters:
ticket - the trade records number (the order field)
order - trade record
Example: TradeCollector.

OrdersGet
TradeRecord* OrdersGet(const time_t from,const time_t to,const int logins,const int count,int total)
Purpose - receiving of trade records for the selected traders and for a certain period of time.
If succeeded, the method returns flag of the array of records that meet the search conditions. The amount of records will be placed in the total. Otherwise, NULL will be returned.
After the working with the obtained array of records has been finished, the memory allocated by this method should be emptied using the macro named
https://support.metaquotes.net/en/articles/print/45
HEAP_FREE.
Parameters:
from - the period origin
to - the period term in ati on
logi ns - the traders’ accounts array
count - the accounts list size
total - the amount of orders

OrdersGetOpen

TradeRecord* OrdersGetOpen(const UserInfo* user,int* total)

Purpose - receiving of open orders of the selected trader.
If succeeded, the method returns the orders array, and the amount of orders will be placed in the total. Otherwise, or in case of no open orders, NULL will be retur ned.
After the working with the obtained array of records has been finished, the memory allocated by this method should be emptied using the macro named HEAP_FREE.
Parameters:
user - description of the account
total - the amount of orders
Example: ClientProfitsVolumes.
OrdersGetClosed
TradeRecord* OrdersGetClosed(const time_t from,const time_t to,const int logins,const int count,int total)
Purpose - receiving of the closed positions for the selected traders and for a certain time period.
If succeeded, it returns the flag of the orders array, and the amount of orders will be placed in the total. Otherwise, or in case of no closed orders, NULL will be retur ned.
After the working with the obtained array of records has been finished, the memory allocated by this method should be emptied using the macro named
HEAP_FREE.
Parameters:
from - the period origin
to - the period term in ati on
logi ns - the traders’ accounts array
count - the amount of accounts
total - the amount of orders

TradesCalcProfit

int TradesCalcProfit(LPCSTR group,TradeRecord *order)

Purpose - profit calculation for a trade position.
This method does not update the current prices for an open position and calculates profit using only data available in the structure. If succeeded, it retur ns TRUE, otherwise FALSE. After calculatio n, the curre nt profit for a positi on will be con tai ned in the profit. Parameters:
group - the group name
order - the open position

TradesMarginlnfo

int TradesMarginInfo(UserInfo *user,double *margin,double *freemargin,double *equity)

Purpose - recei ving of the curre nt marg in requireme nts of the acco unt.
If succeeded, the method retur ns TRUE and fills the marg in, freemargi n, equity lines with in formati on. Otherwise, it retur ns FALSE.
Parameters:
user - description of the account
marg in - the curre nt marg in
freemarg in - the curre nt free marg in
equity - flag of of the current state of the trader’s equity
https://support.metaquotes.net/en/articles/print/45
Example: MarketMakerCollector・

TradesMarginCheck

double TradesMarginCheck(const UserInfo *user,const TradeTransInfo *trade,double *profit, double *new_freemargin,double *prev_margin)

Purpose - recei ving of the clie nt’s marg in requireme nts after the positi on the parameters of which are give n in the trade, has bee n ope ned.
This method should be used before the new position is opened to check for free margin availability. The opening condition is the nonnegative value of the n ew_freemargi n parameter and decreas ing of marg in requireme nts after the positi on has bee n ope ned.
The method returns the margin after the new position has been opened.
Parameters :

OrdersOpen
int OrdersOpen(const TradeTransInfo *trans,UserInfo *user)
Purpose - opening a position for the client.
This method is used to open a position for the client with simultaneous checking the free margin. If it succeeds, the identifier (number) of the added record will be returned, otherwise 0.
Parameters:
trans - a transaction of opening a new position
user - account description

OrdersClose

int OrdersClose(const TradeTransInfo *trans,UserInfo *user)

Purpose - full or partly closing of the client’s position.
The method is used to fully or partly close the clie nt’s positi on with age nt’s commissi on charged. If it succeeds, it returns TRUE, otherwise - FALSE.
Parameters:
trans - a transaction of closing a position
user - account description

OrdersCloseBy

int OrdersCloseBy(const TradeTransInfo *trans,UserInfo *user)

Purpose - closing of the client’s position with a counterorder.
This method is used to close the clie nt’s positi on with a coun terorder and charg ing an age nt’s commissi on. If it succeeds, it returns TRUE, otherwise - FALSE.
Parameters:
trans - a transaction of closing a position with a counterorder
user - account description

Conclusion
The article has presented just a part of opportunities MetaTrader 4 Server API can provide. However, these methods are the important components of the API and enable implementation of non-standard logic of trade operations.

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值