Skip to content

Complete migration of Crypto Loans API from v1(partial support) to v2(full support) #1503

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

ShrewdLuni
Copy link
Contributor

Refactored Crypto Loans General client that partially supported Crypto Loans API v1, to make it fully support new Crypto Loans API v2.

Endpoints:

Added support for new endpoints:

  • RepayCollateralAsync
  • GetFlexibleBorrowHistoryAsync
  • GetLiquidationHistoryAsync
  • GetFlexibleRepayHistoryAsync

Migrated outdated endpoints from API v1 to API v2 standard:

  • GetCollateralAssetsAsync
  • GetLoanableAssetsAsync
  • BorrowAsync
  • RepayAsync
  • AdjustLTVAsync
  • GetFlexibleLtvAdjustHistoryAsync
  • GetCollateralRepayRateAsync
  • GetOpenBorrowOrdersAsync

Fixed parameter naming issue in v1 endpoints:

  • GetBorrowHistoryAsync
  • GetLtvAdjustHistoryAsync
  • GetRepayHistoryAsync

Removed fully retired endpoint:

  • Customize Margin Call

Enums:

Added new Enums:

  • RepayStatus
  • FlexibleBorrowStatus
  • FlexibleBorrowRecordStatus
  • LoanLiquidationStatus

Models:

Added new Models:

  • BinanceCryptoLoanFlexibleBorrowRecord
  • BinanceCryptoLoanFlexibleLtvAdjastRecord
  • BinanceCryptoLoanFlexibleRepayRecord
  • BinanceCryptoLoanLiquidationRecord

Migrated outdated models from API v1 to API v2 standard:

  • BinanceRestClientGeneralApiLoans
  • BinanceCryptoLoanAsset
  • BinanceCryptoLoanCollateralAsset
  • BinanceCryptoLoanBorrow
  • BinanceCryptoLoanLtvAdjust
  • BinanceCryptoLoanRepay
  • BinanceCryptoLoanOpenBorrowOrder
  • BinanceCryptoLoanRepayRate
  • BinanceCryptoLoanFlexibleBorrowRecord

Other Changes:

  • Updated XML documentation to reflect API v2 changes (including docs URLs).
  • Updated IBinanceRestClientGeneralApiLoans interface to match new endpoints.
  • Removed tests related to Crypto Loans API v1 endpoints.

References:

- Changed method orders to replicate api layout
- Tagged methods as MISSING or RETIRED
- Restructured regions
Updated:
Methods:
- `Get Collateral Assets`
- `GetLoanableAssetsAsync`

Models:
- `BinanceCryptoLoanAsset`
- `BinanceCryptoLoanCollateralAsset`
Updated:
Methods:
- `BorrowAsync`
- `RepayAsync`
- `RepayCollateralAsync`
- `AdjustLTVAsync`

Models:
- `BinanceCryptoLoanBorrow`
- `BinanceCryptoLoanRepay`
- `BinanceCryptoLoanLtvAdjust`

Added Enum:
- `RepayStatus`
# Summary:
## Methods:
#### 1. Added missing methods:
  - `GetFlexibleLtvAdjustHistoryAsync`
  - `GetFlexibleBorrowHistoryAsync`
  - `GetLiquidationHistoryAsync`
  - `GetRepayHistoryAsync`
#### 2. Updated outdated/retired method to API v2**:
- `GetCollateralRepayRateAsync`
- `GetOpenBorrowOrdersAsync`

## Enums:
#### Added enums:
- `FlexibleBorrowStatus`
- `LoanLiquidationStatus`

## Models:
#### 1. Added models for missing methods:
- `BinanceCryptoLoanFlexibleBorrowRecord`
- `BinanceCryptoLoanFlexibleRepayRecord`
- `BinanceCryptoLoanFlexibleLtvAdjustRecord`
- `BinanceCryptoLoanLiquidationRecord`

#### 2. Refactored existing models:
- `BinanceCryptoLoanOpenBorrowOrder`
- `BinanceCryptoLoanRepayRate`
parameters.AddOptionalParameter("loanAsset", loanAsset);
parameters.AddOptionalParameter("collateralAsset", collateralAsset);
parameters.AddOptionalParameter("current", page?.ToString(CultureInfo.InvariantCulture));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works fine, but there are also helper methods you can use instead.
You could use parameters.AddOptionalString("current", page) which will internally check for null and convert to string.

Copy link
Contributor Author

@ShrewdLuni ShrewdLuni Apr 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed this in Updated string parameter handling logic Commit

await tester.ValidateAsync(client => client.GeneralApi.CryptoLoans.CustomizeMarginCallAsync(123), "CustomizeMarginCall");
}
//[Test]
//public async Task ValidateGeneralCryptoLoansCalls() // TODO Update Crypto Loans Tests for API v2
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this something you could also add?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was thinking about doing single PR with test fixes, I noticed that there are lots of general client ones missing. I had an idea that I would add support for missing services like NFT, Gift Cards, VIP Loans, etc and then I would make a single big PR focused on tests. I am currently working on VIP Loans, I hope that I will be done today/tomorrow. And I could start working on tests after that.

Moved from manual string conversion to build in helper `AddOptionalString`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants