Documentation Index
Fetch the complete documentation index at: https://finance.dev/llms.txt
Use this file to discover all available pages before exploring further.
Overview
The Orders API allows you to execute trades, modify existing orders, cancel orders, and preview orders before execution.
Package Reference
import (
"log"
aries "github.com/aries-exchange/go-sdk"
)
client := aries.NewClient(
aries.WithClientID("your_client_id"),
aries.WithClientSecret("your_client_secret"),
)
Methods
PlaceOrder()
Place a new trading order.
order, err := client.Orders.PlaceOrder(&aries.OrderRequest{
Symbol: "AAPL",
Quantity: 10,
Side: "buy",
OrderType: "market",
TimeInForce: "day",
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("Order ID: %s\n", order.ID)
fmt.Printf("Status: %s\n", order.Status)
Parameters:
Symbol (string): Stock symbol
Quantity (int): Number of shares
Side (string): “buy” or “sell”
OrderType (string): “market”, “limit”, “stop”, “stop_limit”
Price (float64, optional): Limit price
StopPrice (float64, optional): Stop price
TimeInForce (string): “day”, “gtc”, “ioc”, “fok”
Returns: *Order, error
UpdateOrder()
Modify an existing order.
updated, err := client.Orders.UpdateOrder("ord_123456", &aries.OrderUpdate{
Quantity: 15,
Price: 150.50,
})
if err != nil {
log.Fatal(err)
}
Parameters:
orderID (string): Order ID
update (*OrderUpdate): Fields to update
Returns: *Order, error
CancelOrder()
Cancel an active order.
err := client.Orders.CancelOrder("ord_123456")
if err != nil {
log.Fatal(err)
}
Parameters:
orderID (string): Order ID to cancel
Returns: error
PreviewOrder()
Preview order before placing.
preview, err := client.Orders.PreviewOrder(&aries.OrderRequest{
Symbol: "AAPL",
Quantity: 100,
Side: "buy",
OrderType: "market",
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("Estimated cost: $%.2f\n", preview.EstimatedCost)
Returns: *OrderPreview, error
Order Types
Market Orders
marketBuy, err := client.Orders.PlaceOrder(&aries.OrderRequest{
Symbol: "AAPL",
Quantity: 10,
Side: "buy",
OrderType: "market",
})
Limit Orders
limitBuy, err := client.Orders.PlaceOrder(&aries.OrderRequest{
Symbol: "AAPL",
Quantity: 10,
Side: "buy",
OrderType: "limit",
Price: 150.00,
})
Stop Orders
stopLoss, err := client.Orders.PlaceOrder(&aries.OrderRequest{
Symbol: "AAPL",
Quantity: 10,
Side: "sell",
OrderType: "stop",
StopPrice: 145.00,
})
Stop-Limit Orders
stopLimit, err := client.Orders.PlaceOrder(&aries.OrderRequest{
Symbol: "AAPL",
Quantity: 10,
Side: "sell",
OrderType: "stop_limit",
StopPrice: 145.00,
Price: 144.50,
})
Examples
Preview Before Trading
preview, err := client.Orders.PreviewOrder(&aries.OrderRequest{
Symbol: "TSLA",
Quantity: 5,
Side: "buy",
OrderType: "market",
})
if err != nil {
log.Fatal(err)
}
fmt.Println("Order Preview:")
fmt.Printf("Estimated price: $%.2f\n", preview.EstimatedPrice)
fmt.Printf("Estimated cost: $%.2f\n", preview.EstimatedCost)
fmt.Printf("Commission: $%.2f\n", preview.Commission)
fmt.Printf("Total: $%.2f\n", preview.Total)
if preview.Total <= 5000 {
order, err := client.Orders.PlaceOrder(&aries.OrderRequest{
Symbol: "TSLA",
Quantity: 5,
Side: "buy",
OrderType: "market",
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("Order placed: %s\n", order.ID)
}
Bracket Order Strategy
entry, err := client.Orders.PlaceOrder(&aries.OrderRequest{
Symbol: "NVDA",
Quantity: 10,
Side: "buy",
OrderType: "limit",
Price: 500.00,
})
if err != nil {
log.Fatal(err)
}
if entry.Status == "filled" {
entryPrice := entry.AverageFillPrice
profitTarget, err := client.Orders.PlaceOrder(&aries.OrderRequest{
Symbol: "NVDA",
Quantity: 10,
Side: "sell",
OrderType: "limit",
Price: entryPrice * 1.05,
TimeInForce: "gtc",
})
stopLoss, err := client.Orders.PlaceOrder(&aries.OrderRequest{
Symbol: "NVDA",
Quantity: 10,
Side: "sell",
OrderType: "stop",
StopPrice: entryPrice * 0.97,
TimeInForce: "gtc",
})
fmt.Printf("Profit target: %s\n", profitTarget.ID)
fmt.Printf("Stop loss: %s\n", stopLoss.ID)
}
Type Definitions
type OrderRequest struct {
Symbol string `json:"symbol"`
Quantity int `json:"quantity"`
Side string `json:"side"`
OrderType string `json:"order_type"`
Price float64 `json:"price,omitempty"`
StopPrice float64 `json:"stop_price,omitempty"`
TimeInForce string `json:"time_in_force"`
}
type Order struct {
ID string `json:"id"`
Symbol string `json:"symbol"`
Quantity int `json:"quantity"`
Side string `json:"side"`
OrderType string `json:"order_type"`
Price float64 `json:"price"`
Status string `json:"status"`
FilledQuantity int `json:"filled_quantity"`
AverageFillPrice float64 `json:"average_fill_price"`
TimeInForce string `json:"time_in_force"`
CreatedAt time.Time `json:"created_at"`
}
type OrderPreview struct {
Symbol string `json:"symbol"`
Quantity int `json:"quantity"`
EstimatedPrice float64 `json:"estimated_price"`
EstimatedCost float64 `json:"estimated_cost"`
Commission float64 `json:"commission"`
Total float64 `json:"total"`
}
Error Handling
order, err := client.Orders.PlaceOrder(&aries.OrderRequest{
Symbol: "AAPL",
Quantity: 10,
Side: "buy",
OrderType: "market",
})
if err != nil {
var apiErr *aries.APIError
if errors.As(err, &apiErr) {
switch apiErr.Code {
case "insufficient_funds":
log.Println("Not enough buying power")
case "invalid_symbol":
log.Println("Invalid stock symbol")
case "market_closed":
log.Println("Market is closed")
default:
log.Printf("Error: %s", apiErr.Message)
}
}
}