Skip to content
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

Adding library to the omni-executor for the binance api (Convert) #3279

Open
wants to merge 32 commits into
base: dev
Choose a base branch
from

Conversation

silva-fj
Copy link
Contributor

@silva-fj silva-fj commented Mar 5, 2025

This PR introduces a new library to be able to interact with the Binance API (Convert).

Note: We need to setup a test account to properly test the library. I have not looked into it yet.

silva-fj added 30 commits March 5, 2025 10:28
Add a new crate for interaction with the Binance API, including:
- Project setup with necessary dependencies
Create BinanceApi struct with API credentials and URL configuration
for interacting with Binance REST API endpoints. The client can be
initialized with custom base URL or defaults to the standard Binance API
endpoint.
Add method to fetch available token pairs and their trading limits
from the Binance convert API. The implementation includes proper error
handling and allows filtering by source and destination assets.
Add a reqwest Client instance to the BinanceApi struct to enable
connection pooling and reuse, replacing the static reqwest::get
method with client-based requests for improved performance.
Extract "/sapi/v1/convert" into a CONVERT_API constant to improve code
maintainability and reduce string duplication when constructing Binance
API endpoints.
Implement HMAC SHA256 signing for authenticated Binance API requests,
including helper method for making signed requests and corresponding
test. This enables secure interaction with protected Binance API
endpoints.
Implement get_asset_info method to retrieve precision information for
all supported assets from Binance Convert API. This enhances the API
client's capabilities by allowing access to critical asset metadata.
Added proper handling of request parameters in the API client, allowing
for passing parameters as key-value pairs. This enables methods like
GET and POST to correctly format and send parameters according to the
Binance API requirements.

Improved request signing logic to properly handle all parameters and
updated request building to support different HTTP methods correctly.
as well as RequestQuoteParams to handle building and validating quote
request parameters. This includes handling different wallet types and
proper amount serialization.
Simplify error naming by changing BinanceApiError to Error, improving
code consistency and readability. Also rename specific error variants
to be more concise (e.g., RequestError to RequestFailed).
Add optional recv_window parameter to get_asset_info method to allow
customizing request timeout settings when calling Binance API
endpoints. This improves flexibility for different network conditions.
Add get_quote method to the BinanceApi client to request quotes for
token pairs. This includes support for the RequestQuoteParams type and
proper parameter conversion and validation, with appropriate error
handling.
Add maximum recv_window validation to prevent API errors, changing
parameter type from u64 to u32, and adding MaxRecvWindowExceeded error
variant. This ensures requests stay within Binance API limits of 60000ms.
Add documentation comments to from_amount and to_amount fields in
RequestQuoteParams struct to clarify their purpose in the quote request
process, improving API usability and developer understanding.
Implement accept_quote method in BinanceApi to allow accepting quotes
by their ID. Also add ConvertOrder and ConvertOrderStatus types to
handle API responses for quote acceptance operations, supporting the
order processing workflow.
Add functionality to retrieve convert trade history from the Binance API
with appropriate parameter validation, including:
- New ConvertTradeHistory and ConvertTrade types for response data
- Add LimitExceeded error for handling invalid limit parameters
- Validate time range (max 30 days) and limit (max 1000) parameters
Implement functionality to query the status of convert orders by either
order ID or quote ID with:
- New ConvertOrderStatus struct to represent API response
- Rename ConvertOrderStatus enum to OrderStatus for consistency
- Add validation to ensure at least one ID parameter is provided
Implement functionality for placing limit orders on Binance Convert API:
- Add new PlaceLimitOrderParams struct with validation
- Create OrderSide and ExpiredType enums for request parameters
- Add LimitOrder response type for decoded API responses
- Implement place_limit_order method in BinanceApi client
- Add comprehensive test coverage for parameter validation
Implement functionality to cancel limit orders on Binance Convert API:
- Add CancelOrderLimit struct to represent API response
- Implement cancel_limit_order method in BinanceApi client
- Export the new type through the public API
- Document usage with API endpoint details
Implement functionality to retrieve all open limit orders:
- Add OpenOrders and OpenOrder response types
- Create get_open_orders method in BinanceApi client
- Support passing optional recv_window parameter
- Export the new types through public API
Move Binance Convert API methods to a dedicated module:
- Create new convert_api.rs module with ConvertApi class
- Update lib.rs to expose API through a facade method
- Extract all Convert-specific endpoints to the new module
- Make internal methods public for cross-module usage
- Add helper for making public GET requests
@silva-fj silva-fj requested a review from a team March 5, 2025 17:28
Copy link

linear bot commented Mar 5, 2025

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.

1 participant