Making sense of the trade data

This article details the process of how Scout extracts trade information from dYdX logs and how the data quality is ensured.

Finding the trade data in dYdX protocol can be quite challenging. In this article, we will take an in-depth look at how to use the Scout chart creator and Etherscan to research the trade information from dYdX transactions.

1. The "LogTrade" event

Let's create a chart and select Transactions as the Data Source. You may know the LogTrade event if you have interacted with dYdX smart contracts. This is the log that will be left on the blockchain when people make trades via dYdX. But there are many LogTrade logs from different protocols on the blockchain. Make sure you work with the right ones. In the below screenshot, the second LogTrade is for the soloMargin application and the third one is for the Perpetual application.

We will use the LogTrade from the Perpetual app as the example for our following research.

2. Finding the trading information from the transaction

Based on the dYdX documentation, a trade should have below attributes:

  • transactionHash

  • market

  • side: (BUY or SELL)

  • accountOwner

  • price

  • amount

  • feeAmount

  • liquidity: (MAKER or TAKER)

Let us use the transaction 0xf46cf3d9c0acaa5580c563b94ff1b6724ff096d6d3244db8e78872df3e746140 as an example to find out all the attributes of a trade. Let's add a new condition to the Filter instruction

transactionHash = 0xf46cf3d9c0acaa5580c563b94ff1b6724ff096d6d3244db8e78872df3e746140

You probably have noticed that there is always a LogOrderFilled that comes with LogTrade. These two logs indeed work as a pair that defines one trade participant's data. Based on the source code of dYdX smart contracts, LogOrderFilled is emitted before LogTrade.

2.1 The easiest attribute: market

From the above screenshot, the address in the LogTrade logs tells us the market of this trade: PBTC-USDC.

2.2 The complicated attributes:

To understand the rest of attributes, we are going to compare the data from the web API of dYdX with the on-chain data. In this transaction, there are two pairs of LogOrderFilled and LogTrade . That means there are only two participants in this trade.

The left part is the output from the web API and the right part is the on-chain data.

After some observations, we started making connections between the data from both sides. In the below screen shot, we focus on one pair of the data. The LogTrade and LogOrderFilled have been expanded. So that you can see more details which were not available in the above screenshot.

The liquidity role of the account: According to the PBTC-USDC specification, a maker pays negative fee while the taker pays positive fee,

Fees: -0.025% Maker, 0.15% Taker

In the WETH-PUSD market, the buy / sell logic is reversed.

and decimals...: Here is from dYdX documentation:

Prices: Beware of the price units used by dYdX. Since PBTC has 8 decimals and USDC has 6 decimals, PBTC-USDC prices are shifted by 2 decimals (divided by 100).

3. Putting it all together

The example that we just walked you through was among the simple ones. There are trades which involve multiple participants could be even more complicated. Due to the complexities, we have created a customized Data Source called dydx transactions to track the trades.

And we've build a few dashboards from this data source.

If you are interested in building charts with dydx trade data, drop us an email at support@scout.cool with your account information.

Last updated