-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathtest_instruments.py
More file actions
74 lines (63 loc) · 2.22 KB
/
Copy pathtest_instruments.py
File metadata and controls
74 lines (63 loc) · 2.22 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Test script for instruments() function
"""
from openalgo import api
# API credentials
API_KEY = "c32eb9dee6673190bb9dfab5f18ef0a96b0d76ba484cd36bc5ca5f7ebc8745bf"
HOST = "http://127.0.0.1:5000"
# Initialize client
client = api(api_key=API_KEY, host=HOST)
print("="*80)
print("Testing instruments() function")
print("="*80)
# Test 1: Get all instruments
print("\nTest 1: Get all instruments (no exchange filter)")
print("-"*80)
result = client.instruments()
if isinstance(result, dict) and result.get('status') == 'error':
print(f"[ERROR] {result.get('message')}")
print(f" Error Type: {result.get('error_type')}")
print(f" Code: {result.get('code', 'N/A')}")
else:
import pandas as pd
if isinstance(result, pd.DataFrame):
print(f"[SUCCESS] Retrieved {len(result)} instruments")
print(f"\nFirst 5 instruments:")
print(result.head())
print(f"\nColumns: {list(result.columns)}")
else:
print(f"[ERROR] Unexpected result type: {type(result)}")
# Test 2: Get NSE instruments only
print("\n\nTest 2: Get NSE instruments only")
print("-"*80)
result = client.instruments(exchange="NSE")
if isinstance(result, dict) and result.get('status') == 'error':
print(f"[ERROR] {result.get('message')}")
else:
import pandas as pd
if isinstance(result, pd.DataFrame):
print(f"[SUCCESS] Retrieved {len(result)} NSE instruments")
print(f"\nFirst 5 NSE instruments:")
print(result.head())
else:
print(f"❌ Unexpected result type: {type(result)}")
# Test 3: Get NFO instruments only
print("\n\nTest 3: Get NFO instruments only")
print("-"*80)
result = client.instruments(exchange="NFO")
if isinstance(result, dict) and result.get('status') == 'error':
print(f"[ERROR] {result.get('message')}")
else:
import pandas as pd
if isinstance(result, pd.DataFrame):
print(f"[SUCCESS] Retrieved {len(result)} NFO instruments")
print(f"\nInstrument types in NFO:")
if 'instrumenttype' in result.columns:
print(result['instrumenttype'].value_counts())
else:
print(f"❌ Unexpected result type: {type(result)}")
print("\n" + "="*80)
print("Test completed!")
print("="*80)