Package-level declarations

Types

Link copied to clipboard
data class ClosedPositionMeta(val clientOrderId: String, val strategyId: String)

Meta the poller needs to publish a useful close BrokerEvent.OrderFilled when a ticket disappears from the venue snapshot. Populated by MT5Broker as positions open (either synchronously from a Market/Bracket fill, or asynchronously when a pending order transitions to a position).

Link copied to clipboard
data class InstrumentSpec(val minVolume: BigDecimal, val volumeStep: BigDecimal, val pointSize: BigDecimal, val digits: Int, val tradeStopsLevelPoints: Int)

Per-instrument trading constraints reported by the venue. Used for size/price validation.

Link copied to clipboard
data class MT5AccountInfo(val balance: BigDecimal, val equity: BigDecimal, val currency: String, val leverage: Int)

Account-level snapshot from the MT5 venue — used for equity and leverage tracking.

Link copied to clipboard
class MT5Broker(profile: MT5BrokerProfile, bus: EventBus, clock: Clock, priceTracker: MarketPriceProvider? = null, client: MT5Client = MT5Client( gatewayUrl = profile.gatewayUrl, tzOffsetHours = profile.serverTzOffsetHours, httpTimeoutMs = profile.httpTimeoutMs, retryAttempts = profile.retryAttempts, )) : Broker

Routes orders to a MetaTrader 5 venue via an mt5-gateway HTTP service.

Link copied to clipboard
data class MT5BrokerProfile(val name: String, val gatewayUrl: String, val symbolPolicy: SymbolPolicy, val serverTzOffsetHours: Int = 0, val magic: Int, val instrumentOverrides: Map<String, InstrumentSpec> = emptyMap(), val pollIntervalMs: Long = 1000, val httpTimeoutMs: Long = 5000, val retryAttempts: Int = 3, val deviationPoints: Int = 20, val capabilityRestrictions: Set<OrderTypeCapability> = emptySet())

Per-venue configuration for an MT5Broker.

Link copied to clipboard

Resolves raw YAML broker entries from qkt.config.yaml into MT5BrokerProfiles.

Link copied to clipboard
class MT5Client(gatewayUrl: String, tzOffsetHours: Int, httpTimeoutMs: Long = 5000, retryAttempts: Int = 3)

Low-level HTTP client for the mt5-gateway service.

Link copied to clipboard

Built-in MT5BrokerProfile templates for common brokers.

Link copied to clipboard
data class MT5OrderModification(val price: BigDecimal? = null, val sl: BigDecimal? = null, val tp: BigDecimal? = null, val slDistance: Long? = null, val expiration: Long? = null)

Fields modifiable on a working order. Only non-null fields are sent.

Link copied to clipboard
data class MT5OrderRequest(val symbol: String, val volume: BigDecimal, val type: String, val price: BigDecimal? = null, val sl: BigDecimal? = null, val tp: BigDecimal? = null, val stopLimit: BigDecimal? = null, val slDistance: Long? = null, val deviation: Int = 20, val magic: Int, val comment: String, val expiration: Long? = null, val typeTime: String? = null)

JSON wire shape for POST /order to the gateway.

Link copied to clipboard
data class MT5OrderResponse(val result: MT5OrderResult, val errorMessage: String? = null)

Top-level response from POST /order.

Link copied to clipboard
data class MT5OrderResult(val retcode: Int, val order: Long, val deal: Long, val price: BigDecimal, val comment: String)

Inner result block of a venue order response — retcode is the MQL5 trade return code.

Link copied to clipboard
class MT5OrderTranslator(profile: MT5BrokerProfile, symbol: MT5Symbol, priceTracker: MarketPriceProvider? = null)

Converts qkt OrderRequests into the JSON wire shape understood by mt5-gateway.

Link copied to clipboard
data class MT5PendingOrder(val ticket: Long, val symbol: String, val type: String, val volume: BigDecimal, val priceOpen: BigDecimal, val sl: BigDecimal, val tp: BigDecimal, val magic: Int, val timeSetup: Long, val timeExpiration: Long, val comment: String? = null)

Pending (working) order reported by the gateway. Distinct from MT5Position which tracks filled positions. The pending order is consumed when it triggers (becoming a position) or expires/cancels (disappearing without becoming a position).

Link copied to clipboard
class MT5PendingOrderPoller(client: MT5Client, profile: MT5BrokerProfile, onPendingDisappeared: (Long) -> Unit? = null)

Polls the venue's /orders endpoint for working (pending) orders. Detects when a tracked ticket leaves the pending set — the disappearance can mean two things:

Link copied to clipboard
data class MT5Position(val ticket: Long, val symbol: String, val type: Int, val volume: BigDecimal, val priceOpen: BigDecimal, val sl: BigDecimal, val tp: BigDecimal, val profit: BigDecimal, val magic: Int, val openTime: Long, val comment: String? = null)

Open position on the venue, filtered by MT5BrokerProfile.magic during reconciliation.

Link copied to clipboard
class MT5PositionPoller(client: MT5Client, profile: MT5BrokerProfile, symbol: MT5Symbol, bus: EventBus, clock: Clock, onPositionOpened: (MT5Position) -> Unit? = null, closedTicketMeta: (Long) -> ClosedPositionMeta?? = null, priceProvider: MarketPriceProvider? = null)

Polls open MT5 positions and emits reconciliation events when they drift from local state.

Link copied to clipboard

Protocol-level capabilities for any MT5 venue.

Link copied to clipboard
class MT5StateRecovery(client: MT5Client, profile: MT5BrokerProfile, symbol: MT5Symbol, bus: EventBus)

On-startup state reconciliation for an MT5Broker.

Link copied to clipboard
class MT5Symbol(policy: SymbolPolicy)

Bidirectional translator between qkt-side symbols and broker-side MT5 symbols per a SymbolPolicy.

Link copied to clipboard
data class MT5SymbolInfo(val ask: BigDecimal, val bid: BigDecimal, val digits: Int, val point: BigDecimal, val tradeStopsLevel: Int, val volumeMin: BigDecimal, val volumeStep: BigDecimal)

Symbol metadata reported by the venue — used for size/price validation.

Link copied to clipboard
data class MT5Tick(val symbol: String, val bid: BigDecimal, val ask: BigDecimal, val time: Long)

Bid/ask tick reported by the gateway.

Link copied to clipboard
sealed interface MT5Translation

Result of translating a single qkt OrderRequest to the MT5 wire shape.

Link copied to clipboard
data class SymbolPolicy(val suffix: String = "", val aliases: Map<String, String> = emptyMap())

How a qkt symbol is translated to the broker's MT5 symbol.

Properties

Link copied to clipboard
const val MT5_TRADE_RETCODE_DONE: Int = 10009

MQL5 trade return code for a successful order (TRADE_RETCODE_DONE).

Functions

Link copied to clipboard

Returns true iff retcode indicates a successful order placement.