mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
213 lines
8.5 KiB
Cheetah
213 lines
8.5 KiB
Cheetah
{{define "wrapper"}}
|
|
package {{.Name}}
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"github.com/thrasher-corp/gocryptotrader/common"
|
|
"github.com/thrasher-corp/gocryptotrader/currency/pair"
|
|
"github.com/thrasher-corp/gocryptotrader/exchanges"
|
|
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
|
|
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
|
|
log "github.com/thrasher-corp/gocryptotrader/logger"
|
|
)
|
|
|
|
// Start starts the {{.CapitalName}} go routine
|
|
func ({{.Variable}} *{{.CapitalName}}) Start(wg *sync.WaitGroup) {
|
|
wg.Add(1)
|
|
go func() {
|
|
{{.Variable}}.Run()
|
|
wg.Done()
|
|
}()
|
|
}
|
|
|
|
// Run implements the {{.CapitalName}} wrapper
|
|
func ({{.Variable}} *{{.CapitalName}}) Run() {
|
|
if {{.Variable}}.Verbose {
|
|
{{if .WS}} log.Debugf(log.ExchangeSys, "%s Websocket: %s. (url: %s).\n", {{.Variable}}.GetName(), common.IsEnabled({{.Variable}}.Websocket.IsEnabled()), {{.Variable}}.Websocket.GetWebsocketURL()) {{end}}
|
|
log.Debugf(log.ExchangeSys, "%s polling delay: %ds.\n", {{.Variable}}.GetName(), {{.Variable}}.RESTPollingDelay)
|
|
log.Debugf(log.ExchangeSys, "%s %d currencies enabled: %s.\n", {{.Variable}}.GetName(), len({{.Variable}}.EnabledPairs), {{.Variable}}.EnabledPairs)
|
|
}
|
|
}
|
|
|
|
// UpdateTicker updates and returns the ticker for a currency pair
|
|
func ({{.Variable}} *{{.CapitalName}}) UpdateTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
|
|
var tickerPrice ticker.Price
|
|
// NOTE EXAMPLE FOR GETTING TICKER PRICE
|
|
//tick, err := {{.Variable}}.GetTickers()
|
|
//if err != nil {
|
|
// return tickerPrice, err
|
|
//}
|
|
|
|
//for _, x := range {{.Variable}}.GetEnabledPairs(assetType) {
|
|
//curr := exchange.FormatExchangeCurrency({{.Variable}}.Name, x)
|
|
//for y := range tick {
|
|
// if tick[y].Symbol == curr.String() {
|
|
// tickerPrice.Pair = x
|
|
// tickerPrice.Ask = tick[y].AskPrice
|
|
// tickerPrice.Bid = tick[y].BidPrice
|
|
// tickerPrice.High = tick[y].HighPrice
|
|
// tickerPrice.Last = tick[y].LastPrice
|
|
// tickerPrice.Low = tick[y].LowPrice
|
|
// tickerPrice.Volume = tick[y].Volume
|
|
// ticker.ProcessTicker({{.Variable}}.Name, x, &tickerPrice, assetType)
|
|
// }
|
|
// }
|
|
//}
|
|
//return ticker.GetTicker({{.Variable}}.Name, p, assetType)
|
|
return tickerPrice, nil // NOTE DO NOT USE AS RETURN
|
|
}
|
|
|
|
// FetchTicker returns the ticker for a currency pair
|
|
func ({{.Variable}} *{{.CapitalName}}) FetchTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
|
|
tickerNew, err := ticker.GetTicker({{.Variable}}.GetName(), p, assetType)
|
|
if err != nil {
|
|
return {{.Variable}}.UpdateTicker(p, assetType)
|
|
}
|
|
return tickerNew, nil
|
|
}
|
|
|
|
// FetchOrderbook returns orderbook base on the currency pair
|
|
func ({{.Variable}} *{{.CapitalName}}) FetchOrderbook(currency currency.Pair, assetType asset.Item) (orderbook.Base, error) {
|
|
ob, err := orderbook.Get({{.Variable}}.GetName(), currency, assetType)
|
|
if err != nil {
|
|
return {{.Variable}}.UpdateOrderbook(currency, assetType)
|
|
}
|
|
return ob, nil
|
|
}
|
|
|
|
// UpdateOrderbook updates and returns the orderbook for a currency pair
|
|
func ({{.Variable}} *{{.CapitalName}}) UpdateOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
|
|
var orderBook orderbook.Base
|
|
//NOTE UPDATE ORDERBOOK EXAMPLE
|
|
//orderbookNew, err := {{.Variable}}.GetOrderBook(exchange.FormatExchangeCurrency({{.Variable}}.Name, p).String(), 1000)
|
|
//if err != nil {
|
|
// return orderBook, err
|
|
//}
|
|
|
|
//for _, bids := range orderbookNew.Bids {
|
|
// orderBook.Bids = append(orderBook.Bids, orderbook.Item{Amount: bids.Quantity, Price: bids.Price})
|
|
//}
|
|
|
|
//for _, asks := range orderbookNew.Asks {
|
|
// orderBook.Asks = append(orderBook.Asks, orderbook.Item{Amount: asks.Quantity, Price: asks.Price})
|
|
//}
|
|
|
|
//orderbook.ProcessOrderbook(b.GetName(), p, orderBook, assetType)
|
|
//return orderbook.Get({{.Variable}}.Name, p, assetType)
|
|
return orderBook, nil // NOTE DO NOT USE AS RETURN
|
|
}
|
|
|
|
// GetAccountInfo retrieves balances for all enabled currencies for the
|
|
// {{.CapitalName}} exchange
|
|
func ({{.Variable}} *{{.CapitalName}}) GetAccountInfo() (exchange.AccountInfo, error) {
|
|
return exchange.AccountInfo{}, common.ErrNotYetImplemented
|
|
}
|
|
|
|
// GetFundingHistory returns funding history, deposits and
|
|
// withdrawals
|
|
func ({{.Variable}} *{{.CapitalName}}) GetFundingHistory() ([]exchange.FundHistory, error) {
|
|
return nil, common.ErrNotYetImplemented
|
|
}
|
|
|
|
// GetExchangeHistory returns historic trade data since exchange opening.
|
|
func ({{.Variable}} *{{.CapitalName}}) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]exchange.TradeHistory, error) {
|
|
return nil, common.ErrNotYetImplemented
|
|
}
|
|
|
|
// SubmitOrder submits a new order
|
|
func ({{.Variable}} *{{.CapitalName}}) SubmitOrder(p currency.Pair, side order.Side, orderType order.Type, amount, price float64, clientID string) (order.SubmitResponse, error) {
|
|
return order.SubmitResponse{}, common.ErrNotYetImplemented
|
|
}
|
|
|
|
// ModifyOrder will allow of changing orderbook placement and limit to
|
|
// market conversion
|
|
func ({{.Variable}} *{{.CapitalName}}) ModifyOrder(action *order.Modify) (string, error) {
|
|
return "", common.ErrNotYetImplemented
|
|
}
|
|
|
|
// CancelOrder cancels an order by its corresponding ID number
|
|
func ({{.Variable}} *{{.CapitalName}}) CancelOrder(order *order.Cancel) error {
|
|
return common.ErrNotYetImplemented
|
|
}
|
|
|
|
// CancelAllOrders cancels all orders associated with a currency pair
|
|
func ({{.Variable}} *{{.CapitalName}}) CancelAllOrders(orderCancellation *order.Cancel) (order.CancelAllResponse, error) {
|
|
return order.CancelAllResponse{}, common.ErrNotYetImplemented
|
|
}
|
|
|
|
// GetOrderInfo returns information on a current open order
|
|
func ({{.Variable}} *{{.CapitalName}}) GetOrderInfo(orderID string) (order.Detail, error) {
|
|
return order.Detail{}, common.ErrNotYetImplemented
|
|
}
|
|
|
|
// GetDepositAddress returns a deposit address for a specified currency
|
|
func ({{.Variable}} *{{.CapitalName}}) GetDepositAddress(cryptocurrency pair.CurrencyItem, accountID string) (string, error) {
|
|
return "", common.ErrNotYetImplemented
|
|
}
|
|
|
|
// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is
|
|
// submitted
|
|
func ({{.Variable}} *{{.CapitalName}}) WithdrawCryptocurrencyFunds(withdrawRequest *exchange.WithdrawRequest) (string, error) {
|
|
return "", common.ErrNotYetImplemented
|
|
}
|
|
|
|
// WithdrawFiatFunds returns a withdrawal ID when a withdrawal is
|
|
// submitted
|
|
func ({{.Variable}} *{{.CapitalName}}) WithdrawFiatFunds(withdrawRequest *exchange.WithdrawRequest) (string, error) {
|
|
return "", common.ErrNotYetImplemented
|
|
}
|
|
|
|
// WithdrawFiatFundsToInternationalBank returns a withdrawal ID when a withdrawal is
|
|
// submitted
|
|
func ({{.Variable}} *{{.CapitalName}}) WithdrawFiatFundsToInternationalBank(withdrawRequest *exchange.WithdrawRequest) (string, error) {
|
|
return "", common.ErrNotYetImplemented
|
|
}
|
|
|
|
// GetWebsocket returns a pointer to the exchange websocket
|
|
func ({{.Variable}} *{{.CapitalName}}) GetWebsocket() (*exchange.Websocket, error) {
|
|
return nil, common.ErrNotYetImplemented
|
|
}
|
|
|
|
// GetActiveOrders retrieves any orders that are active/open
|
|
func ({{.Variable}} *{{.CapitalName}}) GetActiveOrders(getOrdersRequest *order.GetOrdersRequest) ([]order.Detail, error) {
|
|
return nil, common.ErrNotYetImplemented
|
|
}
|
|
|
|
// GetOrderHistory retrieves account order information
|
|
// Can Limit response to specific order status
|
|
func ({{.Variable}} *{{.CapitalName}}) GetOrderHistory(getOrdersRequest *order.GetOrdersRequest) ([]order.Detail, error) {
|
|
return nil, common.ErrNotYetImplemented
|
|
}
|
|
|
|
// GetFeeByType returns an estimate of fee based on the type of transaction
|
|
func ({{.Variable}} *{{.CapitalName}}) GetFeeByType(feeBuilder *exchange.FeeBuilder) (float64, error) {
|
|
return 0, common.ErrNotYetImplemented
|
|
}
|
|
|
|
// SubscribeToWebsocketChannels appends to ChannelsToSubscribe
|
|
// which lets websocket.manageSubscriptions handle subscribing
|
|
func ({{.Variable}} *{{.CapitalName}}) SubscribeToWebsocketChannels(channels []monitor.WebsocketChannelSubscription) error {
|
|
{{.Variable}}.Websocket.SubscribeToChannels(channels)
|
|
return nil
|
|
}
|
|
|
|
// UnsubscribeToWebsocketChannels removes from ChannelsToSubscribe
|
|
// which lets websocket.manageSubscriptions handle unsubscribing
|
|
func ({{.Variable}} *{{.CapitalName}}) UnsubscribeToWebsocketChannels(channels []monitor.WebsocketChannelSubscription) error {
|
|
{{.Variable}}.Websocket.UnubscribeToChannels(channels)
|
|
return nil
|
|
}
|
|
|
|
// GetSubscriptions returns a copied list of subscriptions
|
|
func ({{.Variable}} *{{.CapitalName}}) GetSubscriptions() ([]monitor.WebsocketChannelSubscription, error) {
|
|
return nil, common.ErrNotYetImplemented
|
|
}
|
|
|
|
// AuthenticateWebsocket sends an authentication message to the websocket
|
|
func ({{.Variable}} *{{.CapitalName}}) AuthenticateWebsocket() error {
|
|
return common.ErrNotYetImplemented
|
|
}
|
|
|
|
{{end}}
|