Skip to content

go-ftx is a Go client library for accessing the FTX API.

License

Notifications You must be signed in to change notification settings

cloudingcity/go-ftx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-ftx

Test Lint codecov Go Report Card

go-ftx is a Go client library for accessing the FTX API.

Install

go get github.com/cloudingcity/go-ftx

Quick Start

package main

import (
	"fmt"
	"log"

	"github.com/cloudingcity/go-ftx/ftx"
)

func main() {
	client := ftx.New()
	market, err := client.Markets.Get("ETH/USD")
	if err != nil {
		log.Fatalln(err)
	}
	fmt.Printf("%+v", market)
}

Examples

REST API

package main

import (
	"fmt"
	"log"

	"github.com/cloudingcity/go-ftx/ftx"
)

func main() {
	client := ftx.New(
		ftx.WithAuth("your-api-key", "your-api-secret"),
		ftx.WithSubaccount("your-subaccount"), // Omit if not using subaccounts
	)
	account, err := client.Accounts.GetInformation()
	if err != nil {
		log.Fatal()
	}
	fmt.Printf("%+v", account)
}

Websocket

package main

import (
	"fmt"
	"log"

	"github.com/cloudingcity/go-ftx/ftx"
	"github.com/cloudingcity/go-ftx/ftx/stream"
)

func main() {
	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()

	client := ftx.New(
		ftx.WithAuth("your-api-key", "your-api-secret"),
		ftx.WithSubaccount("your-subaccount"), // Omit if not using subaccounts
	)
	conn, err := client.Connect()
	if err != nil {
		log.Fatal(err)
	}
	
	conn.PingRegular(ctx, 50*time.Second) // Keep connection prevent read timeout

	// Ping
	if err := conn.Ping(); err != nil {
		log.Fatal(err)
	}

	// Public Channels
	if err := conn.Subscribe(stream.ChannelTicker, "BTC/USD"); err != nil {
		log.Fatal(err)
	}
	if err := conn.Subscribe(stream.ChannelTrades, "BTC/USD"); err != nil {
		log.Fatal(err)
	}

	// Private Channels
	if err := conn.Login(); err != nil {
		log.Fatal(err)
	}
	if err := conn.Subscribe(stream.ChannelFills); err != nil {
		log.Fatal(err)
	}
	if err := conn.Subscribe(stream.ChannelOrders); err != nil {
		log.Fatal(err)
	}

	for {
		resp, err := conn.Recv()
		if err != nil {
			log.Fatal(err)
			return
		}

		switch v := resp.(type) {
		case stream.General:
			fmt.Println("general:", v)
		case stream.Pong:
			fmt.Println("pong:", v)
		case stream.OrderBook:
			fmt.Println("orderbook:", v)
		case stream.Trade:
			fmt.Println("trade:", v)
		case stream.Ticker:
			fmt.Println("ticker:", v)
		case stream.Fills:
			fmt.Println("fills:", v)
		case stream.Orders:
			fmt.Println("orders:", v)
		case stream.Error:
			fmt.Println("error:", v)
		}
	}
}

Todos

  • REST API
    • Marktes
    • Accounts
    • Subaccounts
    • Futures
    • Wallet
    • Orders
    • Convert
    • Spot Margin
    • Fills
    • Funding Payments
    • Leveraged Tokens
    • Options
    • Staking
  • Websocket API
    • Ping
    • OrderBooks
    • Trade
    • Ticker
    • Markets
    • Grouped Orderbooks
    • Fills
    • Orders

About

go-ftx is a Go client library for accessing the FTX API.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published