Skip to main content

使用 /positions

机器翻译译自英文(docs.alpaca.markets)本页 7 段已全部译完

你可以通过向 /v2/positions 端点发送 GET 请求来查看投资组合中的持仓。如果指定了一个代码,你将只看到关联股票的持仓。

from alpaca.trading.client import TradingClient

trading_client = TradingClient('api-key', 'secret-key')

# Get our position in AAPL.
aapl_position = trading_client.get_open_position('AAPL')

# Get a list of all of our positions.
portfolio = trading_client.get_all_positions()

# Print the quantity of shares for each position.
for position in portfolio:
    print("{} shares of {}".format(position.qty, position.symbol))
const Alpaca = require("@alpacahq/alpaca-trade-api");
const alpaca = new Alpaca();

// Get our position in AAPL.
aaplPosition = alpaca.getPosition("AAPL");

// Get a list of all of our positions.
alpaca.getPositions().then((portfolio) => {
  // Print the quantity of shares for each position.
  portfolio.forEach(function (position) {
    console.log(`${position.qty} shares of ${position.symbol}`);
  });
});
using Alpaca.Markets;
using System;
using System.Net;

var client = Environments.Paper.GetAlpacaTradingClient(
    new SecretKey("YOUR_API_KEY", "YOUR_API_SECRET"));

try
{
    var aaplPosition = await client.GetPositionAsync("AAPL");
    Console.WriteLine($"AAPL position: {aaplPosition.Quantity} shares.");
}
catch (RestClientErrorException exception)
    when (exception.HttpStatusCode == HttpStatusCode.NotFound)
{
    Console.WriteLine("No open AAPL position.");
}

var positions = await client.ListPositionsAsync();
foreach (var position in positions)
{
    Console.WriteLine($"{position.Quantity} shares of {position.Symbol}.");
}
package main

import (
	"fmt"
	"github.com/alpacahq/alpaca-trade-api-go/alpaca"
)

func init() {
	alpaca.SetBaseUrl("https://paper-api.alpaca.markets")
}

func main() {
	// Get our position in AAPL.
	aapl_position, err := alpaca.GetPosition("AAPL")
	if err != nil {
		fmt.Println("No AAPL position.")
	} else {
		fmt.Printf("AAPL position: %v shares.\n", aapl_position.Qty)
	}

	// Get a list of all of our positions.
	positions, err := alpaca.ListPositions()
	if err != nil {
		fmt.Println("No positions found.")
	} else {
		// Print the quantity of shares for each position.
		for _, position := range positions {
			fmt.Printf("%v shares in %s", position.Qty, position.Symbol)
		}
	}
}

所反映的当前价格将基于以下内容:

美东时间 4:00 - 美东时间 9:30 - 基于盘前交易的最后一笔成交

美东时间 9:30 - 美东时间 16:00 - 最后一笔成交

美东时间 16:00 - 美东时间 22:00 - 基于盘后交易的最后一笔成交

美东时间 22:00 - 下一个交易日美东时间 4:00 - 主要交易所美东时间 16:00 的官方收盘价。