mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-16 15:09:57 +00:00
* Added new base logger * updated example and test configs * updated exchange helpers restful router & server * logPath is now passed to the logger to remove dependency on common package * updated everything besides exchanges to use new logger * alphapoint to bitmex done * updated bitmex bitstamp bittrex btcc and also performance changes to logger * btcmarkets coinbase coinut exmo gateio wrappers updated * gateio and gemini logger updated * hitbtc huobi itbit & kraken updated * All exchanges updatd * return correct error for disabled websocket * don't disconnect client on invalid json * updated router internal logging * log.Fatal to t.Error for tests * Changed from fatal to error failure to set maxprocs * output ANSI codes for everything but windows for now due to lack of windows support * added error handling to logger and unit tests * clear wording on print -> log.print * added benchmark test * cleaned up import sections * Updated logger based on PR requests (added default config options on failure/setting errors) * ah this should fix travici enc config issue * Load entire config and clear out logging to hopefully fix travisci issue * wording & test error handling * fixed formatting issues based on feedback * fixed formatting issues based on feedback * changed CheckDir to use mkdirall instead of mkdir and other changes based on feedback
179 lines
6.9 KiB
Cheetah
179 lines
6.9 KiB
Cheetah
{{define "wrapper"}}
|
|
package {{.Name}}
|
|
|
|
import (
|
|
"errors"
|
|
"sync"
|
|
|
|
{{if .WS}} "github.com/thrasher-/gocryptotrader/common" {{end}}
|
|
"github.com/thrasher-/gocryptotrader/currency/pair"
|
|
"github.com/thrasher-/gocryptotrader/exchanges"
|
|
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
|
log "github.com/thrasher-/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("%s Websocket: %s. (url: %s).\n", {{.Variable}}.GetName(), common.IsEnabled({{.Variable}}.Websocket.IsEnabled()), {{.Variable}}.Websocket.GetWebsocketURL()) {{end}}
|
|
log.Debugf("%s polling delay: %ds.\n", {{.Variable}}.GetName(), {{.Variable}}.RESTPollingDelay)
|
|
log.Debugf("%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 pair.CurrencyPair, assetType string) (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}}.GetEnabledCurrencies() {
|
|
//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
|
|
}
|
|
|
|
// GetTickerPrice returns the ticker for a currency pair
|
|
func ({{.Variable}} *{{.CapitalName}}) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
|
|
tickerNew, err := ticker.GetTicker({{.Variable}}.GetName(), p, assetType)
|
|
if err != nil {
|
|
return {{.Variable}}.UpdateTicker(p, assetType)
|
|
}
|
|
return tickerNew, nil
|
|
}
|
|
|
|
// GetOrderbookEx returns orderbook base on the currency pair
|
|
func ({{.Variable}} *{{.CapitalName}}) GetOrderbookEx(currency pair.CurrencyPair, assetType string) (orderbook.Base, error) {
|
|
ob, err := orderbook.GetOrderbook({{.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 pair.CurrencyPair, assetType string) (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.GetOrderbook({{.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) {
|
|
var response exchange.AccountInfo
|
|
return response, errors.New("not implemented")
|
|
}
|
|
|
|
// GetFundingHistory returns funding history, deposits and
|
|
// withdrawals
|
|
func ({{.Variable}} *{{.CapitalName}}) GetFundingHistory() ([]exchange.FundHistory, error) {
|
|
var fundHistory []exchange.FundHistory
|
|
return fundHistory, common.ErrFunctionNotSupported
|
|
}
|
|
|
|
// GetExchangeHistory returns historic trade data since exchange opening.
|
|
func ({{.Variable}} *{{.CapitalName}}) GetExchangeHistory(p pair.CurrencyPair, assetType string) ([]exchange.TradeHistory, error) {
|
|
var resp []exchange.TradeHistory
|
|
|
|
return resp, common.ErrNotYetImplemented
|
|
}
|
|
|
|
// SubmitOrder submits a new order
|
|
func ({{.Variable}} *{{.CapitalName}}) SubmitOrder(p pair.CurrencyPair, side exchange.OrderSide, orderType exchange.OrderType, amount, price float64, clientID string) (exchange.SubmitOrderResponse, error) {
|
|
return "", common.ErrNotYetImplemented
|
|
}
|
|
|
|
// ModifyOrder will allow of changing orderbook placement and limit to
|
|
// market conversion
|
|
func ({{.Variable}} *{{.CapitalName}}) ModifyOrder(action exchange.ModifyOrder) (string, error) {
|
|
return "", common.ErrNotYetImplemented
|
|
}
|
|
|
|
// CancelOrder cancels an order by its corresponding ID number
|
|
func ({{.Variable}} *{{.CapitalName}}) CancelOrder(order exchange.OrderCancellation) error {
|
|
return common.ErrNotYetImplemented
|
|
}
|
|
|
|
// CancelAllOrders cancels all orders associated with a currency pair
|
|
func ({{.Variable}} *{{.CapitalName}}) CancelAllOrders(orderCancellation exchange.OrderCancellation) (exchange.CancelAllOrdersResponse, error) {
|
|
return common.ErrNotYetImplemented
|
|
}
|
|
|
|
// GetOrderInfo returns information on a current open order
|
|
func ({{.Variable}} *{{.CapitalName}}) GetOrderInfo(orderID int64) (exchange.OrderDetail, error) {
|
|
var orderDetail exchange.OrderDetail
|
|
return orderDetail, common.ErrNotYetImplemented
|
|
}
|
|
|
|
// GetDepositAddress returns a deposit address for a specified currency
|
|
func ({{.Variable}} *{{.CapitalName}}) GetDepositAddress(cryptocurrency pair.CurrencyItem) (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
|
|
}
|
|
|
|
{{end}}
|