2.1.41 • Published 5 years ago
@horizon-protocol/horizon-data v2.1.41
horizon-data
This is a collection of utilities to query Horizon data from Ethereum. This data has been indexed by The Graph via the various subgraphs the Horizon team maintains (the subgraph code repo).
Supported queries
The below all return a Promise that resolves with the requested results.
depot.userActions({ user })Get all depot deposit (zUSD) actions for the given user -deposit,withdrawl,unaccepted,removed.depot.clearedDeposits({ fromAddress, toAddress })Get all cleared zasset deposits (payments ofETHforzUSD) either from a givenfromAddressor (and as well as) to a giventoAddressdepot.exchanges({ from })Get all depot exchanges (buying zUSD with ETH) for a givenfromaddress.exchanges.total()Get the total exchange volume, total fees and total number of unique exchange addresses.exchanges.rebates({ minTimestamp = 1 day ago })Get the lastNexchange rebates since the givenminTimestampin seconds. Ordered in reverse chronological order.exchanges.reclaims({ minTimestamp = 1 day ago })Get the lastNexchange reclaims since the givenminTimestampin seconds. Ordered in reverse chronological order.exchanges.since({ minTimestamp = 1 day ago })Get the lastNexchanges since the givenminTimestamp(in seconds, so one hour ago is3600). These are ordered in reverse chronological order.rate.updatesGet all rate updates for zassets in reverse chronological orderzassets.issuersGet all wallets that have invokedIssueonzUSD(other zassets to come)zassets.transfersGet zasset transfers in reverse chronological orderzassets.holdersGet all potential zasset holdershzn.holdersGet the list of wallets that have ever sent or receivedHZN.hzn.rewardsGet the list of reward escrow holders and their latest balance at vesting entry add or vest.hzn.totalGet the total count of uniqueissuersandhznHoldershzn.transfersGet HZN transfers in reverse chronological orderhzn.issuedGet theIssuedevents in reverse chronological order.hzn.burnedGet theBurnedevents in reverse chronological order.hzn.feesClaimedGet theFeesClaimedevents in reverse chronological order, showing fees in zUSD and rewards in hzn.hzn.debtSnapshotGet the historical debt balance for any wallet address.binaryOptions.marketsGet all the binary options markets created.binaryOptions.optionTransactionsGet all the Bid and Refund transactions made to the binary options markets.binaryOptions.historicalOptionPriceGet historical records of every option price for every market.etherCollateral.loansGet the list of all EtherCollateral loans opened.exchanger.exchangeEntriesSettled({ max, from })Get the list of all settled exchanges.exchanges.aggregate({ max, timeSeries })Get the total amount of exchanges aggregated across various time series.rate.hznAggregate({ max, timeSeries })Get the price of hzn aggregated across various time series.hzn.aggregateActiveStakers({ max, timeSeries })Get the number of active stakers across various time series.hzn.totalActiveStakers()Get the current number of active stakers.rate.dailyRateChange({ zassets })get the rate change over the past 24 hours for any zasset. Can pass in a list to retrieve multiple zassets.hzn.accountsRemovedFromLiquidation({ maxTime, minTime, account, max })finds all the accounts that have fixed their c-ratio to avoid being at risk of liquidation after being flagged.hzn.accountsFlaggedForLiquidation({ minTime, maxTime, account, max })finds all the accounts that have been flagged for liquidation.hzn.accountsLiquidated({ maxTime, minTime, account, max })finds all the accounts that have been liquidated after being flagged for liquidation.hzn.getActiveLiquidations({ max, account, minTime, maxTime })finds all the accounts that have been flagged and are still pending liquidation or in a waiting state. Can also just check for a specific account if desired.
Supported subscriptions
The below all return an Observable that when subscribed to with an object.
exchanges.observe()Get an observable tosubscribeto that willnextthe latest exchanges in real time (replays the most recent exchange immediately).rate.observe()Get an observable tosubscribeto that willnextthe latest rates in real time (replays the most recent exchange immediately).
Use this as a node or webpack dependency
const hznData = require('horizon-data'); // common js
// or
import hznData from 'horizon-data'; // es modules
// query and log resolved results
hznData.exchanges
.since({
minTimestamp: Math.floor(Date.now() / 1e3) - 3600 * 24, // one day ago
})
.then(exchanges => console.log(exchanges));
// subscribe and log streaming results
hznData.exchanges.observe().subscribe({
next(val) {
console.log(val);
},
error: console.error,
complete() {
console.log('done');
},
});Use in a browser
<script src="//cdn.jsdelivr.net/npm/horizon-data/browser.js"></script>
<script>
window.hznData.exchanges
.since({
minTimestamp: Math.floor(Date.now() / 1e3) - 3600 * 24, // one day ago
})
.then(console.log);
window.hznData.exchanges.observe().subscribe({ next: console.log });
</script>How to query via the npm library (CLI)
# get last 24 hours of exchange activity, ordered from latest to earliest
npx horizon-data exchanges.since
# get exchanges on horizon as they occur in real time (replays the last exchange first)
npx horizon-data exchanges.subscribe2.1.41
5 years ago