1

I use CCXT to fetchDeposits from FTX. My aim is to find the sum of all Bitcoin deposits to this specific FTX address. Problem happens when I try to get all historical deposits (older than 1 month). FTX only returns past 1 month data.

  • Start date of deposit = 1 April 2022 = 1648771200
  • Dummy end of deposit = 30 April 2022 = 1651363199
  • Intended End date of deposit = now = 1655033415

What I've tried:

  1. fetchDeposits from the past one month = successful. Correct data returns 33 transactions.

  2. fetchDeposits from 1 Apr - 30 Apr = fail. Data returns same as (1). Correct data should return 3 transactions.

  3. fetchDeposits from 1 Apr - now = fail. Data returns same as (1). Correct data should return 44 transactions.

I'm aware of pagination which limits the returned data. However, no matter I've tried, I always get only past one month data. Older data is missing.

Reference:

Code

def get_deposits(asset_name):
    deposits_total = 0
    deposits_count = 0

    since = 1648771200
    param = {"endTime": 1655033415}
    deposits = exchange.fetch_deposits(asset_name, since, limit=None, params=param)

    #This sum up all deposits if such deposit is made to specified deposit address
    for item in deposits:
      if item['addressTo'] == deposit_address[asset_name]:
        deposits_total = deposits_total + item['amount']
        deposits_count = deposits_count +1
        print(item['datetime'])

    return(deposits_total, deposits_count)
Alphatio
  • 47
  • 5
  • 1
    The documentation says the time should be in milleseconds and not seconds like you have entered it. Not sure if it makes a difference but worth a try to put it in ms. Also have you tried to make the query directly with the REST API instead of using CCXT? Might be worth a try to see what is returned. https://docs.ftx.com/?python#get-withdrawal-history If that doesn't work I would contact FTX support. It might be a bug their end. – Alex B Jun 12 '22 at 14:39

1 Answers1

1

Thanks Alex and Kroitor(on Github).

Code below should credit to Kroitor (on Github) https://github.com/ccxt/ccxt/issues/13806

import ccxt

# make sure your version is 1.51+
print('CCXT Version:', ccxt.__version__)

exchange = ccxt.ftx({
    'apiKey': 'YOUR_API_KEY',
    'secret': 'YOUR_SECRET',
    # "headers": {
    #     "FTX-SUBACCOUNT": "YOUR_SUBACCOUNT"
    # }
})


markets = exchange.load_markets ()

# exchange.verbose = True  # uncomment for debugging

all_results = {}
symbol = None
since = None
limit = 200
end_time = exchange.milliseconds()

while True:
    print('------------------------------------------------------------------')
    params = {
        'end_time': int(end_time / 1000),
    }
    results = exchange.fetch_deposits(symbol, since, limit, params)
    if len(results):
        first = results[0]
        last = results[len(results) - 1]
        end_time = first['timestamp']
        print('Fetched', len(results), 'deposits from', first['datetime'], 'till', last['datetime'])
        fetched_new_results = False
        for result in results:
            if result['id'] not in all_results:
                fetched_new_results = True
                all_results[result['id']] = result
        if not fetched_new_results:
            print('Done')
            break
    else:
        print('Done')
        break


all_results = list(all_results.values())
all_results = exchange.sort_by(all_results, 'timestamp')

print('Fetched', len(all_results), 'deposits')
for i in range(0, len(all_results)):
    result = all_results[i]
    print(i, result['id'], result['currency'], result['datetime'], result['amount'])

The easiest way to check the correctness is using

https://chain.so/api/v2/get_address_received/coin_name/your_address

Example https://chain.so/api/v2/get_address_received/DOGE/DM7Yo7YqPtgMsGgphX9RAZFXFhu6Kd6JTT

Compare confirmed_received_value with returned value from FTX

Alphatio
  • 47
  • 5