Skip to content

Commit a22aea5

Browse files
committed
Merge branch 'kite3'
2 parents bcb7746 + 32d4671 commit a22aea5

File tree

105 files changed

+3212
-2674
lines changed

Some content is hidden

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

105 files changed

+3212
-2674
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ sample/out/*
99
out/*
1010
!sample/.idea/
1111
sample/.idea/*
12+
production/*

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2016 Rainmatter Technology Pvt. Ltd. (India)
3+
Copyright (c) 2016 Zerodha Technology Pvt. Ltd. (India)
44

55
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:
66

README.md

Lines changed: 285 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,20 @@
1-
> **NOTICE (Jan 2018): Upgrade to Kite Connect 3.0**
2-
This repository is being phased and will be replaced soon by Kite Connect v3. Use the [kite3](https://github.com/zerodhatech/javakiteconnect/tree/kite3) branch instead. Read the [announcement](https://kite.trade/forum/discussion/2998/upgrade-to-kite-connect-3-0) on the forum.
3-
4-
# The Kite Connect API Java client
5-
1+
# The Kite Connect 3.0 API Java client
62
The official Java client for communicating with [Kite Connect API](https://kite.trade).
73

84
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.
95

10-
[Rainmatter](http://rainmatter.com) (c) 2016. Licensed under the MIT License.
11-
12-
##Documentation
13-
- [Kite Connect HTTP API documentation](https://kite.trade/docs/connect/v1)
14-
- [Java library documentation](https://kite.trade/docs/javakiteconnect)
15-
16-
##Usage
6+
[Zerodha Technology Pvt Ltd](http://rainmatter.com) (c) 2016. Licensed under the MIT License.
177

8+
## Documentation
9+
- [Kite Connect HTTP API documentation](https://kite.trade/docs/connect/v3/)
10+
- [Java library documentation](https://kite.trade/docs/javakiteconnect/v3/)
1811

12+
## Usage
13+
- [Download Kite Connect 3 jar file](https://github.com/zerodhatech/javakiteconnect/tree/kite3/dist) and include it in your build path.
1914

20-
> **This version will be deprecated soon. Please refer to the [kite3](https://github.com/zerodhatech/javakiteconnect/tree/kite3) branch for the Kite Connect 3 API and use the JAR in the dist directory.**
15+
- Include com.rainmatter.kiteconnect into build path from maven. Use version 3.0.0
2116

22-
- [Download jar file](https://github.com/rainmattertech/javakiteconnect/blob/master/dist/kiteconnect.jar) and include it in your build path.
23-
24-
- Include com.rainmatter.kiteconnect into build path from maven. Use version 1.4.5
17+
- To use javakiteconnect in **Android**, you need to include jar file in the libs directory and add the following line in you module's gradle file ``` compile files('libs/kiteconnect.jar') ```
2518

2619
## API usage
2720
```java
@@ -43,15 +36,15 @@ kiteSdk.setAccessToken(userModel.accessToken);
4336
kiteSdk.setPublicToken(userModel.publicToken);
4437

4538
// Set session expiry callback.
46-
kiteSdk.registerHook(new SessionExpiryHook() {
39+
kiteSdk.setSessionExpiryHook(new SessionExpiryHook() {
4740
@Override
4841
public void sessionExpired() {
4942
System.out.println("session expired");
5043
}
5144
});
5245

5346
// Get margins returns margin model, you can pass equity or commodity as arguments to get margins of respective segments.
54-
Margins margins = kiteSdk.getMargins("equity");
47+
Margin margins = kiteSdk.getMargins("equity");
5548
System.out.println(margins.available.cash);
5649
System.out.println(margins.utilised.debits);
5750

@@ -81,48 +74,286 @@ System.out.println(order.orderId);
8174
```
8275
For more details, take a look at Examples.java in sample directory.
8376

84-
##WebSocket live streaming data
77+
## WebSocket live streaming data
8578
```java
79+
/** To get live price use websocket connection.
80+
* 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.
81+
* custom url points to new endpoint which can be used till complete Kite Connect 3 migration is done. */
82+
KiteTicker tickerProvider = new KiteTicker(kiteConnect.getAccessToken(), kiteConnect.getApiKey());
8683

87-
/** To get live price use KiteTicker websocket connection.
88-
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.*/
89-
ArrayList tokens = new ArrayList<>();
90-
tokens.add(53287175);
91-
KiteTicker tickerProvider = new KiteTicker(kiteconnect);
92-
tickerProvider.setOnConnectedListener(new OnConnect() {
93-
@Override
94-
public void onConnected() {
95-
try {
96-
/** Subscribe ticks for token.
97-
* By default, all tokens are subscribed for modeQuote.*/
98-
tickerProvider.subscribe(tokens);
99-
} catch (IOException e) {
100-
e.printStackTrace();
101-
} catch (WebSocketException e) {
102-
e.printStackTrace();
103-
}
104-
}
105-
});
84+
tickerProvider.setOnConnectedListener(new OnConnect() {
85+
@Override
86+
public void onConnected() {
87+
/** Subscribe ticks for token.
88+
* By default, all tokens are subscribed for modeQuote.
89+
* */
90+
tickerProvider.subscribe(tokens);
91+
tickerProvider.setMode(tokens, KiteTicker.modeFull);
92+
}
93+
});
10694

107-
tickerProvider.setOnDisconnectedListener(new OnDisconnect() {
108-
@Override
109-
public void onDisconnected() {
110-
// your code goes here
111-
}
112-
});
95+
tickerProvider.setOnDisconnectedListener(new OnDisconnect() {
96+
@Override
97+
public void onDisconnected() {
98+
// your code goes here
99+
}
100+
});
113101

114-
tickerProvider.setOnTickerArrivalListener(new OnTick() {
115-
@Override
116-
public void onTick(ArrayList<Tick> ticks) {
117-
System.out.println(ticks.size());
118-
}
119-
});
102+
/** Set listener to get order updates.*/
103+
tickerProvider.setOnOrderUpdateListener(new OnOrderUpdate() {
104+
@Override
105+
public void onOrderUpdate(Order order) {
106+
System.out.println("order update "+order.orderId);
107+
}
108+
});
109+
110+
tickerProvider.setOnTickerArrivalListener(new OnTicks() {
111+
@Override
112+
public void onTicks(ArrayList<Tick> ticks) {
113+
NumberFormat formatter = new DecimalFormat();
114+
System.out.println("ticks size "+ticks.size());
115+
if(ticks.size() > 0) {
116+
System.out.println("last price "+ticks.get(0).getLastTradedPrice());
117+
System.out.println("open interest "+formatter.format(ticks.get(0).getOi()));
118+
System.out.println("day high OI "+formatter.format(ticks.get(0).getOpenInterestDayHigh()));
119+
System.out.println("day low OI "+formatter.format(ticks.get(0).getOpenInterestDayLow()));
120+
System.out.println("change "+formatter.format(ticks.get(0).getChange()));
121+
System.out.println("tick timestamp "+ticks.get(0).getTickTimestamp());
122+
System.out.println("tick timestamp date "+ticks.get(0).getTickTimestamp());
123+
System.out.println("last traded time "+ticks.get(0).getLastTradedTime());
124+
System.out.println(ticks.get(0).getMarketDepth().get("buy").size());
125+
}
126+
}
127+
});
128+
129+
tickerProvider.setTryReconnection(true);
130+
//maximum retries and should be greater than 0
131+
tickerProvider.setMaximumRetries(50);
132+
//set maximum retry interval in seconds
133+
tickerProvider.setMaximumRetryInterval(30);
134+
135+
/** connects to com.zerodhatech.com.zerodhatech.ticker server for getting live quotes*/
136+
tickerProvider.connect();
120137

121-
// Connects to ticker server for getting live quotes.
122-
tickerProvider.connect();
138+
/** You can check, if websocket connection is open or not using the following method.*/
139+
boolean isConnected = tickerProvider.isConnectionOpen();
140+
System.out.println(isConnected);
123141

124-
// Disconnect from ticker server.
125-
tickerProvider.disconnect();
142+
/** set mode is used to set mode in which you need tick for list of tokens.
143+
* Ticker allows three modes, modeFull, modeQuote, modeLTP.
144+
* For getting only last traded price, use modeLTP
145+
* For getting last traded price, last traded quantity, average price, volume traded today, total sell quantity and total buy quantity, open, high, low, close, change, use modeQuote
146+
* For getting all data with depth, use modeFull*/
147+
tickerProvider.setMode(tokens, KiteTicker.modeLTP);
148+
149+
// Unsubscribe for a token.
150+
tickerProvider.unsubscribe(tokens);
151+
152+
// After using com.zerodhatech.com.zerodhatech.ticker, close websocket connection.
153+
tickerProvider.disconnect();
126154

127155
```
128156
For more details about different mode of quotes and subscribing for them, take a look at Examples in sample directory.
157+
158+
## Breaking changes from version 2 to version 3
159+
160+
#### Place order (bracket order) parameters
161+
162+
| version 2 | version 3 |
163+
| :---: | :---:|
164+
| squareoff_value | squareoff |
165+
| stoploss_value | stoploss |
166+
167+
#### Model name changes
168+
169+
| version 2 | version 3 |
170+
| :---: | :---:|
171+
| MfHolding | MFHolding |
172+
| MfInstrument | MFInstrument |
173+
| MfOrder | MFOrder |
174+
| MfSip | MFSIP |
175+
176+
##### Order (model)
177+
178+
* The orderTimestamp is now Date type.
179+
* The exchangeTimestamp is now Date type.
180+
181+
#### Trades (model)
182+
183+
* The orderTimestamp is now fillTimestamp.
184+
* The exchangeTimestamp is now Date type.
185+
186+
#### MFOrder (model)
187+
188+
* The orderTimestamp is now Date type.
189+
* The exchangeTimestamp is now Date type.
190+
191+
#### MFSIP (model)
192+
193+
* The created is now Date type.
194+
* The Date is now Date type.
195+
196+
#### MFInstrument (model)
197+
198+
* The purchase_allowed is now boolean type.
199+
* The redemption_allowed is now boolean type.
200+
* The last_price_date is now Date type.
201+
202+
#### Instrument (model)
203+
204+
* The expiry is now Date type.
205+
206+
#### Package name changes
207+
208+
| version 2 | version 3 |
209+
| :---: | :---: |
210+
|com.rainmatter.kitehttp|com.zerodhatech.kiteconnect.kitehttp|
211+
|com.rainmatter.utils|com.zerodhatech.kiteconnect.utils|
212+
|com.rainmatter.kiteconnect|com.zerodhatech.kiteconnect|
213+
|com.rainmatter.ticker|com.zerodhatech.kiteconnect|
214+
|com.rainmatter.models|com.zerodhatech.models|
215+
216+
#### Method name changes
217+
218+
| version 2 | version 3 |
219+
| :---: | :---: |
220+
| requestAccessToken | generateSession |
221+
| modifyProduct | convertPosition |
222+
| getOrder | getOrderHistory |
223+
| getTrades(order_id) | getOrderTrades(order_id) |
224+
| getMfOrders | getMFOrders |
225+
| getMfOrder | getMFOrder |
226+
| getMfSips | getMFSIPs |
227+
| getMfSip | getMFSIP |
228+
| modifySip | modifySIP |
229+
| cancelSip | cancelSIP |
230+
| getMfInstruments | getMFInstruments |
231+
232+
#### Method with signature change
233+
234+
| version 2 |
235+
| :---: |
236+
| placeOrder |
237+
| modifyOrder |
238+
| cancelOrder |
239+
| convertPosition |
240+
| getTriggerRange |
241+
| getHistoricalData |
242+
| placeMFOrder |
243+
| placeMFSIP |
244+
| modifyMFSIP |
245+
246+
For more details about each method go to [KiteConnect.java](https://github.com/zerodhatech/javakiteconnect/blob/kite3/kiteconnect/src/com/zerodhatech/kiteconnect/KiteConnect.java)
247+
248+
#### Funds (model)
249+
250+
| version 2 | version 3 |
251+
| :---: | :---: |
252+
| Margins | Margin |
253+
254+
#### User (model)
255+
256+
* UserModel is now User.
257+
258+
| version 2 | version 3 |
259+
| :---: | :---: |
260+
| product | products |
261+
| exchange | exchanges |
262+
| orderType | orderTypes |
263+
| passwordReset | **NA** |
264+
| memberId | **NA** |
265+
| **NA** | apiKey |
266+
267+
* loginTime is now of Date type.
268+
269+
#### Position (model)
270+
271+
Added new fields
272+
273+
| version 3 |
274+
| :---: |
275+
| dayBuyQuantity |
276+
| daySellQuantity |
277+
| dayBuyPrice |
278+
| daySellPrice |
279+
| dayBuyValue |
280+
| daySellValue |
281+
| value |
282+
283+
#### Kite Ticker (Websockets)
284+
285+
* Kite Ticker is now authenticated using access_token and not public_token.
286+
287+
Version 2:
288+
```java
289+
Kiteconnect kiteSdk = new Kiteconnect("your_apiKey");
290+
```
291+
Version 3:
292+
```java
293+
KiteTicker tickerProvider = new KiteTicker(kiteConnect.getUserId(), kiteConnect.getAccessToken(), kiteConnect.getApiKey());
294+
```
295+
* Order postbacks are now streamed on Kite Ticker.
296+
297+
* Added new fields in full mode.
298+
299+
| version 3 |
300+
| :---: |
301+
| lastTradedTime |
302+
| openInterest |
303+
| oiDayHigh |
304+
| oiDayLow |
305+
| tickTimestamp |
306+
307+
* Changes:
308+
309+
| version 2 | version 3 |
310+
| :---: | :---: |
311+
| OnTick | OnTicks |
312+
| setTimeIntervalForReconnection | **NA** |
313+
| **NA** | setMaximumRetryInterval |
314+
| netPriceChangeFromClosingPrice | change |
315+
316+
#### Quote
317+
318+
* Quote will accept multiple params and returns a map of Quote model.
319+
* Added new fields open interest, tick timestamp, last traded time, average price, day high OI, day low OI.
320+
* lastTradedPrice is now lastPrice.
321+
322+
| version 3 |
323+
| :---: |
324+
| instrumentToken |
325+
| timestamp |
326+
| averagePrice |
327+
| oiDayHigh |
328+
| oiDayLow |
329+
330+
* Changes:
331+
332+
| version 2 | version 3 |
333+
| :---: | :---: |
334+
| lastTime(String) | lastTradedTime(Date) |
335+
| changePercent | **NA** |
336+
| depth(Map<String, ArrayList<Depth>>) | depth(MarketDepth type) |
337+
338+
339+
* Removed:
340+
341+
| version 2 | version 3 |
342+
| :---: | :---: |
343+
| IndicesQuote | **NA** |
344+
345+
#### Profile
346+
347+
* Added new profile API call to fetch user details.
348+
349+
#### Trigger range
350+
351+
* Trigger range API supports fetching trigger range for multiple instruments in one request.
352+
353+
#### TriggerRange (model)
354+
355+
| version 2 | version 3 |
356+
| :---: | :---: |
357+
| start | lower |
358+
| end | upper |
359+
| percent | percentage |

dist/kiteconnect.jar

-1.76 MB
Binary file not shown.

kiteconnect/libs/apache-mime4j.jar

-337 KB
Binary file not shown.
327 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.

kiteconnect/libs/gson-2.6.2.jar

224 KB
Binary file not shown.

0 commit comments

Comments
 (0)