feat: 엔트리포인트 및 로깅 설정 완료, 테스트 mock 개선

Made-with: Cursor
This commit is contained in:
21in7
2026-03-01 12:54:21 +09:00
parent 726e9cfd65
commit a90618896d
3 changed files with 54 additions and 11 deletions

18
main.py Normal file
View File

@@ -0,0 +1,18 @@
import asyncio
from dotenv import load_dotenv
from src.config import Config
from src.bot import TradingBot
from src.logger_setup import setup_logger
load_dotenv()
async def main():
setup_logger(log_level="INFO")
config = Config()
bot = TradingBot(config)
await bot.run()
if __name__ == "__main__":
asyncio.run(main())

24
src/logger_setup.py Normal file
View File

@@ -0,0 +1,24 @@
import sys
from loguru import logger
def setup_logger(log_level: str = "INFO"):
logger.remove()
logger.add(
sys.stdout,
format=(
"<green>{time:YYYY-MM-DD HH:mm:ss}</green> | "
"<level>{level: <8}</level> | "
"<cyan>{name}</cyan>:<cyan>{line}</cyan> - "
"<level>{message}</level>"
),
level=log_level,
colorize=True,
)
logger.add(
"logs/bot_{time:YYYY-MM-DD}.log",
rotation="00:00",
retention="30 days",
level="DEBUG",
encoding="utf-8",
)

View File

@@ -19,19 +19,20 @@ def config():
@pytest.mark.asyncio
async def test_set_leverage(config):
client = BinanceFuturesClient(config)
with patch.object(
client.client,
"futures_change_leverage",
return_value={"leverage": 10},
):
with patch("src.exchange.Client") as MockClient:
mock_binance = MagicMock()
MockClient.return_value = mock_binance
mock_binance.futures_change_leverage.return_value = {"leverage": 10}
client = BinanceFuturesClient(config)
result = await client.set_leverage(10)
assert result is not None
def test_calculate_quantity(config):
client = BinanceFuturesClient(config)
# 잔고 1000 USDT, 리스크 2%, 레버리지 10, 가격 0.5
qty = client.calculate_quantity(balance=1000.0, price=0.5, leverage=10)
# 1000 * 0.02 * 10 / 0.5 = 400
assert qty == pytest.approx(400.0, rel=0.01)
with patch("src.exchange.Client") as MockClient:
MockClient.return_value = MagicMock()
client = BinanceFuturesClient(config)
# 잔고 1000 USDT, 리스크 2%, 레버리지 10, 가격 0.5
qty = client.calculate_quantity(balance=1000.0, price=0.5, leverage=10)
# 1000 * 0.02 * 10 / 0.5 = 400
assert qty == pytest.approx(400.0, rel=0.01)