-
Notifications
You must be signed in to change notification settings - Fork 2
/
market_test.go
111 lines (96 loc) · 2.62 KB
/
market_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package kiteapi
import (
"testing"
"time"
)
func (ts *TestSuite) TestGetQuote(t *testing.T) {
t.Parallel()
marketQuote, err := ts.KiteConnect.GetQuote()
if err != nil {
t.Errorf("Error while fetching MF orders. %v", err)
}
if q, ok := marketQuote["NSE:INFY"]; ok {
if q.InstrumentToken != 408065 {
t.Errorf("Incorrect values set. %v", err)
}
} else {
t.Errorf("Key wanted but not found. %v", err)
}
}
func (ts *TestSuite) TestGetLTP(t *testing.T) {
t.Parallel()
marketLTP, err := ts.KiteConnect.GetLTP()
if err != nil {
t.Errorf("Error while fetching MF orders. %v", err)
}
if ltp, ok := marketLTP["NSE:INFY"]; ok {
if ltp.InstrumentToken != 408065 {
t.Errorf("Incorrect values set. %v", err)
}
} else {
t.Errorf("Key wanted but not found. %v", err)
}
}
func (ts *TestSuite) TestGetHistoricalData(t *testing.T) {
t.Parallel()
marketHistorical, err := ts.KiteConnect.GetHistoricalData(123, "myinterval", time.Unix(0, 0), time.Unix(1, 0), true, true)
if err != nil {
t.Errorf("Error while fetching MF orders. %v", err)
}
for i := 0; i < len(marketHistorical)-1; i++ {
if marketHistorical[i].Date.Unix() > marketHistorical[i+1].Date.Unix() {
t.Errorf("Unsorted candles returned. %v", err)
return
}
}
}
func (ts *TestSuite) TestGetOHLC(t *testing.T) {
t.Parallel()
marketOHLC, err := ts.KiteConnect.GetOHLC()
if err != nil {
t.Errorf("Error while fetching MF orders. %v", err)
}
if ohlc, ok := marketOHLC["NSE:INFY"]; ok {
if ohlc.InstrumentToken != 408065 {
t.Errorf("Incorrect values set. %v", err)
}
} else {
t.Errorf("Key wanted but not found. %v", err)
}
}
func (ts *TestSuite) TestGetInstruments(t *testing.T) {
t.Parallel()
marketInstruments, err := ts.KiteConnect.GetInstruments()
if err != nil {
t.Errorf("Error while fetching MF orders. %v", err)
}
for _, mInstr := range marketInstruments {
if mInstr.InstrumentToken == 0 {
t.Errorf("Incorrect data loaded. %v", err)
}
}
}
func (ts *TestSuite) TestGetInstrumentsByExchange(t *testing.T) {
t.Parallel()
marketInstruments, err := ts.KiteConnect.GetInstrumentsByExchange("nse")
if err != nil {
t.Errorf("Error while fetching MF orders. %v", err)
}
for _, mInstr := range marketInstruments {
if mInstr.Exchange != "NSE" {
t.Errorf("Incorrect data loaded. %v", err)
}
}
}
func (ts *TestSuite) TestGetMFInstruments(t *testing.T) {
t.Parallel()
marketInstruments, err := ts.KiteConnect.GetMFInstruments()
if err != nil {
t.Errorf("Error while fetching MF orders. %v", err)
}
for _, mInstr := range marketInstruments {
if mInstr.Tradingsymbol == "" {
t.Errorf("Incorrect data loaded. %v", err)
}
}
}