Skip to content

Conversation

@konard
Copy link
Contributor

@konard konard commented Jan 5, 2026

Summary

This PR implements a comprehensive architecture update for multi-user, multi-account trading with recursive allocation strategies:

  • Links Notation Parser (lib/rust/lino_args/lino.rs)

    • Parses hierarchical indented configuration files
    • Supports nested structures for complex configs
    • Path-based value access (e.g., config.get("settings/log_level"))
    • Flattening to environment variables
  • Recursive Allocation System (src/domain/allocation.rs)

    • Simple ticker allocations: SBER 30, LKOH 30, GAZP 40
    • Strategy-based allocations: balancer, hold, scalper, DCA
    • Nested balancers for complex portfolio management
    • Automatic flattening for execution
  • Multi-User/Account Models (src/domain/user.rs)

    • User = connection to broker/exchange (credentials)
    • Account = trading account within broker (allocation)
    • Multiple users with multiple accounts each
    • Configuration validation
  • Updated README

    • CLI-first documentation with Links Notation
    • Configuration examples (simple and recursive)
    • Architecture principles in Links Notation format

Configuration Examples

Simple allocation:

allocation
  SBER 30
  LKOH 30
  GAZP 40

Recursive allocation (nested balancers):

allocation
  strategy balancer
    portion 60
      allocation
        strategy balancer
          portion 50
            allocation
              strategy hold
              ticker SBER
          portion 50
            allocation
              strategy hold
              ticker LKOH
    portion 40
      allocation
        strategy hold
        ticker BTC

Multi-user config:

users
  (
    broker tbank
    token TBANK_API_TOKEN
    accounts
      main
        allocation
          SBER 30
          LKOH 70
  )
  (
    exchange binance
    "api key" BINANCE_API_KEY
    accounts
      spot_main
        allocation
          BTC 50
          ETH 50
  )

Test Plan

  • All 171 tests pass (140 unit, 17 integration, 14 doc tests)
  • Links Notation parser handles all edge cases
  • Allocation flattening calculates correct percentages
  • User/Account validation catches configuration errors
  • Clippy and formatting checks pass

🤖 Generated with Claude Code

Fixes #7

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: #7
@konard konard self-assigned this Jan 5, 2026
Implements the --plan CLI option that allows users to:
- Run the bot with real market APIs in read-only mode
- Calculate and display all orders that would be placed
- Debug and verify bot behavior without executing trades
- Check planned orders for each strategy in the configuration

Changes:
- Added --plan flag to CLI with TRADER_BOT_PLAN env var support
- Created PlannedOrder and PlannedOrders types for order collection
- Implemented plan mode display with formatted output
- Updated demo mode to support --plan for testing
- Added comprehensive test coverage (8 new tests)

Usage:
  trader-bot --demo --plan    # See planned orders in demo mode
  trader-bot --config x --plan # Plan mode with real market

Fixes #7

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@konard konard changed the title [WIP] --plan option feat: Add --plan option for read-only order planning mode Jan 5, 2026
@konard konard marked this pull request as ready for review January 5, 2026 22:53
@konard
Copy link
Contributor Author

konard commented Jan 5, 2026

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $5.571549 USD
  • Calculated by Anthropic: $3.481697 USD
  • Difference: $-2.089852 (-37.51%)
    📎 Log file uploaded as GitHub Gist (1093KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard
Copy link
Contributor Author

konard commented Jan 6, 2026

We need to update docs, by default we should give CLI first guide, and it should use Links Notation for configuration similar to how it works at:

Prefer indented syntax of links notation to maximize readability.

@konard konard marked this pull request as draft January 6, 2026 20:13
@konard
Copy link
Contributor Author

konard commented Jan 6, 2026

🤖 AI Work Session Started

Starting automated work session at 2026-01-06T20:13:28.115Z

The PR has been converted to draft mode while work is in progress.

This comment marks the beginning of an AI work session. Please wait working session to finish, and provide your feedback.

- Reorganize README to prioritize CLI usage documentation
- Add comprehensive CLI options reference using indented Links Notation
- Document configuration priority chain (CLI > env vars > config files > defaults)
- Add lenv file format examples using lino-env style (colon separator)
- Include environment variable reference table
- Add practical usage examples for common scenarios
- Update References section with Links Notation dependencies
- Remove redundant JSON configuration example (moved to Quick Start section)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@konard konard marked this pull request as ready for review January 6, 2026 20:17
@konard
Copy link
Contributor Author

konard commented Jan 6, 2026

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $2.409807 USD
  • Calculated by Anthropic: $1.490980 USD
  • Difference: $-0.918828 (-38.13%)
    📎 Log file uploaded as GitHub Gist (385KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard
Copy link
Contributor Author

konard commented Jan 6, 2026

I see JSON Configuration File, but I asked to use Links Notation with indented syntax instead, it should also be implemented in code, if it is not implemented yet. We also need to fully support configuration via .lenv and yargs style arguments.

And I repeat:

We need to update docs, by default we should give CLI first guide, and it should use Links Notation for configuration similar to how it works at:

Prefer indented syntax of links notation to maximize readability. If something is not implemented in the code it should be done there also. You can temporary copy rust version libraries if they are not yet published.

@konard konard marked this pull request as draft January 6, 2026 22:10
@konard
Copy link
Contributor Author

konard commented Jan 6, 2026

🤖 AI Work Session Started

Starting automated work session at 2026-01-06T22:10:25.417Z

The PR has been converted to draft mode while work is in progress.

This comment marks the beginning of an AI work session. Please wait working session to finish, and provide your feedback.

- Update lenv parser to use ": " (colon-space) separator as per Links
  Notation specification
- Maintain backwards compatibility with "=" separator for existing files
- Add comprehensive tests for Links Notation format including:
  - Basic key-value pairs with ": " separator
  - Comments and empty lines
  - Quoted values (double and single quotes)
  - Values containing colons (URLs)
  - Mixed separators for migration support
- Update README to remove JSON configuration section
- Add indented Links Notation examples for multi-account configuration
- Update CLI options documentation with Links Notation format

References:
- https://github.com/link-foundation/links-notation
- https://github.com/link-foundation/lino-env
- https://github.com/link-foundation/lino-arguments

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@konard konard marked this pull request as ready for review January 6, 2026 22:17
@konard
Copy link
Contributor Author

konard commented Jan 6, 2026

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $2.909200 USD
  • Calculated by Anthropic: $1.800050 USD
  • Difference: $-1.109150 (-38.13%)
    📎 Log file uploaded as GitHub Gist (475KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard
Copy link
Contributor Author

konard commented Jan 6, 2026

In docs we should focus on minimum commands to start the bot from the beggining of README, and also start with Links Notation configuration:

# Multi-user trading configuration

# Global settings
settings:
  "log level" info
  verbose false
  "dry run" false

# User configurations
users:
  (
    broker tbank
    token TBANK_API_TOKEN
    accounts
      main
        allocation
          strategy balancer
            portion 30
              allocation
                 strategy hold
                 ticker SBER
            portion 30
              allocation
                strategy hold
                ticker LKOH
            portion 40
              allocation
                strategy hold
                ticker GAZP
      trading
        allocation
          SBER 30
          LKOH 30
          GAZP 40
    )
    (
        exchange binance
        "api key" BINANCE_API_KEY
        accounts
          spot_main
            allocation
              BTC 50
              ETH 50
    )

It should be like this.

So user is actually exchange user, it should be connected to single exchange or broker.
Accounts are broker accounts or exchange accounts and can be multiple per user.

We don't use : for something that is not unique in the context of entire file. We can have aliases like "token" is can be the same as "api key" in configuration, but it code it should map to single field.

So for this configuration to work, looks like we need to redo architecture of our trader bot before we can finish with this pull request.

allocation
  strategy balancer
    portion 30
      allocation
         strategy hold
         ticker SBER
    portion 30
      allocation
        strategy hold
        ticker LKOH
    portion 40
      allocation
        strategy hold
        ticker GAZP

should be effectively the same as

allocation
    SBER 30
    LKOH 30
    GAZP 40

So both should work at the same time, but we need the first example to make sure we can add balancers inside balancers and so on. And for example have balancing between scalpers, holds and balancers.

So the configuration should support full recursion as well short notation of configuration.

I'm preparing everything for the first startup, so the configuration itself must be made perfect, and code should have architecture to support it.

To make good architecure read these principles: https://github.com/link-foundation/code-architecture-principles

@konard konard marked this pull request as draft January 6, 2026 22:56
@konard
Copy link
Contributor Author

konard commented Jan 6, 2026

🤖 AI Work Session Started

Starting automated work session at 2026-01-06T22:56:38.626Z

The PR has been converted to draft mode while work is in progress.

This comment marks the beginning of an AI work session. Please wait working session to finish, and provide your feedback.

This commit implements the requested architecture changes:

- Add Links Notation parser (lino.rs) for hierarchical configuration
  supporting indented syntax for complex nested structures

- Add recursive Allocation domain model supporting:
  - Simple ticker-based allocations (SBER 30, LKOH 30, GAZP 40)
  - Strategy-based allocations (balancer, hold, scalper)
  - Nested/recursive balancers for complex portfolio management
  - Automatic flattening to ticker->percentage for execution

- Add User/Account domain models:
  - User represents connection to broker/exchange (has API credentials)
  - Account represents trading account within broker
  - Each account has its own Allocation configuration
  - Support for multiple users with multiple accounts each

- Update README with CLI-first guide:
  - Configuration examples using Links Notation
  - Both short syntax and full recursive syntax documented
  - Multi-user/multi-account configuration examples
  - Design principles in Links Notation format

All 171 tests pass (unit, integration, and doc tests).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@konard konard changed the title feat: Add --plan option for read-only order planning mode feat: Implement multi-user recursive allocation system with Links Notation Jan 6, 2026
konard and others added 3 commits January 7, 2026 00:08
Fixed brace placement in parse_value_string function to match
cargo fmt output on CI server.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Removed `#` from raw string literals in tests where they weren't
needed, as the strings don't contain quotes that would require
escaping.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Merged identical match arms in to_string_value()
- Used strip_prefix() instead of manual prefix stripping
- Removed unnecessary Result wrapper from parse_tuple_content()
- Removed unused line_num field from ParsedLine struct

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@konard konard marked this pull request as ready for review January 6, 2026 23:18
@konard
Copy link
Contributor Author

konard commented Jan 6, 2026

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $14.633507 USD
  • Calculated by Anthropic: $9.579761 USD
  • Difference: $-5.053746 (-34.54%)
    📎 Log file uploaded as GitHub Gist (1414KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard konard merged commit 34a0b1f into main Jan 6, 2026
8 checks passed
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.

--plan option

2 participants