Consultas para Datos tipo Horizon/RPC
Horizon y RPC proporcionan puntos finales de API para recuperar datos de la red Stellar. Las siguientes consultas de ejemplo recuperan los mismos datos utilizando Hubble con el beneficio añadido de poder devolver datos históricos.
Cuentas
Los usuarios interactúan con la red Stellar a través de cuentas. Todo lo demás en el ledger—activos, ofertas, líneas de confianza, etc.—es propiedad de las cuentas, y las cuentas deben autorizar todos los cambios en el ledger a través de transacciones firmadas.
Obtén más información sobre cuentas.
Información general de cuentas y saldo de XLM
select
account_id
, sequence_number as sequence
, sequence_ledger
, sequence_time
, num_subentries
, home_domain
, last_modified_ledger
, balance
-- please see table schema for more available columns and data
from `crypto-stellar.crypto_stellar.accounts`
where true
-- equivalent account_id parameter
and account_id=<account_id>
-- filter to the specific date or date range
and batch_run_date between '2024-01-01' and '2024-01-02'
order by closed_at desc
Información sobre saldos de activos que no son XLM
select
account_id
, asset_code
, asset_issuer
, asset_type
, balance
-- please see table schema for more available columns and data
from `crypto-stellar.crypto_stellar.trust_lines`
where true
-- equivalent account_id parameter
and account_id=<account_id>
-- filter to the specific date or date range
and batch_run_date between '2024-01-01' and '2024-01-02'
order by closed_at desc
Información del firmante de la cuenta
select
account_id
, signer
-- please see table schema for more available columns and data
from `crypto-stellar.crypto_stellar.account_signers`
where true
-- equivalent account_id parameter
and account_id=<account_id>
-- filter to the specific date or date range
and batch_run_date between '2024-01-01' and '2024-01-02'
order by closed_at desc
Lista todas las cuentas
select
account_id
from `crypto-stellar.crypto_stellar_dbt.accounts_current`
where true
-- limit does not reduce the amount of data BigQuery queries
limit 1000
Recuperar las transacciones de una cuenta
select
id
, transaction_hash
, ledger_sequence
, operation_count
, successful
-- please see table schema for more available columns and data
from `crypto-stellar.crypto_stellar.history_transactions`
where true
-- equivalent account_id parameter
and account=<account_id>
-- highly recommended to provide a date range to reduce amount of data queried
and closed_at >= timestamp(current_date)
-- limit does not reduce the amount of data BigQuery queries
limit 1000
Recuperar las operaciones de una cuenta
select
op_account_id
, op_id
, type_string
, ledger_sequence
-- please see table schema for more available columns and data
from `crypto-stellar.crypto_stellar_dbt.enriched_history_operations`
where true
-- equivalent account_id parameter
and op_account_id=<account_id>
-- highly recommended to provide a date range to reduce amount of data queried
and closed_at >= timestamp(current_date)
-- limit does not reduce the amount of data BigQuery queries
limit 1000
Recuperar los pagos de una cuenta
select
op_account_id
, transaction_id
, transaction_hash
, op_id
, ledger_sequence
, `from`
, `to`
, asset_code
, asset_issuer
, asset_type
, amount
-- please see table schema for more available columns and data
from `crypto-stellar.crypto_stellar_dbt.enriched_history_operations`
where true
-- equivalent account_id parameter
and op_account_id=<account_id>
and type in (0, 1, 2, 13, 8) -- create_account, payment, path_payment_strict_recieve, path_payment_strict_send, and account_merge
-- highly recommended to provide a date range to reduce amount of data queried
and closed_at >= timestamp(current_date)
-- limit does not reduce the amount of data BigQuery queries
limit 1000
Recuperar los efectos de una cuenta
select
eho.op_account_id
, he.operation_id
, eho.type_string
, he.details.asset_code
, he.details.asset_issuer
, he.details.asset_type
, he.details.amount
-- please see table schema for more available columns and data
from `crypto-stellar.crypto_stellar.history_effects` as he
inner join `crypto-stellar.crypto_stellar_dbt.enriched_history_operations` as eho
on he.operation_id = eho.op_id
and eho.closed_at >= timestamp(current_date)
where true
-- equivalent account_id parameter
and op_account_id=<account_id>
-- highly recommended to provide a date range to reduce amount of data queried
and he.closed_at >= timestamp(current_date)
-- limit does not reduce the amount of data BigQuery queries
limit 1000
Recuperar las ofertas de una cuenta
select
seller_id
, offer_id
, selling_asset_code
, buying_asset_code
, amount
-- please see table schema for more available columns and data
from `crypto-stellar.crypto_stellar_dbt.offers_current`
where true
-- equivalent account_id parameter
and seller_id=<account_id>
Recuperar los intercambios de una cuenta
with selling_side as (
select
selling_account_address as account_id
, history_operation_id
, selling_asset_code
, buying_asset_code
, selling_amount as amount
-- please see table schema for more available columns and data
from `crypto-stellar.crypto_stellar.history_trades`
where true
-- equivalent account_id parameter
and selling_account_address=<account_id>
-- highly recommended to provide a date range to reduce amount of data queried
and batch_run_date >= current_date
),
buying_side as (
select
buying_account_address as account_id
, history_operation_id
, selling_asset_code
, buying_asset_code
, buying_amount as amount
-- please see table schema for more available columns and data
from `crypto-stellar.crypto_stellar.history_trades`
where true
-- equivalent account_id parameter
and buying_account_address=<account_id>
-- highly recommended to provide a date range to reduce amount of data queried
and batch_run_date >= current_date
),
union_data as (
select
account_id
, history_operation_id
, selling_asset_code
, buying_asset_code
, amount
from selling_side
union all
select
account_id
, history_operation_id
, selling_asset_code
, buying_asset_code
, amount
from buying_side
)
select * from union_data
Activos
Los activos son representaciones de valor emitidas en la red Stellar. Un activo consiste en un tipo, código e emisor.
Obtén más información sobre activos.
Lista todos los activos
with assets as (
select
asset_code
, asset_issuer
-- please see table schema for more available columns and data
from `crypto-stellar.crypto_stellar.history_assets`
where true
-- equivalent asset_code/asset_issuer parameters
and asset_code=<asset code>
and asset_issuer=<asset issuer>
),
accounts as (
select
count(ac.account_id) as num_accounts
, countif(ac.flags=1) as authorized_accounts
, sum(balance) as amount
from assets
join `crypto-stellar.crypto_stellar_dbt.trust_lines_current` as ac
on assets.asset_code = ac.asset_code
and assets.asset_issuer = ac.asset_issuer
where true
),
liquidity_pools as (
select
count(*) as num_liquidity_pools
, sum(lpc.asset_a_amount) as liquidity_pools_amount
from assets
join `crypto-stellar.crypto_stellar_dbt.liquidity_pools_current` as lpc
on assets.asset_code = lpc.asset_a_code
and assets.asset_issuer = lpc.asset_a_issuer
where true
),
current_claimable_balances as (
-- TODO: This should be replaced with the claimable_balances_current table when available
SELECT
cb.balance_id
, cb.asset_code
, cb.asset_issuer
, cb.asset_amount
, cb.deleted
, cb.last_modified_ledger
, row_number() over(partition by cb.balance_id, cb.asset_code, cb.asset_issuer order by last_modified_ledger desc, deleted desc) as rn
FROM assets
join `crypto-stellar.crypto_stellar.claimable_balances` as cb
on assets.asset_code = cb.asset_code
and assets.asset_issuer = cb.asset_issuer
where true
order by last_modified_ledger asc
),
claimable_balances as (
select
count(*) as num_claimable_balances
, sum(asset_amount) as claimable_balances_amount
from current_claimable_balances
where true
and rn = 1
and deleted = false
)
select
*
from assets
join accounts on true
join liquidity_pools on true
join claimable_balances on true
Obtener información del contrato de activo Stellar
select
count(balance_holder) as num_contracts
, sum(parse_bignumeric(balance)) * .0000001 as contracts_amount
from `crypto-stellar.crypto_stellar_dbt.contract_data_current`
where true
and contract_id = <SAC contract id>
and balance != ""
Saldos reclamables
Un saldo reclamable representa la transferencia de propiedad de una cantidad de un activo. Los saldos reclamables proporcionan un mecanismo para establecer un pago que se puede reclamar en el futuro. Esto te permite hacer pagos a cuentas que actualmente no pueden aceptarlos.
Lista todos los saldos reclamables
current_claimable_balances as (
-- TODO: This should be replaced with the claimable_balances_current table when available
select
balance_id
, asset_code
, asset_issuer
, asset_amount
, deleted
, last_modified_ledger
-- please see table schema for more available columns and data
, row_number() over(partition by balance_id, asset_code, asset_issuer order by last_modified_ledger desc, deleted desc) as rn
from `crypto-stellar.crypto_stellar.claimable_balances` as cb
where true
-- equivalent asset_code/asset_issuer parameters
and asset_code=<asset code>
and asset_issuer=<asset issuer>
order by last_modified_ledger asc
)
select
*
from current_claimable_balances
where true
and rn = 1
and deleted = false
-- other filters for sponsor and claimants
--and sponsor = <sponsor address>
--and claimants.destination = <account address>
Recuperar un saldo reclamable
with assets as (
-- Used to filter to a specific asset
select
asset_code
, asset_issuer
from `crypto-stellar.crypto_stellar.history_assets`
where true
-- equivalent asset_code/asset_issuer parameters
and asset_code=<asset code>
and asset_issuer=<asset issuer>
),
current_claimable_balances as (
-- TODO: This should be replaced with the claimable_balances_current table when available
select
cb.balance_id
, cb.asset_code
, cb.asset_issuer
, cb.asset_amount
, cb.deleted
, cb.last_modified_ledger
-- please see table schema for more available columns and data
, row_number() over(partition by cb.balance_id, cb.asset_code, cb.asset_issuer order by last_modified_ledger desc, deleted desc) as rn
from assets
join `crypto-stellar.crypto_stellar.claimable_balances` as cb
on assets.asset_code = cb.asset_code
and assets.asset_issuer = cb.asset_issuer
where true
order by last_modified_ledger asc
)
select
*
from current_claimable_balances
where true
and rn = 1
and deleted = false
and balance_id = <claimable balance id>
Recuperar operaciones y transacciones relacionadas
select
op_id
, transaction_id
-- please see table schema for more available columns and data
from `crypto-stellar.crypto_stellar_dbt.enriched_history_operations`
where true
and balance_id = <claimable_balance_id>
-- highly recommended to provide a date range to reduce amount of data queried
and closed_at between <start> and <end>
Efectos
Los efectos representan cambios específicos que ocurren en el ledger como resultado de operaciones exitosas, pero no siempre se reflejan directamente en el ledger o en la historia, como lo hacen las transacciones y operaciones.
Lista todos los efectos
select
type
, type_string
-- please see table schema for more available columns and data
from `crypto-stellar.crypto_stellar.history_effects`
where true
-- Optional filtering options
--and operation_id = <operation id>
--and address = <account address>
--and details.liquidity_pool_id = <liquidity pool id>
-- highly recommended to provide a date range to reduce amount of data queried
and closed_at between <start> and <end>
Ledgers
Cada ledger almacena el estado de la red en un momento dado y contiene todos los cambios - transacciones, operaciones, efectos, etc. - a ese estado.
Obtén más información sobre ledgers.
Lista todos los ledgers
select
sequence
-- please see table schema for more available columns and data
from `crypto-stellar.crypto_stellar.history_ledgers`
where true
-- highly recommended to provide a date range to reduce amount of data queried
and closed_at between <start> and <end>
Recuperar las transacciones y operaciones de un ledger
select
ledger_sequence
-- please see table schema for more available columns and data
from `crypto-stellar.crypto_stellar_dbt.enriched_history_operations`
where true
and ledger_sequence = <ledger sequence>
-- highly recommended to provide a date range to reduce amount of data queried
and closed_at between <start> and <end>
Recuperar los pagos de un ledger
select
ledger_sequence
-- please see table schema for more available columns and data
from `crypto-stellar.crypto_stellar_dbt.enriched_history_operations` as eho
where true
and type in (0, 1, 2, 8, 13) -- create_account, payment, path_payment_strict_recieve, path_payment_strict_send, and account_merge
and ledger_sequence = <ledger sequence>
-- highly recommended to provide a date range to reduce amount of data queried
and closed_at between <start> and <end>
Fondos de Liquidez
Los fondos de liquidez proporcionan una forma simple y no interactiva de operar con grandes cantidades de capital y permiten altos volúmenes de comercio.
Lista los fondos de liquidez
select
liquidity_pool_id
, fee
, trustline_count
, asset_a_code
, asset_a_issuer
, asset_a_amount
-- please see table schema for more available columns and data
from `crypto-stellar.crypto_stellar_dbt.liquidity_pools_current`
where true
Recuperar un fondo de liquidez
select
liquidity_pool_id
, fee
, trustline_count
, asset_a_code
, asset_a_issuer
, asset_a_amount
-- please see table schema for more available columns and data
from `crypto-stellar.crypto_stellar_dbt.liquidity_pools_current`
where true
and liquidity_pool_id = <liquidity_pool_id>
Recuperar las transacciones y operaciones de un fondo de liquidez
select
op_id
, transaction_id
-- please see table schema for more available columns and data
from `crypto-stellar.crypto_stellar_dbt.enriched_history_operations`
where true
and liquidity_pool_id = <liquidity_pool_id>
Recuperar los intercambios relacionados de un fondo de liquidez
select
selling_liquidity_pool_id
, selling_amount
, buying_amount
-- please see table schema for more available columns and data
from `crypto-stellar.crypto_stellar.history_trades`
where true
and selling_liquidity_pool_id = <liquidity pool id>
Ofertas
Las ofertas son declaraciones sobre cuánto de un activo una cuenta desea comprar o vender.
Obtén m ás información sobre ofertas.
Lista todas las ofertas
select
offer_id
, seller_id
, selling_asset_code
, selling_asset_issuer
, amount
-- please see table schema for more available columns and data
from `crypto-stellar.crypto_stellar_dbt.offers_current`
where true
-- optional filter by account
--and seller_id = <account address>
and closed_at between <start> and <end>
Recuperar una oferta
select
offer_id
, seller_id
, selling_asset_code
, selling_asset_issuer
, amount
-- please see table schema for more available columns and data
from `crypto-stellar.crypto_stellar_dbt.offers_current`
where true
and offer_id = <offer id>
and closed_at between <start> and <end>
Recuperar los intercambios de una oferta
select
selling_offer_id
, selling_amount
-- please see table schema for more available columns and data
from `crypto-stellar.crypto_stellar.history_trades`
where true
and selling_offer_id = <offer_id>
-- offer_id could also be the buying_offer_id
--and buying_offer_id = <offer_id>
Operaciones
Las operaciones son objetos que representan un cambio deseado en el ledger: pagos, ofertas para intercambiar moneda, cambios realizados en las opciones de cuenta, etc. Las operaciones se envían a la red Stellar agrupadas en una transacción.
Cada una de las operaciones de Stellar tiene un objeto de operación único.
Lista todas las operaciones
select
op_id
-- please see table schema for more available columns and data
from `crypto-stellar.crypto_stellar_dbt.enriched_history_operations`
where true
-- optional filters
--and op_source_account = <account address>
--and ledger_sequence = <ledger sequence>
--and liquidity_pool_id = <liquidity pool id>
--and transaction_hash = <transaction hash>
--and transaction_id = <transaction id>
-- highly recommended to provide a date range to reduce amount of data queried
and closed_at between <start> and <end>
Lista todos los pagos
select
op_id
-- please see table schema for more available columns and data
from `crypto-stellar.crypto_stellar_dbt.enriched_history_operations` as eho
where true
-- optional filters
--and op_source_account = <account address>
--and ledger_sequence = <ledger sequence>
--and liquidity_pool_id = <liquidity pool id>
--and transaction_hash = <transaction hash>
--and transaction_id = <transaction id>
and type in (0, 1, 2, 8, 13) -- create_account, payment, path_payment_strict_recieve, path_payment_strict_send, and account_merge
-- highly recommended to provide a date range to reduce amount of data queried
and closed_at between <start> and <end>
Recuperar una operación
select
op_id
-- please see table schema for more available columns and data
from `crypto-stellar.crypto_stellar_dbt.enriched_history_operations` as eho
where true
-- op_id = <operation id>
-- highly recommended to provide a date range to reduce amount of data queried
and closed_at between <start> and <end>
Recuperar los efectos de una operación
select
operation_id
-- please see table schema for more available columns and data
from `crypto-stellar.crypto_stella.history_effects`
where true
operation_id = <operation id>
-- highly recommended to provide a date range to reduce amount of data queried
and closed_at between <start> and <end>
Intercambios
Cuando una oferta es cumplida total o parcialmente, ocurre un intercambio. Los intercambios también pueden ser causados por pagos de ruta exitosos, porque los pagos de ruta implican cumplir ofertas.
Un intercambio ocurre entre dos partes—base
y contraparte
. Cuál es cuál es arbitrario o determinado por la consulta que llama.
Obtén más información sobre intercambios.
Lista todos los intercambios
select
-- base_asset == selling_asset
-- counter_asset == buying_asset
selling_asset_code
, selling_asset_issuer
, selling_amount
, buying_asset_code
, buying_asset_issuer
, buying_amount
-- please see table schema for more available columns and data
from `crypto-stellar.crypto_stellar.history_trades`
where true
-- optional filter columns
and selling_offer_id = <offer id>
and buying_offer_id = <offer id>
and selling_asset_code = <asset code>
and selling_asset_issuer = <asset issuer>
and selling_liquidity_pool_id = <liquidity pool id>
and selling_account_address = <account address>
-- highly recommended to provide a date range to reduce amount of data queried
and closed_at between <start> and <end>
Transacciones
Las transacciones son comandos que modifican el estado del ledger y constan de una o más operaciones.
Obtén más información sobre transacciones.
Lista todas las transacciones
select
id
, max_fee
, operation_count
-- please see table schema for more available columns and data
from `crypto-stellar.crypto_stellar.history_transactions`
where true
-- optional filters
--and account = <account address>
--and ledger_sequence = <ledger sequence>
-- highly recommended to provide a date range to reduce amount of data queried
and closed_at between <start> and <end>
Recuperar una transacción
select
id
, max_fee
, operation_count
-- please see table schema for more available columns and data
from `crypto-stellar.crypto_stellar.history_transactions`
where true
and id = <transaction id>
-- transaction_hash is also available
--and transaction_hash = <transaction hash>
-- highly recommended to provide a date range to reduce amount of data queried
and closed_at between <start> and <end>
Recuperar las operaciones de una transacción
select
transaction_id
, op_id
, max_fee
, operation_count
-- please see table schema for more available columns and data
from `crypto-stellar.crypto_stellar_dbt.enriched_history_operations`
where true
and transaction_id = <transaction id>
-- transaction_hash is also available
--and transaction_hash = <transaction hash>
-- highly recommended to provide a date range to reduce amount of data queried
and closed_at between <start> and <end>
Agregaciones de intercambios
Una agregación de intercambio representa estadísticas agregadas sobre un par de activos (base y contraparte) para un período de tiempo específico. Las agregaciones de intercambios son útiles para desarrolladores de clientes de intercambio y proporcionan datos históricos de intercambios.
Lista las agregaciones de intercambios
select
date(closed_at)
, selling_asset_code
, selling_asset_issuer
, buying_asset_code
, buying_asset_issuer
, count(1) as number_of_trades
-- please see table schema for more available columns and data
from `crypto-stellar.crypto_stellar.history_trades`
where true
-- there are various columns to filter by
-- and selling_asset_code = <asset code>
-- and selling_asset_issuer = <asset issuer>
-- and buying_asset_code = <asset code>
-- and buying_asset_issuer = <asset issuer>
-- and closed_at between <start> and <end>
group by 1,2,3,4,5
Estadísticas de tarifas
Las estadísticas de tarifas se utilizan para predecir qué tarifa establecer para una transacción antes de enviarla a la red.
Recuperar estadísticas de tarifas
select
day_agg
, fee_charged_max
, fee_charged_min
-- please see table schema for more available columns and data
from `crypto-stellar.crypto_stellar_dbt.fee_stats_agg`
where true
and day_agg between <start> and <end>
getEvents
Los eventos de contratos y eventos de diagnóstico se utilizan para obtener información suplementaria relacionada con una invocación de contrato
select
contract_id
, topics_decoded
, data_decoded
-- please see table schema for more available columns and data
from `crypto-stellar.crypto_stellar.history_contract_events`
where true
-- highly recommended to provide a date range to reduce amount of data queried
and closed_at between <start> and <end>
getLedgerEntries
Permite la recuperación de varios estados del ledger, como cuentas, líneas de confianza, ofertas, datos, saldos reclamables y fondos de liquidez. También proporciona acceso directo para inspeccionar el estado actual de un contrato, su código o cualquier otra entrada del ledger
Entradas de datos del contrato
select
ledger_key_hash
, contract_id
, balance_holder
, balance
from `crypto-stellar.crypto_stellar_dbt.contract_data_current`
where true
and ledger_key_hash = <ledger_key_hash>
Entradas de código del contrato
select
ledger_key_hash
, contract_code_hash
from `crypto-stellar.crypto_stellar_dbt.contract_code_current`
where true
and ledger_key_hash = <ledger_key_hash>
getTransaction
Las transacciones son comandos que modifican el estado del ledger y constan de una o más operaciones.
Obtén más información sobre transacciones.
select
transaction_id
, op_id
, max_fee
, operation_count
-- please see table schema for more available columns and data
from `crypto-stellar.crypto_stellar_dbt.enriched_history_operations`
where true
and transaction_id = <transaction id>
-- transaction_hash is also available
--and transaction_hash = <transaction hash>
-- highly recommended to provide a date range to reduce amount of data queried
and closed_at between <start> and <end>