Get Market Data
Retrieve current market data for a specific instrument, including bids, offers, last price, and more.
public async Task < MarketDataRestApi > GetMarketData (
Instrument instrument ,
short depth = 5 ,
Entry [] entries = null
)
public async Task < MarketDataRestApi > GetMarketData (
string marketId ,
string symbol ,
short depth = 5 ,
Entry [] entries = null
)
Parameters
The instrument to get market data for
Market identifier (e.g., “ROFX”, “MERV”)
Order book depth (number of price levels)
entries
Entry[]
default: "all entries"
Specific market data entries to retrieve. If null, all entries are returned. Available entries: Bids, Offers, Last, Open, Close, SettlementPrice, SessionHighPrice, SessionLowPrice, Volume, OpenInterest, IndexValue, EffectiveVolume, NominalVolume
Response
HTTP status code of the response
Whether data is aggregated
Market data entries object containing: Best buy offers in the order book
Best sell offers in the order book
Last traded price and size
Settlement price (futures only)
Open interest (futures only)
Index value (indices only)
Example
using Primary ;
using Primary . Data ;
var api = new Api ( Api . DemoEndpoint );
await api . Login ( Api . DemoUsername , Api . DemoPassword );
// Get all instruments
var instruments = await api . GetAllInstruments ();
var instrument = instruments . First ();
// Get market data with default depth (5)
var marketData = await api . GetMarketData ( instrument );
// Access bid/offer data
if ( marketData . Data . HasBids ())
{
decimal topBidPrice = marketData . Data . GetTopBidPrice ();
decimal topBidSize = marketData . Data . GetTopBidSize ();
Console . WriteLine ( $"Top Bid: { topBidPrice } x { topBidSize } " );
}
if ( marketData . Data . HasOffers ())
{
decimal topOfferPrice = marketData . Data . GetTopOfferPrice ();
decimal topOfferSize = marketData . Data . GetTopOfferSize ();
Console . WriteLine ( $"Top Offer: { topOfferPrice } x { topOfferSize } " );
}
// Access last traded price
if ( marketData . Data . HasLastPrice ())
{
Console . WriteLine ( $"Last: { marketData . Data . Last . Price } " );
}
Get Specific Entries
// Only get last price and volume
var entries = new [] { Entry . Last , Entry . Volume };
var marketData = await api . GetMarketData ( instrument , depth : 1 , entries : entries );
Console . WriteLine ( $"Last Price: { marketData . Data . Last ? . Price } " );
Console . WriteLine ( $"Volume: { marketData . Data . Volume } " );
Deep Order Book
// Get 10 levels of depth
var marketData = await api . GetMarketData ( instrument , depth : 10 );
// Display all bid levels
foreach ( var bid in marketData . Data . Bids )
{
Console . WriteLine ( $"Bid: { bid . Price } x { bid . Size } " );
}
// Display all offer levels
foreach ( var offer in marketData . Data . Offers )
{
Console . WriteLine ( $"Offer: { offer . Price } x { offer . Size } " );
}
Get Historical Trades
Retrieve historical trade data for a specific instrument and date range.
public async Task < IEnumerable < Trade >> GetHistoricalTrades (
Instrument instrument ,
DateTime dateFrom ,
DateTime dateTo
)
Parameters
Instrument to get trade history for
Start date for historical data (format: yyyy-MM-dd)
End date for historical data (format: yyyy-MM-dd)
Response
Returns an IEnumerable<Trade> where each Trade contains:
Server timestamp in Unix epoch format
Example
var instrument = new Instrument
{
Market = "MERV" ,
Symbol = "MERV - XMEV - GGAL - 48hs"
};
var dateFrom = new DateTime ( 2024 , 1 , 1 );
var dateTo = new DateTime ( 2024 , 1 , 31 );
try
{
var trades = await api . GetHistoricalTrades ( instrument , dateFrom , dateTo );
foreach ( var trade in trades )
{
Console . WriteLine ( $" { trade . DateTime } : { trade . Size } @ { trade . Price } " );
}
// Calculate statistics
decimal avgPrice = trades . Average ( t => t . Price );
decimal totalVolume = trades . Sum ( t => t . Size );
Console . WriteLine ( $"Average Price: { avgPrice } " );
Console . WriteLine ( $"Total Volume: { totalVolume } " );
}
catch ( Exception ex )
{
Console . WriteLine ( $"Error: { ex . Message } " );
}
Notes
The historical trades endpoint internally uses marketId = "MERV" and external = 1 parameters for data retrieval.
Large date ranges may return significant amounts of data. Consider paginating or limiting your date range for better performance.
Market Data Entries
The Entry enum defines all available market data types:
Entry Description BidsBest buy offers in the Market Book OffersBest sell offers in the Market Book LastLast price traded in the Market Book OpenOpening price in the Market Book CloseClosing price in the Market Book SettlementPriceSettlement price (only for futures) SessionHighPriceHighest price traded SessionLowPriceLowest price traded VolumeTraded volume in contracts/nominal OpenInterestOpen interest in contracts (only for futures) IndexValueCalculated index value (only for indices) EffectiveVolumeEffective traded volume NominalVolumeNominal traded volume
Helper Methods
The Entries class provides convenient helper methods:
// Check if data is available
bool hasBids = marketData . Data . HasBids ();
bool hasOffers = marketData . Data . HasOffers ();
bool hasLastPrice = marketData . Data . HasLastPrice ();
// Get top of book
decimal topBidPrice = marketData . Data . GetTopBidPrice ();
decimal topBidSize = marketData . Data . GetTopBidSize ();
decimal topOfferPrice = marketData . Data . GetTopOfferPrice ();
decimal topOfferSize = marketData . Data . GetTopOfferSize ();
API Endpoint
The market data methods use the following REST endpoint:
GET {BaseUri}/rest/marketdata/get?symbol={symbol}&marketId={marketId}&entries={entries}&depth={depth}