Functions of DealsHistory

Service DealsHistory directly works with RWmanager and NATS to get all deals from MT5 on real-time and send it all via BatchWriter to ClickHouse.

The functioning of DealsHistory depends on:

While starting the service DealsHistory you should specify the paths to the config files, that indicate which groups you need to make requests for deals.

After the deals are received, the service converts the data to the desired data structure and sends it to the BatchWriter.

After the BatchWriter has received the data, it writes each deal in ClickHouse to the deals table.

While inserting the uniqueness of the deal is checked by the keys: server_code, login, deal_id.

Structure of deal:

type Deal struct {
	ServerURI       string     `json:"server_uri"`          // Filled in locally. URI of the server where the deal was opened (for example: "http://localhost:8080"). If the server is unknown, then "unknown" is used
	ServerCode      string     `json:"server_code"`         // Filled in locally? Code of the server where the deal was opened (for example: "mt5_real1")
	GroupName       string     `json:"group_name"`          // Group name of the account where the deal was opened
	DealID          int64      `json:"deal_id"`             // Deal ID
	OrderID         int64      `json:"order_id"`            // Order ID
	PositionID      int64      `json:"position_id"`         // Position ID
	Login           string     `json:"login"`               // Login of the account (who the deal was opened)
	Time            int64      `json:"time"`                // Time of the deal opening (in seconds)
	IsEntry         bool       `json:"is_entry,omitempty"`  // Is entry deal
	Action          string     `json:"action"`              // Action of the deal (buy/sell/balance)
	Symbol          string     `json:"symbol"`              // Symbol of the deal
	Price           float64    `json:"price"`               // Price of the deal
	TP              float64    `json:"tp"`                  // Take profit of the deal
	SL              float64    `json:"sl"`                  // Stop loss of the deal
	Volume          float64    `json:"volume"`              // Volume of the deal
	Profit          float64    `json:"profit"`              // Profit of the deal
	ProfitRaw       float64    `json:"profit_raw"`          // Raw profit of the deal
	Swap            float64    `json:"swap"`                // Swap of the deal
	Commission      float64    `json:"commission"`          // Commission of the deal
	Fee             float64    `json:"fee"`                 // Fee of the deal
	ProfitRate      float64    `json:"profit_rate"`         // Profit rate of the deal
	MarginRate      float64    `json:"margin_rate"`         // Margin rate of the deal
	Comment         string     `json:"comment"`             // Comment of the deal
	Balance         float64    `json:"balance"`             // Balance of the account (at the moment of the deal is got from server)
	Equity          float64    `json:"equity"`              // Equity of the account (at the moment of the deal is got from server)
	Floating        float64    `json:"floating"`            // Floating of the account (at the moment of the deal is got from server)
	FreeMargin      float64    `json:"free_margin"`         // Free margin of the account (at the moment of the deal is got from server)
	Margin          float64    `json:"margin"`              // Margin of the account (at the moment of the deal is got from server)
	Credit          float64    `json:"credit"`              // Credit of the account (at the moment of the deal is got from server)
	Leverage        float64    `json:"leverage"`            // Leverage of the account (at the moment of the deal is got from server)
	Gateway         string     `json:"gateway"`             // Gateway If successful, it returns a pointer to the string with the identifier. If the gateway was not involved in the deal execution or no ID is set for the gateway, a zero value is returned.
	Reason          DealReason `json:"reason"`              // Reason of the deal. The reasons for transaction are listed in
	Dealer          uint64     `json:"dealer"`              // Dealer - The login of a dealer, who has processed a deal. If a deal was processed automatically by the server, 0 is returned.
	AccountAgent    uint64     `json:"agent"`               // Agent account number.
	AccountIDNumber string     `json:"account"`             // If successful, it returns a pointer to a string with the account number. Otherwise, it returns an empty string.
	Execution       Execution  `json:"execution"`           //
	ContractSize    float64    `json:"contract_size"`       //
	CalcMode        CalcMode   `json:"calc_mode"`           //
	TsFromMT        int64      `json:"time_from_mt"`        // Metrics: Time when the deal was received from MT
	TsSentNATS      int64      `json:"time_sent_nats"`      // Metrics: Time when the deal was sent to NATS
	TsReceivedDeals int64      `json:"time_received_deals"` // Filled in locally. Metrics: Time when the deal was received from NATS
	TsSentDB        int64      `json:"time_sent_db"`        // Filled in locally. Metrics: Time when the deal was sent to DB
	Type            DealType   `json:"type"`                // Type the order, can 0 - for buy and 1 for sale
}

The deal_type (UInt64) can be the following:

value
description

DEAL_BUY

0

buy

DEAL_SELL

1

sell

DEAL_BALANCE

2

deposit operation

DEAL_CREDIT

3

credit operation

DEAL_CHARGE

4

additional charges/withdrawals

DEAL_CORRECTION

5

correction deals

DEAL_BONUS

6

bonus

DEAL_COMMISSION

7

commission

DEAL_COMMISSION_DAILY

8

daily commission

DEAL_COMMISSION_MONTHLY

9

monthly commission

DEAL_AGENT_DAILY

10

daily agent commission

DEAL_AGENT_MONTHLY

11

monthly agent commission

DEAL_INTERESTRATE

12

interest rate charges

DEAL_BUY_CANCELED

13

canceled buy deal

DEAL_SELL_CANCELED

14

canceled sell deal

DEAL_DIVIDEND

15

dividend operations

DEAL_DIVIDEND_FRANKED

16

franked dividend

DEAL_TAX

17

taxes

DEAL_AGENT

18

instant agent commission

DEAL_SO_COMPENSATION

19

negative balance compensation after stop-out

DEAL_SO_COMPENSATION_CREDIT

20

credit compensation after stop-out

Example of Deal:

Last updated