DEV Community

Cover image for Using Python to track NFT prices on FTX
Nick
Nick

Posted on • Updated on

Using Python to track NFT prices on FTX

Recently during the launch of ChickenTribe on the Solana blockchain, I became intrigued by a certain NFT. 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 for $420 million dollar from 69 investors.

FTX

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 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:

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}')
Enter fullscreen mode Exit fullscreen mode

This returns:

{
  "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
}
Enter fullscreen mode Exit fullscreen mode

While nft/nft/{$id} might be confusing at first. To grab all nfts you would simply call nft/nfts and iterate through the result.

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}')
Enter fullscreen mode Exit fullscreen mode

If you have never run python code on your computer I recommend Google Collab. Here is a link to a worksheet with the above code. You need to run each cell individually, in order.

Sign up for FTX Here

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
Enter fullscreen mode Exit fullscreen mode

Latest comments (1)

Collapse
 
bogdan_vaida_80402424b9a3 profile image
Bogdan Vaida

I'd love a code to approve and swap a token using Solana and Raydium's router.