feat: history tools
This commit is contained in:
@@ -8,6 +8,52 @@ from traderai.uex_client import UEXClient
|
||||
|
||||
class FakeUEX:
|
||||
async def get(self, path, params=None, authenticated=False):
|
||||
if path == "commodities_prices_history":
|
||||
return {
|
||||
"status": "ok",
|
||||
"data": [
|
||||
{
|
||||
"id": 1,
|
||||
"id_terminal": 7,
|
||||
"id_commodity": 3,
|
||||
"commodity_name": "Gold",
|
||||
"terminal_name": "Port Tressler",
|
||||
"price_buy": 4000,
|
||||
"price_sell": 5000,
|
||||
"scu_buy": 100,
|
||||
"scu_sell": 20,
|
||||
"date_added": 100,
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"id_terminal": 7,
|
||||
"id_commodity": 3,
|
||||
"commodity_name": "Gold",
|
||||
"terminal_name": "Port Tressler",
|
||||
"price_buy": 4200,
|
||||
"price_sell": 4800,
|
||||
"scu_buy": 80,
|
||||
"scu_sell": 30,
|
||||
"date_added": 200,
|
||||
},
|
||||
],
|
||||
}
|
||||
if path == "marketplace_prices_history":
|
||||
return {
|
||||
"status": "ok",
|
||||
"data": [
|
||||
{"id": 1, "item_name": "Widget", "operation": "sell", "price": 1000, "currency": "UEC", "date_added": 100},
|
||||
{"id": 2, "item_name": "Widget", "operation": "sell", "price": 1250, "currency": "UEC", "date_added": 200},
|
||||
],
|
||||
}
|
||||
if path == "currencies_index_history":
|
||||
return {
|
||||
"status": "ok",
|
||||
"data": [
|
||||
{"id": 1, "currency": "UEC", "index_value": 100.0, "basket_value": 5000.0, "date_added": 100},
|
||||
{"id": 2, "currency": "UEC", "index_value": 110.0, "basket_value": 5500.0, "date_added": 200},
|
||||
],
|
||||
}
|
||||
if path == "commodities_prices":
|
||||
return {
|
||||
"status": "ok",
|
||||
@@ -170,6 +216,45 @@ def test_schemas_expose_specific_uex_tools_instead_of_generic_api_tool():
|
||||
assert "uex_draft_post" not in names
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_search_uex_api_index_finds_history_tools():
|
||||
registry = ToolRegistry(FakeUEX())
|
||||
|
||||
result = await registry.execute("search_uex_api_index", {"query": "history", "history_only": True})
|
||||
|
||||
tools = {item["tool"] for item in result["get"]}
|
||||
assert "get_uex_commodities_prices_history" in tools
|
||||
assert "get_uex_marketplace_prices_history" in tools
|
||||
assert "get_uex_currencies_index_history" in tools
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_summarize_commodity_price_history_returns_trend_metrics():
|
||||
registry = ToolRegistry(FakeUEX())
|
||||
|
||||
result = await registry.execute(
|
||||
"summarize_uex_commodity_price_history",
|
||||
{"id_terminal": 7, "id_commodity": 3},
|
||||
)
|
||||
|
||||
assert result["resource"] == "commodities_prices_history"
|
||||
assert result["count"] == 2
|
||||
assert result["labels"] == {"commodity_name": "Gold", "terminal_name": "Port Tressler"}
|
||||
assert result["metrics"]["price_buy"]["change"] == 200
|
||||
assert result["metrics"]["price_sell"]["pct_change"] == -4.0
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_summarize_marketplace_and_currency_history():
|
||||
registry = ToolRegistry(FakeUEX())
|
||||
|
||||
market = await registry.execute("summarize_uex_marketplace_price_history", {"item_name": "Widget"})
|
||||
currency = await registry.execute("summarize_uex_currency_index_history", {"currency": "UEC"})
|
||||
|
||||
assert market["metrics"]["price"]["pct_change"] == 25.0
|
||||
assert currency["metrics"]["index_value"]["change"] == 10.0
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@respx.mock
|
||||
async def test_uex_client_get_user_normalizes_user_payload():
|
||||
|
||||
Reference in New Issue
Block a user