diff --git a/index.php b/index.php
index 1cafe97..b94c2a2 100644
--- a/index.php
+++ b/index.php
@@ -1,6 +1,6 @@
diff --git a/main-menu.php b/main-menu.php
index e91edac..90bd3a3 100644
--- a/main-menu.php
+++ b/main-menu.php
@@ -1,6 +1,8 @@
Dashboard
|
+
Markets
+
|
Buy Ships
|
Mining Fleet
diff --git a/market.php b/market.php
new file mode 100644
index 0000000..fec1aff
--- /dev/null
+++ b/market.php
@@ -0,0 +1,244 @@
+
+ * @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
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Credits:
+ | Ships:
+ | Stationed Waypoints:
+
+
+
+
+ No stationed ships found at waypoints, or no market data is available yet.
+
+
+
+
+
+
+
+
+
+
+ System:
+ | Ships Here:
+
+
+
+
+
+
+
+
Imports
+
+
None
+
+
+
+
+
+
+
Exports
+
+
None
+
+
+
+
+
+
+
Exchange
+
+
None
+
+
+
+
+
+
+
+
+