Loading Market Information

List Available Markets

The Aver API keeps an index of all markets on the blockchain and categorizes them so that they can be easily browsed or searched.

You can use methods within the AverClient object to obtain lists of markets, including the market's pubkey - a unique identifier for where you can find that market on-chain.

Below, we have loaded markets too (which you can understand in detail in the Loading an AverMarket Object section below)

#Loading all markets
all_markets = get(get_aver_api_endpoint(SolanaNetwork.DEVNET) + '/v2/markets')

#Load all active markets from endpoint
market_pubkeys = [PublicKey(m['pubkey']) for m in all_markets.json() if m['internal_status'] == 'active']

#Loads market data from onchain
loaded_markets = await AverMarket.load_multiple(client, market_pubkeys)

#Ensure market is in ACTIVE_PRE_EVENT status so we can place orders on it
active_pre_event_markets = list(filter(lambda market: market.market_state.market_status == MarketStatus.ACTIVE_PRE_EVENT, loaded_markets))

#Let's just pick the first market in the list
market = active_pre_event_markets[0]

Loading an AverMarket object

Once you've found the market (or markets) you wish to interact with, you can load an AverMarket object.

This object is a client-side representation of an on-chain market, which can be easily synchronized with on-chain data, and used to represent and interact with the market.

The AverMarket objects includes:

  • Descriptive information - properties, names, times related to the market

  • Indexing of other accounts where data related to this market is stored

  • Parameters and rules specifying how the market operates, limits, etc.

  • Orderbooks and order information for all open orders for each outcome in the market

from pyaver.market import AverMarket

# Load market
market = await AverMarket.load(client, market_pubkey)

# Print market data or specific properties
print('-'*10)
print(f'Market {market_pubkey} loaded...')
print(f'Market name: {market.market_state.market_name}')
for idx, outcome_name in enumerate(market.market_state.outcome_names):
    print(f' - {idx} - {outcome_name}')
print('-'*10)
print('Market state:')
print(market.market_state)

# Print one or more of the orderbooks or orderbook properties from memory
outcome_0_orderbook = market.orderbooks[0]
print('Outcome 0 - Best Ask', outcome_1_orderbook.get_best_ask_price(True))
print('Outcome 0 - Best Bid', outcome_1_orderbook.get_best_bid_price(True))

It's possible to read an enormous amount of information from the AverMarket object to enable various business logic to determine actions.

For each outcome in the market:

  • Level I orderbook data (best bid/buy and ask/sell prices and quantities)

  • Level II orderbook data (price-aggregated orders, counts, size)

  • Level III orderbook data (individual orders)

It's also possible to read relevant properties which may impact trading logic like parameters, conditions, cease trading times, min and max order limits, etc.

You can read more about the properties and methods within the AverMarket object here.

Last updated