Skip to content

Commit

Permalink
Add price helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
ammario committed Jan 5, 2024
1 parent cc94f31 commit 7a3d972
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions portfolio.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ type CreateOrderRequest struct {
Side Side `json:"side"`
}

// SetPrice sets the price of the order based on its side.
func (c *CreateOrderRequest) SetPrice(p Cents) {
if c.Side == Yes {
c.YesPrice = p
} else if c.Side == No {
c.NoPrice = p
}

panic("invalid side: " + string(c.Side))
}

// String returns a human-readable representation of the order.
func (c *CreateOrderRequest) String() string {
var price Cents
Expand Down Expand Up @@ -144,6 +155,15 @@ type Order struct {
YesPrice Cents `json:"yes_price"`
}

func (o *Order) Price() Cents {
if o.Side == Yes {
return o.YesPrice
} else if o.Side == No {
return o.NoPrice
}
panic("invalid side: " + string(o.Side))
}

// Orders is described here:
// https://trading-api.readme.io/reference/getorders.
type OrdersResponse struct {
Expand Down

0 comments on commit 7a3d972

Please sign in to comment.