fragment DataSourceFilter on Filter {
  key {
    name
    type
    numberDecimalPlaces
  }
}

fragment DataSourceSpec on DataSourceDefinition {
  sourceType {
    ... on DataSourceDefinitionExternal {
      sourceType {
        ... on DataSourceSpecConfiguration {
          signers {
            signer {
              ... on PubKey {
                key
              }
              ... on ETHAddress {
                address
              }
            }
          }
          filters {
            ...DataSourceFilter
          }
        }
      }
    }
  }
}

fragment MarketFields on Market {
  id
  decimalPlaces
  positionDecimalPlaces
  state
  tradingMode
  fees {
    factors {
      makerFee
      infrastructureFee
      liquidityFee
    }
  }
  tradableInstrument {
    instrument {
      id
      name
      code
      metadata {
        tags
      }
      product {
        ... on Future {
          settlementAsset {
            id
            symbol
            name
            decimals
            quantum
          }
          quoteName
          dataSourceSpecForTradingTermination {
            id
            data {
              ...DataSourceSpec
            }
          }
          dataSourceSpecForSettlementData {
            id
            data {
              ...DataSourceSpec
            }
          }
          dataSourceSpecBinding {
            settlementDataProperty
            tradingTerminationProperty
          }
        }
      }
    }
  }
  marketTimestamps {
    open
    close
  }
}

query Markets {
  marketsConnection {
    edges {
      node {
        ...MarketFields
      }
    }
  }
}
