zerodha / javakiteconnect Goto Github PK
View Code? Open in Web Editor NEWThe official Java client for communicating with Kite Connect API.
License: MIT License
The official Java client for communicating with Kite Connect API.
License: MIT License
SimpleDateFormat is not thread safe. Hence, we should be using a thread local instance of SimpleDateFormat.
The current README file instructs users to download the JAR file for the Kite Connect Java library. This approach is not ideal for project management.
This task involves updating the README file to include instructions for adding the library as a dependency using both Maven and Gradle.
Specific changes:
Testing:
public void getCombinedMarginCalculation() throws IOException, KiteException{
List params = new ArrayList<>();
MarginCalculationParams param = new MarginCalculationParams();
param.exchange = "NFO";
param.tradingSymbol = "NIFTY21MAY15400PE";
param.orderType = "MARKET";
param.quantity = 75;
param.product = "MIS";
param.variety = "regular";
param.transactionType = "SELL";
// param.price = 141819;
MarginCalculationParams param2 = new MarginCalculationParams();
param2.exchange = "NFO";
param2.tradingSymbol = "NIFTY21MAY14450PE";
param2.orderType = "MARKET";
param2.quantity = (int)(75*ImportantPosition.HEDGED_QTY_MULTIPLIER);
param2.product = "MIS";
param2.variety = "regular";
param.transactionType = "BUY";
// param2.price = 300;
params.add(param2);
params.add(param);
CombinedMarginData combinedMarginData = getKiteConnect().getCombinedMarginCalculation(params, true, false);
System.out.println(combinedMarginData.initialMargin.total);
System.out.println(combinedMarginData.finalMargin.total);
}
I tried gettting margins using above function. It seems SELL margins are wrongly computed. Kindly check.
HI
i have using java library and subscribed for nifty and nifty future via java web socket library.
Everything works good, just one issue is there
With Nifty Index.
change filed contains net change from yesterday close
With Nifty Future
change filed display percentage change from yesterday close
Please find my logs
Token : 256265
ltp : 17320.55
Close : 17629.8
change : -309.25
Avg traded price : 0.0
volume : 0.0
OI : 0.0
o : 17593.85
h : 17642.15
l : 17291.65
C :17629.8
`Here is my java code
tickerProvider.setOnTickerArrivalListener(new OnTicks() {
@Override
public void onTicks(ArrayList ticks) {
System.out.println("tick "+ ticks.size());
ticks.forEach(i->{
System.out.println("Token : " + i.getInstrumentToken());
System.out.println("ltp : " + i.getLastTradedPrice());
System.out.println("Close : " + i.getClosePrice());
System.out.println("change : " + i.getChange());
System.out.println("Avg traded price : " + i.getAverageTradePrice()); // vwap
System.out.println("volume : " + i.getVolumeTradedToday()); // volume
System.out.println("OI : " + i.getOi()); // volume
System.out.println("o : " + i.getOpenPrice());
System.out.println("h : " + i.getHighPrice());
System.out.println("l : " + i.getLowPrice());
System.out.println("C :" + i.getClosePrice());
});
System.out.println("---------");
// FilterTickToDomain.filter(ticks);
}
});`
line 242 : RequestBody body = RequestBody.create(jsonArray.toString(), JSON);
It seems 1st parameter shall be 2nd and 2nd shall be first.
In this line of the code, the mode is hardcoded to modeQuote
.
Which makes setting the mode irrelevant.
int segment = x & 0xff;
int dec1 = (segment == NseCD) ? 10000000 : 100;
BseCD
too?Hello Kite,
Is this library provide IPO/SME IPO List ?
Thanks
Hi,
I have written following code for re-connection -
tickerProvider.setTryReconnection(true);
tickerProvider.setMaximumRetries(50);
tickerProvider.setMaximumRetryInterval(30);
But it is not working. Initially when we call KiteTicker connect() method we receive ticks properly. But once Internet Disconnected and then again Connected then reconnection not working. I recently updated to Kite API v3 and it is not working in v3 but in older version of API it was working properly.
I request you to please check this and help me as soon as possible.
Thanks
Any reason for not including toString methods in model objects ?
I get a random and hard to reproduce IllegalStateException errors with calls to the api GetInstruments. Retrying the same , works. Exception trace below;
java.lang.IllegalStateException: closed
okio.RealBufferedSource.select(RealBufferedSource.kt:83)
okhttp3.internal.Util.readBomAsCharset(Util.kt:256)
okhttp3.ResponseBody.string(ResponseBody.kt:187)
com.zerodhatech.kiteconnect.kitehttp.KiteResponseHandler.handle(KiteResponseHandler.java:34)
at com.zerodhatech.kiteconnect.kitehttp.KiteRequestHandler.getCSVRequest(KiteRequestHandler.java:150)
at com.zerodhatech.kiteconnect.KiteConnect.getInstruments(KiteConnect.java:651)
Version:3.1.0
As per example given below inside setOnTickerArrivalListener()
System.out.println("tick timestamp date "+ticks.get(0).getTickTimestamp());
System.out.println("last traded time "+ticks.get(0).getLastTradedTime());
These 2 lines always return null.
I am trying to get 15minute
and 60minute
data of Silver, Gold etc. My MCX commodity trading is enabled. I have been getting InputException
which is very frustrating.
I tried finding an example, which I did find here. In this example, I get the parse error related to date formatter and date string. Which means, the example in this repo is outdated. Could you please give latest example in the repo to fetch historical data by minute
, 15minute
and 60minute
?
On my own machine I run my "Scala" code like this:
val historicalDayData = kiteConnect.getHistoricalData(
Date.valueOf("2023-10-29"),
Date.valueOf("2023-11-28"),
"65953543",
"day",
true,
true
)
When I fetch the day
data, there is no error. However, in case of 15minute
and 60minute
I am getting InputException
error.
I am having issues with request token like. when I restart app it is getting expired.
I wanted to explore Kite APIs using Java lib connector but I just came to know it's not free and it's okay but I want to develop something before I actually purchase your plan. So I just don't waste money on testing my development. Is there any way to test using sandbox for free?
Side note: I have Zerodha account
{open=311.1, close=310.25, high=315.45, low=310.5, volume=1.8547441E7, lasttradedprice=312.85, change=0.8380338436744634, lasttradedquantity=200.0, volumetradedtoday=0.0, totalbuyquantity=0.0, totalsellquantity=0.0, tradetimestamp=1626421247000}
The volume as 1.8547441E7 is represented in exponential format
For further information please go through the forum discussion page https://kite.trade/forum/discussion/10122/incorrect-volume-data-from-websockets#latest
Hi
Requirement
getQuote function should be able to get the Upper limit and lower limit.
Current Behaviour:
Not getting Upper limit and lower limit with the getQuote function
Expected Behaviour:
Should be getting upper limit and lower limit, as the same is accessible thought API call.
API call details:
curl "https://api.kite.trade/quote?i={instruments]"
-H "X-Kite-Version: 3"
-H "Authorization: token api_key:access_token"
Response:
{ "data": { "6401": { "ohlc": { "high": 1885, "low": 1826.05, "close": 1870.75, "open": 1855 }, "lower_circuit_limit": 1683.7, "upper_circuit_limit": 2057.8, "instrument_token": 6401, "average_price": 0, "oi_day_low": 0, "oi_day_high": 0, "last_trade_time": "2023-04-13 15:59:30", "sell_quantity": 0, "buy_quantity": 0, "net_change": 0, "volume": 0, "last_quantity": 2, "depth": { "buy": [ { "quantity": 0, "price": 0, "orders": 0 }, { "quantity": 0, "price": 0, "orders": 0 }, { "quantity": 0, "price": 0, "orders": 0 }, { "quantity": 0, "price": 0, "orders": 0 }, { "quantity": 0, "price": 0, "orders": 0 } ], "sell": [ { "quantity": 0, "price": 0, "orders": 0 }, { "quantity": 0, "price": 0, "orders": 0 }, { "quantity": 0, "price": 0, "orders": 0 }, { "quantity": 0, "price": 0, "orders": 0 }, { "quantity": 0, "price": 0, "orders": 0 } ] }, "oi": 0, "timestamp": "1970-01-01 05:30:00", "last_price": 1870.75 }, "341249": { "lower_circuit_limit": 1523.2, "ohlc": { "high": 1697.05, "low": 1678.15, "close": 1692.45, "open": 1688.3 }, "upper_circuit_limit": 1861.65, "instrument_token": 341249, "average_price": 0, "oi_day_low": 0, "oi_day_high": 0, "last_trade_time": "2023-04-13 15:58:21", "sell_quantity": 0, "buy_quantity": 0, "net_change": 0, "volume": 0, "last_quantity": 1, "depth": { "buy": [ { "quantity": 0, "price": 0, "orders": 0 }, { "quantity": 0, "price": 0, "orders": 0 }, { "quantity": 0, "price": 0, "orders": 0 }, { "quantity": 0, "price": 0, "orders": 0 }, { "quantity": 0, "price": 0, "orders": 0 } ], "sell": [ { "quantity": 0, "price": 0, "orders": 0 }, { "quantity": 0, "price": 0, "orders": 0 }, { "quantity": 0, "price": 0, "orders": 0 }, { "quantity": 0, "price": 0, "orders": 0 }, { "quantity": 0, "price": 0, "orders": 0 } ] }, "oi": 0, "timestamp": "1970-01-01 05:30:00", "last_price": 1692.45 }, "738561": { "lower_circuit_limit": 2119.95, "ohlc": { "high": 2365.8, "low": 2342, "close": 2355.5, "open": 2353 }, "upper_circuit_limit": 2591.05, "instrument_token": 738561, "average_price": 0, "oi_day_low": 0, "oi_day_high": 0, "last_trade_time": "2023-04-13 15:59:43", "sell_quantity": 0, "buy_quantity": 0, "net_change": 0, "volume": 0, "last_quantity": 9, "depth": { "buy": [ { "quantity": 0, "price": 0, "orders": 0 }, { "quantity": 0, "price": 0, "orders": 0 }, { "quantity": 0, "price": 0, "orders": 0 }, { "quantity": 0, "price": 0, "orders": 0 }, { "quantity": 0, "price": 0, "orders": 0 } ], "sell": [ { "quantity": 0, "price": 0, "orders": 0 }, { "quantity": 0, "price": 0, "orders": 0 }, { "quantity": 0, "price": 0, "orders": 0 }, { "quantity": 0, "price": 0, "orders": 0 }, { "quantity": 0, "price": 0, "orders": 0 } ] }, "oi": 0, "timestamp": "1970-01-01 05:30:00", "last_price": 2355.5 }, "895745": { "lower_circuit_limit": 96.75, "ohlc": { "high": 108.15, "low": 105.9, "close": 107.5, "open": 107.5 }, "upper_circuit_limit": 118.25, "instrument_token": 895745, "average_price": 0, "oi_day_low": 0, "oi_day_high": 0, "last_trade_time": "2023-04-13 15:58:32", "sell_quantity": 0, "buy_quantity": 0, "net_change": 0, "volume": 0, "last_quantity": 1, "depth": { "buy": [ { "quantity": 0, "price": 0, "orders": 0 }, { "quantity": 0, "price": 0, "orders": 0 }, { "quantity": 0, "price": 0, "orders": 0 }, { "quantity": 0, "price": 0, "orders": 0 }, { "quantity": 0, "price": 0, "orders": 0 } ], "sell": [ { "quantity": 0, "price": 0, "orders": 0 }, { "quantity": 0, "price": 0, "orders": 0 }, { "quantity": 0, "price": 0, "orders": 0 }, { "quantity": 0, "price": 0, "orders": 0 }, { "quantity": 0, "price": 0, "orders": 0 } ] }, "oi": 0, "timestamp": "1970-01-01 05:30:00", "last_price": 107.5 } }, "status": "success" }
In the above request I am getting "lower_circuit_limit", and "upper_circuit_limit".
But the quote bean which we are using does not have above two params.
Here by I Propose to add those two fields into the Quote Bean.
Class name: Quote
public class Quote {
@SerializedName("volume")
public double volumeTradedToday;
@SerializedName("last_quantity")
public double lastTradedQuantity;
@SerializedName("last_trade_time")
public Date lastTradedTime;
@SerializedName("net_change")
public double change;
@SerializedName("oi")
public double oi;
@SerializedName("sell_quantity")
public double sellQuantity;
@SerializedName("last_price")
public double lastPrice;
@SerializedName("buy_quantity")
public double buyQuantity;
@SerializedName("ohlc")
public OHLC ohlc;
@SerializedName("instrument_token")
public long instrumentToken;
@SerializedName("timestamp")
public Date timestamp;
@SerializedName("average_price")
public double averagePrice;
@SerializedName("day_high_oi")
public double oiDayHigh;
@SerializedName("day_low_oi")
public double oiDayLow;
@SerializedName("depth")
public MarketDepth depth;
**@SerializedName("lower_circuit_limit")
public double lowerCircuitLimit;
@SerializedName("upper_circuit_limit")
public double upperCircuitLimit;**
}
kiteSdk.setAccessToken(userModel.accessToken);
kiteSdk.setPublicToken(userModel.publicToken);
Sometimes I get below error while placing CO LIMIT order
java.lang.IllegalStateException: closed
at okio.RealBufferedSource.rangeEquals(RealBufferedSource.java:398)
at okio.RealBufferedSource.rangeEquals(RealBufferedSource.java:392)
at okhttp3.internal.Util.bomAwareCharset(Util.java:449)
at okhttp3.ResponseBody.string(ResponseBody.java:174)
at com.zerodhatech.kiteconnect.kitehttp.KiteResponseHandler.handle(KiteResponseHandler.java:24)
at com.zerodhatech.kiteconnect.kitehttp.KiteRequestHandler.postRequest(KiteRequestHandler.java:85)
at com.zerodhatech.kiteconnect.KiteConnect.placeOrder(KiteConnect.java:282)
Please check
// Get accessToken as follows,
User user = kiteSdk.requestAccessToken("request_token", "your_apiSecret");
Currently all the failures returns exceptions like InputException
, KiteException
etc.
but they do not contain detailed error message that is coming from zerodha's rest API, for example, Markets are closed ...
.
This information is present in the mesasge
field in the http response. It would be good if this message can be extracted and put it in the exception.
As per the API doc https://kite.trade/docs/connect/v3/market-quotes/#csv-response-columns,
strike
field type should be float
but it is String
at the moment.
Package logging doesn't exist in okhttp3, not able to compile this.
This import is in KiteRequestHandler.java
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.