diff --git a/portfolio.go b/portfolio.go index b69bf88..37b7a33 100644 --- a/portfolio.go +++ b/portfolio.go @@ -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 @@ -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 {