how to process different API responses and get unified response to work with? [closed]

  softwareengineering

I am trying to make a crypto analysis app. I am new to software designs and trying best to avoid poor code design/repetition so that whenever I have to add any new features or make modification, I don’t have to spend lot of effort in refactoring/maintenance.

My current workflow is like this:

I first fetch trending tokens from all the platforms(dexscreener, dextools, …), filter tokens(based on params say volume, timeframe, market cap, or maybe more), then fetch more details of filtered tokens such as ath, security status, social links, etc from different apis, and then combine them into a single dataset.

For example, I want to work with these fields related to a Token in other parts of the code:

Name: str
Symbol: str
Socials : Socials(Enum)
Address : str
Price :float
PriceChange : float
ATHChange : float
Volume : float
MarketCap : float
Liquidity : float
Swaps1h: float
Swaps : float
SmartMoney : SmartMoney(Enum)
Taxes : Taxes(Enum)
Score: float
Warnings: str
TotalSupply : int
Holders : int
TopHolders : float
Timeframe : str
Age : float
CirculatingSupply : int

And before achieving that, I have to deal with multiple API responses, process them, clean them, and merge them.

API response for dexscreener is like this:

http://jsonblob.com/1225042474409254912

and API response for dextools is like this

https://developer.dextools.io/products/http-api/Documentation#get-/v2/token/-chain-/-address-

Now list<APIResponses(Dexscreener, Dextools, ...)> will be given to the class that will deal with these responses and spit out list<Token>. As you can see, it gets harder when the same token has some information in dexscreener and some in dextools, say Swaps1h wasn’t provided by dexscreener, but was provided by dextools so it needs to be merged into the Token struct, then there are also other details (ath, warnings, score, smartmoney, …) that later needs to be fetched from completely different apis and merge with the Token.

All in all, I need a way to construct this class(es) that can effectively deal with different APIResponses, construct a single dataset, cleans and formats the data and just return list<Token> which I can use in any other class. If you can also refer some resources tackling this same problem, would highly appreciate that. Thanks!

New contributor

Kenny ripper is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

LEAVE A COMMENT