Description
User Story
As a developer, I want to add Bitget as a source for fetching rates for all supported currencies (e.g., NGN, KES, GHS, etc.), so that we can calculate the median rate from multiple providers (Quidax, Binance, and Bitget) to improve accuracy and reliability.
Acceptance Criteria
-
GIVEN a supported currency (e.g., NGN, KES, GHS)
WHEN fetching rates for a token/fiat pair
THEN the system should fetch rates from Bitget, Binance, and Quidax (if applicable) and calculate the median -
GIVEN the currency is NGN
WHEN fetching rates for USDT/NGN
THEN the system should fetch rates from Quidax and Bitget -
GIVEN the currency is not NGN
WHEN fetching rates for USDT/
THEN the system should fetch rates from Binance and Bitget -
GIVEN the logic for fetching rates from external providers
WHEN refactoring the code
THEN the logic should be moved to/utils/external_markets.go
for better organization and reusability -
GIVEN the Bitget API is called
WHEN fetching P2P ads
THEN the system should fetch the last 20 ads and calculate the median price
Tech Details
- Add support for the Bitget API to fetch P2P ads.
- Move the logic for fetching rates from external providers to
/utils/external_markets.go
.- Create utility functions for fetching rates from each provider: Quidax, Binance, and Bitget.
- Rate Calculation:
- For USDT/NGN: Fetch rates from Quidax and Bitget, then calculate the median.
- For other currencies: Fetch rates from Binance and Bitget, then calculate the median.
- Write tests for the new util functions
Notes/Assumptions
- The Bitget API is stable and returns data in the expected format.
- The median rate calculation is sufficient for determining the market rate.
- The system should handle API failures gracefully and continue with available rates.