Skip to content

Commit 01212fd

Browse files
committed
Add OI Fix request error Fix Date
1 parent 5fd2c13 commit 01212fd

28 files changed

+128
-1012
lines changed

LICENSE

+17-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
1-
The MIT License (MIT)
1+
MIT License
22

3-
Copyright (c) 2016 Rainmatter Technology Pvt. Ltd. (India)
3+
Copyright (c) 2020 Varun Batra
44

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:
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
611

7-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
814

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.
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+13-151
Original file line numberDiff line numberDiff line change
@@ -1,161 +1,23 @@
1-
# The Kite Connect API Go client
1+
# kiteapi
22

3-
The official Go client for communicating with the Kite Connect API.
3+
The source is taken from project OTAMIA which is private.
44

5-
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+
# UNOFFICIAL
66

7-
Zerodha Technology (c) 2018. Licensed under the MIT License.
7+
This api is unofficial although, it source codes are borrowed from official API. This is **incompatible** with official api of Zerodha.
88

9-
## Documentation
9+
# Major Differences
1010

11-
- [Client API documentation - GoDoc](https://godoc.org/github.com/zerodhatech/gokiteconnect)
12-
- [Kite Connect HTTP API documentation](https://kite.trade/docs/connect/v3)
11+
1. Supports OI flag in historical data.
12+
2. The error is displayed in debug mode and you will not receive error = nil when there is one. - __FIX__
13+
3. NewConnect and NewTicker are the functions instead of two packages with New. - __Improvement__
14+
4. The structure used for Ticker data and Connect data is now common. - __Improvement__ (Major)
15+
5. int64 is used everywhere while offical discrepancy is: uint32 in ticker VS and int64 in connect that in official API. __Improvement__ which avoids various conversions.
16+
6. Fixed the minute historical data date is not parsed in known utility when doing unmarshal - Converting the JSON to Struct was making dates as 0000-00-00 __FIX__ (Major)
1317

14-
## Installation
18+
# Status
1519

16-
```
17-
go get github.com/zerodhatech/gokiteconnect
18-
```
20+
This is used in the production environment and I will improve it wherever needed!
1921

20-
## API usage
2122

22-
```go
23-
package main
24-
25-
import (
26-
"fmt"
27-
28-
"github.com/zerodhatech/gokiteconnect"
29-
)
30-
31-
const (
32-
apiKey string = "my_api_key"
33-
apiSecret string = "my_api_secret"
34-
)
35-
36-
func main() {
37-
// Create a new Kite connect instance
38-
kc := kiteconnect.New(apiKey)
39-
40-
// Login URL from which request token can be obtained
41-
fmt.Println(kc.GetLoginURL())
42-
43-
// Obtained request token after Kite Connect login flow
44-
requestToken := "request_token_obtained"
45-
46-
// Get user details and access token
47-
data, err := kc.GenerateSession(requestToken, apiSecret)
48-
if err != nil {
49-
fmt.Printf("Error: %v", err)
50-
return
51-
}
52-
53-
// Set access token
54-
kc.SetAccessToken(data.AccessToken)
55-
56-
// Get margins
57-
margins, err := kc.GetUserMargins()
58-
if err != nil {
59-
fmt.Printf("Error getting margins: %v", err)
60-
}
61-
fmt.Println("margins: ", margins)
62-
}
63-
```
64-
65-
## Kite ticker usage
66-
67-
```go
68-
package main
69-
70-
import (
71-
"fmt"
72-
"time"
73-
74-
kiteconnect "github.com/zerodhatech/gokiteconnect"
75-
"github.com/zerodhatech/gokiteconnect/ticker"
76-
)
77-
78-
var (
79-
ticker *kiteticker.Ticker
80-
)
81-
82-
// Triggered when any error is raised
83-
func onError(err error) {
84-
fmt.Println("Error: ", err)
85-
}
86-
87-
// Triggered when websocket connection is closed
88-
func onClose(code int, reason string) {
89-
fmt.Println("Close: ", code, reason)
90-
}
91-
92-
// Triggered when connection is established and ready to send and accept data
93-
func onConnect() {
94-
fmt.Println("Connected")
95-
err := ticker.Subscribe([]uint32{53718535})
96-
if err != nil {
97-
fmt.Println("err: ", err)
98-
}
99-
}
100-
101-
// Triggered when tick is recevived
102-
func onTick(tick kiteticker.Tick) {
103-
fmt.Println("Tick: ", tick)
104-
}
105-
106-
// Triggered when reconnection is attempted which is enabled by default
107-
func onReconnect(attempt int, delay time.Duration) {
108-
fmt.Printf("Reconnect attempt %d in %fs\n", attempt, delay.Seconds())
109-
}
110-
111-
// Triggered when maximum number of reconnect attempt is made and the program is terminated
112-
func onNoReconnect(attempt int) {
113-
fmt.Printf("Maximum no of reconnect attempt reached: %d", attempt)
114-
}
115-
116-
// Triggered when order update is received
117-
func onOrderUpdate(order kiteconnect.Order) {
118-
fmt.Printf("Order: ", order.OrderID)
119-
}
120-
121-
func main() {
122-
apiKey := "my_api_key"
123-
accessToken := "my_access_token"
124-
125-
// Create new Kite ticker instance
126-
ticker = kiteticker.New(apiKey, accessToken)
127-
128-
// Assign callbacks
129-
ticker.OnError(onError)
130-
ticker.OnClose(onClose)
131-
ticker.OnConnect(onConnect)
132-
ticker.OnReconnect(onReconnect)
133-
ticker.OnNoReconnect(onNoReconnect)
134-
ticker.OnTick(onTick)
135-
ticker.OnOrderUpdate(onOrderUpdate)
136-
137-
// Start the connection
138-
ticker.Serve()
139-
}
140-
```
141-
142-
# Examples
143-
144-
Check [examples folder](https://github.com/zerodhatech/gokiteconnect/tree/master/examples) for more examples.
145-
146-
You can run the following after updating the API Keys in the examples:
147-
148-
```bash
149-
go run examples/connect/basic/connect.go
150-
```
151-
152-
## Run unit tests
153-
154-
```
155-
go test -v
156-
```
157-
158-
## Changelog
159-
160-
[Check CHANGELOG.md](CHANGELOG.md)
16123

connect.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package kiteconnect
1+
package kiteapi
22

33
import (
44
"fmt"
@@ -24,7 +24,7 @@ type Client struct {
2424
}
2525

2626
const (
27-
name string = "gokiteconnect"
27+
name string = "otamia/kiteapi"
2828
version string = "3.0.0"
2929
requestTimeout time.Duration = 7000 * time.Millisecond
3030
baseURI string = "https://api.kite.trade"
@@ -132,7 +132,7 @@ const (
132132
)
133133

134134
// New creates a new Kite Connect client.
135-
func New(apiKey string) *Client {
135+
func NewConnect(apiKey string) *Client {
136136
client := &Client{
137137
apiKey: apiKey,
138138
baseURI: baseURI,

connect_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package kiteconnect
1+
package kiteapi
22

33
import (
44
"fmt"
@@ -25,7 +25,7 @@ func TestNewClient(t *testing.T) {
2525
t.Parallel()
2626

2727
apiKey := "api_key"
28-
client := New(apiKey)
28+
client := NewConnect(apiKey)
2929

3030
if client.apiKey != apiKey {
3131
t.Errorf("Api key is not assigned properly.")
@@ -37,7 +37,7 @@ func TestClientSetters(t *testing.T) {
3737
t.Parallel()
3838

3939
apiKey := "kitefront"
40-
client := New(apiKey)
40+
client := NewConnect(apiKey)
4141

4242
customDebug := true
4343
customBaseURI := "test"
@@ -164,7 +164,7 @@ type TestSuite struct {
164164

165165
// Setup the API suit
166166
func (ts *TestSuite) SetupAPITestSuit() {
167-
ts.KiteConnect = New("test_api_key")
167+
ts.KiteConnect = NewConnect("test_api_key")
168168
httpmock.ActivateNonDefault(ts.KiteConnect.httpClient.GetClient().client)
169169

170170
for _, v := range MockResponders {

errors.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* like errors that can be used across other kite packages.
33
*/
44

5-
package kiteconnect
5+
package kiteapi
66

77
import "net/http"
88

errors_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package kiteconnect
1+
package kiteapi
22

33
import (
44
"net/http"

examples/connect/advanced/connect.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"log"
77
"net/http"
88

9-
kiteconnect "github.com/zerodhatech/gokiteconnect"
9+
kiteapi "github.com/VarunBatraIT/kiteapi"
1010
)
1111

1212
const (
@@ -16,7 +16,7 @@ const (
1616

1717
func main() {
1818
// Create a new Kite connect instance
19-
kc := kiteconnect.New(apiKey)
19+
kc := kiteapi.NewConnect(apiKey)
2020

2121
var (
2222
requestToken string

examples/connect/basic/connect.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package main
33
import (
44
"fmt"
55

6-
kiteconnect "github.com/zerodhatech/gokiteconnect"
6+
kiteapi "github.com/VarunBatraIT/kiteapi"
77
)
88

99
const (
@@ -13,7 +13,7 @@ const (
1313

1414
func main() {
1515
// Create a new Kite connect instance
16-
kc := kiteconnect.New(apiKey)
16+
kc := kiteapi.NewConnect(apiKey)
1717

1818
// Login URL from which request token can be obtained
1919
fmt.Println(kc.GetLoginURL())

examples/connect/gtt/connect.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"log"
66
"net/http"
77

8-
kiteconnect "github.com/zerodhatech/gokiteconnect"
8+
kiteapi "github.com/VarunBatraIT/kiteapi"
99
)
1010

1111
const (
@@ -15,7 +15,7 @@ const (
1515

1616
func main() {
1717
// Create a new Kite connect instance
18-
kc := kiteconnect.New(apiKey)
18+
kc := kiteapi.NewConnect(apiKey)
1919

2020
var (
2121
requestToken string
@@ -53,13 +53,13 @@ func main() {
5353

5454
log.Println("Placing GTT...")
5555
// Place GTT
56-
gttResp, err := kc.PlaceGTT(kiteconnect.GTTParams{
56+
gttResp, err := kc.PlaceGTT(kiteapi.GTTParams{
5757
Tradingsymbol: "INFY",
5858
Exchange: "NSE",
5959
LastPrice: 800,
60-
TransactionType: kiteconnect.TransactionTypeBuy,
61-
Trigger: &kiteconnect.GTTSingleLegTrigger{
62-
TriggerParams: kiteconnect.TriggerParams{
60+
TransactionType: kiteapi.TransactionTypeBuy,
61+
Trigger: &kiteapi.GTTSingleLegTrigger{
62+
TriggerParams: kiteapi.TriggerParams{
6363
TriggerValue: 1,
6464
Quantity: 1,
6565
LimitPrice: 1,
@@ -82,13 +82,13 @@ func main() {
8282

8383
log.Println("Modify existing GTT...")
8484

85-
gttModifyResp, err := kc.ModifyGTT(gttResp.TriggerID, kiteconnect.GTTParams{
85+
gttModifyResp, err := kc.ModifyGTT(gttResp.TriggerID, kiteapi.GTTParams{
8686
Tradingsymbol: "INFY",
8787
Exchange: "NSE",
8888
LastPrice: 800,
89-
TransactionType: kiteconnect.TransactionTypeBuy,
90-
Trigger: &kiteconnect.GTTSingleLegTrigger{
91-
TriggerParams: kiteconnect.TriggerParams{
89+
TransactionType: kiteapi.TransactionTypeBuy,
90+
Trigger: &kiteapi.GTTSingleLegTrigger{
91+
TriggerParams: kiteapi.TriggerParams{
9292
TriggerValue: 2,
9393
Quantity: 2,
9494
LimitPrice: 2,

0 commit comments

Comments
 (0)