Scout Chart Creator
  • Overview
  • Get Started
    • Tutorial 1: NMR Daily Transaction Count
    • Tutorial 2: LPT Weekly Volume (USD)
    • Tutorial 3: NMR vs LPT Daily comparison
  • Pipeline
    • Filter
    • Project
    • Group
      • Accumulators
    • Sort
    • Unwind
    • Custom
  • Data Source
    • Transactions
    • States
    • Contracts
    • Aragon
    • Livepeer
    • dYdX
    • Set
    • Token holders
  • Operators
    • Math operators
    • Logic operators
    • Function operators
    • Array operators
    • String operators
  • Config
  • Protocols
    • Dodo
      • 24H trade volume
      • Deposit & Withdraw
    • Livepeer
    • dYdX
      • Making sense of the trade data
    • MakerDao
    • Pickle Finance
      • Example: Daily deposit and withdraw of jar 0.88
      • Example: Listing all borrows of a strategy
  • FAQ
    • Dealing with "logs" field in "Transaction"
    • How to handle "Query Timeout" error?
    • How to use a variable in a Pipeline
  • Research
    • The circulating supply of DODO tokens
    • How are bitcoins doing on Ethereum? (as of Jan 20th 2021)
Powered by GitBook
On this page
  • 1. The "LogTrade" event
  • 2. Finding the trading information from the transaction
  • 3. Putting it all together

Was this helpful?

  1. Protocols
  2. dYdX

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.

PreviousdYdXNextMakerDao

Last updated 4 years ago

Was this helpful?

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 and to research the trade information from dYdX transactions.

1. The "LogTrade" event

Let's create a chart and select 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

  • transactionHash

  • market

  • side: (BUY or SELL)

  • accountOwner

  • price

  • amount

  • feeAmount

  • liquidity: (MAKER or TAKER)

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:

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.

Fees: -0.025% Maker, 0.15% Taker

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

feeAmount=fill.amount∗fill.price∗fill.fee∗fill.isNegativeFeefeeAmount = fill.amount * fill.price * fill.fee * fill.isNegativeFee feeAmount=fill.amount∗fill.price∗fill.fee∗fill.isNegativeFee

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

3. Putting it all together

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.

Based on the , a trade should have below attributes:

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

To understand the rest of attributes, we are going to compare the data from 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.

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 , a maker pays negative fee while the taker pays positive fee,

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.

The amount of fees paid: Follow the red line . The feeAmount is calculated from the parameter fill of LogOrderFilled

Prices: Beware of the 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 to track the trades.

(click on the market to see more insights)

👇
👇
👇
👇
👇
dYdX documentation
0xf46cf3d9c0acaa5580c563b94ff1b6724ff096d6d3244db8e78872df3e746140
Filter
the web API of dYdX
PBTC-USDC specification
price units
dydx transactions
dYdX Trade
dYdX 24H Trading Summary
Scout chart creator
Etherscan
Transactions
There are many different "LogTrade" logs on the blockchain
Notice the selected LogTrade here is specific to Perpetual app.
The matched pairs are marked in blue and red respectively
Click the image to enlarge
Map liquidity
Map trade amount