account

package
v0.2.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 6, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type OrderFlow

type OrderFlow struct {
	// contains filtered or unexported fields
}

func (*OrderFlow) C

func (f *OrderFlow) C() <-chan *exchanges.Order

func (*OrderFlow) Close

func (f *OrderFlow) Close()

func (*OrderFlow) Fills added in v0.2.11

func (f *OrderFlow) Fills() <-chan *exchanges.Fill
Example
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()

adp := &accountRuntimeStubExchange{
	placeResp: &exchanges.Order{
		ClientOrderID: "cli-1",
		Symbol:        "ETH",
		Side:          exchanges.OrderSideBuy,
		Type:          exchanges.OrderTypeLimit,
		Quantity:      decimal.RequireFromString("0.1"),
		Price:         decimal.RequireFromString("100"),
		Status:        exchanges.OrderStatusPending,
	},
}

acct := account.NewTradingAccount(adp, nil)
if err := acct.Start(ctx); err != nil {
	panic(err)
}
defer acct.Close()

flow, err := acct.Place(ctx, &exchanges.OrderParams{
	Symbol:   "ETH",
	Side:     exchanges.OrderSideBuy,
	Type:     exchanges.OrderTypeLimit,
	Quantity: decimal.RequireFromString("0.1"),
	Price:    decimal.RequireFromString("100"),
})
if err != nil {
	panic(err)
}
defer flow.Close()

adp.EmitOrder(&exchanges.Order{
	OrderID:       "exch-1",
	ClientOrderID: "cli-1",
	Symbol:        "ETH",
	Side:          exchanges.OrderSideBuy,
	Type:          exchanges.OrderTypeLimit,
	Quantity:      decimal.RequireFromString("0.1"),
	Price:         decimal.RequireFromString("100"),
	Status:        exchanges.OrderStatusNew,
})
adp.EmitFill(&exchanges.Fill{
	TradeID:       "trade-1",
	OrderID:       "exch-1",
	ClientOrderID: "cli-1",
	Symbol:        "ETH",
	Side:          exchanges.OrderSideBuy,
	Price:         decimal.RequireFromString("101"),
	Quantity:      decimal.RequireFromString("0.04"),
	Timestamp:     1,
})

fill := <-flow.Fills()

order, err := flow.Wait(ctx, func(o *exchanges.Order) bool {
	return o.LastFillQuantity.Equal(decimal.RequireFromString("0.04"))
})
if err != nil {
	panic(err)
}

fmt.Println(fill.TradeID, order.Status, order.LastFillPrice)
Output:
trade-1 PARTIALLY_FILLED 101

func (*OrderFlow) Latest

func (f *OrderFlow) Latest() *exchanges.Order

func (*OrderFlow) Wait

func (f *OrderFlow) Wait(ctx context.Context, predicate func(*exchanges.Order) bool) (*exchanges.Order, error)

type Subscription

type Subscription[T any] struct {
	C <-chan *T // Read-only channel for the consumer
	// contains filtered or unexported fields
}

Subscription represents a single subscriber's channel for receiving events. Call Unsubscribe() to stop receiving events and release resources.

func (*Subscription[T]) Unsubscribe

func (s *Subscription[T]) Unsubscribe()

Unsubscribe removes this subscription and closes the channel.

type TradingAccount

type TradingAccount struct {
	// contains filtered or unexported fields
}

func NewTradingAccount

func NewTradingAccount(adp exchanges.Exchange, logger exchanges.Logger, _ ...TradingAccountOption) *TradingAccount

func (*TradingAccount) Balance

func (a *TradingAccount) Balance() decimal.Decimal

func (*TradingAccount) Cancel

func (a *TradingAccount) Cancel(ctx context.Context, orderID, symbol string) error

func (*TradingAccount) CancelWS

func (a *TradingAccount) CancelWS(ctx context.Context, orderID, symbol string) error

func (*TradingAccount) Close

func (a *TradingAccount) Close()

func (*TradingAccount) OpenOrder

func (a *TradingAccount) OpenOrder(orderID string) (*exchanges.Order, bool)

func (*TradingAccount) OpenOrders

func (a *TradingAccount) OpenOrders() []exchanges.Order

func (*TradingAccount) Place

func (a *TradingAccount) Place(ctx context.Context, params *exchanges.OrderParams) (*OrderFlow, error)

func (*TradingAccount) PlaceWS

func (a *TradingAccount) PlaceWS(ctx context.Context, params *exchanges.OrderParams) (*OrderFlow, error)

func (*TradingAccount) Position

func (a *TradingAccount) Position(symbol string) (*exchanges.Position, bool)

func (*TradingAccount) Positions

func (a *TradingAccount) Positions() []exchanges.Position

func (*TradingAccount) Start

func (a *TradingAccount) Start(ctx context.Context) (err error)

func (*TradingAccount) SubscribeOrders

func (a *TradingAccount) SubscribeOrders() *Subscription[exchanges.Order]

func (*TradingAccount) SubscribePositions

func (a *TradingAccount) SubscribePositions() *Subscription[exchanges.Position]

func (*TradingAccount) Track

func (a *TradingAccount) Track(orderID, clientOrderID string) (*OrderFlow, error)

type TradingAccountOption

type TradingAccountOption func(*TradingAccount)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL