Skip to content

Conversation

@codez0mb1e
Copy link
Owner

@codez0mb1e codez0mb1e commented Nov 20, 2025

Changelog:

  • Add support for Perpetual Futures contracts
  • Inject the MarketSymbol entity
  • Improve Order book events buffering
  • Minor refactor the project structure and ensure consistent naming conventions.

Copilot AI review requested due to automatic review settings November 20, 2025 19:15
@codez0mb1e codez0mb1e self-assigned this Nov 20, 2025
Copy link
Contributor

Copilot AI left a 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 MarketSymbol record with BaseAsset, QuoteAsset, and ContractType to replace string-based symbol representation
  • Refactored namespace organization: moved domain models from BinanceBot.Market.Core to BinanceBot.Market.Domain, utilities from BinanceBot.Market.Utility to BinanceBot.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_Perpetual duplicates most of the logic from UpdateDepth_WithValidData_UpdatesOrderBook except for checking ContractType.Futures. Consider combining these tests using a [Theory] with [InlineData] for different contract types to reduce duplication, similar to the pattern used in Constructor_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.

codez0mb1e and others added 14 commits November 20, 2025 22:35
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>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Contributor

Copilot AI left a 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 symbol throws ArgumentException, but ArgumentNullException would be more appropriate when the parameter is null. Consider using ArgumentNullException.ThrowIfNull(symbol) or explicitly checking if (symbol == null) throw new ArgumentNullException(nameof(symbol)).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codez0mb1e codez0mb1e changed the title Futures API Support Perpetual Futures API Support Nov 21, 2025
codez0mb1e and others added 2 commits November 21, 2025 18:44
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@codez0mb1e codez0mb1e merged commit 3a9f378 into master Nov 21, 2025
4 checks passed
@codez0mb1e codez0mb1e deleted the futures-api-support branch November 21, 2025 15:48
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