forked from symphonyfintech/xts-pythonclient-api-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Example.py
289 lines (239 loc) · 8.61 KB
/
Example.py
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
# from XTConnect import XTSConnect
from Connect import XTSConnect
# logging.basicConfig(level=logging.DEBUG)
# ----------------------------------------------------------------------------------------------------------------------
# Interactive
# ----------------------------------------------------------------------------------------------------------------------
# Interactive API Credentials
# API_KEY = "YOUR_API_KEY_HERE"
# API_SECRET = "YOUR_API_SECRET_HERE"
# clientID = "YOUR_CLIENT_ID_HERE"
# userID = "YOUR_USER_ID_HERE"
# XTS_API_BASE_URL = "https://xts-api.trading"
# source = "WEBAPI"
"Note : For dealer credentials add the clientID and for investor client leave the clientID blank"
"""Dealer credentials"""
API_KEY = "614569687dde8e1d6b5953"
API_SECRET = "Glds375@uv"
clientID = "DV01"
userID = "DVIHAN"
XTS_API_BASE_URL = "https://developers.symphonyfintech.in"
source = "WEBAPI"
"""Investor client credentials"""
# API_KEY = "431c75e076e238bdff8176"
# API_SECRET = "Ieil074#FH"
# clientID = "RUCHA"
# XTS_API_BASE_URL = "https://developers.symphonyfintech.in"
# source = "WEBAPI"
"""Make XTSConnect object by passing your interactive API appKey, secretKey and source"""
xt = XTSConnect(API_KEY, API_SECRET, source)
"""Using the xt object we created call the interactive login Request"""
response = xt.interactive_login()
print("Login: ", response)
clientID = "DV01"
"""Order book Request"""
response = xt.get_order_book(clientID)
print("Order Book: ", response)
"""Place Order Request"""
response = xt.place_order(
exchangeSegment=xt.EXCHANGE_NSECM,
exchangeInstrumentID=2885,
productType=xt.PRODUCT_MIS,
orderType=xt.ORDER_TYPE_MARKET,
orderSide=xt.TRANSACTION_TYPE_BUY,
timeInForce=xt.VALIDITY_DAY,
disclosedQuantity=0,
orderQuantity=10,
limitPrice=0,
stopPrice=0,
orderUniqueIdentifier="454845",
clientID=clientID)
print("Place Order: ", response)
# extracting the order id from response
if response['type'] != 'error':
OrderID = response['result']['AppOrderID']
"""Modify Order Request"""
response = xt.modify_order(
appOrderID=OrderID,
modifiedProductType=xt.PRODUCT_NRML,
modifiedOrderType=xt.ORDER_TYPE_LIMIT,
modifiedOrderQuantity=8,
modifiedDisclosedQuantity=0,
modifiedLimitPrice=1405,
modifiedStopPrice=0,
modifiedTimeInForce=xt.VALIDITY_DAY,
orderUniqueIdentifier="454845",
clientID=clientID
)
print("Modify Order: ", response)
"""Cancel Orders Request"""
response = xt.cancel_order(
appOrderID=OrderID,
orderUniqueIdentifier='454845',
clientID=clientID)
print("Cancel Order: ", response)
"""Get Order History Request"""
response = xt.get_order_history(appOrderID=OrderID,clientID=clientID)
print("Order History: ", response)
"""Get Profile Request"""
response = xt.get_profile(clientID=userID)
print("Profile: ", response)
"""Get Balance Request"""
response = xt.get_balance(clientID=clientID)
print("Balance: ", response)
"""Get Trade Book Request"""
response = xt.get_trade(clientID=clientID)
print("Trade Book: ", response)
"""Get Holdings Request"""
response = xt.get_holding(clientID=clientID)
print("Holdings: ", response)
"""Get Position by DAY Request"""
response = xt.get_position_daywise(clientID=clientID)
print("Position by Day: ", response)
"""Get Position by NET Request"""
response = xt.get_position_netwise(clientID=clientID)
print("Position by Net: ", response)
"""Position Convert Request"""
response = xt.convert_position(
exchangeSegment=xt.EXCHANGE_NSECM,
exchangeInstrumentID=2885,
targetQty=10,
isDayWise=True,
oldProductType=xt.PRODUCT_MIS,
newProductType=xt.PRODUCT_NRML,
clientID=clientID)
print("Position Convert: ", response)
"""Place Cover Order Request"""
response = xt.place_cover_order(
exchangeSegment=xt.EXCHANGE_NSECM,
exchangeInstrumentID=2885,
orderSide=xt.TRANSACTION_TYPE_BUY,
orderType=xt.ORDER_TYPE_LIMIT,
orderQuantity=2,
disclosedQuantity=0,
limitPrice=1802,
stopPrice=1899,
orderUniqueIdentifier="454845",
clientID=clientID)
print("Cover Order:", response)
# extracting the order id from response
if response['type'] != 'error':
OrderID = response['result']['ExitAppOrderID']
"""Exit Cover Order Request"""
response = xt.exit_cover_order(appOrderID=OrderID, clientID=clientID)
print("Exit Cover Order:", response)
"""Cancel all Orders Request"""
response = xt.cancelall_order(exchangeInstrumentID=22,exchangeSegment=xt.EXCHANGE_NSECM)
print("Cancel all Orders: ", response)
"""Interactive logout Request"""
response = xt.interactive_logout(clientID=clientID)
print("Interactive Logout: ", response)
exit()
# ----------------------------------------------------------------------------------------------------------------------
# Marketdata
# ----------------------------------------------------------------------------------------------------------------------
# Marketdata API Credentials
API_KEY = "YOUR_API_KEY_HERE"
API_SECRET = "YOUR_API_SECRET_HERE"
XTS_API_BASE_URL = "https://xts-api.trading"
source = "WEBAPI"
"""Dealer login credentials"""
API_KEY = "22f6f9dad2fe3982419756"
API_SECRET = "Bxtj027$Dr"
XTS_API_BASE_URL = "https://developers.symphonyfintech.in"
source = "WEBAPI"
"""Investor client login credentials"""
API_KEY = "76179cbae91810ddda7774"
API_SECRET = "Bylg203#fv"
XTS_API_BASE_URL = "https://developers.symphonyfintech.in"
source = "WEBAPI"
"""Make the XTSConnect Object with Marketdata API appKey, secretKey and source"""
xt = XTSConnect(API_KEY, API_SECRET, source)
"""Using the object we call the login function Request"""
response = xt.marketdata_login()
print("MarketData Login: ", response)
"""Get Config Request"""
response = xt.get_config()
print('Config :', response)
"""instruments list"""
instruments = [
{'exchangeSegment': 1, 'exchangeInstrumentID': 2885},
{'exchangeSegment': 1, 'exchangeInstrumentID': 22}]
"""Get Quote Request"""
response = xt.get_quote(
Instruments=instruments,
xtsMessageCode=1504,
publishFormat='JSON')
print('Quote :', response)
"""Send Subscription Request"""
response = xt.send_subscription(
Instruments=instruments,
xtsMessageCode=1502)
print('Subscribe :', response)
"""Send Unsubscription Request"""
response = xt.send_unsubscription(
Instruments=instruments,
xtsMessageCode=1502)
print('Unsubscribe :', response)
"""Get Master Instruments Request"""
exchangesegments = [xt.EXCHANGE_NSECM, xt.EXCHANGE_NSEFO]
response = xt.get_master(exchangeSegmentList=exchangesegments)
print("Master: " + str(response))
"""Get OHLC Request"""
response = xt.get_ohlc(
exchangeSegment=xt.EXCHANGE_NSECM,
exchangeInstrumentID=22,
startTime='Dec 16 2019 090000',
endTime='Dec 18 2019 150000',
compressionValue=1)
print("OHLC: " + str(response))
"""Get Series Request"""
response = xt.get_series(exchangeSegment=1)
print('Series:', str(response))
"""Get Equity Symbol Request"""
response = xt.get_equity_symbol(
exchangeSegment=1,
series='EQ',
symbol='Acc')
print('Equity Symbol:', str(response))
"""Get Expiry Date Request"""
response = xt.get_expiry_date(
exchangeSegment=2,
series='FUTIDX',
symbol='NIFTY')
print('Expiry Date:', str(response))
"""Get Future Symbol Request"""
response = xt.get_future_symbol(
exchangeSegment=2,
series='FUTIDX',
symbol='NIFTY',
expiryDate='28MAY25JUN')
print('Future Symbol:', str(response))
"""Get Option Symbol Request"""
response = xt.get_option_symbol(
exchangeSegment=2,
series='OPTIDX',
symbol='NIFTY',
expiryDate='26Mar2020',
optionType='CE',
strikePrice=10000)
print('Option Symbol:', str(response))
"""Get Option Type Request"""
response = xt.get_option_type(
exchangeSegment=2,
series='OPTIDX',
symbol='NIFTY',
expiryDate='26Mar2020')
print('Option Type:', str(response))
"""Get Index List Request"""
response = xt.get_index_list(exchangeSegment=xt.EXCHANGE_NSECM)
print('Index List:', str(response))
"""Search Instrument by ID Request"""
response = xt.search_by_instrumentid(Instruments=instruments)
print('Search By Instrument ID:', str(response))
"""Search Instrument by Scriptname Request"""
response = xt.search_by_scriptname(searchString='REL')
print('Search By Symbol :', str(response))
"""Marketdata Logout Request"""
response = xt.marketdata_logout()
print('Marketdata Logout :', str(response))