Skip to content

Ticks

Raw tick data retrieval services.


Models

Tick

Tick

Bases: BaseModel

A single price tick from the MT5 market data feed.

Wraps the raw tick struct returned by mt5.copy_ticks_from() and mt5.copy_ticks_range(). Each tick represents one price update event; not all fields are updated on every tick β€” the flags bitmask indicates which prices changed.

ATTRIBUTE DESCRIPTION
time

Tick time as a Unix timestamp (seconds).

TYPE: int

bid

Current bid price.

TYPE: float

ask

Current ask price.

TYPE: float

last

Last trade price (exchange instruments only; 0.0 for Forex).

TYPE: float

volume

Last trade volume (exchange instruments only; 0 for Forex).

TYPE: int

time_msc

Tick time in milliseconds.

TYPE: int

flags

Bitmask of TICK_FLAG_* constants indicating which fields were updated in this tick.

TYPE: int

volume_real

Last trade volume as a fractional value.

TYPE: float

spread property

spread: float

Current bid-ask spread in price units.

mid_price property

mid_price: float

Mid-point between bid and ask.

has_bid property

has_bid: bool

Whether this tick carries a bid price update (TICK_FLAG_BID).

has_ask property

has_ask: bool

Whether this tick carries an ask price update (TICK_FLAG_ASK).

has_last property

has_last: bool

Whether this tick carries a last trade price update (TICK_FLAG_LAST).


Service

TickService

TickService

Retrieves tick data from the MT5 terminal.

Wraps mt5.copy_ticks_from() and mt5.copy_ticks_range() via call_mt5, parses the raw tick structs (which may arrive as either attribute-bearing objects or plain dicts depending on the MT5 build) into Tick models, and returns Result[list[Tick]].


Usage

from datetime import datetime, timezone
from syntiq_mt5 import constants

date_from = datetime(2024, 1, 1, 9, 0, tzinfo=timezone.utc)

# Get ticks from a date
res = mt5.copy_ticks_from(
    "EURUSD",
    date_from,
    count=1000,
    flags=constants.COPY_TICKS_ALL,
)

# Get ticks in a range
date_to = datetime(2024, 1, 1, 10, 0, tzinfo=timezone.utc)
res = mt5.copy_ticks_range(
    "EURUSD",
    date_from,
    date_to,
    flags=constants.COPY_TICKS_INFO,
)