goftx

package module
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2021 License: MIT Imports: 19 Imported by: 4

README

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PrepareQueryParams

func PrepareQueryParams(params interface{}) (map[string]string, error)

Types

type Account

type Account struct {
	// contains filtered or unexported fields
}

func (*Account) ChangeAccountLeverage

func (a *Account) ChangeAccountLeverage(leverage decimal.Decimal) error

func (*Account) GetAccountInformation

func (a *Account) GetAccountInformation() (*models.AccountInformation, error)

func (*Account) GetPositions

func (a *Account) GetPositions() ([]*models.Position, error)

type Client

type Client struct {
	SubAccounts
	Markets
	Account
	Stream
	Orders
	Fills
	Converts
	Futures
	SpotMargin
	// contains filtered or unexported fields
}

func New

func New(opts ...Option) *Client

func (*Client) GetServerTime

func (c *Client) GetServerTime() (time.Time, error)

func (Client) Ping added in v1.1.3

func (c Client) Ping() error

func (*Client) SetServerTimeDiff

func (c *Client) SetServerTimeDiff() error

type Converts

type Converts struct {
	// contains filtered or unexported fields
}

func (*Converts) AcceptQuote

func (c *Converts) AcceptQuote(quoteID int64) error

func (*Converts) CreateQuote

func (c *Converts) CreateQuote(payload *models.CreateQuotePayload) (int64, error)

func (*Converts) GetQuotes

func (c *Converts) GetQuotes(quoteID int64, market *string) ([]*models.QuoteStatus, error)

type Fills

type Fills struct {
	// contains filtered or unexported fields
}

func (*Fills) GetFills

func (f *Fills) GetFills(params *models.GetFillsParams) ([]*models.Fill, error)

type Futures

type Futures struct {
	// contains filtered or unexported fields
}

func (*Futures) GetExpiredFutures

func (f *Futures) GetExpiredFutures() ([]*models.FutureExpired, error)

func (*Futures) GetFundingRates

func (f *Futures) GetFundingRates(params *models.GetFundingRatesParams) ([]*models.FundingRate, error)

func (*Futures) GetFuture

func (f *Futures) GetFuture(name string) (*models.Future, error)

func (*Futures) GetFutureStats

func (f *Futures) GetFutureStats(name string) (*models.FutureStats, error)

func (*Futures) GetFutures

func (f *Futures) GetFutures() ([]*models.Future, error)

func (*Futures) GetHistoricalIndex

func (f *Futures) GetHistoricalIndex(market string, params *models.GetHistoricalIndexParams) ([]*models.HistoricalIndex, error)

func (*Futures) GetIndexWeights

func (f *Futures) GetIndexWeights(indexName string) (map[string]decimal.Decimal, error)

type Markets

type Markets struct {
	// contains filtered or unexported fields
}

func (*Markets) GetHistoricalPrices

func (m *Markets) GetHistoricalPrices(marketName string, params *models.GetHistoricalPricesParams) ([]*models.HistoricalPrice, error)

func (*Markets) GetMarketByName

func (m *Markets) GetMarketByName(name string) (*models.Market, error)

func (*Markets) GetMarkets

func (m *Markets) GetMarkets() ([]*models.Market, error)

func (*Markets) GetOrderBook

func (m *Markets) GetOrderBook(marketName string, depth *int) (*models.OrderBook, error)

func (*Markets) GetTrades

func (m *Markets) GetTrades(marketName string, params *models.GetTradesParams) ([]*models.Trade, error)

type Option

type Option func(c *Client)

func WithAuth

func WithAuth(key, secret string, subAccount ...string) Option

func WithFTXUS added in v1.2.1

func WithFTXUS() Option

func WithHTTPClient

func WithHTTPClient(client *http.Client) Option

type Orders

type Orders struct {
	// contains filtered or unexported fields
}

func (*Orders) CancelAllOrders

func (o *Orders) CancelAllOrders(payload *models.CancelAllOrdersPayload) error

func (*Orders) CancelOpenTriggerOrder

func (o *Orders) CancelOpenTriggerOrder(triggerOrderID int64) error

func (*Orders) CancelOrder

func (o *Orders) CancelOrder(orderID int64) error

func (*Orders) CancelOrderByClientID

func (o *Orders) CancelOrderByClientID(clientOrderID int64) error

func (*Orders) GetOpenOrders

func (o *Orders) GetOpenOrders(market string) ([]*models.Order, error)

func (*Orders) GetOpenTriggerOrders

func (o *Orders) GetOpenTriggerOrders(params *models.GetOpenTriggerOrdersParams) ([]*models.TriggerOrder, error)

func (*Orders) GetOrder

func (o *Orders) GetOrder(orderID int64) (*models.Order, error)

func (*Orders) GetOrderByClientID

func (o *Orders) GetOrderByClientID(clientOrderID int64) (*models.Order, error)

func (*Orders) GetOrderTriggers

func (o *Orders) GetOrderTriggers(orderID int64) ([]*models.Trigger, error)

func (*Orders) GetOrdersHistory

func (o *Orders) GetOrdersHistory(params *models.GetOrdersHistoryParams) ([]*models.Order, error)

func (*Orders) GetTriggerOrdersHistory

func (o *Orders) GetTriggerOrdersHistory(params *models.GetTriggerOrdersHistoryParams) ([]*models.TriggerOrder, error)

func (*Orders) ModifyOrder

func (o *Orders) ModifyOrder(payload *models.ModifyOrderPayload, orderID int64) (*models.Order, error)

func (*Orders) ModifyOrderByClientID

func (o *Orders) ModifyOrderByClientID(payload *models.ModifyOrderPayload, clientOrderID int64) (*models.Order, error)

func (*Orders) ModifyTriggerOrder

func (o *Orders) ModifyTriggerOrder(payload *models.ModifyTriggerOrderPayload, orderID int64) (*models.TriggerOrder, error)

func (*Orders) PlaceOrder

func (o *Orders) PlaceOrder(payload *models.PlaceOrderPayload) (*models.Order, error)

func (*Orders) PlaceTriggerOrder

func (o *Orders) PlaceTriggerOrder(payload *models.PlaceTriggerOrderPayload) (*models.TriggerOrder, error)

type Request

type Request struct {
	Auth    bool
	Method  string
	URL     string
	Headers map[string]string
	Params  map[string]string
	Body    []byte
}

type Response

type Response struct {
	Success bool            `json:"success"`
	Result  json.RawMessage `json:"result"`
	Error   string          `json:"error,omitempty"`
}

type SpotMargin

type SpotMargin struct {
	// contains filtered or unexported fields
}

func (*SpotMargin) GetBorrowHistory

func (s *SpotMargin) GetBorrowHistory() ([]*models.BorrowHistory, error)

func (*SpotMargin) GetBorrowRates

func (s *SpotMargin) GetBorrowRates() ([]*models.BorrowRate, error)

func (*SpotMargin) GetDailyBorrowedAmounts

func (s *SpotMargin) GetDailyBorrowedAmounts() ([]*models.BorrowSummary, error)

func (*SpotMargin) GetLendingHistory

func (s *SpotMargin) GetLendingHistory() ([]*models.LendingHistory, error)

func (*SpotMargin) GetLendingInfo

func (s *SpotMargin) GetLendingInfo() ([]*models.LendingInfo, error)

func (*SpotMargin) GetLendingOffers

func (s *SpotMargin) GetLendingOffers() ([]*models.LendingOffer, error)

func (*SpotMargin) GetLendingRates

func (s *SpotMargin) GetLendingRates() ([]*models.LendingRate, error)

func (*SpotMargin) GetMarketInfo

func (s *SpotMargin) GetMarketInfo(market string) ([]*models.GetSpotMarginMarketInfoResponse, error)

func (*SpotMargin) SubmitLendingOffer

func (s *SpotMargin) SubmitLendingOffer(payload *models.LendingOfferPayload) error

type Stream

type Stream struct {
	// contains filtered or unexported fields
}

func (*Stream) SetDebugMode

func (s *Stream) SetDebugMode(isDebugMode bool)

func (*Stream) SetReconnectionCount

func (s *Stream) SetReconnectionCount(count int)

func (*Stream) SetReconnectionInterval

func (s *Stream) SetReconnectionInterval(interval time.Duration)

func (*Stream) SetStreamTimeout

func (s *Stream) SetStreamTimeout(timeout time.Duration)

func (*Stream) SubscribeToFills

func (s *Stream) SubscribeToFills(ctx context.Context) (chan *models.FillResponse, error)

func (*Stream) SubscribeToMarkets

func (s *Stream) SubscribeToMarkets(ctx context.Context) (chan *models.Market, error)

func (*Stream) SubscribeToOrderBooks

func (s *Stream) SubscribeToOrderBooks(ctx context.Context, symbols ...string) (chan *models.OrderBookResponse, error)

nolint: dupl

func (*Stream) SubscribeToOrders

func (s *Stream) SubscribeToOrders(ctx context.Context) (chan *models.OrderResponse, error)

func (*Stream) SubscribeToTickers

func (s *Stream) SubscribeToTickers(ctx context.Context, symbols ...string) (chan *models.TickerResponse, error)

nolint: dupl

func (*Stream) SubscribeToTrades

func (s *Stream) SubscribeToTrades(ctx context.Context, symbols ...string) (chan *models.TradeResponse, error)

type SubAccounts

type SubAccounts struct {
	// contains filtered or unexported fields
}

func (*SubAccounts) ChangeSubaccount

func (s *SubAccounts) ChangeSubaccount(nickname, newNickname string) error

func (*SubAccounts) CreateSubaccount

func (s *SubAccounts) CreateSubaccount(nickname string) (*models.SubAccount, error)

func (*SubAccounts) DeleteSubaccount

func (s *SubAccounts) DeleteSubaccount(nickname string) error

func (*SubAccounts) GetSubaccountBalances

func (s *SubAccounts) GetSubaccountBalances(nickname string) ([]*models.Balance, error)

func (*SubAccounts) GetSubaccounts

func (s *SubAccounts) GetSubaccounts() ([]*models.SubAccount, error)

func (*SubAccounts) Transfer

func (s *SubAccounts) Transfer(payload *models.TransferPayload) (*models.TransferResponse, error)

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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