webserver

package
v0.0.0-...-a5f00ba Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2023 License: ISC Imports: 37 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = &ErrResponse{HTTPStatusCode: 404, StatusText: "Resource not found."}
View Source
var ErrWithdaw = &ErrResponse{HTTPStatusCode: 404, StatusText: "Failed to withdraw."}

Functions

func AssetListCtx

func AssetListCtx(next http.Handler) http.Handler

AssetListCtx fetches currencies from the exchange

func AvailableTransferChainsCtx

func AvailableTransferChainsCtx(next http.Handler) http.Handler

func BalanceCtx

func BalanceCtx(next http.Handler) http.Handler

BalanceCtx amend the request to be within the context of the asset name. Get the account info from the exchange engine. Find the asset code in the account and get the balance. Return the amended request. Add a balance cookie to the response.

func BankTransferCtx

func BankTransferCtx(next http.Handler) http.Handler

func DepositAddressCtx

func DepositAddressCtx(next http.Handler) http.Handler

DepositAddressCtx is a function that returns a context with a depositResponse struct.

func ErrInvalidRequest

func ErrInvalidRequest(err error) render.Renderer

func ErrNotEnoughAccountBalance

func ErrNotEnoughAccountBalance(err error) render.Renderer

func ErrRender

func ErrRender(err error) render.Renderer

func FetchPairsCtx

func FetchPairsCtx(next http.Handler) http.Handler

FetchPairsCtx fetches pairs from the exchange

func GetSubAccountByID

func GetSubAccountByID(e exchange.IBotExchange, accountId string) (account.SubAccount, error)

GetSubAccountByID is a function that returns a subaccount by ID.

func HoldingsExchangeCtx

func HoldingsExchangeCtx(next http.Handler) http.Handler

HoldingsExchangeCtx middleware adds the holdings to the context

func New

func New(ctx context.Context)

func PriceCtx

func PriceCtx(next http.Handler) http.Handler

PriceCtx is the context for the price endpoint

func TWAPCtx

func TWAPCtx(next http.Handler) http.Handler

TWAPCtx is the context for the '/twap' request twap/{exchange}/{pair}/{qty}/{assetType}/{orderType}/{side}

func TradeCtx

func TradeCtx(next http.Handler) http.Handler

TradeCtx is the context for the '/trade' request. trade/{exchange}/{pair}/{qty}/{assetType}/{orderType}/{side}

func WithdrawCtx

func WithdrawCtx(next http.Handler) http.Handler

WithdrawCtx is an HTTP handler function which stores the request input with the help of chi.URLParams get method in the response and call the createExchangeWithdrawResponse to create an exchange withdrawal transaction for the specified exchange

Types

type Asset

type Asset struct {
	Name       string        `json:"name"`
	Item       currency.Item `json:"item"`
	AssocChain string        `json:"chain"`
	Code       currency.Code `json:"code"`
	Exchange   string        `json:"exchange"`
	Address    string        `json:"address"`
	Balance    string        `json:"balance"`
	Rate       float64       `json:"rate"`
}

type BTSEChainSelector

type BTSEChainSelector struct{}

type BinanceChainSelector

type BinanceChainSelector struct{}

func (*BinanceChainSelector) SelectChain

func (c *BinanceChainSelector) SelectChain(chainReq string, availableTransferChains []string) string

type BittrexChainSelector

type BittrexChainSelector struct{}

func (*BittrexChainSelector) SelectChain

func (c *BittrexChainSelector) SelectChain(chainReq string, availableTransferChains []string) string

type ChainSelector

type ChainSelector interface {
	SelectChain(chainReq string, availableTransferChains []string) string
}

func GetChainSelector

func GetChainSelector(exchangeName string) ChainSelector

type CorsConfig

type CorsConfig struct {
	AllowedOrigins   []string // Origins that are allowed to access resources
	AllowedMethods   []string // HTTP Methods that are allowed to be used
	AllowedHeaders   []string // Headers that are allowed in HTTP requests
	ExposedHeaders   []string // Headers that are exposed in HTTP responses
	AllowCredentials bool     // Allow Whether the request can include credentials
	MaxAge           int      // The maximum age (in seconds) of the result of a preflight request
}

CorsConfig is our CORS configuration struct

type ErrResponse

type ErrResponse struct {
	Err            error `json:"-"` // low-level runtime error
	HTTPStatusCode int   `json:"-"` // http response status code

	StatusText string `json:"status"`          // user-level status message
	AppCode    int64  `json:"code,omitempty"`  // application-specific error code
	ErrorText  string `json:"error,omitempty"` // application-level error message, for debugging
}

ErrResponse renderer type for handling all sorts of errors.

In the best case scenario, the excellent github.com/pkg/errors package helps reveal information on the error, setting it on Err, and in the Render() method, using it to set the application-specific error code in AppCode.

func (*ErrResponse) Render

func (e *ErrResponse) Render(w http.ResponseWriter, r *http.Request) error

type ExchangeWithdrawResponse

type ExchangeWithdrawResponse struct {
	ExchangeResponse   *withdraw.ExchangeResponse
	Exchange           string               `json:"exchange"`
	Type               withdraw.RequestType `json:"type"`
	DestinationAddress string               `json:"destination"`
	Time               time.Time            `json:"time"`
	Err                error                `json:"err"`
}

ExchangeWithdrawResponse is a struct that is designed to represent the response from the ExchangesWithdrawals API call. ExchangesWithdrawals is a simple function which returns deposit, withdraw, trade and withdrawal information so we will only add the information there which we are interested in: ExchangesResponse is a struct that includes information about the request as well as the response, we're only interested in the response hence why we've added resp. We've used the Withdrawal struct as that is the response from the exchange (withdraw.ExchangeResponse). The Exchange key is the exchange used to make the request. The Type key represents the type of information requested in the Call function. The DestinationAddress is the address the withdrawal was sent to if the request used the DepositAddress field. The Time key is when the request was made and the Err field returns errors if any occurred.

type FTXChainSelector

type FTXChainSelector struct{}

func (*FTXChainSelector) SelectChain

func (c *FTXChainSelector) SelectChain(chainReq string, availableTransferChains []string) string

type Handler

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

Handler is a struct that encapsulates the resources needed to handle HTTP requests. It contains a `tpl` field for HTML templates that can be used to render web pages, and a `logger` field from the zerolog package for logging information about the requests and responses. Handler methods can use these resources to handle different HTTP requests. For example, the `handleTemplate` method uses the `tpl` field to render HTML pages. A new Handler can be created using the `NewHandler` function, which initializes the templates and logger.

func NewHandler

func NewHandler() *Handler

NewHandler creates and returns a new Handler. It initializes templates and logger for the handler.

type HuobiChainSelector

type HuobiChainSelector struct{}

type KrakenCHainSelector

type KrakenCHainSelector struct{}

type OrderResponse

type OrderResponse struct {
	Response  order.SubmitResponse `json:"response"`
	Order     order.Submit         `json:"order"`
	Pair      string               `json:"pair"`
	QtyUSD    float64              `json:"qtyUSD"`
	Qty       float64              `json:"qty"`
	Price     float64              `json:"price"`
	Timestamp time.Time            `json:"timestamp"`
}

OrderResponse is the response for the '/order' request.

type PriceResponse

type PriceResponse struct {
	Exchange  string        `json:"exchange"`
	Base      currency.Code `json:"base"`
	Quote     currency.Code `json:"quote"`
	Price     float64       `json:"price"`
	AssetType asset.Item    `json:"type"`
	// Error handling
	Error string `json:"error,omitempty"` // TODO find out how to improve error handling for API response
}

PriceResponse represents the response from the price endpoint

type Server

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

func NewServer

func NewServer() (*Server, error)

NewServer creates a new HTTP server and returns a pointer to it.

func (*Server) SetupRoutes

func (s *Server) SetupRoutes(handler *Handler) *chi.Mux

SetupRoutes configures the HTTP routes for the server. It takes a Handler object which contains methods for handling different paths. It returns a configured chi.Mux router object. The function maps URL paths to handler methods. For example, it maps the path "/" to the handler's "handleTemplate" method with "home.html" as a parameter. It also mounts a subrouter for the "/api" path. This allows for a separate set of routes to be defined for API requests. This method should be called as part of the server setup process before starting the server.

func (*Server) SetupService

func (s *Server) SetupService() http.Handler

func (*Server) Start

func (s *Server) Start(ctx context.Context) error

type Status

type Status struct {
	Status string `json:"status"`
	Uptime string `json:"uptime"`
}

type WithdrawHistoryResponse

type WithdrawHistoryResponse struct {
	History []exchange.WithdrawalHistory `json:"history"`
}

func (WithdrawHistoryResponse) Render

Jump to

Keyboard shortcuts

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