forked from vijaykosis/smartapi-java
-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathTest.java
More file actions
125 lines (92 loc) · 3.76 KB
/
Test.java
File metadata and controls
125 lines (92 loc) · 3.76 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
package com.angelbroking.smartapi.sample;
import com.angelbroking.smartapi.SmartConnect;
import com.angelbroking.smartapi.http.exceptions.SmartAPIException;
import com.angelbroking.smartapi.models.User;
public class Test {
public static void main(String[] args) throws SmartAPIException {
try {
SmartConnect smartConnect = new SmartConnect("<api_key>"); // PROVIDE YOUR API KEY HERE
/*
* OPTIONAL - ACCESS_TOKEN AND REFRESH TOKEN SmartConnect smartConnect = new
* SmartConnect("<api_key>", "<YOUR_ACCESS_TOKEN>", "<YOUR_REFRESH_TOKEN>");
*/
/*
* Set session expiry callback. smartConnect.setSessionExpiryHook(new
* SessionExpiryHook() {
*
* @Override public void sessionExpired() {
* System.out.println("session expired"); } });
*
* User user = smartConnect.generateSession("<clientId>", "<password>");
* smartConnect.setAccessToken(user.getAccessToken());
* smartConnect.setUserId(user.getUserId());
*
* /* token re-generate
*/
/*
* TokenSet tokenSet = smartConnect.renewAccessToken(user.getAccessToken(),
* user.getRefreshToken());
* smartConnect.setAccessToken(tokenSet.getAccessToken());
*/
Examples examples = new Examples();
/* System.out.println("getProfile"); */
examples.getProfile(smartConnect);
/* System.out.println("placeOrder"); */
examples.placeOrder(smartConnect);
/* System.out.println("modifyOrder"); */
examples.modifyOrder(smartConnect);
/* System.out.println("cancelOrder"); */
examples.cancelOrder(smartConnect);
/* System.out.println("getOrder"); */
examples.getOrder(smartConnect);
/* System.out.println("getLTP"); */
examples.getLTP(smartConnect);
/* System.out.println("getTrades"); */
examples.getTrades(smartConnect);
/* System.out.println("getRMS"); */
examples.getRMS(smartConnect);
/* System.out.println("getHolding"); */
examples.getHolding(smartConnect);
/* System.out.println("getPosition"); */
examples.getPosition(smartConnect);
/* System.out.println("convertPosition"); */
examples.convertPosition(smartConnect);
/* System.out.println("createRule"); */
examples.createRule(smartConnect);
/* System.out.println("ModifyRule"); */
examples.modifyRule(smartConnect);
/* System.out.println("cancelRule"); */
examples.cancelRule(smartConnect);
/* System.out.println("Rule Details"); */
examples.ruleDetails(smartConnect);
/* System.out.println("Rule List"); */
examples.ruleList(smartConnect);
/* System.out.println("Historic candle Data"); */
examples.getCandleData(smartConnect);
/* System.out.println("Search script api"); */
examples.getSearchScrip(smartConnect);
/* System.out.println("Market Data"); */
examples.getMarketData(smartConnect);
/* System.out.println("logout"); */
examples.logout(smartConnect);
/* SmartAPITicker */
String clientId = "<clientId>";
User user = smartConnect.generateSession("<clientId>", "<password>", "<totp>");
String feedToken = user.getFeedToken();
String strWatchListScript = "nse_cm|2885&nse_cm|1594&nse_cm|11536&mcx_fo|221658";
String task = "mw";
examples.tickerUsage(clientId, feedToken, strWatchListScript, task);
/*
* String jwtToken = user.getAccessToken(); String apiKey = "smartapi_key";
* String actionType = "subscribe"; String feedType = "order_feed";
*
* examples.smartWebSocketUsage(clientId, jwtToken, apiKey, actionType,
* feedType);
*
*/
} catch (Exception e) {
System.out.println("Exception: " + e.getMessage());
e.printStackTrace();
}
}
}