Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Stream Market Data With Classes
00:00
5 left

Stream Market Data With Classes

MediumSQL · PostgreSQL

Problem

Implement a class structure to manage a stream of incoming market data.

Treat each row in market_data as an incoming event. A usable event has non-null, positive bid and ask prices, with the bid no greater than the ask. Return the latest usable event for every known instrument.

Output

  1. One row per known instrument with at least one usable event.
  2. Columns: instrument_id, symbol, received_at, bid_price, ask_price, bid_size, ask_size.
  3. Sort by symbol ascending; for equal timestamps, use the highest event_id.

Schema

instruments
ColumnTypeDescription
instrument_idPKINTUnique instrument identifier
symbolVARCHAR(20)Tradable instrument symbol
asset_classVARCHAR(20)Instrument asset class
market_data
ColumnTypeDescription
event_idPKBIGINTUnique incoming market-data event
instrument_idINTReferenced instrument identifier
received_atTIMESTAMPTZTime the event was received
bid_priceNUMERIC(14,4)Best bid price
ask_priceNUMERIC(14,4)Best ask price
bid_sizeINTQuantity available at the bid
ask_sizeINTQuantity available at the ask
Tablesinstrumentsmarket_data
Interviewer

Your question is Stream Market Data With Classes. Start with the requirements and the two tables in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.