Skip to content

Commit bd2ff59

Browse files
ariadngclaude
andcommitted
Fix strptime crash on already-parsed datetime in candles/date endpoint
FastAPI auto-parses date query params into datetime objects, but parse_date() called strptime() expecting a string. Now handles both. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 25418a3 commit bd2ff59

5 files changed

Lines changed: 11 additions & 7 deletions

File tree

CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
MCP server enabling AI assistants to trade on MetaTrader 5 via natural language. Provides both MCP (stdio) and HTTP/REST interfaces.
66

77
**Stack**: Python 3.10+ • FastMCP • FastAPI • MetaTrader5 SDK • Pandas • Pydantic • pytest
8-
**Version**: 0.5.0 (Beta)
8+
**Version**: 0.5.1 (Beta)
99
**Repo**: https://github.com/ariadng/metatrader-mcp-server
1010

1111
---

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
742742
743743
## 📊 Project Stats
744744
745-
- **Version**: 0.5.0
745+
- **Version**: 0.5.1
746746
- **Python**: 3.10+
747747
- **License**: MIT
748748
- **Status**: Active Development

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "metatrader-mcp-server"
7-
version = "0.5.0"
7+
version = "0.5.1"
88
authors = [
99
{ name = "Aria Dhanang", email = "ariadng@gmail.com" },
1010
]

src/metatrader_client/market/get_candles_by_date.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Optional
1+
from typing import Optional, Union
22
import pandas as pd
33
from datetime import datetime, timezone, timedelta
44
import MetaTrader5 as mt5
@@ -10,8 +10,8 @@ def get_candles_by_date(
1010
connection,
1111
symbol_name: str,
1212
timeframe: str,
13-
from_date: Optional[str] = None,
14-
to_date: Optional[str] = None,
13+
from_date: Optional[Union[str, datetime]] = None,
14+
to_date: Optional[Union[str, datetime]] = None,
1515
) -> pd.DataFrame:
1616
if not get_symbols(connection, symbol_name):
1717
raise SymbolNotFoundError(f"Symbol '{symbol_name}' not found")
@@ -21,6 +21,10 @@ def get_candles_by_date(
2121
from_datetime = None
2222
to_datetime = None
2323
def parse_date(date_str, is_to_date=False):
24+
if isinstance(date_str, datetime):
25+
if date_str.tzinfo is None:
26+
return date_str.replace(tzinfo=timezone.utc)
27+
return date_str
2428
for fmt in ("%Y-%m-%d %H:%M", "%Y-%m-%d"):
2529
try:
2630
dt = datetime.strptime(date_str, fmt)

src/metatrader_openapi/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Settings(BaseSettings):
2222
docs_url: str = "/docs"
2323
redoc_url: str = "/redoc"
2424
title: str = "MetaTrader MCP API"
25-
version: str = "0.5.0"
25+
version: str = "0.5.1"
2626

2727
# Load from env vars prefixed with OPENAPI_
2828
model_config = SettingsConfigDict(env_prefix="OPENAPI_")

0 commit comments

Comments
 (0)