-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathbasic_tool.py
More file actions
36 lines (27 loc) · 1.05 KB
/
basic_tool.py
File metadata and controls
36 lines (27 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""Basic example of creating and using a QuantMind tool."""
from quantmind.tools import tool, validate_tool_arguments
@tool
def calculate_position_value(
price: float, quantity: float, side: str = "long"
) -> float:
"""Compute the signed notional value for a position.
Args:
price (float): Latest unit price in dollars.
quantity (float): Position size in units.
side (str): Trading direction (choices: ["long", "short"])
Returns:
float: Signed notional value for the position.
"""
direction = 1 if side == "long" else -1
return direction * price * quantity
def main():
"""Run the tool, validate inputs, and display metadata."""
payload = {"price": 420.5, "quantity": 2, "side": "long"}
validate_tool_arguments(calculate_position_value, payload)
result = calculate_position_value(**payload)
print(f"Position value: {result}")
print("Tool inputs:")
for name, schema in calculate_position_value.inputs.items():
print(f" {name}: {schema}")
if __name__ == "__main__":
main()