syntax = "proto3";

package pragma_common;

enum InstrumentType {
  SPOT = 0;
  PERP = 1;
}

enum Chain {
  STARKNET = 0;
  SOLANA = 1;
  SUI = 2;
  APTOS = 3;
  ETHEREUM = 4;
  BASE = 5;
  ARBITRUM = 6;
  OPTIMISM = 7;
  ZKSYNC = 8;
  POLYGON = 9;
  BNB = 10;
  AVALANCHE = 11;
  GNOSIS = 12;
  WORLDCHAIN = 13;
}

enum UpdateType {
  TARGET = 0;
  DELTA = 1;
}

message OrderbookUpdateType {
  oneof update_type {
    UpdateType update = 1;
    bool snapshot = 2;
  }
}

enum TradeSide {
  BUY = 0;
  SELL = 1;
}

message UInt128 {
  uint64 low = 1;
  uint64 high = 2;
}

message Pair {
  string base = 1;
  string quote = 2;
}

message BidOrAsk {
  double price = 1;
  double quantity = 2;
}

message OrderbookData {
  uint64 update_id = 1;
  repeated BidOrAsk bids = 2;
  repeated BidOrAsk asks = 3;
}

message PriceEntry {
  string source = 1;
  oneof chainOption {
    bool noChain = 2;
    Chain chain = 3;
  }
  Pair pair = 4;
  int64 timestampMs = 5;
  UInt128 price = 6;
  UInt128 volume = 7;
  oneof expirationOption {
    bool noExpiration = 8;
    int64 expirationTimestamp = 9;
  }
  InstrumentType instrumentType = 10;
  int64 receivedTimestampMs = 11;
}

message OrderbookEntry {
  string source = 1;
  InstrumentType instrumentType = 2;
  Pair pair = 3;
  OrderbookUpdateType type = 4;
  OrderbookData data = 5;
  int64 timestampMs = 6;
  int64 receivedTimestampMs = 7;
}

message FundingRateEntry {
  string source = 1;
  Pair pair = 2;
  double annualizedRate = 3;
  int64 timestampMs = 4;
  InstrumentType instrumentType = 5;
  int64 receivedTimestampMs = 6;
}

message OpenInterestEntry {
  string source = 1;
  Pair pair = 2;
  double openInterest = 3;
  int64 timestampMs = 4;
  InstrumentType instrumentType = 5;
  int64 receivedTimestampMs = 6;
}

message VolumeEntry {
  string source = 1;
  InstrumentType instrumentType = 2;
  Pair pair = 3;
  double volumeDaily = 4;
  int64 timestampMs = 5;
  int64 receivedTimestampMs = 6;
}

message TradeEntry {
  string source = 1;
  InstrumentType instrumentType = 2;
  Pair pair = 3;
  string tradeId = 4;
  string buyerAddress = 5;
  string sellerAddress = 6;
  TradeSide side = 7;
  double size = 8;
  double price = 9;
  int64 timestampMs = 10;
  int64 receivedTimestampMs = 11;
}

message PositionEntry {
  string source = 1;
  InstrumentType instrumentType = 2;
  Pair pair = 3;
  int64 timestampMs = 4;
  int64 receivedTimestampMs = 5;
  TradeSide side = 6;
  double notional_in_usd = 7; 
  double size = 8; 
}

message GlobalExposureEntry {
  string source = 1;
  int64 timestamp_ms= 2;
  string asset = 3;
  double gross_position_size = 4; 
  double net_position_size = 5; 
}
