Describes github.com/stxapp/stx-go v0.3.1, the current release.
CombosService
Section titled “CombosService”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. Its Player and Maker open a stream of their own; to share one socket with other subscriptions, use Stream.ComboPlayer and Stream.ComboMaker.
Where an exchange does not offer combos, joining returns an error matching ErrNotAvailable.
Available
Section titled “Available”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.
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
Section titled “Player”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
Section titled “ComboBestQuote”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
Section titled “ComboBestQuoteEvent”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
Section titled “ComboCashOut”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.
ComboEvent
Section titled “ComboEvent”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
Section titled “ComboLeg”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
Section titled “ComboMaker”type ComboMaker struct { // contains filtered or unexported fields}ComboMaker is the maker’s side of combos, on combo_quote:<user_id>. Get one with Stream.ComboMaker. 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 with the exchange’s reason in Code.
ComboMaker.Close
Section titled “ComboMaker.Close”func (m *ComboMaker) Close() errorClose leaves the topic, which withdraws every quote placed on it.
ComboMaker.Done
Section titled “ComboMaker.Done”func (m *ComboMaker) Done() <-chan struct{}Done is closed when the maker ends.
ComboMaker.Err
Section titled “ComboMaker.Err”func (m *ComboMaker) Err() errorErr returns why the maker ended, like Subscription.Err.
ComboMaker.Events
Section titled “ComboMaker.Events”func (m *ComboMaker) Events() <-chan ComboEventEvents returns the channel typed events arrive on, closed when the maker ends.
ComboMaker.ExternalID
Section titled “ComboMaker.ExternalID”func (m *ComboMaker) ExternalID() stringExternalID returns your pseudonym. Makers’ pseudonyms are shown to no one.
ComboMaker.History
Section titled “ComboMaker.History”func (m *ComboMaker) History() []ComboEventHistory returns the events received so far (the latest 1000), oldest first.
ComboMaker.Quote
Section titled “ComboMaker.Quote”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
Section titled “ComboMaker.Topic”func (m *ComboMaker) Topic() stringTopic returns the wire topic.
ComboMaker.WaitFor
Section titled “ComboMaker.WaitFor”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.
ComboMaker.WithdrawQuote
Section titled “ComboMaker.WithdrawQuote”func (m *ComboMaker) WithdrawQuote(ctx context.Context, rfqID, quoteID string) errorWithdrawQuote removes one of your quotes.
ComboMakerPlacedEvent
Section titled “ComboMakerPlacedEvent”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
Section titled “ComboOutcome”type ComboOutcome stringComboOutcome is what the combination needs of a leg: “won” or “lost”.
const ( ComboWon ComboOutcome = "won" ComboLost ComboOutcome = "lost")The outcomes of a leg.
ComboPlacedEvent
Section titled “ComboPlacedEvent”type ComboPlacedEvent struct { RFQID string `json:"rfq_id"` ComboPlacement}ComboPlacedEvent is “placed” to the player: the bind placed your order.
ComboPlacement
Section titled “ComboPlacement”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
Section titled “ComboPlayer”type ComboPlayer struct { // contains filtered or unexported fields}ComboPlayer is the player’s side of combos, on rfq:<user_id>. Get one with Stream.ComboPlayer.
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 with the exchange’s reason in Code.
Example
Ask for quotes on a combination and accept the best one.
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
Section titled “ComboPlayer.Accept”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 matching ErrComboPriceMoved, 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
Section titled “ComboPlayer.Cancel”func (p *ComboPlayer) Cancel(ctx context.Context, rfqID string) errorCancel ends the request and drops every quote on it.
ComboPlayer.CashOut
Section titled “ComboPlayer.CashOut”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
Section titled “ComboPlayer.Close”func (p *ComboPlayer) Close() errorClose 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
Section titled “ComboPlayer.Done”func (p *ComboPlayer) Done() <-chan struct{}Done is closed when the player ends.
ComboPlayer.Err
Section titled “ComboPlayer.Err”func (p *ComboPlayer) Err() errorErr returns why the player ended, like Subscription.Err.
ComboPlayer.Events
Section titled “ComboPlayer.Events”func (p *ComboPlayer) Events() <-chan ComboEventEvents returns the channel typed events arrive on, closed when the player ends.
ComboPlayer.ExternalID
Section titled “ComboPlayer.ExternalID”func (p *ComboPlayer) ExternalID() stringExternalID returns your pseudonym, which makers see on your requests.
ComboPlayer.History
Section titled “ComboPlayer.History”func (p *ComboPlayer) History() []ComboEventHistory returns the events received so far (the latest 1000), oldest first.
ComboPlayer.RequestQuote
Section titled “ComboPlayer.RequestQuote”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
Section titled “ComboPlayer.Snapshot”func (p *ComboPlayer) Snapshot(ctx context.Context, rfqID string) (ComboSnapshot, error)Snapshot returns the request now, with the live best quote.
ComboPlayer.Topic
Section titled “ComboPlayer.Topic”func (p *ComboPlayer) Topic() stringTopic returns the wire topic.
ComboPlayer.WaitFor
Section titled “ComboPlayer.WaitFor”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.
ComboQuote
Section titled “ComboQuote”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. It carries no price or size: the bind sets those.
ComboQuoteAcceptedEvent
Section titled “ComboQuoteAcceptedEvent”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
Section titled “ComboQuoteClosedEvent”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
Section titled “ComboQuoteRequest”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
Section titled “ComboRFQClosedEvent”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
Section titled “ComboRFQLeg”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
Section titled “ComboRFQOpenedEvent”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
Section titled “ComboRequest”type ComboRequest struct { RFQID string `json:"rfq_id"`}ComboRequest is the reply to ComboPlayer.RequestQuote.
ComboRequestClosedEvent
Section titled “ComboRequestClosedEvent”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
Section titled “ComboSnapshot”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: the request now.
ComboWait
Section titled “ComboWait”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 and ComboMaker.WaitFor wait for. Empty fields match anything.

