SpaceTraders is an open-universe game and learning platform that offers a set of HTTP endpoints to control a fleet of ships and explore a multiplayer universe.
The API is documented using OpenAPI. You can send your first request right here in your browser to check the status of the game server.
{
\"method\": \"GET\",
\"url\": \"https://api.spacetraders.io/v2\",
}
Unlike a traditional game, SpaceTraders does not have a first-party client or app to play the game. Instead, you can use the API to build your own client, write a script to automate your ships, or try an app built by the community.
We have a Discord channel where you can share your projects, ask questions, and get help from other players.
This API client was generated by the OpenAPI Generator project. By using the OpenAPI-spec from a remote server, you can easily generate an API client.
- API version: 2.0.0
- Package version: 2.0.0
- Build package: org.openapitools.codegen.languages.GoClientCodegen
This particuler client code was generated using this script:
openapi-generator-cli generate \
-i https://raw.githubusercontent.com/SpaceTradersAPI/api-docs/main/reference/SpaceTraders.json \
-o ./ \
-g go \
--git-user-id binayakd \
--git-repo-id spacetraders-openapi-go-client \
--additional-properties=packageName=spacetraders_openapi_go_client \
--additional-properties=packageVersion=2.0.0 \
--additional-properties=structPrefix \
--additional-properties=enumClassPrefix
Install the following dependencies:
go get github.com/stretchr/testify/assert
go get golang.org/x/net/context
Put the package under your project folder and add the following in import:
import spacetraders_openapi_go_client "github.com/binayakd/spacetraders-openapi-go-client"
To use a proxy, set the environment variable HTTP_PROXY
:
os.Setenv("HTTP_PROXY", "http://proxy_name:proxy_port")
Default configuration comes with Servers
field that contains server objects as defined in the OpenAPI specification.
For using other server than the one defined on index 0 set context value sw.ContextServerIndex
of type int
.
ctx := context.WithValue(context.Background(), spacetraders_openapi_go_client.ContextServerIndex, 1)
Templated server URL is formatted using default variables from configuration or from context value sw.ContextServerVariables
of type map[string]string
.
ctx := context.WithValue(context.Background(), spacetraders_openapi_go_client.ContextServerVariables, map[string]string{
"basePath": "v2",
})
Note, enum values are always validated and all unused variables are silently ignored.
Each operation can use different server URL defined using OperationServers
map in the Configuration
.
An operation is uniquely identified by "{classname}Service.{nickname}"
string.
Similar rules for overriding default operation server index and variables applies by using sw.ContextOperationServerIndices
and sw.ContextOperationServerVariables
context maps.
ctx := context.WithValue(context.Background(), spacetraders_openapi_go_client.ContextOperationServerIndices, map[string]int{
"{classname}Service.{nickname}": 2,
})
ctx = context.WithValue(context.Background(), spacetraders_openapi_go_client.ContextOperationServerVariables, map[string]map[string]string{
"{classname}Service.{nickname}": {
"port": "8443",
},
})
All URIs are relative to https://api.spacetraders.io/v2
Class | Method | HTTP request | Description |
---|---|---|---|
AgentsApi | GetMyAgent | Get /my/agent | My Agent Details |
ContractsApi | AcceptContract | Post /my/contracts/{contractId}/accept | Accept Contract |
ContractsApi | DeliverContract | Post /my/contracts/{contractId}/deliver | Deliver Contract |
ContractsApi | FulfillContract | Post /my/contracts/{contractId}/fulfill | Fulfill Contract |
ContractsApi | GetContract | Get /my/contracts/{contractId} | Get Contract |
ContractsApi | GetContracts | Get /my/contracts | List Contracts |
DefaultApi | GetStatus | Get / | Get Status |
DefaultApi | Register | Post /register | Register New Agent |
FactionsApi | GetFaction | Get /factions/{factionSymbol} | Get Faction |
FactionsApi | GetFactions | Get /factions | List Factions |
FleetApi | CreateChart | Post /my/ships/{shipSymbol}/chart | Create Chart |
FleetApi | CreateShipShipScan | Post /my/ships/{shipSymbol}/scan/ships | Scan Ships |
FleetApi | CreateShipSystemScan | Post /my/ships/{shipSymbol}/scan/systems | Scan Systems |
FleetApi | CreateShipWaypointScan | Post /my/ships/{shipSymbol}/scan/waypoints | Scan Waypoints |
FleetApi | CreateSurvey | Post /my/ships/{shipSymbol}/survey | Create Survey |
FleetApi | DockShip | Post /my/ships/{shipSymbol}/dock | Dock Ship |
FleetApi | ExtractResources | Post /my/ships/{shipSymbol}/extract | Extract Resources |
FleetApi | GetMyShip | Get /my/ships/{shipSymbol} | Get Ship |
FleetApi | GetMyShipCargo | Get /my/ships/{shipSymbol}/cargo | Get Ship Cargo |
FleetApi | GetMyShips | Get /my/ships | List Ships |
FleetApi | GetShipCooldown | Get /my/ships/{shipSymbol}/cooldown | Get Ship Cooldown |
FleetApi | GetShipNav | Get /my/ships/{shipSymbol}/nav | Get Ship Nav |
FleetApi | Jettison | Post /my/ships/{shipSymbol}/jettison | Jettison Cargo |
FleetApi | JumpShip | Post /my/ships/{shipSymbol}/jump | Jump Ship |
FleetApi | NavigateShip | Post /my/ships/{shipSymbol}/navigate | Navigate Ship |
FleetApi | NegotiateContract | Post /my/ships/{shipSymbol}/negotiate/contract | Negotiate Contract |
FleetApi | OrbitShip | Post /my/ships/{shipSymbol}/orbit | Orbit Ship |
FleetApi | PatchShipNav | Patch /my/ships/{shipSymbol}/nav | Patch Ship Nav |
FleetApi | PurchaseCargo | Post /my/ships/{shipSymbol}/purchase | Purchase Cargo |
FleetApi | PurchaseShip | Post /my/ships | Purchase Ship |
FleetApi | RefuelShip | Post /my/ships/{shipSymbol}/refuel | Refuel Ship |
FleetApi | SellCargo | Post /my/ships/{shipSymbol}/sell | Sell Cargo |
FleetApi | ShipRefine | Post /my/ships/{shipSymbol}/refine | Ship Refine |
FleetApi | TransferCargo | Post /my/ships/{shipSymbol}/transfer | Transfer Cargo |
FleetApi | WarpShip | Post /my/ships/{shipSymbol}/warp | Warp Ship |
SystemsApi | GetJumpGate | Get /systems/{systemSymbol}/waypoints/{waypointSymbol}/jump-gate | Get Jump Gate |
SystemsApi | GetMarket | Get /systems/{systemSymbol}/waypoints/{waypointSymbol}/market | Get Market |
SystemsApi | GetShipyard | Get /systems/{systemSymbol}/waypoints/{waypointSymbol}/shipyard | Get Shipyard |
SystemsApi | GetSystem | Get /systems/{systemSymbol} | Get System |
SystemsApi | GetSystemWaypoints | Get /systems/{systemSymbol}/waypoints | List Waypoints |
SystemsApi | GetSystems | Get /systems | List Systems |
SystemsApi | GetWaypoint | Get /systems/{systemSymbol}/waypoints/{waypointSymbol} | Get Waypoint |
- AcceptContract200Response
- AcceptContract200ResponseData
- Agent
- Chart
- ConnectedSystem
- Contract
- ContractDeliverGood
- ContractPayment
- ContractTerms
- Cooldown
- CreateChart201Response
- CreateChart201ResponseData
- CreateShipShipScan201Response
- CreateShipShipScan201ResponseData
- CreateShipSystemScan201Response
- CreateShipSystemScan201ResponseData
- CreateShipWaypointScan201Response
- CreateShipWaypointScan201ResponseData
- CreateSurvey201Response
- CreateSurvey201ResponseData
- DeliverContract200Response
- DeliverContract200ResponseData
- DeliverContractRequest
- DockShip200Response
- ExtractResources201Response
- ExtractResources201ResponseData
- ExtractResourcesRequest
- Extraction
- ExtractionYield
- Faction
- FactionTrait
- FulfillContract200Response
- GetContract200Response
- GetContracts200Response
- GetFaction200Response
- GetFactions200Response
- GetJumpGate200Response
- GetMarket200Response
- GetMyAgent200Response
- GetMyShip200Response
- GetMyShipCargo200Response
- GetMyShips200Response
- GetShipCooldown200Response
- GetShipNav200Response
- GetShipyard200Response
- GetStatus200Response
- GetStatus200ResponseAnnouncementsInner
- GetStatus200ResponseLeaderboards
- GetStatus200ResponseLeaderboardsMostCreditsInner
- GetStatus200ResponseLeaderboardsMostSubmittedChartsInner
- GetStatus200ResponseLinksInner
- GetStatus200ResponseServerResets
- GetStatus200ResponseStats
- GetSystem200Response
- GetSystemWaypoints200Response
- GetSystems200Response
- GetWaypoint200Response
- Jettison200Response
- Jettison200ResponseData
- JettisonRequest
- JumpGate
- JumpShip200Response
- JumpShip200ResponseData
- JumpShipRequest
- Market
- MarketTradeGood
- MarketTransaction
- Meta
- NavigateShip200Response
- NavigateShip200ResponseData
- NavigateShipRequest
- NegotiateContract200Response
- NegotiateContract200ResponseData
- OrbitShip200Response
- OrbitShip200ResponseData
- PatchShipNavRequest
- PurchaseCargo201Response
- PurchaseCargoRequest
- PurchaseShip201Response
- PurchaseShip201ResponseData
- PurchaseShipRequest
- RefuelShip200Response
- RefuelShip200ResponseData
- Register201Response
- Register201ResponseData
- RegisterRequest
- ScannedShip
- ScannedShipEngine
- ScannedShipFrame
- ScannedShipMountsInner
- ScannedShipReactor
- ScannedSystem
- ScannedWaypoint
- SellCargo201Response
- SellCargo201ResponseData
- SellCargoRequest
- Ship
- ShipCargo
- ShipCargoItem
- ShipCrew
- ShipEngine
- ShipFrame
- ShipFuel
- ShipFuelConsumed
- ShipModule
- ShipMount
- ShipNav
- ShipNavFlightMode
- ShipNavRoute
- ShipNavRouteWaypoint
- ShipNavStatus
- ShipReactor
- ShipRefine200Response
- ShipRefine200ResponseData
- ShipRefine200ResponseDataProducedInner
- ShipRefineRequest
- ShipRegistration
- ShipRequirements
- ShipRole
- ShipType
- Shipyard
- ShipyardShip
- ShipyardShipTypesInner
- ShipyardTransaction
- Survey
- SurveyDeposit
- System
- SystemFaction
- SystemType
- SystemWaypoint
- TradeGood
- TradeSymbol
- TransferCargo200Response
- TransferCargoRequest
- Waypoint
- WaypointFaction
- WaypointOrbital
- WaypointTrait
- WaypointType
- Type: HTTP Bearer token authentication
Example
auth := context.WithValue(context.Background(), sw.ContextAccessToken, "BEARER_TOKEN_STRING")
r, err := client.Service.Operation(auth, args)
Due to the fact that model structure members are all pointers, this package contains a number of utility functions to easily obtain pointers to values of basic types. Each of these functions takes a value of the given basic type and returns a pointer to it:
PtrBool
PtrInt
PtrInt32
PtrInt64
PtrFloat
PtrFloat32
PtrFloat64
PtrString
PtrTime