fragment OrderFields on Order {
  id
  market {
    id
  }
  type
  side
  size
  status
  rejectionReason
  price
  timeInForce
  remaining
  expiresAt
  createdAt
  updatedAt
  postOnly
  reduceOnly
  liquidityProvision {
    __typename
  }
  peggedOrder {
    __typename
    reference
    offset
  }
  icebergOrder {
    __typename
    peakSize
    minimumVisibleSize
    reservedRemaining
  }
}

query OrderById($orderId: ID!) {
  orderByID(id: $orderId) {
    ...OrderFields
  }
}

query Orders(
  $partyId: ID!
  $marketIds: [ID!]
  $pagination: Pagination
  $filter: OrderFilter
) {
  party(id: $partyId) {
    id
    ordersConnection(
      pagination: $pagination
      filter: { order: $filter, marketIds: $marketIds }
    ) {
      edges {
        node {
          ...OrderFields
        }
        cursor
      }
      pageInfo {
        startCursor
        endCursor
        hasNextPage
        hasPreviousPage
      }
    }
  }
}

fragment OrderUpdateFields on OrderUpdate {
  id
  marketId
  type
  side
  size
  status
  rejectionReason
  price
  timeInForce
  remaining
  expiresAt
  createdAt
  updatedAt
  liquidityProvisionId
  peggedOrder {
    __typename
    reference
    offset
  }
  icebergOrder {
    __typename
    peakSize
    minimumVisibleSize
    reservedRemaining
  }
}

subscription OrdersUpdate($partyId: ID!, $marketIds: [ID!]) {
  orders(filter: { partyIds: [$partyId], marketIds: $marketIds }) {
    ...OrderUpdateFields
  }
}

fragment OrderSubmissionFields on OrderSubmission {
  marketId
  price
  size
  side
  timeInForce
  expiresAt
  type
  reference
  peggedOrder {
    reference
    offset
  }
  postOnly
  reduceOnly
}

fragment StopOrderFields on StopOrder {
  id
  ocoLinkId
  expiresAt
  expiryStrategy
  triggerDirection
  status
  createdAt
  updatedAt
  partyId
  marketId
  order {
    ...OrderFields
  }
  trigger {
    ... on StopOrderPrice {
      price
    }
    ... on StopOrderTrailingPercentOffset {
      trailingPercentOffset
    }
  }
  submission {
    ...OrderSubmissionFields
  }
}

query StopOrders($filter: StopOrderFilter) {
  stopOrders(filter: $filter) {
    edges {
      node {
        ...StopOrderFields
      }
    }
  }
}

query StopOrderById($stopOrderId: ID!) {
  stopOrder(id: $stopOrderId) {
    ...StopOrderFields
  }
}
