Thanks to visit codestin.com
Credit goes to github.com

Skip to content

defi-maker/golighter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

golighter

Go client for the Lighter HTTP API generated from openapi.json and wrapped with a few ergonomic helpers. The layout mirrors the lighter-python/examples collection so you can switch between Python and Go with minimal friction.

  • All REST endpoints from the specification are available through the generated package github.com/defi-maker/golighter/api.
  • The client package builds on top of the generated code and provides:
    • sensible defaults for the HTTP transport (configurable via options),
    • convenience helpers for form-based endpoints such as sendTx and notification/ack,
    • TxClient utilities that wrap github.com/elliottech/lighter-go/types for signing L2 transactions,
    • WebSocket services (Public/Private) compatible with the Python SDK.

Quick Start

package main

import (
    "context"
    "log"

    lighterapi "github.com/defi-maker/golighter/api"
    "github.com/defi-maker/golighter/client"
)

func main() {
    ctx := context.Background()

    c, err := client.New("https://mainnet.zklighter.elliot.ai")
    if err != nil {
        log.Fatal(err)
    }

    status, err := c.Status(ctx)
    if err != nil {
        log.Fatal(err)
    }
    log.Printf("network=%d status=%d", status.NetworkId, status.Status)

    orderBook, err := c.OrderBookOrders(ctx, &lighterapi.OrderBookOrdersParams{MarketId: 1, Limit: 50})
    if err != nil {
        log.Fatal(err)
    }
    log.Printf("asks=%d bids=%d", len(orderBook.Asks), len(orderBook.Bids))
}

More complete snippets can be found in examples/ (see examples/README.md for the mapping to the Python samples).

Options

client.New(baseURL,
    client.WithHTTPClient(customHTTP),   // override the underlying http.Client
    client.WithChannelName("my-channel"),
    client.WithPriceProtection(false),   // default toggle for sendTx
)

All operations are available as context-aware methods on client.Client. If you prefer to drive the generated code directly, use Client.API() to obtain the underlying lighterapi.ClientWithResponsesInterface.

Examples

The examples/ folder mirrors the scenarios covered in ../lighter-python/examples:

Purpose Python script Go command
Public REST queries get_info.py go run examples/get_info
Create & cancel order create_cancel_order.py go run examples/create_cancel_order
Batch submissions send_tx_batch.py go run examples/send_tx_batch
WebSocket order book ws.py go run examples/ws

Populate the following environment variables (or an .env file) before running the samples:

LIGHTER_ENDPOINT=https://mainnet.zklighter.elliot.ai
LIGHTER_ACCOUNT_INDEX=...
LIGHTER_API_KEY_INDEX=...
LIGHTER_API_KEY_PRIVATE_KEY=0x...
LIGHTER_CHAIN_ID=0

To bootstrap API keys on testnet you can reuse the Python helper system_setup.py, then feed the produced values into the Go examples.

Development

The generated sources under api/ come from openapi.jsonopenapi3.yaml (via swagger2openapi) → oapi-codegen. Re-run the pipeline when the specification changes:

npx json5 -c openapi.json -o openapi_fixed.json
npx swagger2openapi --outfile openapi3.yaml openapi_fixed.json
$(go env GOBIN)/oapi-codegen -generate types,client -package lighterapi -o api/lighter.gen.go openapi3.yaml

The helper wrappers in client/generated_wrappers.go are generated by scripts/gen_wrappers.py.

About

go wrapper for lighter.xyz

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •