sfox

package module
v0.0.0-...-b38da3e Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2020 License: MIT Imports: 13 Imported by: 0

README

sfox-sdk-go

An unofficial client to trade on SFOX.

Usage

package main

import (
    "fmt"

    "github.com/mrasband/sfox-sdk-go"
    "github.com/shopspring/decimal"
)

func main() {
    c := sfox.New(os.Getenv("SFOX_API_KEY"))

    fmt.Println("Placing order...")
    order, err := c.PlaceOrder(sfox.Buy, sfox.NewOrder{
        Quantity: decimal.NewFromFloat(0.04),
        AlgoID:   sfox.SmartAlgo,
        Pair:     "ethusd",
        Price:    decimal.NewFromFloat(125),
    })
    if err != nil {
        fmt.Printf("Err: %s\n", err)
        return
    }
    fmt.Printf("Order: %+v\n", order)

    fmt.Println("Getting open orders...")
    orders, err := c.OpenOrders()
    if err != nil {
        fmt.Printf("Err: %s\n", err)
        return
    }
    fmt.Printf("Orders: %+v\n", orders)

    fmt.Println("Getting order...")
    order2, err := c.GetOrder(order.ID)
    if err != nil {
        fmt.Printf("Err: %s\n", err)
        return
    }
    fmt.Printf("Order: %+v\n", order2)

    time.Sleep(10 * time.Second)

    fmt.Println("Cancelling order...")
    err = c.CancelOrder(order.ID)
    if err != nil {
        fmt.Printf("Err: %s\n", err)
        return
    }
    fmt.Println("OK")

    fmt.Println("Getting cancelled order...")
    order2, err = c.GetOrder(order.ID)
    if err != nil {
        fmt.Printf("Err: %s\n", err)
        return
    }
    fmt.Printf("Order: %+v\n", order2)
}

Documentation

Index

Constants

View Source
const (
	ProductionWebsocketHost = "wss://ws.sfox.com/ws"
)

Variables

View Source
var (
	ErrUnknownPayload = errors.New("Unknown payload")
)

Functions

This section is empty.

Types

type ACHResponse

type ACHResponse struct {
	TXStatus int    `json:"tx_status"`
	Success  bool   `json:"success"`
	Error    string `json:"error"`
}

type Address

type Address struct {
	Address  string `json:"address"`
	Currency string `json:"currency"`
}

type AlgoID

type AlgoID int
const (
	SmartAlgo     AlgoID = 200
	GorillaAlgo   AlgoID = 301
	TortoiseAlgo  AlgoID = 302
	HareAlgo      AlgoID = 303
	StopLossAlgo  AlgoID = 304
	PolarBearAlgo AlgoID = 305
	SniperAlgo    AlgoID = 306
	TWAPAlgo      AlgoID = 307
)

type AssetPair

type AssetPair struct {
	FormattedSymbol string `json:"formatted_symbol"`
	Symbol          string `json:"symbol"`
}

type AssetPairs

type AssetPairs map[string]AssetPair

type Balance

type Balance struct {
	Currency  string          `json:"currency"`
	Balance   decimal.Decimal `json:"balance"`
	Available decimal.Decimal `json:"available"`
	Held      decimal.Decimal `json:"held"`
}

type BidAsk

type BidAsk struct {
	Price    decimal.Decimal
	Size     decimal.Decimal
	Exchange string
}

func (*BidAsk) UnmarshalJSON

func (ba *BidAsk) UnmarshalJSON(b []byte) error

type Client

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

func New

func New(apiKey string) *Client

func NewWithHost

func NewWithHost(apiKey, host string) *Client

func (*Client) ACHDeposit

func (c *Client) ACHDeposit(amount decimal.Decimal) (ACHResponse, error)

func (*Client) AccountBalance

func (c *Client) AccountBalance() ([]Balance, error)

func (*Client) AssetPairs

func (c *Client) AssetPairs() (AssetPairs, error)

func (*Client) BestPrice

func (c *Client) BestPrice(side Side, amount decimal.Decimal, pair string) (Price, error)

func (*Client) CancelOrder

func (c *Client) CancelOrder(orderID int64) error

func (*Client) CreateAddress

func (c *Client) CreateAddress(currency string) (Address, error)

func (*Client) CryptoAddresses

func (c *Client) CryptoAddresses(currency string) ([]Address, error)

func (*Client) GetOrder

func (c *Client) GetOrder(orderID int64) (Order, error)

func (*Client) OpenOrders

func (c *Client) OpenOrders() ([]Order, error)

func (*Client) Orderbook

func (c *Client) Orderbook(pair string) (Orderbook, error)

func (*Client) PlaceOrder

func (c *Client) PlaceOrder(side Side, newOrder NewOrder) (Order, error)

Place an order. Example of an "Instant" buy: NewOrder{Quantity: decimal.NewFromFloat(0.001)} Smart buy (no limit): NewOrder{Quantity: decimal.NewFromFloat(0.04), AlgoID: SmartAlgo, Pair: "ethusd"}

func (*Client) Transactions

func (c *Client) Transactions(t ...TimeBasedPagination) ([]Transaction, error)

Transactions retrieves all the user's transactions, by default this will be all transactions inception to date.

func (*Client) Withdraw

func (c *Client) Withdraw(amount decimal.Decimal, currency, address string) (WithdrawResponse, error)

type ErrHttp

type ErrHttp struct {
	StatusCode int
	Text       string
}

func (ErrHttp) Error

func (e ErrHttp) Error() string

type ErrHttpClient

type ErrHttpClient struct {
	ErrHttp
}

type ErrHttpServer

type ErrHttpServer struct {
	ErrHttp
}

type Event

type Event struct {
	Msg WebsocketEnvelope
	Err error
}

type NewOrder

type NewOrder struct {
	Quantity      decimal.Decimal        `json:"quantity"`
	Pair          string                 `json:"currency_pair"`
	Price         decimal.Decimal        `json:"price"`
	AlgoID        AlgoID                 `json:"algorithm_id"`
	ClientOrderID string                 `json:"client_order_id"`
	Interval      int64                  `json:"interval"`   // seconds
	TotalTime     int64                  `json:"total_time"` // seconds
	RoutingType   string                 `json:"routing_type"`
	Extra         map[string]interface{} `json:"extra"`
}

type Order

type Order struct {
	ID            int64           `json:"id"`
	Quantity      decimal.Decimal `json:"quantity"`
	Price         decimal.Decimal `json:"price"`
	Action        string          `json:"o_action"`
	Pair          string          `json:"pair"`
	Type          string          `json:"type"`
	VWAP          decimal.Decimal `json:"vwap"`
	Filled        decimal.Decimal `json:"filled"`
	Status        string          `json:"status"`
	StatusCode    int             `json:"status_code"`
	ClientOrderID string          `json:"client_order_id"`
	Updated       Time            `json:"dateupdated"`
	Expires       *Time           `json:"expires"`
	Fees          decimal.Decimal `json:"fees"`
	NetProceeds   decimal.Decimal `json:"net_proceeds"`
	Proceeds      decimal.Decimal `json:"proceeds"`
}

type Orderbook

type Orderbook struct {
	Bids         []BidAsk
	Asks         []BidAsk
	MarketMaking []struct {
		Bids []BidAsk
		Asks []BidAsk
	}
	// TODO: we should clarify what the two entries in the time slice are
	Timestamps    map[string][]Time
	Pair          string
	Currency      string
	LastPublished Time
	LastUpdated   Time
}

type OrderbookMsg

type OrderbookMsg struct {
	Bids          []BidAsk          `json:"bids"`
	Asks          []BidAsk          `json:"asks"`
	Timestamps    map[string][]Time `json:"timestamps"`
	LastUpdated   Time              `json:"lastupdated"`
	LastPublished Time              `json:"lastpublished"`
	Pair          string            `json:"pair"`
	Currency      string            `json:"currency"`
}

type Price

type Price struct {
	Fees     decimal.Decimal `json:"fees"`
	Price    decimal.Decimal `json:"price"`
	Quantity decimal.Decimal `json:"quantity"`
	Total    decimal.Decimal `json:"total"`
	VWAP     decimal.Decimal `json:"vwap"`
}

type Side

type Side int
const (
	Buy Side
	Sell
)

func (Side) String

func (s Side) String() string

type TickerMsg

type TickerMsg struct {
	Amount   decimal.Decimal `json:"amount"`
	Exchange string          `json:"exchange"`
	Open     decimal.Decimal `json:"open"`
	High     decimal.Decimal `json:"high"`
	Low      decimal.Decimal `json:"low"`
	Last     decimal.Decimal `json:"last"`
	Volume   decimal.Decimal `json:"volume"`
	VWAP     decimal.Decimal `json:"vwap"`
	Pair     string          `json:"pair"`
	Route    string          `json:"route"`
	Source   string          `json:"source"`
	Time     Time            `json:"timestamp"`
}

type Time

type Time time.Time

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(b []byte) error

type TimeBasedPagination

type TimeBasedPagination struct {
	From time.Time
	To   time.Time
}

type TradeMsg

type TradeMsg struct {
	ID          string          `json:"id"`
	Pair        string          `json:"pair"`
	Price       decimal.Decimal `json:"price,string"`
	Quantity    decimal.Decimal `json:"quantity,string"`
	Side        string          `json:"side"`
	BuyOrderID  string          `json:"buy_order_id"`
	SellOrderID string          `json:"sell_order_id"`
	Exchange    string          `json:"exchange"`
	ExchangeID  int             `json:"exchange_id"`
	Timestamp   Time            `json:"timestamp"`
}

type Transaction

type Transaction struct {
	ID              int64           `json:"id"`
	OrderID         string          `json:"order_id"`
	ClientOrderID   string          `json:"client_order_id"`
	Day             Time            `json:"day"`
	Action          string          `json:"action"` // TODO: make a type for these
	Currency        string          `json:"currency"`
	Amount          decimal.Decimal `json:"amount"`
	NetProceeds     decimal.Decimal `json:"net_proceeds"`
	Price           decimal.Decimal `json:"price"`
	Fees            decimal.Decimal `json:"fees"`
	Status          string          `json:"status"`
	HoldExpires     Time            `json:"hold_expires"`
	TxHash          string          `json:"tx_hash"`
	AlgoName        string          `json:"algo_name"`
	AlgoID          string          `json:"algo_id"`
	AccountBalance  decimal.Decimal `json:"account_balance"`
	WalletDisplayID string          `json:"wallet_display_id"`
}

type Websocket

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

func NewWebsocket

func NewWebsocket() *Websocket

func NewWebsocketWithHost

func NewWebsocketWithHost(host string) *Websocket

func (*Websocket) Listen

func (w *Websocket) Listen(ctx context.Context, feeds []string) (<-chan Event, error)

type WebsocketEnvelope

type WebsocketEnvelope struct {
	Type       string          `json:"type"`
	Sequence   int64           `json:"sequence"`
	Timestamp  int64           `json:"timestamp"`
	Recipient  string          `json:"recipient"`
	RawPayload json.RawMessage `json:"payload"` // delay parsing
}

func (*WebsocketEnvelope) Payload

func (wse *WebsocketEnvelope) Payload() (interface{}, error)

type WithdrawResponse

type WithdrawResponse struct {
	Success bool   `json:"success"`
	Error   string `json:"error"`
}

Jump to

Keyboard shortcuts

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