Documentation ¶
Index ¶
- Variables
- func AssetListCtx(next http.Handler) http.Handler
- func AvailableTransferChainsCtx(next http.Handler) http.Handler
- func BalanceCtx(next http.Handler) http.Handler
- func BankTransferCtx(next http.Handler) http.Handler
- func DepositAddressCtx(next http.Handler) http.Handler
- func ErrInvalidRequest(err error) render.Renderer
- func ErrNotEnoughAccountBalance(err error) render.Renderer
- func ErrRender(err error) render.Renderer
- func FetchPairsCtx(next http.Handler) http.Handler
- func GetSubAccountByID(e exchange.IBotExchange, accountId string) (account.SubAccount, error)
- func HoldingsExchangeCtx(next http.Handler) http.Handler
- func New(ctx context.Context)
- func PriceCtx(next http.Handler) http.Handler
- func TWAPCtx(next http.Handler) http.Handler
- func TradeCtx(next http.Handler) http.Handler
- func WithdrawCtx(next http.Handler) http.Handler
- type Asset
- type BTSEChainSelector
- type BinanceChainSelector
- type BittrexChainSelector
- type ChainSelector
- type CorsConfig
- type ErrResponse
- type ExchangeWithdrawResponse
- type FTXChainSelector
- type Handler
- type HuobiChainSelector
- type KrakenCHainSelector
- type OrderResponse
- type PriceResponse
- type Server
- type Status
- type WithdrawHistoryResponse
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = &ErrResponse{HTTPStatusCode: 404, StatusText: "Resource not found."}
var ErrWithdaw = &ErrResponse{HTTPStatusCode: 404, StatusText: "Failed to withdraw."}
Functions ¶
func AssetListCtx ¶
AssetListCtx fetches currencies from the exchange
func BalanceCtx ¶
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 DepositAddressCtx ¶
DepositAddressCtx is a function that returns a context with a depositResponse struct.
func ErrInvalidRequest ¶
func FetchPairsCtx ¶
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 ¶
HoldingsExchangeCtx middleware adds the holdings to the context
func TWAPCtx ¶
TWAPCtx is the context for the '/twap' request twap/{exchange}/{pair}/{qty}/{assetType}/{orderType}/{side}
func TradeCtx ¶
TradeCtx is the context for the '/trade' request. trade/{exchange}/{pair}/{qty}/{assetType}/{orderType}/{side}
func WithdrawCtx ¶
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 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 (*Server) SetupRoutes ¶
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 ¶
type WithdrawHistoryResponse ¶
type WithdrawHistoryResponse struct {
History []exchange.WithdrawalHistory `json:"history"`
}
func (WithdrawHistoryResponse) Render ¶
func (history WithdrawHistoryResponse) Render(w http.ResponseWriter, r *http.Request) error