forked from zerodha/gokiteconnect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
market_test.go
131 lines (112 loc) · 3.26 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package kiteconnect
import (
"testing"
"time"
"github.com/stretchr/testify/require"
)
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, false)
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) TestGetHistoricalDataWithOI(t *testing.T) {
t.Parallel()
marketHistorical, err := ts.KiteConnect.GetHistoricalData(456, "myinterval", time.Unix(0, 0), time.Unix(1, 0), true, true)
require.Nil(t, err)
require.Equal(t, 6, len(marketHistorical))
for i := 0; i < len(marketHistorical)-1; i++ {
require.Greater(t, marketHistorical[i+1].Date.Unix(), marketHistorical[i].Date.Unix())
require.NotEqual(t, marketHistorical[i].OI, 0)
}
}
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)
}
if mInstr.InstrumentToken == 12074242 {
if mInstr.Expiry.Year() != 2018 {
t.Errorf("Incorrectly parsed timestamp for instruments")
}
}
}
}
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)
}
}
}