Cover Image for Arbitrum DEX APIs - A Comprehensive Guide to Bitquery's Arbitrum DEX APIs​

Arbitrum DEX APIs - A Comprehensive Guide to Bitquery's Arbitrum DEX APIs​

Arbitrum
Blockchain
Tokens
DEX Trades

Over the past year, the Ethereum blockchain network has faced huge network traffic which causes expensive gas and slow transaction speed. People are using a special solution called "Layer 2" or L2s to mitigate the issues with the Layer-1 Ethereum network. Arbitrum is one of the fastest-growing layer-2 blockchain network solutions.

DEX trading data plays a crucial role in promoting transparency, accessibility, and innovation in the cryptocurrency market, ultimately empowering traders and fostering the growth of decentralized finance.

In this article, We’re going to learn how to use Bitquery APIs to to get data from DEXes across Arbitrum Network like Uniwap, 1inch, etc.Bitquery gives us data about things like trades, pairs, pools, addresses and more.

Bitquery APIs

Bitquery provides historical and real-time indexed data for over 40 blockchains through various interfaces such as GraphQL APIs. These APIs offer a wide range of data including:

  • Transfers
  • Token trades and transfers
  • Holders
  • Transactions
  • Address balances
  • Smart contract events & calls
  • NFT trades, and transfers

This comprehensive data access enables developers to build multi-chain solutions for compliance, DEX trading, NFT marketplaces, analytics, and more. Let’s write some queries to get data from Arbitrum DEX. If you have an issue with any of the queries, you refer to our DEX API docs which should resolve those issues.

Analyze DEXes on Arbitrum with Bitquery APIs

Note:- we are using Arbitrum Network governance token Arbitrum across all queries ( address: 0x912CE59144191C1204E64559FE8253a0e49E6548), you can change the address of the token according to your needs.

Trading pairs API on Arbitrum DEX

If you want to get all trades of a token, you might want to know all its trading pairs. Protocols like Uniswap have pairs or pools.We are using V2 IDE here Let’s see how you can fetch this data using Bitquery APIs.

All Pairs for a Token on any Arbitrum DEX

Let's get all pairs of the ARB token. In the following query, we are not defining any DEX details; therefore, we will get pairs across DEXs supported by Bitquery. We are just providing the ARB token as buy currency.

{
  EVM(dataset: combined, network: arbitrum) {
    DEXTrades(
      where: {Trade: {Buy: {Currency: {SmartContract: {is: "0x912CE59144191C1204E64559FE8253a0e49E6548"}}}}}
      limit: {count: 10}
      limitBy: {by: Trade_Sell_Currency_SmartContract, count: 1}
    ) {
      Trade {
        Dex {
          ProtocolName
          OwnerAddress
          ProtocolVersion
          Pair {
            SmartContract
            Name
            Symbol
          }
        }
        Buy {
          Currency {
            Name
            SmartContract
          }
        }
        Sell {
          Currency {
            Name
            SmartContract
          }
        }
      }
    }
  }
}

Open the above query on GraphQL IDE using this link.

All Pairs on a Specific Arbitrum DEX

Now, let's see an example of getting all pairs of a token for a specific Arbitrum DEX. In this example, we will get all pairs of the ARB token for the Uniswap v3 protocol; therefore, we will mention Uniswap v3 factory smart contract address.

{
  EVM(dataset: combined, network: arbitrum) {
    DEXTrades(
      where: {
        Trade: {
          Buy: {
            Currency: {
              SmartContract: {
                is: "0x912CE59144191C1204E64559FE8253a0e49E6548"
              }
            }
          }
          Dex: {
            OwnerAddress: { is: "0x1f98431c8ad98523631ae4a59f267346ea31f984" }
          }
        }
      }
      limit: { count: 10 }
      limitBy: { by: Trade_Sell_Currency_SmartContract, count: 1 }
    ) {
      Trade {
        Dex {
          ProtocolName
          OwnerAddress
        }
        Buy {
          Currency {
            Name
            SmartContract
          }
        }
        Sell {
          Currency {
            Name
            SmartContract
          }
        }
      }
    }
  }
}

Open the above query on GraphQL IDE using this link.

Trade Metrics for a Token Pair

This query can be used to get all trade metrics (trade amount, TX count) for a given pair ( in this case ARB/USDT) on arbitrum network over a particular time period.

query {
  EVM(network:arbitrum, dataset: combined) {
    Unique_Buyers: DEXTrades(
      where: {Block: {Time: {since: "2023-09-27T01:00:00Z", till: "2023-09-27T02:00:00Z"}}, Trade: {Buy: {Currency: {SmartContract: {is:"0x912ce59144191c1204e64559fe8253a0e49e6548"}}}, Sell: {Currency: {SmartContract: {is: "0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9"}}}}}
    ) {
      count(distinct: Trade_Buy_Buyer)
    }
    Unique_Sellers: DEXTrades(
      where: {Block: {Time: {since: "2023-08-26T01:00:00Z", till: "2023-08-26T02:00:00Z"}}, Trade: {Sell: {Currency: {SmartContract: {is: "0x912ce59144191c1204e64559fe8253a0e49e6548"}}}, Buy:{Currency:{SmartContract:{is: "0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9"}}}}}
    ) {
      count(distinct: Trade_Sell_Seller)
    }
    Total_Transactions: DEXTrades(
      where: {Block: {Time: {since: "2023-09-27T01:00:00Z", till: "2023-09-27T02:00:00Z"}}, Trade: {Buy: {Currency: {SmartContract: {is: "0x912ce59144191c1204e64559fe8253a0e49e6548"}}}, Sell: {Currency: {SmartContract: {is:"0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9"}}}}}
    ) {
      count(distinct: Transaction_Hash)
    }
    Total_Buy_Amount: DEXTrades(
      where: {Block: {Time: {since: "2023-09-27T01:00:00Z", till: "2023-09-27T02:00:00Z"}}, Trade: {Buy: {Currency: {SmartContract: {is: "0x912ce59144191c1204e64559fe8253a0e49e6548"}}}, Sell: {Currency: {SmartContract: {is:"0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9"}}}}}
    ) {
      sum(of:Trade_Buy_Amount)
    }
    Total_Sell_Amount: DEXTrades(
      where: {Block: {Time: {since: "2023-09-27T01:00:00Z", till: "2023-09-27T02:00:00Z"}}, Trade: {Buy: {Currency: {SmartContract: {is: "0x912ce59144191c1204e64559fe8253a0e49e6548"}}}, Sell: {Currency: {SmartContract: {is: "0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9"}}}}}
    ) {
      sum(of:Trade_Sell_Amount)
    }
  }
}

Open the above query on GraphQL IDE using this link.

OHLC API for Arbitrum DEXs

You can build your crypto coin ticker using our DEX APIs based on the requirements of the data field. Also, you can set any time interval you need. Let's see an example. In this example, we are getting the Arbitrum price against USDT on Arbitrum Blockchain aggregating different DEXs.

{
  EVM(dataset: realtime, network: arbitrum) {
    DEXTradeByTokens(
      orderBy: {ascendingByField: "Block_Time"}
      where: {Trade: {Side: {Currency: {SmartContract: {is: "0x912ce59144191c1204e64559fe8253a0e49e6548"}}}, Currency: {SmartContract: {is: "0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9"}}}}
    ) {
      Block { 
        Time(interval: {in: minutes, count: 10})
        lastTradeTime: Time(maximum: Block_Time)
        FirstTradeTime: Time(minimum: Block_Time)
        LastTradeBlock: Number(maximum: Block_Number)
        FirstTradeBlock: Number(minimum: Block_Number)
      }
      volume: sum(of: Trade_Amount)
      Trade {
        Buyer
        Amount
        Currency {
          Name
          Symbol
        }
        Seller
        Price
        Sender
        Side {
          Currency {
            Name
            Symbol
          }
          Amount
        }
        high: Price(maximum: Trade_Price)
        low: Price(minimum: Trade_Price)
        open: Price(minimum: Block_Number)
        close: Price(maximum: Block_Number)
      }
      count
    }
  }
}

Open the above query on GraphQL IDE using this link.

Latest trading pairs for DEX

Let's see how we can get the latest trading pairs created on DEXs. In this example we use Smart Contract Events to track PoolCreated events for Uniswap v3 factory contract.

Because whenever a new pool gets created, the Uniswapv3 factory contract emits a PoolCreated event with the details of the pool.

{
  EVM(dataset: combined, network: arbitrum) {
    Events(
      orderBy: {descending: Block_Number}
      limit: {count: 10}
      where: {Log: {SmartContract: {is: "0x1f98431c8ad98523631ae4a59f267346ea31f984"}, Signature: {Name: {is: "PoolCreated"}}}}
    ) {
      Log {
        Signature {
          Name
          Parsed
          Signature
        }
        SmartContract
      }
      Transaction {
        Hash
      }
      Block {
        Date
        Number
      }
      Arguments {
        Name
        Value {
          ... on EVM_ABI_String_Value_Arg {
            string
          }
        }
        Type 
      }
    }
  }
}

Open the above query on GraphQL IDE using this link.

Token Trades API

Historical Token Trades & Price API

Let's see an example where we get trades of ARB Token in the past. As you can see, we are using Block -> Time filter, which includes the time. If you want to filter by date, then use Block -> Date. You can also use Block -> Number if you want to filter based on block height. We are setting the seller and buyer to 1inch router 0x1111111254eeb25477b68fb85ed929f73a960582 to get both buys and sells of the ARB token.

{
  EVM(dataset: combined, network: arbitrum) {
    buyside: DEXTrades(
      limit: {count: 10}
      orderBy: {descending: Block_Time}
      where: {Trade: {Buy: {Currency: {SmartContract: {is: "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1"}}, Seller: {is: "0x1111111254eeb25477b68fb85ed929f73a960582 "}}}, Block: {Time: {since: "2023-03-03T01:00:00Z", till: "2023-03-05T05:15:23Z"}}}
    ) {
      Block {
        Number
        Time
      }
      Transaction {
        From
        To
        Hash
      }
      Trade {
        Buy {
          Amount
          Buyer
          Currency {
            Name
            Symbol
            SmartContract
          }
          Seller
          Price
        }
        Sell {
          Amount
          Buyer
          Currency {
            Name
            SmartContract
            Symbol
          }
          Seller
          Price
        }
      }
    }
    sellside: DEXTrades(
      limit: {count: 10}
      orderBy: {descending: Block_Time}
      where: {Trade: {Sell: {Currency: {SmartContract: {is: "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1"}}, Buyer: {is: "0x1111111254eeb25477b68fb85ed929f73a960582"}}}, Block: {Time: {since: "2023-03-03T01:00:00Z", till: "2023-03-05T05:15:23Z"}}}
    ) {
      Block {
        Number
        Time
      }
      Transaction {
        From
        To
        Hash
      }
      Trade {
        Buy {
          Amount
          Buyer
          Currency {
            Name
            Symbol
            SmartContract
          }
          Seller
          Price
        }
        Sell {
          Amount
          Buyer
          Currency {
            Name
            SmartContract
            Symbol
          }
          Seller
          Price
        }
      }
    }
  }
}

Open the above query on GraphQL IDE using this link.

First X Buyers of a Token

This query retrieves the first X number of buyers for a specific token within the Arbitrum network. Replace the token address of the token you want in the Currency SmartContract field.

  EVM(dataset: archive, network: arbitrum) {
    buyside: DEXTrades(
      limit: {count: 10}
      limitBy: {by: Transaction_From, count: 1}
      orderBy: {ascending: Block_Time}
      where: {Trade: {Buy: {Currency: {SmartContract: {is: "0x912ce59144191c1204e64559fe8253a0e49e6548"}}}}}
    ) {
      Block {
        Number
        Time
      }
      Transaction {
        From
        To
        Hash
      }
      Trade {
        Buy {
          Amount
          Buyer
          Currency {
            Name
            Symbol
          }
          Seller
          Price
        }
      }
    }
  }
}

Open the above query on GraphQL IDE using this link.

Get Least Traded Token

The following query gets least traded tokens within a specified time frame on the Ethereum network. By querying the DEX trades and sorting them based on the least number of trades, it provides insights into tokens with minimal trading activity during the designated period.

query MyQuery {
  EVM(dataset: archive, network: arbitrum) {
    DEXTradeByTokens(
      limit: {count: 10}
      where: {Block: {Time: {after: "2023-11-20T00:00:00Z", before: "2023-11-27T00:00:00Z"}}}
      orderBy: {ascendingByField: "count"}
    ) {
      Trade {
        Currency {
          Name
          SmartContract
        }
      }
      count
    }
  }
}

Open the above query on GraphQL IDE using this link.

Token trade from a specific DEX

If you are looking for token trades on a specific arbitrum dex, use the following API as an example. Here we are getting Arbitrum token trades from the Uniswap V3 DEX. To filter all trades from Uniswap V3, we can use the ProtocolName filter and pass the value of "uniswap_v3". This will give us all the trades from Uniswap V3 deployed on Arbitrum.

{
  EVM(dataset: archive, network: arbitrum) {
    buyside: DEXTrades(
      limit: {count: 5}
      orderBy: {descending: Block_Time}
      where: {Trade: {Buy: {Currency: {SmartContract: {is: "0x912ce59144191c1204e64559fe8253a0e49e6548"}}}, Dex: {ProtocolName: {is: "uniswap_v3"}}}}
    ) {
      Block {
        Number
        Time
      }
      Transaction {
        From
        To
        Hash
      }
      Trade {
        Buy {
          Amount
          Buyer
          Currency {
            Name
            Symbol
            SmartContract
          }
          Seller
          Price
        }
        Sell {
          Amount
          Buyer
          Currency {
            Name
            SmartContract
            Symbol
          }
          Seller
          Price
        }
        Dex {
          ProtocolFamily
          ProtocolName
          SmartContract
          Pair {
            SmartContract
          }
        }
      }
    }
  }
}

You can also use the factory contract of Uniswap-like protocols in the DEX -> OwnerAddress filter to get trades for that DEX.Open the above query on GraphQL IDE using this link.

Address Trades API ( Arbitrum Mainnet )

Latest Trades for a given address

This GraphQL query retrieves the latest 10 buy-side and sell-side trades from the DEXTrades dataset on the Ethereum network for a specific buyer/seller.

{
  EVM(dataset: combined, network: arbitrum ) {
    buyside: DEXTrades(
      limit: {count: 10}
      orderBy: {descending: Block_Time}
      where: {Trade: {Buy: {Buyer: {is: "0x1f77dfeb0e6fed1ecf0b41d4c81330df6a6fb167"}}}}
    ) {
      Block {
        Number
        Time
      }
      Transaction {
        From
        To
        Hash
      }
      Trade {
        Buy {
          Amount
          Buyer
          Currency {
            Name
            Symbol
            SmartContract
          }
          Seller
          Price
        }
        Sell {
          Amount
          Buyer
          Currency {
            Name
            SmartContract
            Symbol
          }
          Seller
          Price
        }
      }
    }
    sellside: DEXTrades(
      limit: {count: 10}
      orderBy: {descending: Block_Time}
      where: {Trade: {Buy: {Seller: {is: "0x1f77dfeb0e6fed1ecf0b41d4c81330df6a6fb167"}}}}
    ) {
      Block {
        Number
        Time
      }
      Transaction {
        From
        To
        Hash
      }
      Trade {
        Buy {
          Amount
          Buyer
          Currency {
            Name
            Symbol
            SmartContract
          }
          Seller
          Price
        }
        Sell {
          Amount
          Buyer
          Currency {
            Name
            SmartContract
            Symbol
          }
          Seller
          Price
        }
      }
    }
  }
}

Open the above query on GraphQL IDE using this link.

Trades Where the Address is Buyer OR Seller

The below query gives you trades where the specified address is either as a buyer or a seller. This is achieved by utilizing the any filter, which acts as an OR condition to encompass both buyer and seller roles in the results.

query MyQuery {
  EVM(dataset: archive, network: arbitrum) {
    DEXTrades(
      where: {any: [{Trade: {Buy: {Buyer: {is: "0x0938C63109801Ee4243a487aB84DFfA2Bba4589e"}}}}, 
        {Trade: {Buy: {Seller: {is: "0x0938C63109801Ee4243a487aB84DFfA2Bba4589e"}}}}]}
      limit: {count: 10}
      orderBy: {descending: Block_Time}
    ) {
      Trade {
        Buy {
          Buyer
          Amount
          Currency {
            Name
          }
        }
        Dex {
          ProtocolName
        }
        Sell {
          Buyer
          Price
          Currency {
            Name
          }
        }
      }
      Transaction {
        Hash
      }
    }
  }
}

Open the above query on GraphQL IDE using this link.

Applications

Let’s delve into the applications of using Bitquery GraphQL APIs for Arbitrum DEX data and explore how this information can be harnessed effectively.

  • Monitoring DEX Activity

    • Bitquery’s DEX Trades API provides real-time and historical data on decentralized exchange (DEX) trades within the Arbitrum ecosystem. By querying this API, you can track trading volumes, liquidity changes, and price movements across various DEXs.

    • Developers and traders can use this data to monitor the health and performance of different DEX protocols. For instance, you can analyze which tokens are most actively traded, identify emerging tokens across arbitrum network on different DEXes, and track liquidity pools’ dynamics.

  • Algorithmic Trading Strategies

    • Armed with DEX trade data, you can design and optimize algorithmic trading strategies. These strategies can automate buy/sell decisions based on specific conditions, such as price fluctuations, volume spikes, or liquidity imbalances.

    • By integrating Bitquery’s APIs into your trading bots, you can execute trades on Arbitrum DEXs efficiently. For instance, you might create a strategy that rebalances a portfolio by swapping tokens across different DEXs to maintain desired weightings.

  • Market Research and Insights

    • Researchers and analysts can leverage Bitquery’s APIs to gain deep insights into the Arbitrum DEX landscape. By querying token transfers, liquidity pools, and historical trade data, you can uncover trends, anomalies, and market behavior.

    • These insights can inform investment decisions, guide token listings, and provide valuable context for understanding the overall health of the Arbitrum DEX ecosystem.

Conclusion

Bitquery's robust GraphQL APIs open up a treasure of data from Arbitrum's DEX ecosystem. As this layer 2 scaling solution gains traction, analyzing on-chain activity across DEX protocols like Uniswap, Sushiswap, and 1Inch becomes invaluable.

By leveraging Bitquery's APIs, developers can build tools to monitor real-time trading, research market dynamics, design algo trading systems, and more. The ability to query historical trades, liquidity pools, smart contract events, and other granular data unlocks new opportunities.

As Arbitrum cements itself as a leading layer 2 network, its DEX landscape will continue to evolve. Bitquery provides a flexible data infrastructure to keep up with this innovation. Whether you're an analyst, trader, or builder - these powerful APIs equip you with actionable data to maximize opportunities in DeFi.

About Bitquery

Bitquery is a set of software tools that parse, index, access, search, and use information across blockchain networks in a unified way. Our products are:

  • Coinpath® APIs provide blockchain money flow analysis for more than 24 blockchains. With Coinpath’s APIs, you can monitor blockchain transactions, investigate crypto crimes such as bitcoin money laundering, and create crypto forensics tools. Read this to get started with Coinpath®.
  • Digital Assets API provides index information related to all major cryptocurrencies, coins, and tokens.
  • DEX API provides real-time deposits and transactions, trades, and other related data on different DEX protocols like Uniswap, Kyber Network, Airswap, Matching Network, etc.

If you have any questions about our products, ask them on our Telegram channel or email us at sales@bitquery.io. Also, subscribe to our newsletter below, we will keep you updated with the latest in the cryptocurrency world.

Subscribe to our newsletter

Subscribe and never miss any updates related to our APIs, new developments & latest news etc. Our newsletter is sent once a week on Monday.