Add raw crypto trades endpoint with Binance provider - #7549
Open
parthdongre wants to merge 2 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds raw crypto trade support to the OpenBB crypto price extension through a new exchange-neutral
CryptoTradesstandard model and an initial provider implementation for Binance Spot public market data.It introduces a new
crypto.price.trades(...)command that is intended to return recent execution-level crypto trades, starting with Binance as the first provider.The Binance implementation is not limited to Bitcoin. It supports any valid Binance Spot trading pair, such as:
BTCUSDTETHUSDTSOLUSDTBNBUSDTDOGEUSDTETHBTCBNB/BTCETH/USDTSOL-USDTThe symbol is normalized before making the request, so common formats like
BTC/USDTandBTC-USDTare converted into Binance's expected format,BTCUSDT.What Changed
This PR adds:
A new
CryptoTradesstandard model.A new
crypto.price.trades(...)router command under the crypto price extension.A new
openbb-binanceprovider package.A Binance recent trades fetcher using Binance Spot public recent trades data.
Support for any valid Binance Spot trading pair.
Symbol normalization support for common formats:
BTCUSDTBTC/USDTBTC-USDTETH/USDTSOL-USDTBNB/BTCTrade-side conversion from Binance's
isBuyerMakerfield into an aggressor-side value:buysellUnit tests for:
README documentation for the new Binance provider.
Motivation
OpenBB already supports crypto historical price data, but raw execution-level trade data is useful for more detailed market analysis.
Historical OHLCV candles show aggregated price movement over time, while raw trades show the individual executions that create those candles. This gives users access to a more granular market-data layer.
Recent raw trades provide a foundation for future crypto market data features such as:
This PR keeps the first implementation intentionally focused by adding the standard model, route, and one public provider implementation.
New Command
Other valid Binance Spot pairs can also be requested:
New Standard Model
This PR adds a new
CryptoTradesstandard model with the following fields:The model is intended to be exchange-neutral so additional providers can implement the same interface later.
Binance Provider Behavior
The Binance implementation uses Binance Spot public recent trades data.
The fetcher:
isBuyerMakerinto an aggressor-side value.Symbol normalization examples:
Trade-side conversion:
Reasoning:
isBuyerMaker=True, the buyer was the maker, so the seller was the taker/aggressor.isBuyerMaker=False, the buyer was the taker/aggressor.Example Output
A live fetcher test returned transformed rows like:
Example Use Cases
This endpoint can be used to retrieve execution-level trade data for:
Example pair requests:
Testing
Unit Tests
PYTHONPATH="$PWD/openbb_platform/core:$PWD/openbb_platform/providers/binance" \ python -m pytest openbb_platform/providers/binance/tests -qResult:
Syntax Checks
Live Fetcher Test
Result:
Example transformed output:
Test Cases Covered
The included test file covers:
Symbol Normalization
Side Conversion
Query Transformation
Example input:
{"symbol": "BTC/USDT", "limit": 100}Expected transformed query:
Data Transformation
The tests verify that Binance raw trade payloads are transformed into OpenBB model data with:
Limit Validation
The standard query validation enforces Binance's supported limit range.
Example invalid input:
{"symbol": "BTCUSDT", "limit": 1001}Expected behavior:
Files Added / Modified
Added:
openbb_platform/core/openbb_core/provider/standard_models/crypto_trades.pyopenbb_platform/providers/binance/README.mdopenbb_platform/providers/binance/pyproject.tomlopenbb_platform/providers/binance/openbb_binance/__init__.pyopenbb_platform/providers/binance/openbb_binance/models/__init__.pyopenbb_platform/providers/binance/openbb_binance/models/crypto_trades.pyopenbb_platform/providers/binance/openbb_binance/utils/__init__.pyopenbb_platform/providers/binance/openbb_binance/utils/helpers.pyopenbb_platform/providers/binance/tests/test_binance_fetchers.pyModified:
openbb_platform/extensions/crypto/openbb_crypto/price/price_router.pyNotes
This PR uses Binance public market data and does not require credentials.
The current implementation depends on Binance Spot symbols being valid. If a symbol does not exist on Binance Spot, the provider will return a Binance API error.
The live fetcher test was run against
BTCUSDT, while the implementation is symbol-generic and works for any valid Binance Spot pair accepted by Binance's public recent trades endpoint.This PR does not claim that the full installed
obb.crypto.price.trades(...)command was tested end-to-end. The testing performed includes unit tests, syntax checks, and a live fetcher-level Binance API test.Follow-Up Work
Possible follow-up PRs can build on this standard model by adding:
Coinbase support for
CryptoTrades.Kraken support for
CryptoTrades.Additional exchange providers using the same standard model.
Trade-derived summary metrics such as:
A higher-level trade summary endpoint built from raw trades.
More detailed provider-level tests with mocked HTTP responses.
Additional live examples for other pairs such as
ETHUSDT,SOLUSDT, andBNBBTC.