* @license MIT License * @version GIT: * @link https://git.keithsolomon.net/keith/Spacetraders */ require_once __DIR__ . '/lib/spacetraders-api.php'; require_once __DIR__ . '/lib/spacetraders-storage.php'; $config = require __DIR__ . '/lib/project-config.php'; $storage = new SpacetradersStorage( $config['db_path'] ); $token = $storage->getAgentToken(); $errorMessage = ''; $agent = array(); $ships = array(); $marketRecords = array(); if (! is_string( $token ) || trim( $token ) === '' ) { $envToken = getenv( 'SPACETRADERS_TOKEN' ); if (is_string( $envToken ) && trim( $envToken ) !== '' ) { $token = trim( $envToken ); $storage->setAgentToken( $token ); } } if (! is_string( $token ) || trim( $token ) === '' ) { $tokenError = 'No token found. Set one in config.php or SPACETRADERS_TOKEN.'; } if (! isset( $tokenError ) ) { $client = new SpacetradersApi( trim( $token ), $config['api_base_url'], (int) $config['api_timeout'], $storage, (int) $config['cache_ttl'] ); } try { if (! isset( $tokenError ) ) { $agentResponse = $client->getMyAgent(); $shipsResponse = $client->listMyShips(); $agent = $agentResponse['data'] ?? $agentResponse; $ships = $shipsResponse['data'] ?? $shipsResponse; $waypointShipMap = array(); foreach ( $ships as $ship ) { $shipSymbol = (string) ( $ship['symbol'] ?? '' ); $status = (string) ( $ship['nav']['status'] ?? '' ); $systemSymbol = (string) ( $ship['nav']['systemSymbol'] ?? '' ); $waypointSymbol = (string) ( $ship['nav']['waypointSymbol'] ?? '' ); if ($shipSymbol === '' || $systemSymbol === '' || $waypointSymbol === '' ) { continue; } if ($status === 'IN_TRANSIT' ) { continue; } if (! isset( $waypointShipMap[ $waypointSymbol ] ) ) { $waypointShipMap[ $waypointSymbol ] = array( 'systemSymbol' => $systemSymbol, 'shipSymbols' => array(), ); } $waypointShipMap[ $waypointSymbol ]['shipSymbols'][] = $shipSymbol; } foreach ( $waypointShipMap as $waypointSymbol => $stationedData ) { $record = array( 'waypointSymbol' => (string) $waypointSymbol, 'systemSymbol' => (string) ( $stationedData['systemSymbol'] ?? '' ), 'shipSymbols' => (array) ( $stationedData['shipSymbols'] ?? array() ), 'data' => array(), 'error' => '', ); if ($record['systemSymbol'] === '' ) { $record['error'] = 'Missing system symbol for this waypoint.'; $marketRecords[] = $record; continue; } try { $marketResponse = $client->getWaypointMarket( $record['systemSymbol'], $record['waypointSymbol'] ); $record['data'] = (array) ( $marketResponse['data'] ?? array() ); } catch (SpacetradersApiException $e) { $record['error'] = $e->getMessage(); } $marketRecords[] = $record; } usort( $marketRecords, static function ( array $left, array $right ): int { return strcmp( (string) ( $left['waypointSymbol'] ?? '' ), (string) ( $right['waypointSymbol'] ?? '' ) ); } ); } } catch (SpacetradersApiException $e) { $errorMessage = $e->getMessage(); } ?> Spacetraders - Markets

Spacetraders - Markets

Open Shop

Credits: | Ships: | Stationed Waypoints:

No stationed ships found at waypoints, or no market data is available yet.

System: | Ships Here:

Shop At This Waypoint

Imports

None

  • ()

Exports

None

  • ()

Exchange

None

  • ()