Skip to content

Commit 1a6be08

Browse files
committed
updated to include open, low close and high
1 parent 684a8bb commit 1a6be08

4 files changed

Lines changed: 57 additions & 9 deletions

File tree

main.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package main
2+
3+
import (
4+
5+
chart "github.com/piquette/finance-go/chart"
6+
finance "github.com/piquette/finance-go"
7+
"github.com/piquette/finance-go/datetime"
8+
"fmt"
9+
)
10+
11+
12+
13+
func GetHistoricalQuote(symbol string, month int, day int, year int) (*finance.ChartBar, error) {
14+
p := &chart.Params{
15+
Symbol: symbol,
16+
Start: &datetime.Datetime{Month: month, Day: day, Year: year},
17+
End: &datetime.Datetime{Month: month, Day: day, Year: year},
18+
Interval: datetime.OneDay,
19+
}
20+
iter := chart.Get(p)
21+
for iter.Next() {
22+
b := iter.Bar()
23+
return b, nil
24+
}
25+
26+
return nil, nil
27+
}
28+
29+
func main() {
30+
q, _ := GetHistoricalQuote("AAPL", 1, 11, 2018)
31+
fmt.Println(q)
32+
}

quote/client.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@ package quote
33
import (
44
"context"
55
"strings"
6+
"reflect"
67

8+
chart "github.com/piquette/finance-go/chart"
9+
"fmt"
710
finance "github.com/piquette/finance-go"
811
"github.com/piquette/finance-go/form"
912
"github.com/piquette/finance-go/iter"
13+
"github.com/piquette/finance-go/datetime"
1014
)
1115

1216
// Client is used to invoke quote APIs.
@@ -41,22 +45,19 @@ func (i *Iter) Quote() *finance.Quote {
4145
}
4246

4347
//Gives the Day's Close when you input a historical date
44-
func GetHistoricalQuote(symbol string, month int, day int, year int) (float64, error) {
48+
func GetHistoricalQuote(symbol string, month int, day int, year int) (*finance.ChartBar, error) {
4549
p := &chart.Params{
4650
Symbol: symbol,
4751
Start: &datetime.Datetime{Month: month, Day: day, Year: year},
48-
End: &datetime.Datetime{Month: month, Day: day+1, Year: year},
52+
End: &datetime.Datetime{Month: month, Day: day, Year: year},
4953
Interval: datetime.OneDay,
5054
}
5155
iter := chart.Get(p)
52-
r := iter.Iter.Meta()
53-
v := reflect.ValueOf(r)
54-
55-
values := make([]interface{}, v.NumField())
56-
for i := 0; i < v.NumField(); i++ {
57-
values[i] = v.Field(i).Interface()
56+
for iter.Next() {
57+
b := iter.Bar()
58+
return b, nil
5859
}
59-
return values[8].(float64), nil
60+
return nil, nil
6061
}
6162

6263
// Get returns an Quote quote that matches the parameters specified.

quote/client_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@ func TestGetRegularMarketQuote(t *testing.T) {
1919
assert.Equal(t, tests.TestEquitySymbol, q.Symbol)
2020
}
2121

22+
func TestHistoricalQuote(t *testing.T) {
23+
TestMonth := 1
24+
TestDay := 11
25+
TestYear := 2018
26+
27+
q, err := GetHistoricalQuote(tests.TestEquitySymbol, TestMonth, TestDay, TestYear)
28+
29+
assert.Nil(t, err)
30+
assert.NotNil(t, q)
31+
assert.Equal(t, 185.80 , q)
32+
}
33+
2234
func TestGetPostMarketQuote(t *testing.T) {
2335
tests.SetMarket(finance.MarketStatePost)
2436

testing/testing.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ const (
3333
TestForexPairSymbol = "USDGBP=X"
3434
TestCryptoPairSymbol = "BTC-USD"
3535
TestStraddleSymbol = "AMD"
36+
TestMonth = 1
37+
TestDay = 11
38+
TestYear = 2018
3639
)
3740

3841
func init() {

0 commit comments

Comments
 (0)