Skip to content

Commit 338a290

Browse files
sujithsujith
authored andcommitted
changes to project structure and added new Quote LTP and OHLC APIs
1 parent 7f81076 commit 338a290

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+4091
-0
lines changed

LICENSE

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016 Rainmatter Technology Pvt. Ltd. (India)
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# The Kite Connect API Java client
2+
The official Java client for communicating with [Kite Connect API](https://kite.trade).
3+
4+
Kite Connect is a set of REST-like APIs that expose many capabilities required to build a complete investment and trading platform. Execute orders in real time, manage user portfolio, stream live market data (WebSockets), and more, with the simple HTTP API collection.
5+
6+
[Rainmatter](http://rainmatter.com) (c) 2016. Licensed under the MIT License.
7+
8+
##Documentation
9+
- [Kite Connect HTTP API documentation](https://kite.trade/docs/connect/v1)
10+
- [Java library documentation](https://kite.trade/docs/javakiteconnect)
11+
12+
##Usage
13+
- [Download jar file](https://github.com/rainmattertech/kiteconnectjava/raw/master/dist/kiteconnectjava.jar) and include it in your build path.
14+
15+
- Include com.rainmatter.kiteconnect into build path from maven. Use version 1.4.4
16+
17+
## API usage
18+
```java
19+
// Initialize Kiteconnect using apiKey.
20+
Kiteconnect kiteSdk = new Kiteconnect("your_apiKey");
21+
22+
// Set userId.
23+
kiteSdk.setUserId("your_userId");
24+
25+
/* First you should get request_token, public_token using kitconnect login and then use request_token, public_token, api_secret to make any kiteconnect api call.
26+
Get login url. Use this url in webview to login user, after authenticating user you will get requestToken. Use the same to get accessToken. */
27+
String url = kiteSdk.getLoginUrl();
28+
29+
// Get accessToken as follows,
30+
UserModel userModel = kiteSdk.requestAccessToken("request_token", "your_apiSecret");
31+
32+
// Set request token and public token which are obtained from login process.
33+
kiteSdk.setAccessToken(userModel.accessToken);
34+
kiteSdk.setPublicToken(userModel.publicToken);
35+
36+
// Set session expiry callback.
37+
kiteSdk.registerHook(new SessionExpiryHook() {
38+
@Override
39+
public void sessionExpired() {
40+
System.out.println("session expired");
41+
}
42+
});
43+
44+
// Get margins returns margin model, you can pass equity or commodity as arguments to get margins of respective segments.
45+
Margins margins = kiteSdk.getMargins("equity");
46+
System.out.println(margins.available.cash);
47+
System.out.println(margins.utilised.debits);
48+
49+
/* Place order method requires a map argument which contains,
50+
tradingsymbol, exchange, transaction_type, order_type, quantity, product, price, trigger_price, disclosed_quantity, validity
51+
squareoff_value, stoploss_value, trailing_stoploss
52+
and variety which can be value can be regular, bo, co, amo.
53+
place order which will return order model which will have only orderId in the order model.
54+
55+
Following is an example param for SL order,
56+
if a call fails then KiteException will have error message in it
57+
Success of this call implies only order has been placed successfully, not order execution.*/
58+
Map<String, Object> param = new HashMap<String, Object>(){
59+
{
60+
put("quantity", "1");
61+
put("order_type", "SL");
62+
put("tradingsymbol", "HINDALCO");
63+
put("product", "CNC");
64+
put("exchange", "NSE");
65+
put("transaction_type", "BUY");
66+
put("validity", "DAY");
67+
put("price", "158.0");
68+
put("trigger_price", "157.5");
69+
}};
70+
Order order = kiteconnect.placeOrder(param, "regular");
71+
System.out.println(order.orderId);
72+
```
73+
For more details, take a look at Examples.java in sample directory.
74+
75+
##WebSocket live streaming data
76+
```java
77+
78+
/** To get live price use KiteTicker websocket connection.
79+
It is recommended to use only one websocket connection at any point of time and make sure you stop connection, once user goes out of app.*/
80+
ArrayList tokens = new ArrayList<>();
81+
tokens.add(53287175);
82+
KiteTicker tickerProvider = new KiteTicker(kiteconnect);
83+
tickerProvider.setOnConnectedListener(new OnConnect() {
84+
@Override
85+
public void onConnected() {
86+
try {
87+
/** Subscribe ticks for token.
88+
* By default, all tokens are subscribed for modeQuote.*/
89+
tickerProvider.subscribe(tokens);
90+
} catch (IOException e) {
91+
e.printStackTrace();
92+
} catch (WebSocketException e) {
93+
e.printStackTrace();
94+
}
95+
}
96+
});
97+
98+
tickerProvider.setOnDisconnectedListener(new OnDisconnect() {
99+
@Override
100+
public void onDisconnected() {
101+
// your code goes here
102+
}
103+
});
104+
105+
tickerProvider.setOnTickerArrivalListener(new OnTick() {
106+
@Override
107+
public void onTick(ArrayList<Tick> ticks) {
108+
System.out.println(ticks.size());
109+
}
110+
});
111+
112+
// Connects to ticker server for getting live quotes.
113+
tickerProvider.connect();
114+
115+
// Disconnect from ticker server.
116+
tickerProvider.disconnect();
117+
118+
```
119+
For more details about different mode of quotes and subscribing for them, take a look at Examples in sample directory.

dist/kiteconnect.jar

3.1 MB
Binary file not shown.

kiteconnect/libs/apache-mime4j.jar

337 KB
Binary file not shown.
258 KB
Binary file not shown.
60.4 KB
Binary file not shown.

kiteconnect/libs/gson-1.4.jar

162 KB
Binary file not shown.
173 KB
Binary file not shown.
34.2 KB
Binary file not shown.
719 KB
Binary file not shown.

0 commit comments

Comments
 (0)