repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | import { ClaWDPerps } from "@openclawdsolana/clawd-perps"; |
| #2 | import type { ToolResult } from "@openclawdsolana/clawd-perps"; |
| #3 | import type { PerpsRuntimeConfig } from "../config.js"; |
| #4 | |
| #5 | export interface PhoenixPerpMarketView { |
| #6 | symbol: string; |
| #7 | markPrice?: number | null; |
| #8 | spotPrice?: number | null; |
| #9 | fundingRate?: number | null; |
| #10 | openInterest?: number | null; |
| #11 | status?: string | null; |
| #12 | } |
| #13 | |
| #14 | export interface PhoenixRiseAdapter { |
| #15 | listMarkets(): Promise<PhoenixPerpMarketView[]>; |
| #16 | getTicker(symbol?: string): Promise<unknown>; |
| #17 | getOrderbook(symbol: string, depth?: number): Promise<unknown>; |
| #18 | getTraderSnapshot(authority?: string): Promise<unknown>; |
| #19 | getPositions(authority?: string): Promise<unknown>; |
| #20 | health(): Promise<unknown>; |
| #21 | } |
| #22 | |
| #23 | function unwrapResult<T>(label: string, result: ToolResult): T { |
| #24 | if (!result.success) { |
| #25 | throw new Error(result.error ?? `${label} failed`); |
| #26 | } |
| #27 | return result.data as T; |
| #28 | } |
| #29 | |
| #30 | export class ClawdPhoenixRiseAdapter implements PhoenixRiseAdapter { |
| #31 | private readonly perps: ClaWDPerps; |
| #32 | |
| #33 | constructor(private readonly config: PerpsRuntimeConfig) { |
| #34 | this.perps = new ClaWDPerps({ |
| #35 | apiUrl: config.apiUrl, |
| #36 | rpcUrl: config.rpcUrl, |
| #37 | walletName: config.wallet, |
| #38 | traderPdaIndex: config.traderPdaIndex, |
| #39 | traderSubaccountIndex: config.traderSubaccountIndex, |
| #40 | }); |
| #41 | } |
| #42 | |
| #43 | async listMarkets(): Promise<PhoenixPerpMarketView[]> { |
| #44 | return unwrapResult<PhoenixPerpMarketView[]>("listMarkets", await this.perps.listMarkets()); |
| #45 | } |
| #46 | |
| #47 | async getTicker(symbol?: string): Promise<unknown> { |
| #48 | const result = symbol |
| #49 | ? await this.perps.getTicker(symbol) |
| #50 | : await this.perps.getAllTickers(); |
| #51 | return unwrapResult("getTicker", result); |
| #52 | } |
| #53 | |
| #54 | async getOrderbook(symbol: string, depth = 20): Promise<unknown> { |
| #55 | return unwrapResult("getOrderbook", await this.perps.getOrderbook(symbol, depth)); |
| #56 | } |
| #57 | |
| #58 | async getTraderSnapshot(authority?: string): Promise<unknown> { |
| #59 | return unwrapResult("getPortfolio", await this.perps.getPortfolio(authority)); |
| #60 | } |
| #61 | |
| #62 | async getPositions(authority?: string): Promise<unknown> { |
| #63 | return unwrapResult("listPositions", await this.perps.listPositions(authority)); |
| #64 | } |
| #65 | |
| #66 | async health(): Promise<unknown> { |
| #67 | return unwrapResult("health", await this.perps.health()); |
| #68 | } |
| #69 | } |
| #70 | |
| #71 | export function createPhoenixRiseAdapter(config: PerpsRuntimeConfig): PhoenixRiseAdapter { |
| #72 | return new ClawdPhoenixRiseAdapter(config); |
| #73 | } |
| #74 |