-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathtest_optionsmultiorder.py
More file actions
159 lines (146 loc) · 5.7 KB
/
test_optionsmultiorder.py
File metadata and controls
159 lines (146 loc) · 5.7 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# -*- coding: utf-8 -*-
"""
Test script for optionsmultiorder function
"""
import time
from openalgo import api
# Initialize with API key
client = api(
api_key="c32eb9dee6673190bb9dfab5f18ef0a96b0d76ba484cd36bc5ca5f7ebc8745bf",
host="http://127.0.0.1:5000"
)
print("=" * 60)
print("Testing optionsmultiorder function")
print("=" * 60)
# Test 1: Long Straddle (2 legs - BUY only)
print("\n1. Testing Long Straddle (2 BUY legs)")
print("-" * 40)
result = client.optionsmultiorder(
strategy="Long Straddle Test",
underlying="NIFTY",
exchange="NSE_INDEX",
expiry_date="25NOV25",
legs=[
{"offset": "ATM", "option_type": "CE", "action": "BUY", "quantity": 75},
{"offset": "ATM", "option_type": "PE", "action": "BUY", "quantity": 75}
]
)
print(f"Status: {result.get('status')}")
if result.get('status') == 'success':
print(f"Underlying LTP: {result.get('underlying_ltp')}")
if 'mode' in result:
print(f"Mode: {result.get('mode')}")
print("Results:")
for leg_result in result.get('results', []):
print(f" Leg {leg_result.get('leg')}: {leg_result.get('symbol')} - "
f"{leg_result.get('action')} {leg_result.get('option_type')} - "
f"Status: {leg_result.get('status')} - Order: {leg_result.get('orderid')}")
else:
print(f"Error: {result.get('message')}")
time.sleep(3)
# Test 2: Iron Condor (4 legs - mixed BUY/SELL)
print("\n2. Testing Iron Condor (4 legs - BUY first, then SELL)")
print("-" * 40)
result = client.optionsmultiorder(
strategy="Iron Condor Test",
underlying="NIFTY",
exchange="NSE_INDEX",
expiry_date="25NOV25",
legs=[
{"offset": "OTM10", "option_type": "CE", "action": "BUY", "quantity": 75},
{"offset": "OTM10", "option_type": "PE", "action": "BUY", "quantity": 75},
{"offset": "OTM5", "option_type": "CE", "action": "SELL", "quantity": 75},
{"offset": "OTM5", "option_type": "PE", "action": "SELL", "quantity": 75}
]
)
print(f"Status: {result.get('status')}")
if result.get('status') == 'success':
print(f"Underlying LTP: {result.get('underlying_ltp')}")
if 'mode' in result:
print(f"Mode: {result.get('mode')}")
print("Results:")
for leg_result in result.get('results', []):
print(f" Leg {leg_result.get('leg')}: {leg_result.get('symbol')} - "
f"{leg_result.get('action')} {leg_result.get('option_type')} - "
f"Status: {leg_result.get('status')} - Order: {leg_result.get('orderid')}")
else:
print(f"Error: {result.get('message')}")
time.sleep(3)
# Test 3: Bull Call Spread
print("\n3. Testing Bull Call Spread (2 legs)")
print("-" * 40)
result = client.optionsmultiorder(
strategy="Bull Call Spread Test",
underlying="NIFTY",
exchange="NSE_INDEX",
expiry_date="25NOV25",
legs=[
{"offset": "ATM", "option_type": "CE", "action": "BUY", "quantity": 75},
{"offset": "OTM3", "option_type": "CE", "action": "SELL", "quantity": 75}
]
)
print(f"Status: {result.get('status')}")
if result.get('status') == 'success':
print(f"Underlying LTP: {result.get('underlying_ltp')}")
if 'mode' in result:
print(f"Mode: {result.get('mode')}")
print("Results:")
for leg_result in result.get('results', []):
print(f" Leg {leg_result.get('leg')}: {leg_result.get('symbol')} - "
f"{leg_result.get('action')} {leg_result.get('option_type')} - "
f"Status: {leg_result.get('status')} - Order: {leg_result.get('orderid')}")
else:
print(f"Error: {result.get('message')}")
time.sleep(3)
# Test 4: Calendar Spread (same strike, different expiries)
print("\n4. Testing Calendar Spread (per-leg expiry dates)")
print("-" * 40)
result = client.optionsmultiorder(
strategy="Calendar Spread Test",
underlying="NIFTY",
exchange="NSE_INDEX",
legs=[
{"offset": "ATM", "option_type": "CE", "action": "BUY", "quantity": 75, "expiry_date": "30DEC25"},
{"offset": "ATM", "option_type": "CE", "action": "SELL", "quantity": 75, "expiry_date": "25NOV25"}
]
)
print(f"Status: {result.get('status')}")
if result.get('status') == 'success':
print(f"Underlying LTP: {result.get('underlying_ltp')}")
if 'mode' in result:
print(f"Mode: {result.get('mode')}")
print("Results:")
for leg_result in result.get('results', []):
print(f" Leg {leg_result.get('leg')}: {leg_result.get('symbol')} - "
f"{leg_result.get('action')} {leg_result.get('option_type')} - "
f"Status: {leg_result.get('status')} - Order: {leg_result.get('orderid')}")
else:
print(f"Error: {result.get('message')}")
time.sleep(3)
# Test 5: Diagonal Spread (different strikes and expiries)
print("\n5. Testing Diagonal Spread (per-leg expiry dates)")
print("-" * 40)
result = client.optionsmultiorder(
strategy="Diagonal Spread Test",
underlying="NIFTY",
exchange="NSE_INDEX",
legs=[
{"offset": "ITM2", "option_type": "CE", "action": "BUY", "quantity": 75, "expiry_date": "30DEC25"},
{"offset": "OTM2", "option_type": "CE", "action": "SELL", "quantity": 75, "expiry_date": "25NOV25"}
]
)
print(f"Status: {result.get('status')}")
if result.get('status') == 'success':
print(f"Underlying LTP: {result.get('underlying_ltp')}")
if 'mode' in result:
print(f"Mode: {result.get('mode')}")
print("Results:")
for leg_result in result.get('results', []):
print(f" Leg {leg_result.get('leg')}: {leg_result.get('symbol')} - "
f"{leg_result.get('action')} {leg_result.get('option_type')} - "
f"Status: {leg_result.get('status')} - Order: {leg_result.get('orderid')}")
else:
print(f"Error: {result.get('message')}")
print("\n" + "=" * 60)
print("Tests completed")
print("=" * 60)