Documentation
¶
Index ¶
- Constants
- Variables
- func FromTime(t time.Time) int64
- func FromTimeMsc(t time.Time) int64
- func ToTime(unix int64) time.Time
- func ToTimeMsc(msc int64) time.Time
- type AccountInfo
- type BookEntry
- type BookType
- type CheckResult
- type Client
- func (c *Client) AccountInfo(ctx context.Context) (*AccountInfo, error)
- func (c *Client) Build() int
- func (c *Client) Close() error
- func (c *Client) Connected() bool
- func (c *Client) CopyRatesFrom(ctx context.Context, symbol string, timeframe Timeframe, dateFrom int64, ...) ([]Rate, error)
- func (c *Client) CopyRatesFromPos(ctx context.Context, symbol string, timeframe Timeframe, startPos, count int) ([]Rate, error)
- func (c *Client) CopyRatesRange(ctx context.Context, symbol string, timeframe Timeframe, ...) ([]Rate, error)
- func (c *Client) CopyTicksFrom(ctx context.Context, symbol string, dateFrom int64, count int, ...) ([]Tick, error)
- func (c *Client) CopyTicksRange(ctx context.Context, symbol string, dateFrom, dateTo int64, ...) ([]Tick, error)
- func (c *Client) HistoryDealsGet(ctx context.Context, filter *HistoryFilter) ([]Deal, error)
- func (c *Client) HistoryDealsTotal(ctx context.Context, dateFrom, dateTo int64) (int, error)
- func (c *Client) HistoryOrdersGet(ctx context.Context, filter *HistoryFilter) ([]Order, error)
- func (c *Client) HistoryOrdersTotal(ctx context.Context, dateFrom, dateTo int64) (int, error)
- func (c *Client) LastError() error
- func (c *Client) Login(ctx context.Context, login int64, password, server string) error
- func (c *Client) MarketBookAdd(ctx context.Context, symbol string) error
- func (c *Client) MarketBookGet(ctx context.Context, symbol string) ([]BookEntry, error)
- func (c *Client) MarketBookRelease(ctx context.Context, symbol string) error
- func (c *Client) OrderCalcMargin(ctx context.Context, action TradeAction, symbol string, volume, price float64) (float64, error)
- func (c *Client) OrderCalcProfit(ctx context.Context, action TradeAction, symbol string, ...) (float64, error)
- func (c *Client) OrderCheck(ctx context.Context, request TradeRequest) (*CheckResult, error)
- func (c *Client) OrderSend(ctx context.Context, request TradeRequest) (*TradeResult, error)
- func (c *Client) OrdersGet(ctx context.Context, filter *OrderFilter) ([]Order, error)
- func (c *Client) OrdersTotal(ctx context.Context) (int, error)
- func (c *Client) PositionsGet(ctx context.Context, filter *PositionFilter) ([]Position, error)
- func (c *Client) PositionsTotal(ctx context.Context) (int, error)
- func (c *Client) SendRaw(ctx context.Context, cmdID uint32, params []byte) ([]byte, error)
- func (c *Client) State() ConnState
- func (c *Client) SubscribeTicks(ctx context.Context, symbol string) (<-chan Tick, error)
- func (c *Client) SubscribeTicksWithErrors(ctx context.Context, symbol string) (<-chan Tick, <-chan error, error)
- func (c *Client) SymbolInfo(ctx context.Context, symbol string) (*SymbolInfo, error)
- func (c *Client) SymbolInfoTick(ctx context.Context, symbol string) (*Tick, error)
- func (c *Client) SymbolSelect(ctx context.Context, symbol string, enable bool) error
- func (c *Client) SymbolsGet(ctx context.Context, group string) ([]SymbolInfo, error)
- func (c *Client) SymbolsTotal(ctx context.Context) (int, error)
- func (c *Client) TerminalInfo(ctx context.Context) (*TerminalInfo, error)
- func (c *Client) UnsubscribeTicks(symbol string) error
- func (c *Client) Version(ctx context.Context) (*VersionInfo, error)
- type ConnState
- type CopyTicksFlag
- type Deal
- type DealEntry
- type DealType
- type DisconnectHook
- type HistoryFilter
- type Logger
- type MT5Error
- type Option
- func WithAutoReconnect(enabled bool) Option
- func WithDebug(enabled bool) Option
- func WithHeartbeatInterval(d time.Duration) Option
- func WithLogger(l Logger) Option
- func WithOnDisconnect(hook DisconnectHook) Option
- func WithOnReconnect(hook ReconnectHook) Option
- func WithOnRequest(hook RequestHook) Option
- func WithPipeName(name string) Option
- func WithReconnectConfig(initial, max time.Duration, maxRetries int) Option
- func WithTickBufferSize(size int) Option
- func WithTickPollInterval(d time.Duration) Option
- func WithTimeout(d time.Duration) Option
- type Order
- type OrderFilling
- type OrderFilter
- type OrderTime
- type OrderType
- type Position
- type PositionFilter
- type PositionType
- type Rate
- type ReconnectConfig
- type ReconnectHook
- type RequestHook
- type SymbolInfo
- type TerminalInfo
- type Tick
- type Timeframe
- type TradeAction
- type TradeError
- type TradeRequest
- type TradeResult
- type VersionInfo
Constants ¶
View Source
const ( ResOK = 1 ResEFail = -1 ResEInvalidParams = -2 ResENoMemory = -3 ResENotFound = -4 ResEInvalidVersion = -5 ResEAuthFailed = -6 ResEUnsupported = -7 ResEAutoTradingDisabled = -8 ResEInternalFail = -10000 ResEInternalFailSend = -10001 ResEInternalFailReceive = -10002 ResEInternalFailInit = -10003 ResEInternalFailConnect = -10004 ResEInternalFailTimeout = -10005 )
View Source
const ( RetcodeOK uint32 = 10009 RetcodeDone uint32 = 10008 RetcodeRequote uint32 = 10004 RetcodeReject uint32 = 10006 RetcodeCancel uint32 = 10007 RetcodeInvalidFill uint32 = 10030 RetcodeInvalidVolume uint32 = 10015 RetcodeInvalidPrice uint32 = 10016 RetcodeInvalidStops uint32 = 10017 RetcodeTradeDisabled uint32 = 10018 RetcodeMarketClosed uint32 = 10019 RetcodeNoQuotes uint32 = 10024 RetcodeTooManyOrders uint32 = 10028 )
Variables ¶
View Source
var ( ErrNotConnected = errors.New("mt5: not connected") ErrTimeout = errors.New("mt5: request timeout") ErrWindows = errors.New("mt5: native pipe requires Windows") ErrFailed = errors.New("mt5: request failed") ErrDisconnected = errors.New("mt5: disconnected") ErrReconnecting = errors.New("mt5: reconnecting") ErrTerminalClose = errors.New("mt5: terminal closed") ErrTradeDisabled = errors.New("mt5: trading disabled") )
Functions ¶
func FromTimeMsc ¶ added in v0.1.1
Types ¶
type AccountInfo ¶
type AccountInfo struct {
Login int64 `json:"login"`
TradeMode int64 `json:"trade_mode"`
Leverage int64 `json:"leverage"`
LimitOrders int64 `json:"limit_orders"`
MarginSOMode int64 `json:"margin_so_mode"`
TradeAllowed bool `json:"trade_allowed"`
TradeExpert bool `json:"trade_expert"`
MarginMode int64 `json:"margin_mode"`
CurrencyDigits int64 `json:"currency_digits"`
FIFOClose bool `json:"fifo_close"`
Balance float64 `json:"balance"`
Credit float64 `json:"credit"`
Profit float64 `json:"profit"`
Equity float64 `json:"equity"`
Margin float64 `json:"margin"`
FreeMargin float64 `json:"free_margin"`
MarginLevel float64 `json:"margin_level"`
MarginSOCall float64 `json:"margin_so_call"`
MarginSOSO float64 `json:"margin_so_so"`
MarginInitial float64 `json:"margin_initial"`
MarginMaintenance float64 `json:"margin_maintenance"`
Assets float64 `json:"assets"`
Liabilities float64 `json:"liabilities"`
CommissionBlocked float64 `json:"commission_blocked"`
Name string `json:"name"`
Server string `json:"server"`
Currency string `json:"currency"`
Company string `json:"company"`
}
type CheckResult ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func NewClientFromConn ¶
func (*Client) AccountInfo ¶
func (c *Client) AccountInfo(ctx context.Context) (*AccountInfo, error)
func (*Client) CopyRatesFrom ¶
func (*Client) CopyRatesFromPos ¶
func (*Client) CopyRatesRange ¶
func (*Client) CopyTicksFrom ¶
func (*Client) CopyTicksRange ¶
func (*Client) HistoryDealsGet ¶
func (*Client) HistoryDealsTotal ¶
func (*Client) HistoryOrdersGet ¶
func (*Client) HistoryOrdersTotal ¶
func (*Client) MarketBookAdd ¶ added in v0.1.1
func (*Client) MarketBookGet ¶ added in v0.1.1
func (*Client) MarketBookRelease ¶ added in v0.1.1
func (*Client) OrderCalcMargin ¶
func (*Client) OrderCalcProfit ¶
func (*Client) OrderCheck ¶
func (c *Client) OrderCheck(ctx context.Context, request TradeRequest) (*CheckResult, error)
func (*Client) OrderSend ¶
func (c *Client) OrderSend(ctx context.Context, request TradeRequest) (*TradeResult, error)
func (*Client) PositionsGet ¶
func (*Client) SubscribeTicks ¶ added in v0.1.1
func (*Client) SubscribeTicksWithErrors ¶ added in v0.1.1
func (*Client) SymbolInfo ¶
func (*Client) SymbolInfoTick ¶
func (*Client) SymbolSelect ¶ added in v0.1.1
func (*Client) SymbolsGet ¶ added in v0.1.1
func (*Client) TerminalInfo ¶
func (c *Client) TerminalInfo(ctx context.Context) (*TerminalInfo, error)
func (*Client) UnsubscribeTicks ¶ added in v0.1.1
type CopyTicksFlag ¶
type CopyTicksFlag int
const ( CopyTicksAll CopyTicksFlag = -1 CopyTicksInfo CopyTicksFlag = 1 CopyTicksTrade CopyTicksFlag = 2 )
func (CopyTicksFlag) String ¶ added in v0.1.1
func (f CopyTicksFlag) String() string
type Deal ¶
type Deal struct {
Ticket int64 `json:"ticket"`
Order int64 `json:"order"`
Time int64 `json:"time"`
TimeMsc int64 `json:"time_msc"`
Type DealType `json:"type"`
Entry DealEntry `json:"entry"`
Magic int64 `json:"magic"`
PositionID int64 `json:"position_id"`
Reason int64 `json:"reason"`
Volume float64 `json:"volume"`
Price float64 `json:"price"`
Commission float64 `json:"commission"`
Swap float64 `json:"swap"`
Profit float64 `json:"profit"`
Fee float64 `json:"fee"`
Symbol string `json:"symbol"`
Comment string `json:"comment"`
ExternalID string `json:"external_id"`
}
type DealType ¶
type DealType int
const ( DealTypeBuy DealType = 0 DealTypeSell DealType = 1 DealTypeBalance DealType = 2 DealTypeCredit DealType = 3 DealTypeCharge DealType = 4 DealTypeCorrection DealType = 5 DealTypeBonus DealType = 6 DealTypeCommission DealType = 7 DealTypeCommissionDaily DealType = 8 DealTypeCommissionMonthly DealType = 9 DealTypeCommissionAgent DealType = 10 DealTypeInterest DealType = 11 DealTypeBuyCanceled DealType = 12 DealTypeSellCanceled DealType = 13 DealTypeDividend DealType = 14 DealTypeDividendFranked DealType = 15 DealTypeTax DealType = 16 )
type DisconnectHook ¶ added in v0.1.1
type DisconnectHook func(err error)
type HistoryFilter ¶ added in v0.1.1
type Option ¶
type Option func(*options)
func WithAutoReconnect ¶ added in v0.1.1
func WithHeartbeatInterval ¶ added in v0.1.1
func WithLogger ¶ added in v0.1.1
func WithOnDisconnect ¶ added in v0.1.1
func WithOnDisconnect(hook DisconnectHook) Option
func WithOnReconnect ¶ added in v0.1.1
func WithOnReconnect(hook ReconnectHook) Option
func WithOnRequest ¶ added in v0.1.1
func WithOnRequest(hook RequestHook) Option
func WithPipeName ¶
func WithReconnectConfig ¶ added in v0.1.1
func WithTickBufferSize ¶ added in v0.1.1
func WithTickPollInterval ¶ added in v0.1.1
func WithTimeout ¶
type Order ¶
type Order struct {
Ticket int64 `json:"ticket"`
TimeSetup int64 `json:"time_setup"`
TimeSetupMsc int64 `json:"time_setup_msc"`
TimeDone int64 `json:"time_done"`
TimeDoneMsc int64 `json:"time_done_msc"`
TimeExpiration int64 `json:"time_expiration"`
Type OrderType `json:"type"`
TypeTime OrderTime `json:"type_time"`
TypeFilling OrderFilling `json:"type_filling"`
State int64 `json:"state"`
Magic int64 `json:"magic"`
PositionID int64 `json:"position_id"`
PositionByID int64 `json:"position_by_id"`
Reason int64 `json:"reason"`
VolumeInitial float64 `json:"volume_initial"`
VolumeCurrent float64 `json:"volume_current"`
PriceOpen float64 `json:"price_open"`
PriceCurrent float64 `json:"price_current"`
PriceSL float64 `json:"price_sl"`
PriceTP float64 `json:"price_tp"`
PriceStopLimit float64 `json:"price_stoplimit"`
Symbol string `json:"symbol"`
Comment string `json:"comment"`
ExternalID string `json:"external_id"`
}
func (*Order) TimeDoneUTC ¶ added in v0.1.1
func (*Order) TimeSetupUTC ¶ added in v0.1.1
type OrderFilling ¶
type OrderFilling int
const ( OrderFillingFOK OrderFilling = 0 OrderFillingIOC OrderFilling = 1 OrderFillingReturn OrderFilling = 2 OrderFillingBOC OrderFilling = 3 )
func (OrderFilling) String ¶ added in v0.1.1
func (f OrderFilling) String() string
type OrderFilter ¶ added in v0.1.1
type Position ¶
type Position struct {
Ticket int64 `json:"ticket"`
Time int64 `json:"time"`
TimeMsc int64 `json:"time_msc"`
TimeUpdate int64 `json:"time_update"`
TimeUpdateMsc int64 `json:"time_update_msc"`
Type PositionType `json:"type"`
Magic int64 `json:"magic"`
Identifier int64 `json:"identifier"`
Reason int64 `json:"reason"`
Volume float64 `json:"volume"`
PriceOpen float64 `json:"price_open"`
PriceCurrent float64 `json:"price_current"`
PriceSL float64 `json:"price_sl"`
PriceTP float64 `json:"price_tp"`
Swap float64 `json:"swap"`
Profit float64 `json:"profit"`
Symbol string `json:"symbol"`
Comment string `json:"comment"`
ExternalID string `json:"external_id"`
}
func (*Position) TimeUpdateUTC ¶ added in v0.1.1
type PositionFilter ¶ added in v0.1.1
type PositionType ¶
type PositionType int
const ( PositionTypeBuy PositionType = 0 PositionTypeSell PositionType = 1 )
func (PositionType) String ¶ added in v0.1.1
func (p PositionType) String() string
type Rate ¶
type ReconnectConfig ¶ added in v0.1.1
type ReconnectHook ¶ added in v0.1.1
type ReconnectHook func()
type RequestHook ¶ added in v0.1.1
type SymbolInfo ¶
type SymbolInfo struct {
Custom bool `json:"custom"`
ChartMode int64 `json:"chart_mode"`
Select bool `json:"select"`
Visible bool `json:"visible"`
SessionDeals int64 `json:"session_deals"`
SessionBuyOrders int64 `json:"session_buy_orders"`
SessionSellOrders int64 `json:"session_sell_orders"`
Volume int64 `json:"volume"`
VolumeHigh int64 `json:"volumehigh"`
VolumeLow int64 `json:"volumelow"`
Time int64 `json:"time"`
Digits int64 `json:"digits"`
Spread int64 `json:"spread"`
SpreadFloat bool `json:"spread_float"`
TicksBookDepth int64 `json:"ticks_bookdepth"`
TradeCalcMode int64 `json:"trade_calc_mode"`
TradeMode int64 `json:"trade_mode"`
StartTime int64 `json:"start_time"`
ExpirationTime int64 `json:"expiration_time"`
TradeStopsLevel int64 `json:"trade_stops_level"`
TradeFreezeLevel int64 `json:"trade_freeze_level"`
TradeExeMode int64 `json:"trade_exemode"`
SwapMode int64 `json:"swap_mode"`
SwapRollover3Days int64 `json:"swap_rollover3days"`
MarginHedgedUseLeg bool `json:"margin_hedged_use_leg"`
ExpirationMode int64 `json:"expiration_mode"`
FillingMode int64 `json:"filling_mode"`
OrderMode int64 `json:"order_mode"`
OrderGTCMode int64 `json:"order_gtc_mode"`
OptionMode int64 `json:"option_mode"`
OptionRight int64 `json:"option_right"`
Bid float64 `json:"bid"`
BidHigh float64 `json:"bidhigh"`
BidLow float64 `json:"bidlow"`
Ask float64 `json:"ask"`
AskHigh float64 `json:"askhigh"`
AskLow float64 `json:"asklow"`
Last float64 `json:"last"`
LastHigh float64 `json:"lasthigh"`
LastLow float64 `json:"lastlow"`
VolumeReal float64 `json:"volume_real"`
VolumeHighReal float64 `json:"volumehigh_real"`
VolumeLowReal float64 `json:"volumelow_real"`
OptionStrike float64 `json:"option_strike"`
Point float64 `json:"point"`
TradeTickValue float64 `json:"trade_tick_value"`
TradeTickValueProfit float64 `json:"trade_tick_value_profit"`
TradeTickValueLoss float64 `json:"trade_tick_value_loss"`
TradeTickSize float64 `json:"trade_tick_size"`
TradeContractSize float64 `json:"trade_contract_size"`
TradeAccruedInterest float64 `json:"trade_accrued_interest"`
TradeFaceValue float64 `json:"trade_face_value"`
TradeLiquidityRate float64 `json:"trade_liquidity_rate"`
VolumeMin float64 `json:"volume_min"`
VolumeMax float64 `json:"volume_max"`
VolumeStep float64 `json:"volume_step"`
VolumeLimit float64 `json:"volume_limit"`
SwapLong float64 `json:"swap_long"`
SwapShort float64 `json:"swap_short"`
MarginInitial float64 `json:"margin_initial"`
MarginMaintenance float64 `json:"margin_maintenance"`
SessionVolume float64 `json:"session_volume"`
SessionTurnover float64 `json:"session_turnover"`
SessionInterest float64 `json:"session_interest"`
SessionBuyOrdersVolume float64 `json:"session_buy_orders_volume"`
SessionSellOrdersVolume float64 `json:"session_sell_orders_volume"`
SessionOpen float64 `json:"session_open"`
SessionClose float64 `json:"session_close"`
SessionAW float64 `json:"session_aw"`
SessionPriceSettlement float64 `json:"session_price_settlement"`
SessionPriceLimitMin float64 `json:"session_price_limit_min"`
SessionPriceLimitMax float64 `json:"session_price_limit_max"`
MarginHedged float64 `json:"margin_hedged"`
PriceChange float64 `json:"price_change"`
PriceVolatility float64 `json:"price_volatility"`
PriceTheoretical float64 `json:"price_theoretical"`
PriceGreeksDelta float64 `json:"price_greeks_delta"`
PriceGreeksTheta float64 `json:"price_greeks_theta"`
PriceGreeksGamma float64 `json:"price_greeks_gamma"`
PriceGreeksVega float64 `json:"price_greeks_vega"`
PriceGreeksRho float64 `json:"price_greeks_rho"`
PriceGreeksOmega float64 `json:"price_greeks_omega"`
PriceSensitivity float64 `json:"price_sensitivity"`
Basis string `json:"basis"`
Category string `json:"category"`
CurrencyBase string `json:"currency_base"`
CurrencyProfit string `json:"currency_profit"`
CurrencyMargin string `json:"currency_margin"`
Bank string `json:"bank"`
Description string `json:"description"`
Exchange string `json:"exchange"`
Formula string `json:"formula"`
ISIN string `json:"isin"`
SymbolName string `json:"name"`
Page string `json:"page"`
Path string `json:"path"`
}
type TerminalInfo ¶
type TerminalInfo struct {
CommunityAccount bool `json:"community_account"`
CommunityConnection bool `json:"community_connection"`
Connected bool `json:"connected"`
DLLsAllowed bool `json:"dlls_allowed"`
TradeAllowed bool `json:"trade_allowed"`
TradeAPIDisabled bool `json:"tradeapi_disabled"`
EmailEnabled bool `json:"email_enabled"`
FTPEnabled bool `json:"ftp_enabled"`
NotificationsEnabled bool `json:"notifications_enabled"`
MQID bool `json:"mqid"`
Build int64 `json:"build"`
MaxBars int64 `json:"maxbars"`
CodePage int64 `json:"codepage"`
PingLast int64 `json:"ping_last"`
CommunityBalance float64 `json:"community_balance"`
Retransmission float64 `json:"retransmission"`
Company string `json:"company"`
Name string `json:"name"`
Language string `json:"language"`
Path string `json:"path"`
DataPath string `json:"data_path"`
CommonDataPath string `json:"commondata_path"`
}
type Tick ¶
type Timeframe ¶
type Timeframe int
const ( TimeframeM1 Timeframe = 1 TimeframeM2 Timeframe = 2 TimeframeM3 Timeframe = 3 TimeframeM4 Timeframe = 4 TimeframeM5 Timeframe = 5 TimeframeM6 Timeframe = 6 TimeframeM10 Timeframe = 10 TimeframeM12 Timeframe = 12 TimeframeM15 Timeframe = 15 TimeframeM20 Timeframe = 20 TimeframeM30 Timeframe = 30 TimeframeH1 Timeframe = 16385 TimeframeH2 Timeframe = 16386 TimeframeH3 Timeframe = 16387 TimeframeH4 Timeframe = 16388 TimeframeH6 Timeframe = 16390 TimeframeH8 Timeframe = 16392 TimeframeH12 Timeframe = 16396 TimeframeD1 Timeframe = 16408 TimeframeW1 Timeframe = 32769 TimeframeMN1 Timeframe = 49153 )
type TradeAction ¶
type TradeAction int
const ( TradeActionDeal TradeAction = 1 TradeActionPending TradeAction = 5 TradeActionSLTP TradeAction = 6 TradeActionModify TradeAction = 7 TradeActionRemove TradeAction = 8 TradeActionCloseBy TradeAction = 10 )
func (TradeAction) String ¶ added in v0.1.1
func (a TradeAction) String() string
type TradeError ¶ added in v0.1.1
type TradeError struct {
Result TradeResult
Request TradeRequest
}
func (*TradeError) Error ¶ added in v0.1.1
func (e *TradeError) Error() string
type TradeRequest ¶
type TradeRequest struct {
Action TradeAction `json:"action"`
Magic int64 `json:"magic,omitempty"`
Order int64 `json:"order,omitempty"`
Symbol string `json:"symbol,omitempty"`
Volume float64 `json:"volume,omitempty"`
Price float64 `json:"price,omitempty"`
StopLimit float64 `json:"stoplimit,omitempty"`
SL float64 `json:"sl,omitempty"`
TP float64 `json:"tp,omitempty"`
Deviation int `json:"deviation,omitempty"`
Type OrderType `json:"type,omitempty"`
TypeFilling OrderFilling `json:"type_filling,omitempty"`
TypeTime OrderTime `json:"type_time,omitempty"`
Expiration int64 `json:"expiration,omitempty"`
Comment string `json:"comment,omitempty"`
Position int64 `json:"position,omitempty"`
PositionBy int64 `json:"position_by,omitempty"`
}
func (*TradeRequest) Validate ¶ added in v0.1.1
func (r *TradeRequest) Validate() error
type TradeResult ¶
type TradeResult struct {
Retcode uint32 `json:"retcode"`
Deal int64 `json:"deal"`
Order int64 `json:"order"`
Volume float64 `json:"volume"`
Price float64 `json:"price"`
Bid float64 `json:"bid"`
Ask float64 `json:"ask"`
Comment string `json:"comment"`
RequestID uint32 `json:"request_id"`
RetcodeExt int32 `json:"retcode_external"`
}
func (*TradeResult) IsOK ¶ added in v0.1.1
func (r *TradeResult) IsOK() bool
type VersionInfo ¶
Source Files
¶
Click to show internal directories.
Click to hide internal directories.