zirobtc commited on
Commit
044ed6d
·
1 Parent(s): 7901ae2

Upload data/data_fetcher.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. data/data_fetcher.py +5 -5
data/data_fetcher.py CHANGED
@@ -342,7 +342,7 @@ class DataFetcher:
342
 
343
  def fetch_wallet_holdings(self, wallet_addresses: List[str], T_cutoff: datetime.datetime) -> Dict[str, List[Dict[str, Any]]]:
344
  """
345
- Fetches top 3 wallet holding records for a list of wallet addresses that were active at T_cutoff.
346
  Batches queries to avoid "Max query size exceeded" errors.
347
  Returns a dictionary mapping wallet_address to a LIST of its holding data.
348
  """
@@ -357,10 +357,10 @@ class DataFetcher:
357
  for i in range(0, total_wallets, BATCH_SIZE):
358
  batch_addresses = wallet_addresses[i : i + BATCH_SIZE]
359
 
360
- # --- NEW: Time-aware query based on user's superior logic ---
361
  # 1. For each holding, find the latest state at or before T_cutoff.
362
  # 2. Filter for holdings where the balance was greater than 0.
363
- # 3. Rank these active holdings by USD volume and take the top 3 per wallet.
364
  query = """
365
  WITH point_in_time_holdings AS (
366
  SELECT
@@ -368,7 +368,7 @@ class DataFetcher:
368
  COALESCE(history_bought_cost_sol, 0) + COALESCE(history_sold_income_sol, 0) AS total_volume_usd,
369
  ROW_NUMBER() OVER(PARTITION BY wallet_address, mint_address ORDER BY updated_at DESC) as rn_per_holding
370
  FROM wallet_holdings
371
- WHERE
372
  wallet_address IN %(addresses)s
373
  AND updated_at <= %(T_cutoff)s
374
  ),
@@ -380,7 +380,7 @@ class DataFetcher:
380
  )
381
  SELECT *
382
  FROM ranked_active_holdings
383
- WHERE rn_per_wallet <= 3;
384
  """
385
  params = {'addresses': batch_addresses, 'T_cutoff': T_cutoff}
386
 
 
342
 
343
  def fetch_wallet_holdings(self, wallet_addresses: List[str], T_cutoff: datetime.datetime) -> Dict[str, List[Dict[str, Any]]]:
344
  """
345
+ Fetches top 10 wallet holding records for a list of wallet addresses that were active at T_cutoff.
346
  Batches queries to avoid "Max query size exceeded" errors.
347
  Returns a dictionary mapping wallet_address to a LIST of its holding data.
348
  """
 
357
  for i in range(0, total_wallets, BATCH_SIZE):
358
  batch_addresses = wallet_addresses[i : i + BATCH_SIZE]
359
 
360
+ # --- Time-aware query ---
361
  # 1. For each holding, find the latest state at or before T_cutoff.
362
  # 2. Filter for holdings where the balance was greater than 0.
363
+ # 3. Rank these active holdings by USD volume and take the top 10 per wallet.
364
  query = """
365
  WITH point_in_time_holdings AS (
366
  SELECT
 
368
  COALESCE(history_bought_cost_sol, 0) + COALESCE(history_sold_income_sol, 0) AS total_volume_usd,
369
  ROW_NUMBER() OVER(PARTITION BY wallet_address, mint_address ORDER BY updated_at DESC) as rn_per_holding
370
  FROM wallet_holdings
371
+ WHERE
372
  wallet_address IN %(addresses)s
373
  AND updated_at <= %(T_cutoff)s
374
  ),
 
380
  )
381
  SELECT *
382
  FROM ranked_active_holdings
383
+ WHERE rn_per_wallet <= 10;
384
  """
385
  params = {'addresses': batch_addresses, 'T_cutoff': T_cutoff}
386