Skip to main content

Overview

The Accounts API provides access to account-level data including balances, buying power, positions, and order history.

Package Reference

import (
    "fmt"
    "log"
    aries "github.com/aries-exchange/go-sdk"
)

client := aries.NewClient(
    aries.WithClientID("your_client_id"),
    aries.WithClientSecret("your_client_secret"),
)

Methods

GetBalances()

Retrieve account balances and buying power.
balances, err := client.Accounts.GetBalances("acc_123456")
if err != nil {
    log.Fatal(err)
}

fmt.Printf("Cash: $%.2f\n", balances.Cash)
fmt.Printf("Buying Power: $%.2f\n", balances.BuyingPower)
fmt.Printf("Portfolio Value: $%.2f\n", balances.PortfolioValue)
Parameters:
  • accountID (string): Account ID
Returns: *Balances, error

GetOrders()

Retrieve all orders for an account.
orders, err := client.Accounts.GetOrders("acc_123456", &aries.OrderFilters{
    Status: "open",
})
if err != nil {
    log.Fatal(err)
}
Parameters:
  • accountID (string): Account ID
  • filters (*OrderFilters, optional): Filter options
Returns: []Order, error

GetPositions()

Retrieve all positions for an account.
positions, err := client.Accounts.GetPositions("acc_123456")
if err != nil {
    log.Fatal(err)
}

for _, position := range positions {
    fmt.Printf("%s: %d shares, P/L: $%.2f\n",
        position.Symbol, position.Quantity, position.UnrealizedPL)
}
Parameters:
  • accountID (string): Account ID
Returns: []Position, error

Type Definitions

type Balances struct {
    Cash                    float64 `json:"cash"`
    BuyingPower            float64 `json:"buying_power"`
    PortfolioValue         float64 `json:"portfolio_value"`
    Equity                 float64 `json:"equity"`
    LongMarketValue        float64 `json:"long_market_value"`
    DayTradingBuyingPower  float64 `json:"day_trading_buying_power"`
}

type Position struct {
    Symbol              string  `json:"symbol"`
    Quantity            int     `json:"quantity"`
    AverageCost         float64 `json:"average_cost"`
    CurrentPrice        float64 `json:"current_price"`
    MarketValue         float64 `json:"market_value"`
    UnrealizedPL        float64 `json:"unrealized_pl"`
    UnrealizedPLPercent float64 `json:"unrealized_pl_percent"`
    Side                string  `json:"side"`
}

Examples

Check Balance Before Trading

balances, err := client.Accounts.GetBalances("acc_123456")
if err != nil {
    log.Fatal(err)
}

fmt.Printf("Available: $%.2f\n", balances.BuyingPower)

orderCost := 1500.00
if balances.BuyingPower >= orderCost {
    order, err := client.Orders.PlaceOrder(&aries.OrderRequest{
        Symbol:    "AAPL",
        Quantity:  10,
        Side:      "buy",
        OrderType: "market",
    })
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("Order placed: %s\n", order.ID)
}

Monitor Positions

positions, err := client.Accounts.GetPositions("acc_123456")
if err != nil {
    log.Fatal(err)
}

var totalPL float64
for _, position := range positions {
    fmt.Printf("%s: %d @ $%.2f\n",
        position.Symbol, position.Quantity, position.CurrentPrice)
    fmt.Printf("  P/L: $%.2f (%+.2f%%)\n",
        position.UnrealizedPL, position.UnrealizedPLPercent)

    totalPL += position.UnrealizedPL
}

fmt.Printf("\nTotal P/L: $%.2f\n", totalPL)
  • Orders - Place and manage orders
  • Users - Get list of user accounts