Initial functional commit

This commit is contained in:
Options Vamp
2024-05-14 21:50:57 -04:00
parent 70888184fa
commit 461b8cef7b
23 changed files with 2704 additions and 1 deletions

137
option_test.go Normal file
View File

@@ -0,0 +1,137 @@
package tastytrade
import (
"net/http"
"net/http/httptest"
"testing"
)
func TestListOptionsChainsDetailed(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
rw.Write([]byte(`{"context": "test", "data": {"items": [{"symbol": "AAPL", "underlying-symbol": "AAPL"}]}}`))
}))
defer server.Close()
api := NewTastytradeAPI(server.URL)
resp, err := api.ListOptionsChainsDetailed("AAPL")
if err != nil {
t.Errorf("expected nil, got %v", err)
}
if resp.Context != "test" {
t.Errorf("expected %s, got %s", "test", resp.Context)
}
if len(resp.Data.Items) != 1 {
t.Errorf("expected %d, got %d", 1, len(resp.Data.Items))
}
if resp.Data.Items[0].Symbol != "AAPL" {
t.Errorf("expected %s, got %s", "AAPL", resp.Data.Items[0].Symbol)
}
if resp.Data.Items[0].UnderlyingSymbol != "AAPL" {
t.Errorf("expected %s, got %s", "AAPL", resp.Data.Items[0].UnderlyingSymbol)
}
}
func TestListOptionChainsNested(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
rw.Write([]byte(`{"context": "test", "data": {"items": [{"underlying-symbol": "AAPL", "root-symbol": "AAPL"}]}}`))
}))
defer server.Close()
api := NewTastytradeAPI(server.URL)
resp, err := api.ListOptionChainsNested("AAPL")
if err != nil {
t.Errorf("expected nil, got %v", err)
}
if resp.Context != "test" {
t.Errorf("expected %s, got %s", "test", resp.Context)
}
if len(resp.Data.Items) != 1 {
t.Errorf("expected %d, got %d", 1, len(resp.Data.Items))
}
if resp.Data.Items[0].UnderlyingSymbol != "AAPL" {
t.Errorf("expected %s, got %s", "AAPL", resp.Data.Items[0].UnderlyingSymbol)
}
}
func TestGetOptionChainsCompact(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
rw.Write([]byte(`{"context": "test", "data": {"items": [{"underlying-symbol": "AAPL", "root-symbol": "AAPL"}]}}`))
}))
defer server.Close()
api := NewTastytradeAPI(server.URL)
resp, err := api.GetOptionChainsCompact("AAPL")
if err != nil {
t.Errorf("expected nil, got %v", err)
}
if resp.Context != "test" {
t.Errorf("expected %s, got %s", "test", resp.Context)
}
if len(resp.Data.Items) != 1 {
t.Errorf("expected %d, got %d", 1, len(resp.Data.Items))
}
if resp.Data.Items[0].UnderlyingSymbol != "AAPL" {
t.Errorf("expected %s, got %s", "AAPL", resp.Data.Items[0].UnderlyingSymbol)
}
}
func TestGetEquityOptions(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
rw.Write([]byte(`{"context": "test", "data": {"items": [{"symbol": "AAPL", "instrument-type": "equity-option"}]}}`))
}))
defer server.Close()
api := NewTastytradeAPI(server.URL)
resp, err := api.GetEquityOptions(&EquityOptionsQueryParams{Symbol: []string{"AAPL"}})
if err != nil {
t.Errorf("expected nil, got %v", err)
}
if resp.Context != "test" {
t.Errorf("expected %s, got %s", "test", resp.Context)
}
if len(resp.Data.Items) != 1 {
t.Errorf("expected %d, got %d", 1, len(resp.Data.Items))
}
if resp.Data.Items[0].Symbol != "AAPL" {
t.Errorf("expected %s, got %s", "AAPL", resp.Data.Items[0].Symbol)
}
}
func TestGetEquityOption(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
rw.Write([]byte(`{"context": "test", "data": {"symbol": "AAPL", "instrument-type": "equity-option"}}`))
}))
defer server.Close()
api := NewTastytradeAPI(server.URL)
resp, err := api.GetEquityOption("AAPL")
if err != nil {
t.Errorf("expected nil, got %v", err)
}
if resp.Context != "test" {
t.Errorf("expected %s, got %s", "test", resp.Context)
}
if resp.Data.Symbol != "AAPL" {
t.Errorf("expected %s, got %s", "AAPL", resp.Data.Symbol)
}
}