vimpelican / upbit-bollinger-trader

오픈소스소프트웨어 프로젝트
MIT License
0 stars 0 forks source link

Refactor Project Structure for Upbit API Integration #6

Open vimpelican opened 1 month ago

vimpelican commented 1 month ago

Description

To improve the maintainability, modularity, and scalability of our crypto trading bot, we need to refactor the project structure. The goal is to organize the code into separate modules, each with a single responsibility. This will make the code easier to manage, test, and extend in the future.

Current State

The current implementation is a single test script that handles everything from fetching environment variables to making API requests and printing the response.

Proposed Structure

crypto_bot/
├── main.py
├── api/
│   ├── __init__.py
│   ├── upbit_api.py
├── utils/
│   ├── __init__.py
│   ├── config.py
├── trading/
│   ├── __init__.py
│   ├── strategy.py
├── requirements.txt
└── README.md

Details

  1. main.py : The entry point of the application
  2. api/upbit_api.py : Handles all interactions with the Upbit API.
  3. utils/config.py : Manages configuration settings and environment variables.
  4. traidng/strategy.py : Contains the core trading logic and strategies.

Tasks

  1. Create Project Structure :
    • Create directories: api, utils, trading.
    • Add init.py files to each directory.
  2. Refactor Code :
    • Move the Upbit API interaction code to api/upbit_api.py.
    • Move environment variable fetching to utils/config.py.
    • Create a basic trading strategy in trading/strategy.py.
  3. Update main.py :
    • Import the necessary modules from the new structure.
    • Initialize the API client and trading strategy.
    • Execute the trading strategy.
vimpelican commented 4 weeks ago

Feedback

Strengths:

  1. Modular Design: You've divided the project into logical modules like api, utils, and trading, which promotes reusability and makes it easier to extend functionality in the future.

  2. Entry Point (main.py): Having a clear entry point (main.py) is a good practice, as it keeps the flow of your application easy to understand.

  3. Separation of Concerns:

    • api/upbit_api.py handles all Upbit API interactions, making your code cleaner by isolating external dependencies.
    • trading/strategy.py contains your trading logic, which keeps the trading strategy separate from data fetching or utility functions, improving maintainability.
    • utils/config.py manages settings and environment variables, which is a great practice to keep configuration details out of the main logic and avoid hardcoding values.
    • Supporting Files: Including requirements.txt and README.md is good practice for sharing your project. They help others (and yourself in the future) quickly understand the dependencies and purpose of the project.

Areas for Improvement:

  1. .gitignore File: Ensure your .gitignore includes common Python files/folders like pycache/, .env, and *.pyc. This will help keep unnecessary or sensitive files out of your version control.

  2. Environment Variables: You mentioned managing environment variables in utils/config.py. Consider using a library like python-dotenv to load environment variables from a .env file securely, especially for API keys.

  3. Logging: Adding a logging/ directory or a utils/logger.py file could help you manage logs effectively, especially in a trading bot where tracking errors and data flow is crucial.

  4. Testing Module: Consider adding a tests/ directory for unit tests. This will help ensure that your trading logic and API interactions work correctly as you add more complexity.

  5. Documentation: Expand your README.md to include setup instructions, usage examples, and basic project architecture details. This will make it more useful to others and yourself as the project evolves.

  6. Typo Correction: The folder traidng/ should be corrected to trading/ to avoid confusion.

Updated Structure

crypto_bot/
├── main.py
├── api/
│   ├── __init__.py
│   ├── upbit_api.py
├── utils/
│   ├── __init__.py
│   ├── config.py
│   ├── logger.py   # Optional: Handles logging
├── trading/
│   ├── __init__.py
│   ├── strategy.py
├── tests/          # Optional: Unit tests for your project
│   ├── __init__.py
│   ├── test_upbit_api.py
│   ├── test_strategy.py
├── requirements.txt
├── .gitignore
├── LICENSE
└── README.md