go-ftx

module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 1, 2021 License: MIT

README

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() {
	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)
	}

	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

Directories

Path Synopsis
ftx

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL