Documentation
¶
Index ¶
- type OrderFlow
- type Subscription
- type TradingAccount
- func (a *TradingAccount) Balance() decimal.Decimal
- func (a *TradingAccount) Cancel(ctx context.Context, orderID, symbol string) error
- func (a *TradingAccount) CancelWS(ctx context.Context, orderID, symbol string) error
- func (a *TradingAccount) Close()
- func (a *TradingAccount) OpenOrder(orderID string) (*exchanges.Order, bool)
- func (a *TradingAccount) OpenOrders() []exchanges.Order
- func (a *TradingAccount) Place(ctx context.Context, params *exchanges.OrderParams) (*OrderFlow, error)
- func (a *TradingAccount) PlaceWS(ctx context.Context, params *exchanges.OrderParams) (*OrderFlow, error)
- func (a *TradingAccount) Position(symbol string) (*exchanges.Position, bool)
- func (a *TradingAccount) Positions() []exchanges.Position
- func (a *TradingAccount) Start(ctx context.Context) (err error)
- func (a *TradingAccount) SubscribeOrders() *Subscription[exchanges.Order]
- func (a *TradingAccount) SubscribePositions() *Subscription[exchanges.Position]
- func (a *TradingAccount) Track(orderID, clientOrderID string) (*OrderFlow, error)
- type TradingAccountOption
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) Fills ¶ added in v0.2.11
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
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) SubscribeOrders ¶
func (a *TradingAccount) SubscribeOrders() *Subscription[exchanges.Order]
func (*TradingAccount) SubscribePositions ¶
func (a *TradingAccount) SubscribePositions() *Subscription[exchanges.Position]
type TradingAccountOption ¶
type TradingAccountOption func(*TradingAccount)
Click to show internal directories.
Click to hide internal directories.