PhoenixPerpetualsDocs API v1
Get an API key

Cookbook

Account history⁠.

An account's history: the equity curve by day, the result of each trading day, closed positions and fills.

View as Markdown

The whole program, in each language. Set PHOENIXPERPS_API_KEY to a sandbox key (ppk_test_...) and run it.

import { PhoenixPerps } from '@phoenixperps/sdk';

const client = new PhoenixPerps();
const [account] = (await client.accounts.list()).data;

const equity = await client.history.equity(account.id, { resolution: 'day' });
console.log(`equity: ${equity.points.length} points`, equity.points.slice(-3));

for (const d of (await client.history.daily(account.id)).data) {
  console.log(`${d.date}: ${d.trades} trades, P&L ${d.pnl}, fees ${d.fees}`);
}
for (const p of (await client.positions.listClosed(account.id, { limit: 10 })).data) {
  console.log(`closed ${p.market} ${p.side} ${p.size}: ${p.entry_price} -> ${p.exit_price}, P&L ${p.pnl}`);
}
let n = 0;
for await (const f of client.fills.list(account.id, {}, { maxItems: 100 })) {
  n += 1;
  if (n <= 5) console.log(`fill ${f.market} ${f.side} ${f.size} @ ${f.price}`);
}
console.log(`${n} fills read (every page, at most 100)`);
from phoenixperps import PhoenixPerps

client = PhoenixPerps()
account = client.accounts.list().data[0]

equity = client.history.equity(account["id"], {"resolution": "day"})
print(f'equity: {len(equity["points"])} points', equity["points"][-3:])

for d in client.history.daily(account["id"]).data:
    print(f'{d["date"]}: {d["trades"]} trades, P&L {d["pnl"]}, fees {d["fees"]}')
for p in client.positions.list_closed(account["id"], {"limit": 10}).data:
    print(f'closed {p["market"]} {p["side"]} {p["size"]}: {p["entry_price"]} -> {p["exit_price"]}, P&L {p["pnl"]}')

n = 0
for f in client.fills.list(account["id"]).auto_paging_iter(max_items=100):  # every page, at most 100
    n += 1
    if n <= 5:
        print(f'fill {f["market"]} {f["side"]} {f["size"]} @ {f["price"]}')
print(f"{n} fills read")
package main

import (
	"context"
	"fmt"
	"log"

	phoenixperps "github.com/phoenixperps/sdk/go"
)

func or(d *phoenixperps.Decimal) string {
	if d == nil {
		return "-"
	}
	return string(*d)
}

func main() {
	ctx := context.Background()
	client, err := phoenixperps.NewClient()
	if err != nil {
		log.Fatal(err)
	}
	accounts, err := client.Accounts.List(ctx)
	if err != nil {
		log.Fatal(err)
	}
	account := accounts.Data[0].ID

	equity, err := client.History.Equity(ctx, account, &phoenixperps.HistoryEquityParams{Resolution: phoenixperps.Ptr(phoenixperps.ResolutionDay)})
	if err != nil {
		log.Fatal(err)
	}
	last := equity.Points[max(0, len(equity.Points)-3):]
	fmt.Printf("equity: %d points, last %+v\n", len(equity.Points), last)

	daily, err := client.History.Daily(ctx, account)
	if err != nil {
		log.Fatal(err)
	}
	for _, d := range daily.Data {
		fmt.Printf("%s: %d trades, P&L %s, fees %s\n", d.Date, d.Trades, d.PnL, d.Fees)
	}
	closed, err := client.Positions.ListClosed(ctx, account, &phoenixperps.PositionsListClosedParams{Limit: phoenixperps.Ptr[int64](10)})
	if err != nil {
		log.Fatal(err)
	}
	for _, p := range closed.Data {
		fmt.Printf("closed %s %s %s: %s -> %s, P&L %s\n", p.Market, p.Side, p.Size, or(p.EntryPrice), or(p.ExitPrice), p.PnL)
	}
	n := 0
	for f, err := range client.Fills.ListAutoPaging(ctx, account, nil, phoenixperps.WithMaxItems(100)) { // every page, at most 100
		if err != nil {
			log.Fatal(err)
		}
		n++
		if n <= 5 {
			fmt.Printf("fill %s %s @ %s\n", f.Market, f.Size, f.Price)
		}
	}
	fmt.Printf("%d fills read\n", n)
}
#:package PhoenixPerps.Sdk@1.0.0
using System.Globalization;
using PhoenixPerps;

CultureInfo.CurrentCulture = CultureInfo.InvariantCulture; // decimals print as 0.0001 on every machine

using var client = new PhoenixPerpsClient();
var account = (await client.Accounts.ListAsync()).Data[0].Id;

var equity = await client.History.EquityAsync(account, new HistoryEquityParams { Resolution = Resolution.Day });
Console.WriteLine($"equity: {equity.Points.Count} points");

foreach (var d in (await client.History.DailyAsync(account)).Data)
    Console.WriteLine($"{d.Date}: {d.Trades} trades, P&L {d.Pnl}, fees {d.Fees}");
foreach (var p in (await client.Positions.ListClosedAsync(account, new PositionsListClosedParams { Limit = 10 })).Data)
    Console.WriteLine($"closed {p.Market} {p.Side} {p.Size}: {p.EntryPrice} -> {p.ExitPrice}, P&L {p.Pnl}");

var n = 0;
await foreach (var f in client.Fills.ListAutoPagingAsync(account, options: new RequestOptions { MaxItems = 100 })) // every page, at most 100
{
    if (++n <= 5) Console.WriteLine($"fill {f.Market} {f.Side} {f.Size} @ {f.Price}");
}
Console.WriteLine($"{n} fills read");
import com.phoenixperpsfunding.sdk.PhoenixPerpsClient;
import com.phoenixperpsfunding.sdk.RequestOptions;
import com.phoenixperpsfunding.sdk.gen.ClosedPosition;
import com.phoenixperpsfunding.sdk.gen.DailyResult;
import com.phoenixperpsfunding.sdk.gen.EquityHistory;
import com.phoenixperpsfunding.sdk.gen.Fill;
import com.phoenixperpsfunding.sdk.gen.HistoryEquityParams;
import com.phoenixperpsfunding.sdk.gen.PositionsListClosedParams;
import com.phoenixperpsfunding.sdk.gen.Resolution;

final class Example09 {
    public static void main(String[] args) {
        PhoenixPerpsClient client = PhoenixPerpsClient.fromEnv();
        String account = client.accounts().list().data().get(0).id();

        EquityHistory equity = client.history().equity(account, new HistoryEquityParams().resolution(Resolution.DAY));
        System.out.printf("equity: %d points%n", equity.points().size());

        for (DailyResult d : client.history().daily(account).data()) {
            System.out.printf("%s: %d trades, P&L %s, fees %s%n", d.date(), d.trades(), d.pnl(), d.fees());
        }
        for (ClosedPosition p : client.positions().listClosed(account, new PositionsListClosedParams().limit(10L)).data()) {
            System.out.printf("closed %s %s %s: %s -> %s, P&L %s%n", p.market(), p.side(), p.size(), p.entryPrice(), p.exitPrice(), p.pnl());
        }
        int n = 0;
        for (Fill f : client.fills().listAutoPaging(account, null, RequestOptions.none().withMaxItems(100))) { // every page, at most 100
            if (++n <= 5) System.out.printf("fill %s %s %s @ %s%n", f.market(), f.side(), f.size(), f.price());
        }
        System.out.printf("%d fills read%n", n);
    }
}
use futures_util::StreamExt;
use phoenixperps::{Client, HistoryEquityParams, PositionsListClosedParams, RequestOptions, Resolution};

#[tokio::main]
async fn main() -> phoenixperps::Result<()> {
    let client = Client::from_env()?;
    let account = client.accounts().list().await?.data[0].id.clone();

    let equity = client.history().equity(&account, Some(&HistoryEquityParams { resolution: Some(Resolution::Day) })).await?;
    println!("equity: {} points", equity.points.len());

    for d in &client.history().daily(&account).await?.data {
        println!("{}: {} trades, P&L {}, fees {}", d.date, d.trades, d.pnl, d.fees);
    }
    let params = PositionsListClosedParams { limit: Some(10), ..Default::default() };
    for p in &client.positions().list_closed(&account, Some(&params)).await?.data {
        println!("closed {} {} {}: {:?} -> {:?}, P&L {}", p.market, p.side, p.size, p.entry_price, p.exit_price, p.pnl);
    }

    let options = RequestOptions { max_items: Some(100), ..Default::default() }; // every page, at most 100
    let mut fills = Box::pin(client.fills().list_auto_paging(&account, None, &options));
    let mut n = 0;
    while let Some(fill) = fills.next().await {
        let f = fill?;
        n += 1;
        if n <= 5 {
            println!("fill {} {} @ {}", f.market, f.size, f.price);
        }
    }
    println!("{n} fills read");
    Ok(())
}
<?php
require 'vendor/autoload.php';

use PhoenixPerps\Client;
use PhoenixPerps\RequestOptions;

$client = new Client();
$account = $client->accounts->list()->data[0]->id;

$equity = $client->history->equity($account, ['resolution' => 'day']);
printf("equity: %d points\n", count($equity->points));

foreach ($client->history->daily($account)->data as $d) {
    printf("%s: %d trades, P&L %s, fees %s\n", $d->date, $d->trades, $d->pnl, $d->fees);
}
foreach ($client->positions->listClosed($account, ['limit' => 10])->data as $p) {
    printf("closed %s %s %s: %s -> %s, P&L %s\n", $p->market, $p->side, $p->size, $p->entryPrice ?? '-', $p->exitPrice ?? '-', $p->pnl);
}
$n = 0;
foreach ($client->fills->listAutoPaging($account, null, new RequestOptions(maxItems: 100)) as $f) { // every page, at most 100
    if (++$n <= 5) {
        printf("fill %s %s %s @ %s\n", $f->market, $f->side, $f->size, $f->price);
    }
}
printf("%d fills read\n", $n);

Guides, endpoints, fields and error codes.