• This repository has been archived on 29/Nov/2022
  • Stars
    star
    103
  • Rank 333,046 (Top 7 %)
  • Language
    Go
  • License
    MIT License
  • Created about 5 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

go-ftx is API wrapper for FTX exchange, with go.

go-ftx

FTX exchange API version2, renew at 2020/04.

Description

go-ftx is a go client library for FTX API Document.

Supported

  • Public & Private
  • Orders
  • Leveraged tokens
  • Options
  • Websocket
  • SubAccounts

Not Supported

  • FIX API

Installation

$ go get -u github.com/go-numb/go-ftx

Usage

package main

import (
	"fmt"
	"github.com/dustin/go-humanize"
	"github.com/go-numb/go-ftx/auth"
	"github.com/go-numb/go-ftx/rest"
	"github.com/go-numb/go-ftx/rest/private/orders"
	//"log"
	"github.com/go-numb/go-ftx/rest/private/account"
	"github.com/go-numb/go-ftx/rest/public/futures"
	"github.com/go-numb/go-ftx/rest/public/markets"
	"github.com/go-numb/go-ftx/types"
	"github.com/labstack/gommon/log"
	"sort"
	"strings"
)

func main() {
	// Only main account
	client := rest.New(auth.New("<key>", "<secret>"))

	// or
	// UseSubAccounts
	clientWithSubAccounts := rest.New(
		auth.New(
			"<key>",
			"<secret>",
			auth.SubAccount{
				UUID:     1,
				Nickname: "subaccount_1",
			},
			auth.SubAccount{
				UUID:     2,
				Nickname: "subaccount_2",
			},
			// many....
		))
	// switch subaccount
	clientWithSubAccounts.Auth.UseSubAccountID(1) // or 2... this number is key in map[int]SubAccount

	// account informations
	// client or clientWithSubAccounts in this time.
	c := client // or clientWithSubAccounts
	info, err := c.Information(&account.RequestForInformation{})
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("%v\n", info)

	// lev, err := c.Leverage(5)
	lev, err := c.Leverage(&account.RequestForLeverage{
		Leverage: 3,
	})

	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("%v\n", lev)

	market, err := c.Markets(&markets.RequestForMarkets{
		ProductCode: "XRPBULL/USDT",
	})

	if err != nil {
		log.Fatal(err)
	}

	// products List
	fmt.Printf("%+v\n", strings.Join(market.List(), "\n"))
	// product ranking by USD
	fmt.Printf("%+v\n", strings.Join(market.Ranking(markets.ALL), "\n"))

	// FundingRate
	rates, err := c.Rates(&futures.RequestForRates{})
	if err != nil {
		log.Fatal(err)
	}
	// Sort by FundingRate & Print
	// Custom sort
	sort.Sort(sort.Reverse(rates))
	for _, v := range *rates {
		fmt.Printf("%s			%s		%s\n", humanize.Commaf(v.Rate), v.Future, v.Time.String())
	}

	order, err := c.PlaceOrder(&orders.RequestForPlaceOrder{
		Type:   types.LIMIT,
		Market: "BTC-PERP",
		Side:   types.BUY,
		Price:  6200,
		Size:   0.01,
		// Optionals
		ClientID:   "use_original_client_id",
		Ioc:        false,
		ReduceOnly: false,
		PostOnly:   false,
	})
	if err != nil {
		// client.Logger.Error(err) // Logger does not seem to exist @tuanito
	}

	fmt.Printf("%+v\n", order)

	ok, err := c.CancelByID(&orders.RequestForCancelByID{
		OrderID: 1,
		// either... , prioritize clientID
		ClientID:       "",
		TriggerOrderID: "",
	})
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(ok)
	// ok is status comment

}

Websocket

package main

import (
	"context"
	"fmt"
	"github.com/go-numb/go-ftx/realtime"
	"github.com/go-numb/go-ftx/auth"

	"github.com/labstack/gommon/log"
)


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

	ch := make(chan realtime.Response)
	go realtime.Connect(ctx, ch, []string{"ticker"}, []string{"BTC-PERP", "ETH-PERP"}, nil)
	go realtime.ConnectForPrivate(ctx, ch, "<key>", "<secret>", []string{"orders", "fills"}, nil)

	for {
		select {
		case v := <-ch:
			switch v.Type {
			case realtime.TICKER:
				fmt.Printf("%s	%+v\n", v.Symbol, v.Ticker)

			case realtime.TRADES:
				fmt.Printf("%s	%+v\n", v.Symbol, v.Trades)
				for i := range v.Trades {
					if v.Trades[i].Liquidation {
						fmt.Printf("-----------------------------%+v\n", v.Trades[i])
					}
				}

			case realtime.ORDERBOOK:
				fmt.Printf("%s	%+v\n", v.Symbol, v.Orderbook)

			case realtime.ORDERS:
				fmt.Printf("%d	%+v\n", v.Type, v.Orders)

			case realtime.FILLS:
				fmt.Printf("%d	%+v\n", v.Type, v.Fills)

			case realtime.UNDEFINED:
				fmt.Printf("UNDEFINED %s	%s\n", v.Symbol, v.Results.Error())
			}
		}
	}
}

Author

@_numbP

License

MIT

More Repositories

1

go-dydx

go-dydx is a go client library for dYdX exchange API.
Go
14
star
2

go-diff-exchanges

This program gets price by each exchanges websocket, and insert influxDB.
Go
7
star
3

go-bitbank

Go
4
star
4

go-crypto-bot-framework-for-distribution

This program is framework for trading on crypto exchanges.
Go
4
star
5

go-liquid

Liquid by Quoine API version2 with websocket
Go
3
star
6

go-bitflyer

renew
Go
3
star
7

board-trading-system

This pkg is board trading system. ※ Price is integer.
Go
3
star
8

exec-to-mongo

bitflyer realtime api (executions) to mongoDB
Go
2
star
9

go-bybt

Bybt of General information for Crypto. This client is wrapper of Bybt.
Go
2
star
10

go-obm

go-obm is orderbook manager. set, update, sort, get best price and more.
Go
2
star
11

TalkWithRustGPT

GUI: Tauri + React + Typescript. Switch API: OpenAI ChatGPT. Anthropic Claude.
Rust
2
star
12

nuxt-config

nuxt.jsでよく使うconfig set
JavaScript
1
star
13

go-scalping

Go
1
star
14

go-bitmex

Bitmex REST/Realtime APIs & Managed API Limit with Go
Go
1
star
15

go-games

create atomic game programs for teaching children.
Go
1
star
16

chatgpt-prompts-maker

This package creates instructions that give CHATGPT various roles.
Go
1
star
17

go-bf-rankers

This program is get bitflyer every 15 minutes, save to levelDB.
Go
1
star
18

docgen

このリポジトリは、指定されたディレクトリ内 のファイル群を分析し、その内容に基づいてドキュメントを生成するツールです。 this name comes from the [document generator].
Rust
1
star
19

go-rage-undertake

Go
1
star
20

go-stalk-users

this program gets tweet from seted each twitter users. Each 5 sec.
Go
1
star
21

go-mercari-scraper

go-mercari-scraper is scrape MERCARI.
Go
1
star
22

TalkWithGPT

CHATGPTとお話しするアプリ、VoiceVox冥鳴ひまりちゃんおすすめ
Go
1
star
23

gcloud-spread-tweets

Spread to twitter/x with Google cloud services
Go
1
star
24

make-permutations

make-permutations for test to create NFTs
Go
1
star
25

obmrs

取引参加者として、取引所配信のOrderbookを受信し、保持及び入出力するための構造体を作成します。
Rust
1
star