Giter Club home page Giter Club logo

goftx's Introduction

goftx

FTX exchange golang library

Install

go get github.com/grishinsana/goftx

Usage

See examples directory and test cases for more examples

TODO

  • Wallet
  • Funding Payments
  • Leveraged Tokens
  • Options
  • SRM Staking

REST

package main

import (
	"fmt"
	"net/http"
	"time"

	"github.com/grishinsana/goftx"
)

func main() {
	client := goftx.New(
		goftx.WithAuth("API-KEY", "API-SECRET"),
		goftx.WithHTTPClient(&http.Client{
			Timeout: 5 * time.Second,
		}),
	)

	info, err := client.Account.GetAccountInformation()
	if err != nil {
		panic(err)
	}
	fmt.Println(info)
}

WebSocket

package main

import (
	"context"
	"log"
	"os"
	"os/signal"
	"syscall"
	"time"

	"github.com/grishinsana/goftx"
)

func main() {
    sigs := make(chan os.Signal, 1)
    signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
    
    ctx, cancel := context.WithCancel(context.Background())
    
    client := goftx.New()
    client.Stream.SetDebugMode(true)
    
    data, err := client.Stream.SubscribeToTickers(ctx, "ETH/BTC")
    if err != nil {
        log.Fatalf("%+v", err)
    }

    go func() {
        for {
            select {
            case <-ctx.Done():
                return
            case msg, ok := <-data:
                if !ok {
                    return
                }
                log.Printf("%+v\n", msg)
            }
        }
    }()

    <-sigs
    cancel()
    time.Sleep(time.Second)
}

FTX US Mode

If you need to use FTX US than you could set goftx.WithFTXUS option

    client := goftx.New(
		goftx.WithFTXUS(),
	)

Websocket Debug Mode

If need, it is possible to set debug mode to look error and system messages in stream methods

    client := goftx.New()
    client.Stream.SetDebugMode(true)

No Logged In Error

"Not logged in" errors usually come from a wrong signatures. FTX released an article on how to authenticate https://blog.ftx.com/blog/api-authentication/

If you have unauthorized error to private methods, then you need to use SetServerTimeDiff()

ftx := New()
ftx.SetServerTimeDiff()

goftx's People

Contributors

grishinsana avatar mm2175 avatar trading-peter avatar dreson4 avatar m11y avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.