Using Python to track NFT prices on FTX
Published: 2021-10-30 14:49:30

Recently during the launch of [ChickenTribe](https://twitter.com/chickentribe) on the Solana blockchain, I became intrigued by a certain [NFT](https://ftx.us/nfts/token/485223445421518089). If you watch TV or don't have adblocker you've probably seen ads for FTX everywhere. FTX, in my opinion, is the premier trading platform for cryptocurrencies. I prefer it to coinbase and I think its relevance will only grow. They just completed a [fundraising round](https://www.cnbc.com/2021/10/21/crypto-exchange-ftx-raises-420-million-at-25-billion.html) for $420 million dollar from 69 investors. 

![FTX](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jy6sl215kj97gsh9lo01.jpeg)

During this time, `ChickenTribe #0` was listed for sale, but returned an error when I clicked purchase. I thought, let me try to create an api to ping this until it's able to sell and buy it programmatically. What I was surprised by was just how easy it is to call FTX via its [API](https://docs.ftx.com/#overview) and act on the data you receive. 

To get info about a particular NFT all we need to do is write and run this python program:

```py
import requests
import json
while True:
    try:
        data = requests.get('https://ftx.us/api/nft/nft/485223445421518089').json()      
        result = data['result']
        result_formatted = json.dumps(result, indent=2)
        print(result_formatted)
        break
    except Exception as e:
        print(f'Error obtaining NFT data: {e}')
```
This returns:
```py
{
  "id": "485223445421518089",
  "name": "ChickenTribe #0",
  "description": null,
  "issuer": "ChickenTribe",
  "collection": "ChickenTribe",
  "series": "ChickenTribe",
  "solMintAddress": "Du7roiVM8VzX6GFiQLYePcp1fLnkDhxWdFeQN4GMpAQF",
  "ethContractAddress": null,
  "imageUrl": "https://www.arweave.net/FnSVZj95IP0uYpU0mcHVr3TPUvCewxwTNgCQ1Ff6Xjc?ext=png",
  "videoUrl": null,
  "animationUrl": null,
  "thumbnailUrl": null,
  "attributes": {
    "Backgrounds": "Rust Red",
    "Bodies": "Fall",
    "Heads": "Ruby",
    "Faces": "Lava",
    "Combs": "Basic Purple",
    "Eyes": "None",
    "Accessories": "None",
    "Smokes": "None"
  },
  "attributesList": [
    {
      "value": "Rust Red",
      "trait_type": "Backgrounds"
    },
  ],
  "number": "0",
  "totalQuantity": null,
  "redeemable": false,
  "redeemed": false,
  "offerPrice": null,
  "donation": false,
  "status": "approved",
  "needsListingFee": false,
  "featured": false,
  "created_at": "2021-10-29T15:42:44.431599+00:00",
  "createdAt": "2021-10-29T15:42:44.431599+00:00",
  "quoteCurrency": "SOL",
  "auction": null,
  "depositMethods": [],
  "withdrawalMethods": [
    "sol"
  ],
  "totalSellerFeeRate": 0.07,
  "royaltyFeeRate": 0.05
}
```
While nft/nft/{$id} might be confusing at first. To grab all nfts you would simply call nft/nfts and iterate through the result. 

```py
while True:
    try:
        data = requests.get('https://ftx.us/api/nft/nfts').json()      
        result = data['result']
        for nft in result:
          result_formatted = json.dumps(nft, indent=2)
          print(result_formatted)
        break
    except Exception as e:
        print(f'Error obtaining NFT data: {e}')
```

If you have never run python code on your computer I recommend Google Collab. Here is a [link to a worksheet](https://colab.research.google.com/drive/1x5bBcQp_DAO35Y8nn79uSmirwWCv3OYc?usp=sharing) with the above code. You need to run each cell individually, in order.

#### [Sign up for FTX Here](https://ftx.us/#a=ApolloToday)

Let me know what you would like to see in future tutorials. Next tutorial I will be covering authentication to act on the data we retrieved.

```
If you found this helpful, consider sending a tip to the author. 
2vta8S9QJEeZSRTXxR5eL3tfpFVbHhRAKMnQmQeCBKAV
```