Skip to content

Commit

Permalink
Merge pull request #11 from t-hale/proto
Browse files Browse the repository at this point in the history
use proto.* instead of custom utils.Ptr() method
  • Loading branch information
t-hale authored Dec 17, 2023
2 parents 38468aa + 8e14970 commit 2f49778
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 19 deletions.
1 change: 1 addition & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ go_library(
"//gen/stox",
"//utils",
"@com_github_alpacahq_alpaca_trade_api_go_v3//marketdata",
"@com_github_golang_protobuf//proto:go_default_library",
"@com_github_polygon_io_client_go//rest",
"@com_github_polygon_io_client_go//rest/models",
],
Expand Down
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ bazel_dep(name = "gazelle", version = "0.34.0", repo_name = "bazel_gazelle")

go_deps = use_extension("@bazel_gazelle//:extensions.bzl", "go_deps")
go_deps.from_file(go_mod = "//:go.mod")
use_repo(go_deps, "com_github_alpacahq_alpaca_trade_api_go_v3", "com_github_google_go_cmp", "com_github_polygon_io_client_go", "com_github_rs_zerolog", "design_goa_goa_v3", "design_goa_plugins_v3", "org_golang_google_protobuf")
use_repo(go_deps, "com_github_alpacahq_alpaca_trade_api_go_v3", "com_github_golang_protobuf", "com_github_google_go_cmp", "com_github_polygon_io_client_go", "com_github_rs_zerolog", "design_goa_goa_v3", "design_goa_plugins_v3", "org_golang_google_protobuf")
11 changes: 6 additions & 5 deletions MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.20

require (
github.com/alpacahq/alpaca-trade-api-go/v3 v3.0.1
github.com/golang/protobuf v1.5.3
github.com/google/go-cmp v0.6.0
github.com/polygon-io/client-go v1.13.1
github.com/rs/zerolog v1.29.1
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ github.com/go-resty/resty/v2 v2.7.0 h1:me+K9p3uhSmXtrBZ4k9jcEAfJmuC8IivWHwaLZwPr
github.com/go-resty/resty/v2 v2.7.0/go.mod h1:9PWDzw47qPphMRFfhsyk0NnSgvluHcljSMVIq3w7q0I=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
Expand Down Expand Up @@ -106,6 +108,7 @@ golang.org/x/tools v0.7.0 h1:W4OVu8VVOaIO0yzWMNdepAulS7YfoS3Zabrm8DOXXU4=
golang.org/x/tools v0.7.0/go.mod h1:4pg6aUX35JBAogB10C9AtvVL+qowtN4pT3CGSQex14s=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
21 changes: 11 additions & 10 deletions stox.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"github.com/alpacahq/alpaca-trade-api-go/v3/marketdata"
"github.com/golang/protobuf/proto"
polygon "github.com/polygon-io/client-go/rest"
"github.com/polygon-io/client-go/rest/models"
"github.com/t-hale/stox/errors"
Expand Down Expand Up @@ -73,7 +74,7 @@ func (s *stoxsrvc) calculateVestingPlan(p *stox.VestingPlanRequest, trade *marke

vestEvent := &stox.VestEvent{
Date: utils.PtrTo(stox.Date(curDate.Format(time.DateOnly))),
UnitsGranted: utils.PtrTo(int64(0)),
UnitsGranted: proto.Int64(0),
UnitsRemaining: &p.UnitsGranted,
}

Expand Down Expand Up @@ -107,10 +108,10 @@ func (s *stoxsrvc) calculateVestingPlan(p *stox.VestingPlanRequest, trade *marke

for i := 0; i < numEvents; i++ {

vestEvents[i].UnitsRemaining = utils.PtrTo(unitsRemaining)
vestEvents[i].TotalUnitsGranted = utils.PtrTo(totalUnitsGranted)
vestEvents[i].AmountGranted = utils.PtrTo(0.0)
vestEvents[i].TotalAmountGranted = utils.PtrTo(0.0)
vestEvents[i].UnitsRemaining = proto.Int64(unitsRemaining)
vestEvents[i].TotalUnitsGranted = proto.Int64(totalUnitsGranted)
vestEvents[i].AmountGranted = proto.Float64(0.0)
vestEvents[i].TotalAmountGranted = proto.Float64(0.0)

if i == 0 {
continue
Expand All @@ -123,11 +124,11 @@ func (s *stoxsrvc) calculateVestingPlan(p *stox.VestingPlanRequest, trade *marke
totalUnitsGranted += unitsGrantedPerEvent
unitsRemaining -= unitsGrantedPerEvent

vestEvents[i].UnitsGranted = utils.PtrTo(unitsGrantedPerEvent)
vestEvents[i].UnitsRemaining = utils.PtrTo(unitsRemaining)
vestEvents[i].AmountGranted = utils.PtrTo(float64(unitsGrantedPerEvent) * trade.Price)
vestEvents[i].TotalAmountGranted = utils.PtrTo(float64(totalUnitsGranted) * trade.Price)
vestEvents[i].TotalUnitsGranted = utils.PtrTo(totalUnitsGranted)
vestEvents[i].UnitsGranted = proto.Int64(unitsGrantedPerEvent)
vestEvents[i].UnitsRemaining = proto.Int64(unitsRemaining)
vestEvents[i].AmountGranted = proto.Float64(float64(unitsGrantedPerEvent) * trade.Price)
vestEvents[i].TotalAmountGranted = proto.Float64(float64(totalUnitsGranted) * trade.Price)
vestEvents[i].TotalUnitsGranted = proto.Int64(totalUnitsGranted)
}

return &stox.VestingPlanResponse{
Expand Down
6 changes: 3 additions & 3 deletions stox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestCalculateVestDates(t *testing.T) {
Price: 100.13,
},
want: &stox.VestingPlanResponse{
Symbol: utils.PtrTo("FOO"),
Symbol: proto.String("FOO"),
Price: proto.Float64(100.13),
VestPlan: []*stox.VestEvent{
{
Expand Down Expand Up @@ -176,7 +176,7 @@ func TestCalculateVestDates(t *testing.T) {
Price: 72.45,
},
want: &stox.VestingPlanResponse{
Symbol: utils.PtrTo("FOO"),
Symbol: proto.String("FOO"),
Price: proto.Float64(72.45),
VestPlan: []*stox.VestEvent{
{
Expand Down Expand Up @@ -236,7 +236,7 @@ func TestCalculateVestDates(t *testing.T) {
Price: 5.71,
},
want: &stox.VestingPlanResponse{
Symbol: utils.PtrTo("BAR"),
Symbol: proto.String("BAR"),
Price: proto.Float64(5.71),
VestPlan: []*stox.VestEvent{
{
Expand Down

0 comments on commit 2f49778

Please sign in to comment.