Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MarketDataApp committed Feb 16, 2024
1 parent b603e64 commit 44945ed
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 22 deletions.
24 changes: 12 additions & 12 deletions models/stocks_bulkcandles.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@ import (
// It contains arrays of stock symbols, timestamps, opening, high, low, closing prices, and volumes for each candle.
//
// # Generated By
//
//
// - BulkStockCandlesRequest.Packed(): Generates a BulkStockCandlesResponse from a bulk stock candles request.
//
//
// # Methods
//
//
// - Unpack() ([]Candle, error): Converts the BulkStockCandlesResponse into a slice of Candle structs.
// - String() string: Provides a string representation of the BulkStockCandlesResponse.
//
//
// # Notes
//
//
// - The Date field uses UNIX timestamps to represent the time for each candle.
// - Ensure the slices within BulkStockCandlesResponse have equal lengths to prevent index out-of-range errors.
type BulkStockCandlesResponse struct {
Symbol []string `json:"symbol" human:"Symbol"` // Symbol holds the stock ticker of the candle.
Date []int64 `json:"t" human:"Date"` // Date holds UNIX timestamps for each candle.
Open []float64 `json:"o" human:"Open"` // Open holds the opening prices for each candle.
High []float64 `json:"h" human:"High"` // High holds the highest prices reached in each candle.
Low []float64 `json:"l" human:"Low"` // Low holds the lowest prices reached in each candle.
Close []float64 `json:"c" human:"Close"` // Close holds the closing prices for each candle.
Volume []int64 `json:"v" human:"Volume"` // Volume represents the trading volume in each candle.
Symbol []string `json:"symbol"` // Symbol holds the stock ticker of the candle.
Date []int64 `json:"t"` // Date holds UNIX timestamps for each candle.
Open []float64 `json:"o"` // Open holds the opening prices for each candle.
High []float64 `json:"h"` // High holds the highest prices reached in each candle.
Low []float64 `json:"l"` // Low holds the lowest prices reached in each candle.
Close []float64 `json:"c"` // Close holds the closing prices for each candle.
Volume []int64 `json:"v"` // Volume represents the trading volume in each candle.
}

// Unpack converts a BulkStockCandlesResponse into a slice of Candle.
Expand Down
16 changes: 8 additions & 8 deletions models/stocks_candles.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ import (
// - The optional fields VWAP and N are only available for version 2 candles.
// - The Date field uses UNIX timestamps to represent the date and time of each candle.
type StockCandlesResponse struct {
Date []int64 `json:"t" human:"Date"` // Date holds UNIX timestamps for each candle.
Open []float64 `json:"o" human:"Open"` // Open holds the opening prices for each candle.
High []float64 `json:"h" human:"High"` // High holds the highest prices reached in each candle.
Low []float64 `json:"l" human:"Low"` // Low holds the lowest prices reached in each candle.
Close []float64 `json:"c" human:"Close"` // Close holds the closing prices for each candle.
Volume []int64 `json:"v" human:"Volume"` // Volume represents the trading volume in each candle.
VWAP *[]float64 `json:"vwap,omitempty" human:"VWAP,omitempty"` // VWAP holds the Volume Weighted Average Price for each candle, optional.
N *[]int64 `json:"n,omitempty" human:"No. of Trades,omitempty"` // N holds the number of trades for each candle, optional.
Date []int64 `json:"t"` // Date holds UNIX timestamps for each candle.
Open []float64 `json:"o"` // Open holds the opening prices for each candle.
High []float64 `json:"h"` // High holds the highest prices reached in each candle.
Low []float64 `json:"l"` // Low holds the lowest prices reached in each candle.
Close []float64 `json:"c"` // Close holds the closing prices for each candle.
Volume []int64 `json:"v"` // Volume represents the trading volume in each candle.
VWAP *[]float64 `json:"vwap,omitempty"` // VWAP holds the Volume Weighted Average Price for each candle, optional.
N *[]int64 `json:"n,omitempty"` // N holds the number of trades for each candle, optional.
}

// Unpack converts a StockCandlesResponse into a slice of StockCandle. This method is primarily used to transform the aggregated
Expand Down
4 changes: 2 additions & 2 deletions options_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
//
// | Method | Execution Level | Return Type | Description |
// |------------|-----------------|------------------------------|----------------------------------------------------------------------------------------------------------------------------------|
// | **Get** | Direct | `[]OptionQuote` | Immediately fetches a slice of `[]models.OptionQuote`, allowing direct access to the options chain data. |
// | **Packed** | Intermediate | `*OptionQuotesResponse` | Delivers a `*models.OptionQuotesResponse` object containing the data, which requires unpacking to access the `OptionQuote` data. |
// | **Get** | Direct | `[]OptionQuote` | Immediately fetches a slice of `[]OptionQuote`, allowing direct access to the options chain data. |
// | **Packed** | Intermediate | `*OptionQuotesResponse` | Delivers a `*OptionQuotesResponse` object containing the data, which requires unpacking to access the `OptionQuote` data. |
// | **Raw** | Low-level | `*resty.Response` | Offers the unprocessed `*resty.Response` for those seeking full control and access to the raw JSON or `*http.Response`. |
package client

Expand Down
11 changes: 11 additions & 0 deletions stocks_candles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@ package client

import "fmt"

func ExampleStockCandlesRequest_raw() {
scr, err := StockCandles().Resolution("4H").Symbol("AAPL").From("2023-01-01").To("2023-01-04").Raw()
if err != nil {
fmt.Print(err)
return
}
fmt.Println(scr)

// Output: {"s":"ok","t":[1672756200,1672770600,1672842600,1672857000],"o":[130.28,124.6699,126.89,127.265],"h":[130.9,125.42,128.6557,127.87],"l":[124.19,124.17,125.08,125.28],"c":[124.6499,125.05,127.2601,126.38],"v":[64411753,30727802,49976607,28870878]}
}

func ExampleStockCandlesRequest_packed() {
scr, err := StockCandles().Resolution("4H").Symbol("AAPL").From("2023-01-01").To("2023-01-04").Packed()
if err != nil {
Expand Down
19 changes: 19 additions & 0 deletions stocks_earnings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,28 @@ package client

import (
"fmt"
"regexp"
"time"
)

func ExampleStockEarningsRequest_raw() {
ser, err := StockEarnings().Symbol("AAPL").From("2022-01-01").To("2022-01-31").Raw()
if err != nil {
fmt.Print(err)
return
}

// Convert the response to a string if it's not already
serString := ser.String()

// Use regex to remove the "updated" key and its value so that the output is consistent between runs.
re := regexp.MustCompile(`,"updated":\[\d+\]`)
cleanedSerString := re.ReplaceAllString(serString, "")

fmt.Println(cleanedSerString)
// Output: {"s":"ok","symbol":["AAPL"],"fiscalYear":[2022],"fiscalQuarter":[1],"date":[1640926800],"reportDate":[1643259600],"reportTime":["after close"],"currency":["USD"],"reportedEPS":[2.1],"estimatedEPS":[1.89],"surpriseEPS":[0.21],"surpriseEPSpct":[0.1111]}
}

func ExampleStockEarningsRequest_packed() {
ser, err := StockEarnings().Symbol("AAPL").From("2022-01-01").To("2022-01-31").Packed()
if err != nil {
Expand Down
Loading

0 comments on commit 44945ed

Please sign in to comment.