fragment PositionFields on Position {
  realisedPNL
  openVolume
  unrealisedPNL
  averageEntryPrice
  updatedAt
  positionStatus
  lossSocializationAmount
  market {
    id
  }
  party {
    id
  }
}

query Positions($partyIds: [ID!]!) {
  positions(filter: { partyIds: $partyIds }) {
    edges {
      node {
        ...PositionFields
      }
    }
  }
}

subscription PositionsSubscription($partyId: ID!) {
  positions(partyId: $partyId) {
    realisedPNL
    openVolume
    unrealisedPNL
    averageEntryPrice
    updatedAt
    marketId
    lossSocializationAmount
    positionStatus
    partyId
  }
}

query EstimatePosition(
  $marketId: ID!
  $openVolume: String!
  $orders: [OrderInfo!]
  $collateralAvailable: String
) {
  estimatePosition(
    marketId: $marketId
    openVolume: $openVolume
    orders: $orders
    collateralAvailable: $collateralAvailable
  ) {
    margin {
      worstCase {
        maintenanceLevel
        searchLevel
        initialLevel
        collateralReleaseLevel
      }
      bestCase {
        maintenanceLevel
        searchLevel
        initialLevel
        collateralReleaseLevel
      }
    }
    liquidation {
      worstCase {
        open_volume_only
        including_buy_orders
        including_sell_orders
      }
      bestCase {
        open_volume_only
        including_buy_orders
        including_sell_orders
      }
    }
  }
}
