Cookbook
Your key and accounts.
Who you are (the key, its access and limits) and your accounts.
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(); // the key: PHOENIXPERPS_API_KEY (a sandbox key: the sandbox)
const me = await client.me.get();
console.log(`${me.credential.kind} "${me.credential.name}" on ${me.credential.environment}: ${me.credential.access} access`);
console.log(`limits: ${me.budgets.read_per_min} reads and ${me.budgets.trade_per_min} trading calls a minute`);
const { data } = await client.accounts.list();
for (const account of data) {
console.log(`${account.id} ${account.stage} ${account.status} balance ${account.balance ?? '-'}`);
}from phoenixperps import PhoenixPerps
client = PhoenixPerps() # the key: PHOENIXPERPS_API_KEY (a sandbox key: the sandbox)
me = client.me.get()
c = me["credential"]
print(f'{c["kind"]} "{c["name"]}" on {c["environment"]}: {c["access"]} access')
print(f'limits: {me["budgets"]["read_per_min"]} reads and {me["budgets"]["trade_per_min"]} trading calls a minute')
for account in client.accounts.list().data:
print(f'{account["id"]} {account["stage"]} {account["status"]} balance {account.get("balance") or "-"}')package main
import (
"context"
"fmt"
"log"
phoenixperps "github.com/phoenixperps/sdk/go"
)
func main() {
ctx := context.Background()
client, err := phoenixperps.NewClient() // the key: PHOENIXPERPS_API_KEY (a sandbox key: the sandbox)
if err != nil {
log.Fatal(err)
}
me, err := client.Me.Get(ctx)
if err != nil {
log.Fatal(err)
}
c := me.Credential
fmt.Printf("%s %q on %s: %s access\n", c.Kind, c.Name, c.Environment, c.Access)
fmt.Printf("limits: %d reads and %d trading calls a minute\n", me.Budgets.ReadPerMin, me.Budgets.TradePerMin)
accounts, err := client.Accounts.List(ctx)
if err != nil {
log.Fatal(err)
}
for _, a := range accounts.Data {
balance := "-"
if a.Balance != nil {
balance = string(*a.Balance)
}
fmt.Printf("%s %s %s balance %s\n", a.ID, a.Stage, a.Status, balance)
}
}#: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(); // the key: PHOENIXPERPS_API_KEY (a sandbox key: the sandbox)
var me = await client.Me.GetAsync();
var c = me.Credential;
Console.WriteLine($"{c.Kind} \"{c.Name}\" on {c.Environment}: {c.Access} access");
Console.WriteLine($"limits: {me.Budgets.ReadPerMin} reads and {me.Budgets.TradePerMin} trading calls a minute");
var accounts = await client.Accounts.ListAsync();
foreach (var a in accounts.Data)
Console.WriteLine($"{a.Id} {a.Stage} {a.Status} balance {a.Balance?.ToString() ?? "-"}");import com.phoenixperpsfunding.sdk.PhoenixPerpsClient;
import com.phoenixperpsfunding.sdk.gen.Account;
import com.phoenixperpsfunding.sdk.gen.Me;
final class Example01 {
public static void main(String[] args) {
PhoenixPerpsClient client = PhoenixPerpsClient.fromEnv(); // the key: PHOENIXPERPS_API_KEY (a sandbox key: the sandbox)
Me me = client.me().get();
System.out.printf("%s \"%s\" on %s: %s access%n", me.credential().kind(), me.credential().name(), me.credential().environment(), me.credential().access());
System.out.printf("limits: %d reads and %d trading calls a minute%n", me.budgets().readPerMin(), me.budgets().tradePerMin());
for (Account a : client.accounts().list().data()) {
System.out.printf("%s %s %s balance %s%n", a.id(), a.stage(), a.status(), a.balance() == null ? "-" : a.balance().toPlainString());
}
}
}use phoenixperps::Client;
#[tokio::main]
async fn main() -> phoenixperps::Result<()> {
let client = Client::from_env()?; // the key: PHOENIXPERPS_API_KEY (a sandbox key: the sandbox)
let me = client.me().get().await?;
let c = &me.credential;
println!("{} \"{}\" on {}: {} access", c.kind, c.name, c.environment, c.access);
println!("limits: {} reads and {} trading calls a minute", me.budgets.read_per_min, me.budgets.trade_per_min);
for a in &client.accounts().list().await?.data {
let balance = a.balance.map(|b| b.to_string()).unwrap_or_else(|| "-".into());
println!("{} {} {} balance {}", a.id, a.stage, a.status, balance);
}
Ok(())
}<?php
require 'vendor/autoload.php';
use PhoenixPerps\Client;
$client = new Client(); // the key: PHOENIXPERPS_API_KEY (a sandbox key: the sandbox)
$me = $client->me->get();
$c = $me->credential;
printf("%s \"%s\" on %s: %s access\n", $c->kind, $c->name, $c->environment, $c->access);
printf("limits: %d reads and %d trading calls a minute\n", $me->budgets->readPerMin, $me->budgets->tradePerMin);
foreach ($client->accounts->list()->data as $a) {
printf("%s %s %s balance %s\n", $a->id, $a->stage, $a->status, $a->balance ?? '-');
}