-
Notifications
You must be signed in to change notification settings - Fork 32
Perpetual Futures API Support #20
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for Futures/Perpetual contracts to the BinanceBot trading system by introducing a strongly-typed MarketSymbol entity and refactoring the codebase structure. The changes enable the bot to work with both Spot and Futures markets through a unified interface while improving order book synchronization reliability.
Key Changes:
- Introduced
MarketSymbolrecord withBaseAsset,QuoteAsset, andContractTypeto replace string-based symbol representation - Refactored namespace organization: moved domain models from
BinanceBot.Market.CoretoBinanceBot.Market.Domain, utilities fromBinanceBot.Market.UtilitytoBinanceBot.Market.Core/BinanceBot.Market.Extensions - Enhanced order book buffering logic with increased buffer time (from 2x to 5x update interval, minimum 1000ms)
Reviewed Changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 12 comments.
Show a summary per file
| File | Description |
|---|---|
| src/BinanceBot.Market/Domain/Symbol.cs | Introduces new MarketSymbol record and ContractType enum for typed symbol representation |
| src/BinanceBot.Market/Domain/MarketDepth.cs | Updates constructor to accept MarketSymbol instead of string; renames LastUpdateTime to LastUpdateId; updates namespace from Core to Domain |
| src/BinanceBot.Market/MarketDepthManager.cs | Adds Futures API support with contract type switching; improves buffering; removes critical update gap validation |
| src/BinanceBot.Market/Domain/Quote.cs | Namespace change from Core to Domain |
| src/BinanceBot.Market/Domain/MarketDepthPair.cs | Namespace change from Core to Domain |
| src/BinanceBot.Market/Extensions/QuoteExtensions.cs | Namespace change from Utility to Extensions; imports from Domain |
| src/BinanceBot.Market/Core/DescDecimalComparer.cs | Namespace change from Utility to Core |
| src/BinanceBot.Market/Abstracts/IMarketDepthPublisher.cs | Updates imports to use Domain namespace |
| src/BinanceBot.Market/Abstracts/IMarketBot.cs | Changes Symbol property type from string to MarketSymbol |
| src/BinanceBot.Market/Abstracts/BaseMarketBot.cs | Updates constructor and property to use MarketSymbol |
| src/BinanceBot.Market/MarketMakerBot.cs | Updates to use MarketSymbol and accesses FullName property when calling APIs |
| src/BinanceBot.Market/Strategies/NaiveMarketMakerStrategy.cs | Updates imports to use Domain namespace |
| src/BinanceBot.MarketViewer.Console/Program.cs | Updates to use MarketSymbol; moves "Press Enter to exit..." into event handler causing repeated printing |
| src/BinanceBot.MarketBot.Console/Program.cs | Updates to use MarketSymbol; has formatting/redundancy issues |
| tests/BinanceBot.Market.Tests/Core/MarketDepthTests.cs | Updates tests for MarketSymbol; adds redundant import alias; adds duplicate Futures tests |
| tests/BinanceBot.Market.Tests/MarketDepthManagerTests.cs | Updates test helper; has unused import; lacks test coverage for new Futures functionality |
Comments suppressed due to low confidence (1)
tests/BinanceBot.Market.Tests/Core/MarketDepthTests.cs:94
- [nitpick] The test
UpdateDepth_WithValidData_UpdatesOrderBook_Perpetualduplicates most of the logic fromUpdateDepth_WithValidData_UpdatesOrderBookexcept for checkingContractType.Futures. Consider combining these tests using a[Theory]with[InlineData]for different contract types to reduce duplication, similar to the pattern used inConstructor_WithValidSymbol_CreatesInstance.
[Fact]
public void UpdateDepth_WithValidData_UpdatesOrderBook_Perpetual()
{
// Arrange
var marketDepth = CreateTestMarketDepthPerpetual();
var asks = new List<BinanceOrderBookEntry>
{
new() { Price = 50000m, Quantity = 1.5m },
new() { Price = 50100m, Quantity = 2.0m }
};
var bids = new List<BinanceOrderBookEntry>
{
new() { Price = 49900m, Quantity = 1.0m },
new() { Price = 49800m, Quantity = 0.5m }
};
// Act
marketDepth.UpdateDepth(asks, bids, 123456);
// Assert
Assert.Equal(ContractType.Futures, marketDepth.Symbol.ContractType);
Assert.Equal(123456, marketDepth.LastUpdateId);
Assert.Equal(2, marketDepth.Asks.Count());
Assert.Equal(2, marketDepth.Bids.Count());
Assert.Equal(50000m, marketDepth.BestAsk.Price);
Assert.Equal(49900m, marketDepth.BestBid.Price);
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…tract type representation
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This reverts commit 3d33f06.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 17 out of 17 changed files in this pull request and generated 6 comments.
Comments suppressed due to low confidence (1)
src/BinanceBot.Market/Domain/MarketDepth.cs:19
- The null check for
symbolthrowsArgumentException, butArgumentNullExceptionwould be more appropriate when the parameter is null. Consider usingArgumentNullException.ThrowIfNull(symbol)or explicitly checkingif (symbol == null) throw new ArgumentNullException(nameof(symbol)).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Changelog:
MarketSymbolentity