# Combos

> CombosService, ComboPlayer and ComboMaker: requests for quote, quotes and their events.

Source: https://docs.stxapp.io/sdks/go/reference/combos/

## CombosService

```go
type CombosService struct {
	// contains filtered or unexported fields
}
```

CombosService trades combos: requests for quote as a player (taker), and quotes as a maker. Use it through [Client.Combos](/sdks/go/reference/client/#client). Its Player and Maker open a stream of their own; to share one socket with other subscriptions, use [Stream.ComboPlayer](/sdks/go/reference/websocket/#streamcomboplayer) and [Stream.ComboMaker](/sdks/go/reference/websocket/#streamcombomaker).

Where an exchange does not offer combos, joining returns an error matching [ErrNotAvailable](/sdks/go/reference/errors/#constants-and-variables).

### Available

```go
func (s *CombosService) Available(ctx context.Context) (bool, error)
```

Available reports whether this exchange offers combos, by joining a player topic nobody owns: the exchange answers "unmatched topic" where it has no combos, and refuses the join for another reason where it does. Nothing is created.

### Maker

```go
func (s *CombosService) Maker(ctx context.Context, opts ...StreamOption) (*ComboMaker, error)
```

Maker opens a stream and joins the maker topic. Closing the maker closes that stream.

### Player

```go
func (s *CombosService) Player(ctx context.Context, opts ...StreamOption) (*ComboPlayer, error)
```

Player opens a stream and joins the player topic. Closing the player closes that stream.

## ComboBestQuote

```go
type ComboBestQuote struct {
	QuoteID   string  `json:"quote_id"`
	Amount    Decimal `json:"amount"`
	ExpiresAt int64   `json:"expires_at"`
}
```

ComboBestQuote is the best live quote. Every field is empty when nothing is live. ExpiresAt is in Unix microseconds.

## ComboBestQuoteEvent

```go
type ComboBestQuoteEvent struct {
	RFQID    string `json:"rfq_id"`
	MarketID string `json:"market_id"`
	ComboBestQuote
}
```

ComboBestQuoteEvent is "best\_quote" to the player: the best quote changed.

## ComboCashOut

```go
type ComboCashOut struct {
	RFQID string `json:"rfq_id"`
	// MarketID is the combination being sold.
	MarketID string `json:"market_id"`
	// Quantity is set by the exchange: what you hold less your resting sells.
	Quantity Decimal `json:"quantity"`
}
```

ComboCashOut is the reply to [ComboPlayer.CashOut](/sdks/go/reference/combos/#comboplayercashout).

## ComboEvent

```go
type ComboEvent struct {
	// Event is the event name, for example "best_quote" or "rfq_opened".
	Event string
	// RFQID is the request it is about; QuoteID the quote, on maker events
	// that name one.
	RFQID   string
	QuoteID string
	Payload json.RawMessage
	// Data is the typed payload. To the player: *ComboBestQuoteEvent,
	// *ComboPlacedEvent or *ComboRequestClosedEvent. To the maker:
	// *ComboRFQOpenedEvent, *ComboRFQClosedEvent, *ComboQuoteAcceptedEvent,
	// *ComboMakerPlacedEvent or *ComboQuoteClosedEvent.
	Data any
}
```

ComboEvent is one push on a combo topic.

## ComboLeg

```go
type ComboLeg struct {
	MarketID string       `json:"market_id"`
	Outcome  ComboOutcome `json:"outcome"`
}
```

ComboLeg is one leg of a quote request: an open, ordinary market and the outcome the combination needs of it.

## ComboMaker

```go
type ComboMaker struct {
	// contains filtered or unexported fields
}
```

ComboMaker is the maker's side of combos, on combo\_quote:&lt;user\_id&gt;. Get one with [Stream.ComboMaker](/sdks/go/reference/websocket/#streamcombomaker). Joining subscribes to every request opened from then on ("rfq\_opened"); earlier requests are not replayed.

A quote belongs to this topic: closing it or a dropped socket withdraws it. Every refusal is a \*[ComboRefusedError](/sdks/go/reference/errors/#comborefusederror) with the exchange's reason in Code.

### ComboMaker.Close

```go
func (m *ComboMaker) Close() error
```

Close leaves the topic, which withdraws every quote placed on it.

### ComboMaker.Done

```go
func (m *ComboMaker) Done() <-chan struct{}
```

Done is closed when the maker ends.

### ComboMaker.Err

```go
func (m *ComboMaker) Err() error
```

Err returns why the maker ended, like [Subscription.Err](/sdks/go/reference/websocket/#subscriptionerr).

### ComboMaker.Events

```go
func (m *ComboMaker) Events() <-chan ComboEvent
```

Events returns the channel typed events arrive on, closed when the maker ends.

### ComboMaker.ExternalID

```go
func (m *ComboMaker) ExternalID() string
```

ExternalID returns your pseudonym. Makers' pseudonyms are shown to no one.

### ComboMaker.History

```go
func (m *ComboMaker) History() []ComboEvent
```

History returns the events received so far (the latest 1000), oldest first.

### ComboMaker.Quote

```go
func (m *ComboMaker) Quote(ctx context.Context, q ComboQuoteRequest) (ComboQuote, error)
```

Quote offers an amount on a request. Price it against the request's MaxPrice and TickSize.

### ComboMaker.Topic

```go
func (m *ComboMaker) Topic() string
```

Topic returns the wire topic.

### ComboMaker.WaitFor

```go
func (m *ComboMaker) WaitFor(ctx context.Context, w ComboWait) (ComboEvent, error)
```

WaitFor returns the first event that matches w, looking first at the events already received. It takes nothing from [ComboMaker.Events](/sdks/go/reference/combos/#combomakerevents).

### ComboMaker.WithdrawQuote

```go
func (m *ComboMaker) WithdrawQuote(ctx context.Context, rfqID, quoteID string) error
```

WithdrawQuote removes one of your quotes.

## ComboMakerPlacedEvent

```go
type ComboMakerPlacedEvent struct {
	RFQID      string  `json:"rfq_id"`
	MarketID   string  `json:"market_id"`
	ExternalID string  `json:"external_id"`
	QuoteID    string  `json:"quote_id"`
	OrderID    string  `json:"order_id"`
	Quantity   Decimal `json:"quantity"`
	Price      Decimal `json:"price"`
}
```

ComboMakerPlacedEvent is "placed" to the maker: the quote bound and your order was placed, at the same size and price as the player's.

## ComboOutcome

```go
type ComboOutcome string
```

ComboOutcome is what the combination needs of a leg: "won" or "lost".

```go
const (
	ComboWon  ComboOutcome = "won"
	ComboLost ComboOutcome = "lost"
)
```

The outcomes of a leg.

## ComboPlacedEvent

```go
type ComboPlacedEvent struct {
	RFQID string `json:"rfq_id"`
	ComboPlacement
}
```

ComboPlacedEvent is "placed" to the player: the bind placed your order.

## ComboPlacement

```go
type ComboPlacement struct {
	MarketID string  `json:"market_id"`
	OrderID  string  `json:"order_id"`
	Quantity Decimal `json:"quantity"`
	Price    Decimal `json:"price"`
}
```

ComboPlacement is what an accept placed for you: your order on the combination's market. Its fills arrive on the fills channel.

## ComboPlayer

```go
type ComboPlayer struct {
	// contains filtered or unexported fields
}
```

ComboPlayer is the player's side of combos, on rfq:&lt;user\_id&gt;. Get one with [Stream.ComboPlayer](/sdks/go/reference/websocket/#streamcomboplayer).

A request belongs to this topic: closing it or a dropped socket ends the request "cancelled", and the stream's rejoin does not bring it back. Every refusal is a \*[ComboRefusedError](/sdks/go/reference/errors/#comborefusederror) with the exchange's reason in Code.

**Example**

Ask for quotes on a combination and accept the best one.

```go
ctx := context.Background()
client, err := stx.New(stx.WithProfile("us-demo"))
if err != nil {
	log.Fatal(err)
}
player, err := client.Combos.Player(ctx)
if err != nil {
	log.Fatal(err)
}
defer player.Close()

req, err := player.RequestQuote(ctx, []stx.ComboLeg{
	{MarketID: "71692895-2991-440b-923d-7dfb6783cb17", Outcome: stx.ComboWon},
	{MarketID: "e00651a3-10cb-4bc1-9e1f-c5ea1796c83b", Outcome: stx.ComboWon},
}, "250.00")
if err != nil {
	log.Fatal(err)
}
ev, err := player.WaitFor(ctx, stx.ComboWait{Events: []string{"best_quote"}, RFQID: req.RFQID})
if err != nil {
	log.Fatal(err)
}
best := ev.Data.(*stx.ComboBestQuoteEvent)
placed, err := player.Accept(ctx, req.RFQID, best.QuoteID, best.Amount)
if err != nil {
	log.Fatal(err)
}
fmt.Println(placed.MarketID, placed.Quantity, placed.Price)
```

### ComboPlayer.Accept

```go
func (p *ComboPlayer) Accept(ctx context.Context, rfqID, quoteID string, amount Decimal) (ComboPlacement, error)
```

Accept binds the request at amount or better, normally the amount "best\_quote" showed; the best live quote binds, so the placement can be better than amount. It waits up to 35 seconds unless ctx ends first.

When nothing at least as good is live it returns a \*[ComboRefusedError](/sdks/go/reference/errors/#comborefusederror) matching [ErrComboPriceMoved](/sdks/go/reference/errors/#constants-and-variables), with the live quote in Best; the request stays open and you can accept again. The reply says what was placed; fills arrive on the fills channel.

### ComboPlayer.Cancel

```go
func (p *ComboPlayer) Cancel(ctx context.Context, rfqID string) error
```

Cancel ends the request and drops every quote on it.

### ComboPlayer.CashOut

```go
func (p *ComboPlayer) CashOut(ctx context.Context, marketID string) (ComboCashOut, error)
```

CashOut asks makers to quote for what you hold of a combination, by the market id from "placed". The exchange sets the size.

### ComboPlayer.Close

```go
func (p *ComboPlayer) Close() error
```

Close leaves the topic. Every request still open on it ends "cancelled". To see each request's own close first, cancel it and wait for its "negotiation\_closed" before closing.

### ComboPlayer.Done

```go
func (p *ComboPlayer) Done() <-chan struct{}
```

Done is closed when the player ends.

### ComboPlayer.Err

```go
func (p *ComboPlayer) Err() error
```

Err returns why the player ended, like [Subscription.Err](/sdks/go/reference/websocket/#subscriptionerr).

### ComboPlayer.Events

```go
func (p *ComboPlayer) Events() <-chan ComboEvent
```

Events returns the channel typed events arrive on, closed when the player ends.

### ComboPlayer.ExternalID

```go
func (p *ComboPlayer) ExternalID() string
```

ExternalID returns your pseudonym, which makers see on your requests.

### ComboPlayer.History

```go
func (p *ComboPlayer) History() []ComboEvent
```

History returns the events received so far (the latest 1000), oldest first.

### ComboPlayer.RequestQuote

```go
func (p *ComboPlayer) RequestQuote(ctx context.Context, legs []ComboLeg, amount Decimal) (ComboRequest, error)
```

RequestQuote asks makers to quote on these legs for a stake in dollars, such as "250.00" (whole cents). Makers quote what you win; quotes arrive as "best\_quote" events.

### ComboPlayer.Snapshot

```go
func (p *ComboPlayer) Snapshot(ctx context.Context, rfqID string) (ComboSnapshot, error)
```

Snapshot returns the request now, with the live best quote.

### ComboPlayer.Topic

```go
func (p *ComboPlayer) Topic() string
```

Topic returns the wire topic.

### ComboPlayer.WaitFor

```go
func (p *ComboPlayer) WaitFor(ctx context.Context, w ComboWait) (ComboEvent, error)
```

WaitFor returns the first event that matches w, looking first at the events already received. It takes nothing from [ComboPlayer.Events](/sdks/go/reference/combos/#comboplayerevents).

## ComboQuote

```go
type ComboQuote struct {
	QuoteID string  `json:"quote_id"`
	Amount  Decimal `json:"amount"`
	// ExternalID is the player's pseudonym.
	ExternalID string `json:"external_id"`
}
```

ComboQuote is the reply to [ComboMaker.Quote](/sdks/go/reference/combos/#combomakerquote). It carries no price or size: the bind sets those.

## ComboQuoteAcceptedEvent

```go
type ComboQuoteAcceptedEvent struct {
	RFQID      string `json:"rfq_id"`
	MarketID   string `json:"market_id"`
	ExternalID string `json:"external_id"`
	QuoteID    string `json:"quote_id"`
}
```

ComboQuoteAcceptedEvent is "quote\_accepted" to the maker: this quote is about to be bound.

## ComboQuoteClosedEvent

```go
type ComboQuoteClosedEvent struct {
	RFQID      string `json:"rfq_id"`
	MarketID   string `json:"market_id"`
	ExternalID string `json:"external_id"`
	QuoteID    string `json:"quote_id"`
	Reason     string `json:"reason"`
}
```

ComboQuoteClosedEvent is "negotiation\_closed" to the maker: this quote stopped standing. Reason is "placed\_elsewhere", "maker\_refused", "cancelled", "expired", "leg\_not\_quotable", "unknown\_leg" or "player\_refused".

## ComboQuoteRequest

```go
type ComboQuoteRequest struct {
	// RFQID is the request, from "rfq_opened".
	RFQID string
	// Amount, in dollars: on a buy what the player wins, on a cash out what
	// you pay for the whole size.
	Amount Decimal
	// ExpiresIn is how long the quote stands, counted from receipt, in whole
	// milliseconds. The quote ends no later than its request.
	ExpiresIn time.Duration
	// ClientOrderID (at most 255 bytes) is copied onto your order if the
	// quote binds.
	ClientOrderID string
}
```

ComboQuoteRequest is a maker's quote.

## ComboRFQClosedEvent

```go
type ComboRFQClosedEvent struct {
	RFQID    string `json:"rfq_id"`
	MarketID string `json:"market_id"`
	Reason   string `json:"reason"`
}
```

ComboRFQClosedEvent is "rfq\_closed" to makers: a request ended. Reason is "placed", "cancelled", "expired", "leg\_not\_quotable", "unknown\_leg", "player\_refused", "maker\_refused" or "ended".

## ComboRFQLeg

```go
type ComboRFQLeg struct {
	MarketID  string       `json:"market_id"`
	Outcome   ComboOutcome `json:"outcome"`
	ShortName string       `json:"short_name"`
}
```

ComboRFQLeg is one leg as makers see it. ShortName is the leg market's display name, when the exchange has one.

## ComboRFQOpenedEvent

```go
type ComboRFQOpenedEvent struct {
	RFQID string `json:"rfq_id"`
	// MarketID is empty on a buy and the combination on a cash out.
	MarketID string `json:"market_id"`
	// ExternalID is the player's pseudonym.
	ExternalID string `json:"external_id"`
	// Side is the player's side; you take the other.
	Side      string        `json:"side"`
	Amount    Decimal       `json:"amount"`
	Quantity  Decimal       `json:"quantity"`
	MaxPrice  Decimal       `json:"max_price"`
	TickSize  Decimal       `json:"tick_size"`
	ExpiresAt int64         `json:"expires_at"`
	Legs      []ComboRFQLeg `json:"legs"`
}
```

ComboRFQOpenedEvent is "rfq\_opened" to makers: a player opened a request. Price it against MaxPrice and TickSize, not constants.

## ComboRequest

```go
type ComboRequest struct {
	RFQID string `json:"rfq_id"`
}
```

ComboRequest is the reply to [ComboPlayer.RequestQuote](/sdks/go/reference/combos/#comboplayerrequestquote).

## ComboRequestClosedEvent

```go
type ComboRequestClosedEvent struct {
	RFQID    string `json:"rfq_id"`
	MarketID string `json:"market_id"`
	Reason   string `json:"reason"`
}
```

ComboRequestClosedEvent is "negotiation\_closed" to the player: the request ended without placing. Reason is "cancelled", "expired", "leg\_not\_quotable", "unknown\_leg", "player\_refused" or "maker\_refused".

## ComboSnapshot

```go
type ComboSnapshot struct {
	RFQID string `json:"rfq_id"`
	// MarketID is empty on a buy until a bind places, and the combination on
	// a cash out.
	MarketID string `json:"market_id"`
	// Status is "open", or "binding" while an acceptance waits for its next
	// bind attempt.
	Status string `json:"status"`
	// Side is "buy" for a request, "sell" for a cash out.
	Side string `json:"side"`
	// Amount is the stake on a buy; Quantity the size on a cash out.
	Amount    Decimal        `json:"amount"`
	Quantity  Decimal        `json:"quantity"`
	ExpiresAt int64          `json:"expires_at"`
	BestQuote ComboBestQuote `json:"best_quote"`
}
```

ComboSnapshot is the reply to [ComboPlayer.Snapshot](/sdks/go/reference/combos/#comboplayersnapshot): the request now.

## ComboWait

```go
type ComboWait struct {
	// Events are the event names to match, for example "best_quote".
	Events  []string
	RFQID   string
	QuoteID string
}
```

ComboWait selects the event [ComboPlayer.WaitFor](/sdks/go/reference/combos/#comboplayerwaitfor) and [ComboMaker.WaitFor](/sdks/go/reference/combos/#combomakerwaitfor) wait for. Empty fields match anything.
