mirror of
https://github.com/luxfi/dex.git
synced 2026-09-24 00:26:31 +00:00
Lux Partners Limited is not the entity behind this work. Every place the old name stood — copyright lines, site footers, brand config, legal and compliance text — now names the company that actually holds it. lux.fund is the exception and is not renamed to match: that site belongs to Lux Assets Management LLC, a different company, and it says so. Two kinds of line were left for a person rather than rewritten. A dated news item recording that Lux Partners Limited was established in the Isle of Man is a historical fact, and renaming it would falsify the record. And a sentence asserting that the company is domiciled in the Isle of Man is a claim about a jurisdiction, not a name — an Inc or an LLC is not an Isle of Man company, so swapping the name there would assert something untrue. Co-authored-by: Hanzo Dev <[email protected]>
99 lines
3.1 KiB
Go
99 lines
3.1 KiB
Go
// Copyright 2024 Lux Industries Inc. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
/*
|
|
Package adapters provides venue adapter implementations for the trading SDK.
|
|
|
|
This package implements the trading.VenueAdapter interface for various
|
|
trading venues:
|
|
|
|
# Native Adapters
|
|
|
|
LxDexAdapter connects to the native LX DEX (Central Limit Order Book):
|
|
|
|
adapter := adapters.NewLxDexAdapter("lx_dex", &trading.NativeVenueConfig{
|
|
VenueType: "dex",
|
|
APIURL: "https://api.lx.exchange",
|
|
APIKey: apiKey,
|
|
APISecret: apiSecret,
|
|
})
|
|
|
|
LxAmmAdapter connects to the native LX AMM:
|
|
|
|
adapter := adapters.NewLxAmmAdapter("lx_amm", &trading.NativeVenueConfig{
|
|
VenueType: "amm",
|
|
APIURL: "https://api.amm.lux.network",
|
|
})
|
|
|
|
# CCXT Adapter
|
|
|
|
CcxtAdapter connects to CCXT-supported exchanges via an HTTP gateway.
|
|
This requires running a CCXT gateway service:
|
|
|
|
adapter := adapters.NewCcxtAdapter("binance", &trading.CcxtConfig{
|
|
ExchangeID: "binance",
|
|
APIKey: apiKey,
|
|
APISecret: apiSecret,
|
|
BaseURL: "http://localhost:8080", // CCXT gateway
|
|
})
|
|
|
|
Supported exchanges include: Binance, MEXC, OKX, Kraken, Coinbase, and
|
|
any other exchange supported by CCXT.
|
|
|
|
# Hummingbot Gateway Adapter
|
|
|
|
HummingbotAdapter connects to DEXs via Hummingbot Gateway:
|
|
|
|
adapter := adapters.NewHummingbotAdapter("uniswap", &trading.HummingbotConfig{
|
|
Host: "localhost",
|
|
Port: 15888,
|
|
Connector: "uniswap",
|
|
Chain: "ethereum",
|
|
Network: "mainnet",
|
|
})
|
|
|
|
# Adapter Registration
|
|
|
|
Adapters are automatically registered with the trading package via init():
|
|
|
|
import _ "github.com/luxfi/trading/adapters"
|
|
|
|
This enables the trading.Client to create adapters based on configuration.
|
|
|
|
# Implementing Custom Adapters
|
|
|
|
To implement a custom adapter, implement the trading.VenueAdapter interface:
|
|
|
|
type VenueAdapter interface {
|
|
Name() string
|
|
VenueType() VenueType
|
|
Capabilities() VenueCapabilities
|
|
IsConnected() bool
|
|
LatencyMs() *int64
|
|
Info() VenueInfo
|
|
Connect(ctx context.Context) error
|
|
Disconnect(ctx context.Context) error
|
|
GetMarkets(ctx context.Context) ([]MarketInfo, error)
|
|
GetTicker(ctx context.Context, symbol string) (Ticker, error)
|
|
GetOrderbook(ctx context.Context, symbol string, depth int) (*Orderbook, error)
|
|
GetTrades(ctx context.Context, symbol string, limit int) ([]Trade, error)
|
|
GetBalances(ctx context.Context) ([]Balance, error)
|
|
GetBalance(ctx context.Context, asset string) (Balance, error)
|
|
GetOpenOrders(ctx context.Context, symbol string) ([]Order, error)
|
|
PlaceOrder(ctx context.Context, request OrderRequest) (Order, error)
|
|
CancelOrder(ctx context.Context, orderID, symbol string) (Order, error)
|
|
CancelAllOrders(ctx context.Context, symbol string) ([]Order, error)
|
|
// AMM methods (return ErrNotSupported if not applicable)
|
|
GetSwapQuote(...) (SwapQuote, error)
|
|
ExecuteSwap(...) (Trade, error)
|
|
GetPoolInfo(...) (PoolInfo, error)
|
|
AddLiquidity(...) (LiquidityResult, error)
|
|
RemoveLiquidity(...) (LiquidityResult, error)
|
|
GetLpPositions(ctx context.Context) ([]LpPosition, error)
|
|
}
|
|
|
|
Use trading.BaseAdapter to get default implementations of common methods.
|
|
*/
|
|
package adapters
|