Fetch historical price of asset

I’d like to be able to fetch historical price data of assets I’ve purchased so I can easily calculate PnL. At the moment the balances api does a fantastic of giving me the current balance of all the tokens in my wallet. But I don’t know how much was spent on each token.

There are two ways, One if you purchased through DEX then you can get your DEX trades history.

Another way to get all incoming(inbound) and outgoing(outbound) transaction history.

Inbound example - All inbound transactions of a specific wallet

outbound example - All outbound transactions of a specific wallet

Thanks Gaurav,

Unfortunately the first method does not return every trade made by a specific wallet for the given date range. It just returns some of the trades, not sure why?

As for the second/third method, they fetch the inbound/outbound txs in separate calls. That could get expensive quickly so not sure if that’s the best method going forward.

In essence all I’m trying to do is for a particular wallet, get all their trades and amount paid. Then get the current value of those some tokens and use that to calculate taxes.

Can you tell me which ones are missing?

See this example of getting both inbound and outbound in one API call

Let me know what else is missing here?

The second example for getting inbound/outbound in one api call works well for BTC network, what do I need to do to fix it for bsc?

{
  ethereum(network: bsc) {
    inbound: transfers(
      options: {desc: "block.timestamp.time", asc: "currency.symbol", limit: 10}
      amount: {gt: 0}
      receiver: {is: "0x239dd292f52cfb2523873993aac618ee1cb4f886"}
    ) {
      block {
        timestamp {
          time(format: "%Y-%m-%d %H:%M:%S")
        }
        height
      }
      address: sender {
        address
        annotation
      }
      currency {
        address
        symbol
      }
      gasValue
      amount
      transaction {
        hash
      }
      external
    }
    outbound: transfers(
      options: {desc: "block.timestamp.time", asc: "currency.symbol", limit: 10}
      amount: {gt: 0}
      sender: {is: "0x239dd292f52cfb2523873993aac618ee1cb4f886"}
    ) {
      block {
        timestamp {
          time(format: "%Y-%m-%d %H:%M:%S")
        }
        height
      }
      address: receiver {
        address
        annotation
      }
      currency {
        address
        symbol
      }
      amount
      transaction {
        hash
      }
      gasValue
      external
    }
  }
}