-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from rhnvrm/gtt
GTT Orders
- Loading branch information
Showing
27 changed files
with
782 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
go.sum | ||
.chglog |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,71 @@ | ||
# Changelog | ||
<a name="unreleased"></a> | ||
## [Unreleased] | ||
|
||
|
||
<a name="v3.1.0"></a> | ||
## [v3.1.0] - 2019-09-09 | ||
### Chore | ||
- update examples and changelog | ||
- modify examples | ||
- add go 1.11 to travis config | ||
|
||
### Feat | ||
- implement gtt orders api | ||
- add models for gtt | ||
|
||
### Fix | ||
- travis config, update go versions | ||
- change type of instrument token in orders response struct to uint32 | ||
- access token and api key getting appended multiple times in ticker | ||
- ticker SetRootURL() method didn't set root URL | ||
|
||
### Test | ||
- fix test for Cancel Order | ||
|
||
### Tests | ||
- update test package, gtt tests | ||
|
||
### Pull Requests | ||
- Merge pull request [#11](https://github.com/zerodhatech/gokiteconnect/issues/11) from rhnvrm/master | ||
- Merge pull request [#10](https://github.com/zerodhatech/gokiteconnect/issues/10) from rhnvrm/master | ||
|
||
|
||
<a name="v3.0.0"></a> | ||
## v3.0.0 - 2018-09-03 | ||
### Chore | ||
- add travis ci config | ||
|
||
### Connect_test | ||
- Refactor setting up mock responders | ||
|
||
### Feat | ||
- convert package to go module | ||
- fix tests and make struct members of instrument public | ||
|
||
### Fix | ||
- fix goversion in travis | ||
- add custom go get command in travis | ||
- travis config | ||
- remove models.PlainResponse from user and portfolio calls | ||
|
||
### Refactor | ||
- calculate depthitem info | ||
- minor cosmetic change | ||
|
||
### Test | ||
- added tests for errors | ||
|
||
### Tests | ||
- market | ||
|
||
### Pull Requests | ||
- Merge pull request [#7](https://github.com/zerodhatech/gokiteconnect/issues/7) from zerodhatech/gomod | ||
- Merge pull request [#5](https://github.com/zerodhatech/gokiteconnect/issues/5) from rhnvrm/markettest | ||
- Merge pull request [#4](https://github.com/zerodhatech/gokiteconnect/issues/4) from rhnvrm/errors_test | ||
- Merge pull request [#3](https://github.com/zerodhatech/gokiteconnect/issues/3) from rhnvrm/master | ||
- Merge pull request [#1](https://github.com/zerodhatech/gokiteconnect/issues/1) from mr-karan/tests | ||
- Merge pull request [#2](https://github.com/zerodhatech/gokiteconnect/issues/2) from zerodhatech/travis | ||
|
||
|
||
[Unreleased]: https://github.com/zerodhatech/gokiteconnect/compare/v3.1.0...HEAD | ||
[v3.1.0]: https://github.com/zerodhatech/gokiteconnect/compare/v3.0.0...v3.1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
"net/http" | ||
|
||
kiteconnect "github.com/zerodhatech/gokiteconnect" | ||
) | ||
|
||
const ( | ||
apiKey string = "my_api_key" | ||
apiSecret string = "my_api_secret" | ||
) | ||
|
||
func main() { | ||
// Create a new Kite connect instance | ||
kc := kiteconnect.New(apiKey) | ||
|
||
var ( | ||
requestToken string | ||
) | ||
|
||
// Login URL from which request token can be obtained | ||
fmt.Println("Open the following url in your browser:\n", kc.GetLoginURL()) | ||
|
||
// Obtain request token after Kite Connect login flow | ||
// Run a temporary server to listen for callback | ||
srv := &http.Server{Addr: ":8080"} | ||
http.HandleFunc("/api/user/callback/kite/", func(w http.ResponseWriter, r *http.Request) { | ||
requestToken = r.URL.Query()["request_token"][0] | ||
log.Println("request token", requestToken) | ||
go srv.Shutdown(context.TODO()) | ||
w.Write([]byte("login successful!")) | ||
return | ||
}) | ||
srv.ListenAndServe() | ||
|
||
// Get user details and access token | ||
data, err := kc.GenerateSession(requestToken, apiSecret) | ||
if err != nil { | ||
fmt.Printf("Error: %v", err) | ||
return | ||
} | ||
|
||
// Set access token | ||
kc.SetAccessToken(data.AccessToken) | ||
log.Println("data.AccessToken", data.AccessToken) | ||
|
||
// Get margins | ||
margins, err := kc.GetUserMargins() | ||
if err != nil { | ||
fmt.Printf("Error getting margins: %v", err) | ||
} | ||
fmt.Println("margins: ", margins) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"net/http" | ||
|
||
kiteconnect "github.com/zerodhatech/gokiteconnect" | ||
) | ||
|
||
const ( | ||
apiKey string = "my_api_key" | ||
apiSecret string = "my_api_secret" | ||
) | ||
|
||
func main() { | ||
// Create a new Kite connect instance | ||
kc := kiteconnect.New(apiKey) | ||
|
||
var ( | ||
requestToken string | ||
) | ||
|
||
// Login URL from which request token can be obtained | ||
log.Println(kc.GetLoginURL()) | ||
|
||
// Obtained request token after Kite Connect login flow | ||
srv := &http.Server{Addr: ":8080"} | ||
http.HandleFunc("/api/user/callback/kite/", func(w http.ResponseWriter, r *http.Request) { | ||
requestToken = r.URL.Query()["request_token"][0] | ||
go srv.Shutdown(context.TODO()) | ||
w.Write([]byte("login successful!")) | ||
return | ||
}) | ||
srv.ListenAndServe() | ||
|
||
// Get user details and access token | ||
data, err := kc.GenerateSession(requestToken, apiSecret) | ||
if err != nil { | ||
log.Printf("Error: %v", err) | ||
return | ||
} | ||
|
||
// Set access token | ||
kc.SetAccessToken(data.AccessToken) | ||
|
||
log.Println("Fetching GTTs...") | ||
orders, err := kc.GetGTTs() | ||
if err != nil { | ||
log.Fatalf("Error getting GTTs: %v", err) | ||
} | ||
log.Printf("gtt: %v", orders) | ||
|
||
log.Println("Placing GTT...") | ||
// Place GTT | ||
gttResp, err := kc.PlaceGTT(kiteconnect.GTTParams{ | ||
Tradingsymbol: "INFY", | ||
Exchange: "NSE", | ||
LastPrice: 800, | ||
TransactionType: kiteconnect.TransactionTypeBuy, | ||
Trigger: &kiteconnect.GTTSingleLegTrigger{ | ||
TriggerParams: kiteconnect.TriggerParams{ | ||
TriggerValue: 1, | ||
Quantity: 1, | ||
LimitPrice: 1, | ||
}, | ||
}, | ||
}) | ||
if err != nil { | ||
log.Fatalf("error placing gtt: %v", err) | ||
} | ||
|
||
log.Println("placed GTT trigger_id = ", gttResp.TriggerID) | ||
|
||
log.Println("Fetching details of placed GTT...") | ||
|
||
order, err := kc.GetGTT(gttResp.TriggerID) | ||
if err != nil { | ||
log.Fatalf("Error getting GTTs: %v", err) | ||
} | ||
log.Printf("gtt: %v", order) | ||
|
||
log.Println("Modify existing GTT...") | ||
|
||
gttModifyResp, err := kc.ModifyGTT(gttResp.TriggerID, kiteconnect.GTTParams{ | ||
Tradingsymbol: "INFY", | ||
Exchange: "NSE", | ||
LastPrice: 800, | ||
TransactionType: kiteconnect.TransactionTypeBuy, | ||
Trigger: &kiteconnect.GTTSingleLegTrigger{ | ||
TriggerParams: kiteconnect.TriggerParams{ | ||
TriggerValue: 2, | ||
Quantity: 2, | ||
LimitPrice: 2, | ||
}, | ||
}, | ||
}) | ||
if err != nil { | ||
log.Fatalf("error placing gtt: %v", err) | ||
} | ||
|
||
log.Println("modified GTT trigger_id = ", gttModifyResp.TriggerID) | ||
|
||
gttDeleteResp, err := kc.DeleteGTT(gttResp.TriggerID) | ||
if err != nil { | ||
log.Fatalf("Error getting GTTs: %v", err) | ||
} | ||
log.Printf("gtt deleted: %v", gttDeleteResp) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.