syntax = "proto3";

option java_multiple_files = true;
option java_package = "com.dexorder.proto";

// Single OHLC row
message OHLC {
  // Timestamp in nanoseconds since epoch
  uint64 timestamp = 1;

  // Prices are stored as integers (Nautilus-aligned with precision denominator).
  // Always non-null — ingestor forward-fills interior gaps with the previous close.
  int64 open = 2;
  int64 high = 3;
  int64 low = 4;
  int64 close = 5;
  optional int64 volume = 6;
  optional int64 buy_vol = 7;
  optional int64 sell_vol = 8;
  optional int64 open_time = 9;
  optional int64 high_time = 10;
  optional int64 low_time = 11;
  optional int64 close_time = 12;
  optional int64 open_interest = 13;
  string ticker = 14;  // Nautilus format: "BTC/USDT.BINANCE"
}

// Batch of OHLC rows with metadata for historical request tracking
// Used for Kafka messages from ingestor → Flink
message OHLCBatch {
  // Metadata for tracking this request through the pipeline
  OHLCBatchMetadata metadata = 1;

  // OHLC rows in this batch
  repeated OHLC rows = 2;
}

// Metadata for tracking historical data requests through the pipeline
message OHLCBatchMetadata {
  // Request ID from client
  string request_id = 1;

  // Optional client ID for notification routing
  optional string client_id = 2;

  // Market identifier
  string ticker = 3;

  // OHLC period in seconds
  uint32 period_seconds = 4;

  // Time range requested (nanoseconds since epoch)
  uint64 start_time = 5;
  uint64 end_time = 6;

  // Status for marker messages (OK, NOT_FOUND, ERROR)
  string status = 7;

  // Error message if status is ERROR
  optional string error_message = 8;

  // True on the final page of a historical query (including error/not-found markers).
  // Flink publishes HistoryReadyNotification only when this is true.
  bool is_last_page = 9;
}
