Lux Docs
Lux Skills Reference

Lux FX - Cryptocurrency Pricing API Gateway

Documentation for Lux FX - Cryptocurrency Pricing API Gateway

Overview

Lux FX is a cryptocurrency pricing API gateway that proxies CoinGecko with an in-memory cache. It is a single-file Go service with no external dependencies beyond the standard library. Deployed to K8s as markets in the lux-gateway namespace, serving fx.lux.network.

When to use

  • Querying cryptocurrency prices from Lux ecosystem services
  • Replacing direct CoinGecko API calls with a cached, self-hosted gateway
  • Deploying a lightweight pricing microservice on K8s

Quick reference

ItemValue
Repogithub.com/luxfi/fx
Go modulegithub.com/luxfi/pricing
LanguageGo 1.26
DependenciesNone (standard library only)
Default port8080
Cache TTL1 hour
LicenseMIT
Default branchmain
Container imageghcr.io/luxfi/pricing:latest

Project structure

fx/
  .github/          # CI/CD workflows
  k8s/              # Kubernetes manifests
    deployment.yaml  # 2 replicas, lux-gateway namespace
    ingress.yaml     # fx.lux.network
    secret.yaml      # CoinGecko API key
    service.yaml     # ClusterIP on port 8080
  main.go            # Entire application (single file)
  go.mod             # Module definition
  Dockerfile         # Multi-stage alpine build
  compose.yml        # Local development

API endpoints

EndpointDescription
GET /healthHealth check (JSON status + time)
GET /price/\{token_id\}?currency=usdSingle token price with market data
GET /prices?ids=bitcoin,ethereum&currency=usdMultiple token prices in one request
GET /simple/price?ids=bitcoin&vs_currencies=usd,eurCoinGecko-compatible simple format

One-file quickstart

git clone https://github.com/luxfi/fx.git
cd fx
export COINGECKO_API_KEY=your-api-key
go run main.go

Architecture

Client --> FX API (port 8080) --> In-Memory Cache (1h TTL) --> CoinGecko API

Key types

  • PriceCache -- Thread-safe in-memory cache with RWMutex, auto-fetches on miss
  • CachedPrice -- Price, currency, 24h change, market cap, volume, timestamp
  • PriceResponse -- API response with cached boolean indicator
  • MultiPriceResponse -- Batch response wrapping multiple PriceResponse entries

Behavior

  • Cache hit returns stale data if CoinGecko is unreachable (graceful degradation)
  • Batch fetches reduce CoinGecko API calls for multi-token requests
  • CORS enabled for all origins (*)
  • Cache-Control: public, max-age=3600 on all price responses

Environment variables

VariableRequiredDefaultDescription
COINGECKO_API_KEYYes-CoinGecko API key (demo or pro)
PORTNo8080Server listen port

Development

# Build
go build -o pricing .

# Run with Docker
docker compose up -d

# Deploy to K8s
kubectl apply -f k8s/

K8s deployment details

FieldValue
Namespacelux-gateway
Deployment namemarkets
Replicas2
CPU request/limit100m / 500m
Memory request/limit64Mi / 256Mi
Liveness probeGET /health every 10s
Readiness probeGET /health every 5s
Secretmarkets-secrets (key: coingecko-api-key)
  • lux/lux-market.md -- Market data and trading
  • lux/lux-node.md -- Lux node infrastructure

On this page