I have a recent dump - which I can refresh on demand - of the Hyperliquid leaderboard based on PnL over the last 24h.
I'd like to understand, in aggregate, what the top 100 wallets are longing and shorting, their approximate entry price and size.
Of course, in many cases a given wallet may have had a long or short open for a long time, and only in the last 24h price action has done something which has made them profitable. A good example is yesterday's FOMC which ushered in plenty of volatility.
As I proceed to review each wallet, I'd like a deeper dive on when the wallet opened a given trade.
Of especial interest are new wallets, or wallets where someone has dumped a bunch of money and quickly capitalised on an emerging trend.
I have to say the Hyperliquid APIs don't make the above incredibly easy.
How would you suggest breaking these tasks down for a capable API with unit tests all the way and appropriate tests to ensure it's not hallucinating or leading me up the garden path?
Assistant
User
Actually, your response epitomises the issue here.
The hyperliquid API does not expose leaderboard data. I'm getting it from elsewhere. EVERY SINGLE LLM WITHOUT EXCEPTION SEEMS JUST TO ASSUME THAT THE API WILL HAVE THE NECESSARY FUNCTIONS. So the very first question is: how should I proceed with an LLM that has such certainty? Firstly it needs to probe the API, surely? We have to assume that the documentation for these things is not entirely adequate. So first we need to evaluate the available APIs and workarounds, and only then can we really derive a solution.
The hyperliquid API DOES allow for more scrupulous investigation of a given wallet's activities. That said, even here there has to be quite a bit of sleuthing, because smart money will DCA in over time, resulting in hundreds of trades which have to be intelligently put together.
Assistant
To tackle this problem, you can break it down into the following steps:
Fetch the Leaderboard Data: Start by fetching the leaderboard data from the Hyperliquid API. This will give you the top 100 wallets based on their PnL over the last 24 hours.
Analyze the Leaderboard Data: Once you have the leaderboard data, you can start analyzing it to understand the positions and trades of the top 100 wallets. This can be done by parsing the data and extracting the relevant information, such as the wallet address, the asset being traded, the position (long or short), the entry price, and the trade size.
Fetch Historical Trade Data: To get a deeper understanding of when the wallets opened their positions, you'll need to fetch the historical trade data for each of the top 100 wallets. This can be done by making additional API calls to the Hyperliquid API, using the wallet addresses as the input.
Aggregate the Data: After fetching the historical trade data, you can aggregate the information to get a better understanding of the trading activities of the top 100 wallets. This can include calculating the average entry price, the total trade size, and the duration of the trades.
Identify New Wallets and Significant Trades: As part of the analysis, you can also identify new wallets that have recently entered the leaderboard, as well as any significant trades that have been made by the top 100 wallets.
Implement Unit Tests: To ensure the reliability and accuracy of your analysis, you should implement a comprehensive suite of unit tests. This can include tests to validate the API responses, the data parsing, and the aggregation logic.
Implement Integration Tests: In addition to unit tests, you should also implement integration tests to ensure that the entire workflow, from fetching the leaderboard data to analyzing the historical trade data, is working as expected.
Implement Defensive Checks: To prevent your analysis from being led up the garden path, you should implement defensive checks throughout your code. This can include checks for invalid or missing data, as well as checks for any unexpected behavior in the API responses.
Here's a high-level pseudocode to give you an idea of how you can approach this problem:
python
def get_top_100_wallets_positions():
# Fetch the leaderboard data from the Hyperliquid API
leaderboard_data = fetch_leaderboard_data()
# Initialize a dictionary to store the positions of the top 100 wallets
wallet_positions = {}
for wallet in leaderboard_data[:100]:
wallet_address = wallet['wallet_address']
wallet_positions[wallet_address] = {
'pnl': wallet['pnl'],
'positions': []
}
# Fetch the historical trade data for the wallet
trade_history = fetch_trade_history(wallet_address)
for trade in trade_history:
wallet_positions[wallet_address]['positions'].append({
'asset': trade['asset'],
'position': trade['position'],
'entry_price': trade['entry_price'],
'size': trade['size'],
'opened_at': trade['opened_at']
})
return wallet_positions
def identify_new_wallets_and_significant_trades(wallet_positions):
new_wallets = []
significant_trades = []
for wallet_address, wallet_data in wallet_positions.items():
# Check if the wallet is new to the leaderboard
if wallet_address not in previous_leaderboard_data:
new_wallets.append(wallet_address)
# Check for any significant trades
for position in wallet_data['positions']:
if position['size'] > 1000000:
significant_trades.append({
'wallet_address': wallet_address,
'asset': position['asset'],
'position': position['position'],
'entry_price': position['entry_price'],
'size': position['size'],
'opened_at': position['opened_at']
})
return new_wallets, significant_trades
# Usage
wallet_positions = get_top_100_wallets_positions()
new_wallets, significant_trades = identify_new_wallets_and_significant_trades(wallet_positions)
print("New Wallets:", new_wallets)
print("Significant Trades:", significant_trades)
This is a high-level example, and you'll need to fill in the details of the API calls, data parsing, and test implementation. Remember to use appropriate libraries and frameworks for your programming language, and to follow best practices for API interactions, data handling, and testing.
You're absolutely right, and I should not have assumed the availability of certain API functions without first investigating the actual capabilities of the Hyperliquid API. Let me rethink this approach:
Investigate the Hyperliquid API: The first step should be to thoroughly investigate the Hyperliquid API and understand its actual capabilities. This includes:
Reviewing the API documentation to identify the available endpoints and their functionality.
Potentially reaching out to the Hyperliquid team to inquire about any undocumented features or workarounds that could be useful for your use case.
Experimenting with the API by making sample requests and analyzing the responses to understand the data structure and any limitations.
Identify Data Sources: Since the Hyperliquid API may not provide the exact data you need, you should explore alternative data sources that could supplement the information you can gather from the API. This could include:
Scraping data from public sources, such as leaderboards or trading activity pages.
Leveraging other APIs or data providers that may have relevant information.
Considering ways to combine data from multiple sources to get a more comprehensive view.
Design a Flexible and Extensible Solution: Given the limitations of the Hyperliquid API and the need to potentially work with multiple data sources, your solution should be designed to be flexible and extensible. This could involve:
Implementing a modular architecture that allows for easy integration of new data sources or API endpoints.
Designing a data processing pipeline that can handle different data formats and structures.
Incorporating robust error handling and defensive checks to ensure the reliability of your analysis.
Implement Incremental Testing: Rather than assuming the availability of certain API functions, you should take an incremental approach to testing and development. This could involve:
Starting with basic functionality, such as fetching and parsing data from the Hyperliquid API.
Gradually expanding the scope of your tests and implementation as you uncover new data sources or API capabilities.
Regularly reviewing and updating your test suite to ensure it covers all the relevant scenarios.
Collaborate with the Hyperliquid Team: If possible, consider reaching out to the Hyperliquid team to discuss your use case and explore any potential collaboration or support they can provide. This could help you better understand the API's capabilities and identify any undocumented features or workarounds that could be useful for your analysis.
By taking this more cautious and iterative approach, you can avoid making assumptions about the API's capabilities and instead focus on developing a robust and flexible solution that can adapt to the actual data sources and limitations you encounter.