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.
Last updated
This article details the process of how Scout extracts trade information from dYdX logs and how the data quality is ensured.
Last updated
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.
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.
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
.
From the above screenshot, the address in the LogTrade
logs tells us the market of this trade: PBTC-USDC
.
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.
accountOwner: The "maker" address of LogTrade
is 0x1b7835d2074914161dD6A2d48E393Be1dbf296D1
which is the accountOwner on the left. (Although the parameter of LogTrade
is called "maker", it doesn't have anything to do with the maker/taker relationship from a liquidity provider perspective). Follow the green line 👇
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
Based on that, this accountOwner is a taker
. Follow the purple line 👇
The trading amount of the account: Follow the yellow line 👇 , you can find the trading amount.
Is this trade a buy or sell? Follow the BLUE line 👇 to find out which side this trader is on. In the PBTC-USDC market, "isBuy" equals true means this trader is buying USDC which translates to "selling" PBTC. That's why the value is "SELL" in the web api.
In the WETH-PUSD market, the buy / sell logic is reversed.
The amount of fees paid: Follow the red line 👇. The feeAmount
is calculated from the parameter fill
of LogOrderFilled
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).
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.
dYdX 24H Trading Summary (click on the market to see more insights)
If you are interested in building charts with dydx trade data, drop us an email at support@scout.cool with your account information.