-
Notifications
You must be signed in to change notification settings - Fork 34
/
options_test.go
49 lines (37 loc) · 1018 Bytes
/
options_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
package robinhood
import (
"context"
"fmt"
"os"
"testing"
"time"
"github.com/davecgh/go-spew/spew"
"github.com/stretchr/testify/assert"
)
func TestMarketData(t *testing.T) {
if os.Getenv("ROBINHOOD_USERNAME") == "" {
t.Skip("No username set")
return
}
asrt := assert.New(t)
o := &OAuth{
Username: os.Getenv("ROBINHOOD_USERNAME"),
Password: os.Getenv("ROBINHOOD_PASSWORD"),
}
c, err := Dial(context.Background(), &CredsCacher{Creds: o})
asrt.NoError(err)
asrt.NotNil(c)
i, err := c.GetInstrumentForSymbol(context.Background(), "SPY")
asrt.NoError(err)
ch, err := c.GetOptionChains(context.Background(), i)
asrt.NoError(err)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
insts, err := ch[0].GetInstrument(ctx, "call", NewDate(2019, 2, 1))
asrt.NoError(err)
fmt.Printf("len(insts) = %+v\n", len(insts))
is, err := c.MarketData(context.Background(), insts...)
asrt.NoError(err)
spew.Dump(is)
fmt.Printf("len(is) = %+v\n", len(is))
}