mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-30 07:26:46 +00:00
GCT: general updates across codebase (#699)
* orderbook: export orderbook nodes for external strategy inspection * orderbook: Add in methods for locking and unlocking multiple books at the same time e.g. book1.LockWith(book2); defer book1.UnlockWith(book2) * include waiting functionality for depth change alert * backtester: add word. * log: include logger changes to impl with downstream integration * engine: reduce params for loading exchange * assort: rm verbose in tests, change wording in ob, expose sync.waitgroup for ext. sync options * ticker: reduce map look ups and contention when using RW mutex when there are over 80% writes adds find last function to get the latest rate * engine/syncmanager: add in waitgroup for step over for external package calls * cleaup * engine: linter fix * currency/fx: include all references to fiat currencies to default * orderbook: Add in fields to Unsafe type for strategies to detect potential out of sync book operations * syncmanager: changed config variable to display correct time * ordermanager: Add time when none provided * currency/manager: update getasset param to get enabled assets for minor optimizations * ftx: use get all wallet balances for a better accounts breakdown * orderbook: unlock in reverse order * bithumb: fixes bug on market buy and sell orders * bithumb: fix bug for nonce is also time window sensitive * bithumb: get orders add required parameter * bithumb: Add asset type to account struct * currency: improve log output when checking currency and it fails * bithumb: Add error return on incomplete pair * ticker:unexport all service related methods * ticker/currency: fixes * orderbook: fix comment * engine: revert variable name in LoadExchange method * sync_manager: fix panic when enabling disabling manager * engine: fix naming convention of exported function and comments * engine: update comment * orderbook: fix comment for unsafe type
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
@@ -262,8 +263,14 @@ func (b *Bithumb) GetLastTransaction() (LastTransactionTicker, error) {
|
||||
// (2014-11-28 16:40:01 = 1417160401000)
|
||||
func (b *Bithumb) GetOrders(orderID, transactionType, count, after, currency string) (Orders, error) {
|
||||
response := Orders{}
|
||||
|
||||
params := url.Values{}
|
||||
|
||||
if currency == "" {
|
||||
return response, errors.New("order currency is required")
|
||||
}
|
||||
|
||||
params.Set("order_currency", strings.ToUpper(currency))
|
||||
|
||||
if len(orderID) > 0 {
|
||||
params.Set("order_id", orderID)
|
||||
}
|
||||
@@ -280,10 +287,6 @@ func (b *Bithumb) GetOrders(orderID, transactionType, count, after, currency str
|
||||
params.Set("after", after)
|
||||
}
|
||||
|
||||
if len(currency) > 0 {
|
||||
params.Set("currency", strings.ToUpper(currency))
|
||||
}
|
||||
|
||||
return response,
|
||||
b.SendAuthenticatedHTTPRequest(exchange.RestSpot, privateOrders, params, &response)
|
||||
}
|
||||
@@ -422,11 +425,12 @@ func (b *Bithumb) RequestKRWWithdraw(bank, account string, price int64) (ActionS
|
||||
// currency: BTC, ETH, DASH, LTC, ETC, XRP, BCH, XMR, ZEC, QTUM, BTG, EOS
|
||||
// (default value: BTC)
|
||||
// units: Order quantity
|
||||
func (b *Bithumb) MarketBuyOrder(currency string, units float64) (MarketBuy, error) {
|
||||
func (b *Bithumb) MarketBuyOrder(pair currency.Pair, units float64) (MarketBuy, error) {
|
||||
response := MarketBuy{}
|
||||
|
||||
params := url.Values{}
|
||||
params.Set("currency", strings.ToUpper(currency))
|
||||
params.Set("order_currency", strings.ToUpper(pair.Base.String()))
|
||||
params.Set("payment_currency", strings.ToUpper(pair.Quote.String()))
|
||||
params.Set("units", strconv.FormatFloat(units, 'f', -1, 64))
|
||||
|
||||
return response,
|
||||
@@ -438,11 +442,12 @@ func (b *Bithumb) MarketBuyOrder(currency string, units float64) (MarketBuy, err
|
||||
// currency: BTC, ETH, DASH, LTC, ETC, XRP, BCH, XMR, ZEC, QTUM, BTG, EOS
|
||||
// (default value: BTC)
|
||||
// units: Order quantity
|
||||
func (b *Bithumb) MarketSellOrder(currency string, units float64) (MarketSell, error) {
|
||||
func (b *Bithumb) MarketSellOrder(pair currency.Pair, units float64) (MarketSell, error) {
|
||||
response := MarketSell{}
|
||||
|
||||
params := url.Values{}
|
||||
params.Set("currency", strings.ToUpper(currency))
|
||||
params.Set("order_currency", strings.ToUpper(pair.Base.String()))
|
||||
params.Set("payment_currency", strings.ToUpper(pair.Quote.String()))
|
||||
params.Set("units", strconv.FormatFloat(units, 'f', -1, 64))
|
||||
|
||||
return response,
|
||||
@@ -478,7 +483,9 @@ func (b *Bithumb) SendAuthenticatedHTTPRequest(ep exchange.URL, path string, par
|
||||
params = url.Values{}
|
||||
}
|
||||
|
||||
n := b.Requester.GetNonceMilli().String()
|
||||
// This is time window sensitive
|
||||
tnMS := time.Now().UnixNano() / int64(time.Millisecond)
|
||||
n := strconv.FormatInt(tnMS, 10)
|
||||
|
||||
params.Set("endpoint", path)
|
||||
payload := params.Encode()
|
||||
|
||||
@@ -211,7 +211,8 @@ func TestRequestKRWWithdraw(t *testing.T) {
|
||||
|
||||
func TestMarketBuyOrder(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.MarketBuyOrder(testCurrency, 0)
|
||||
p := currency.NewPair(currency.BTC, currency.KRW)
|
||||
_, err := b.MarketBuyOrder(p, 0)
|
||||
if err == nil {
|
||||
t.Error("Bithumb MarketBuyOrder() Expected error")
|
||||
}
|
||||
@@ -219,7 +220,8 @@ func TestMarketBuyOrder(t *testing.T) {
|
||||
|
||||
func TestMarketSellOrder(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.MarketSellOrder(testCurrency, 0)
|
||||
p := currency.NewPair(currency.BTC, currency.KRW)
|
||||
_, err := b.MarketSellOrder(p, 0)
|
||||
if err == nil {
|
||||
t.Error("Bithumb MarketSellOrder() Expected error")
|
||||
}
|
||||
|
||||
@@ -26,6 +26,8 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
var errNotEnoughPairs = errors.New("at least one currency is required to fetch order history")
|
||||
|
||||
// GetDefaultConfig returns a default exchange config
|
||||
func (b *Bithumb) GetDefaultConfig() (*config.ExchangeConfig, error) {
|
||||
b.SetDefaults()
|
||||
@@ -307,6 +309,7 @@ func (b *Bithumb) UpdateAccountInfo(assetType asset.Item) (account.Holdings, err
|
||||
|
||||
info.Accounts = append(info.Accounts, account.SubAccount{
|
||||
Currencies: exchangeBalances,
|
||||
AssetType: assetType,
|
||||
})
|
||||
|
||||
info.Exchange = b.Name
|
||||
@@ -403,14 +406,14 @@ func (b *Bithumb) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
|
||||
var orderID string
|
||||
if s.Side == order.Buy {
|
||||
var result MarketBuy
|
||||
result, err = b.MarketBuyOrder(fPair.Base.String(), s.Amount)
|
||||
result, err = b.MarketBuyOrder(fPair, s.Amount)
|
||||
if err != nil {
|
||||
return submitOrderResponse, err
|
||||
}
|
||||
orderID = result.OrderID
|
||||
} else if s.Side == order.Sell {
|
||||
var result MarketSell
|
||||
result, err = b.MarketSellOrder(fPair.Base.String(), s.Amount)
|
||||
result, err = b.MarketSellOrder(fPair, s.Amount)
|
||||
if err != nil {
|
||||
return submitOrderResponse, err
|
||||
}
|
||||
@@ -583,43 +586,50 @@ func (b *Bithumb) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail,
|
||||
if err := req.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(req.Pairs) == 0 {
|
||||
return nil, errNotEnoughPairs
|
||||
}
|
||||
|
||||
format, err := b.GetPairFormat(req.AssetType, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var orders []order.Detail
|
||||
resp, err := b.GetOrders("", "", "1000", "", "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
format, err := b.GetPairFormat(asset.Spot, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for i := range resp.Data {
|
||||
if resp.Data[i].Status != "placed" {
|
||||
continue
|
||||
for x := range req.Pairs {
|
||||
resp, err := b.GetOrders("", "", "1000", "", req.Pairs[x].Base.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
orderDate := time.Unix(resp.Data[i].OrderDate, 0)
|
||||
orderDetail := order.Detail{
|
||||
Amount: resp.Data[i].Units,
|
||||
Exchange: b.Name,
|
||||
ID: resp.Data[i].OrderID,
|
||||
Date: orderDate,
|
||||
Price: resp.Data[i].Price,
|
||||
RemainingAmount: resp.Data[i].UnitsRemaining,
|
||||
Status: order.Active,
|
||||
Pair: currency.NewPairWithDelimiter(resp.Data[i].OrderCurrency,
|
||||
resp.Data[i].PaymentCurrency,
|
||||
format.Delimiter),
|
||||
}
|
||||
for i := range resp.Data {
|
||||
if resp.Data[i].Status != "placed" {
|
||||
continue
|
||||
}
|
||||
|
||||
if resp.Data[i].Type == "bid" {
|
||||
orderDetail.Side = order.Buy
|
||||
} else if resp.Data[i].Type == "ask" {
|
||||
orderDetail.Side = order.Sell
|
||||
}
|
||||
orderDate := time.Unix(resp.Data[i].OrderDate, 0)
|
||||
orderDetail := order.Detail{
|
||||
Amount: resp.Data[i].Units,
|
||||
Exchange: b.Name,
|
||||
ID: resp.Data[i].OrderID,
|
||||
Date: orderDate,
|
||||
Price: resp.Data[i].Price,
|
||||
RemainingAmount: resp.Data[i].UnitsRemaining,
|
||||
Status: order.Active,
|
||||
Pair: currency.NewPairWithDelimiter(resp.Data[i].OrderCurrency,
|
||||
resp.Data[i].PaymentCurrency,
|
||||
format.Delimiter),
|
||||
}
|
||||
|
||||
orders = append(orders, orderDetail)
|
||||
if resp.Data[i].Type == "bid" {
|
||||
orderDetail.Side = order.Buy
|
||||
} else if resp.Data[i].Type == "ask" {
|
||||
orderDetail.Side = order.Sell
|
||||
}
|
||||
|
||||
orders = append(orders, orderDetail)
|
||||
}
|
||||
}
|
||||
|
||||
order.FilterOrdersBySide(&orders, req.Side)
|
||||
@@ -635,42 +645,48 @@ func (b *Bithumb) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(req.Pairs) == 0 {
|
||||
return nil, errNotEnoughPairs
|
||||
}
|
||||
|
||||
format, err := b.GetPairFormat(req.AssetType, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var orders []order.Detail
|
||||
resp, err := b.GetOrders("", "", "1000", "", "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
format, err := b.GetPairFormat(asset.Spot, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for i := range resp.Data {
|
||||
if resp.Data[i].Status == "placed" {
|
||||
continue
|
||||
for x := range req.Pairs {
|
||||
resp, err := b.GetOrders("", "", "1000", "", req.Pairs[x].Base.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
orderDate := time.Unix(resp.Data[i].OrderDate, 0)
|
||||
orderDetail := order.Detail{
|
||||
Amount: resp.Data[i].Units,
|
||||
Exchange: b.Name,
|
||||
ID: resp.Data[i].OrderID,
|
||||
Date: orderDate,
|
||||
Price: resp.Data[i].Price,
|
||||
RemainingAmount: resp.Data[i].UnitsRemaining,
|
||||
Pair: currency.NewPairWithDelimiter(resp.Data[i].OrderCurrency,
|
||||
resp.Data[i].PaymentCurrency,
|
||||
format.Delimiter),
|
||||
}
|
||||
for i := range resp.Data {
|
||||
if resp.Data[i].Status == "placed" {
|
||||
continue
|
||||
}
|
||||
|
||||
if resp.Data[i].Type == "bid" {
|
||||
orderDetail.Side = order.Buy
|
||||
} else if resp.Data[i].Type == "ask" {
|
||||
orderDetail.Side = order.Sell
|
||||
}
|
||||
orderDate := time.Unix(resp.Data[i].OrderDate, 0)
|
||||
orderDetail := order.Detail{
|
||||
Amount: resp.Data[i].Units,
|
||||
Exchange: b.Name,
|
||||
ID: resp.Data[i].OrderID,
|
||||
Date: orderDate,
|
||||
Price: resp.Data[i].Price,
|
||||
RemainingAmount: resp.Data[i].UnitsRemaining,
|
||||
Pair: currency.NewPairWithDelimiter(resp.Data[i].OrderCurrency,
|
||||
resp.Data[i].PaymentCurrency,
|
||||
format.Delimiter),
|
||||
}
|
||||
|
||||
orders = append(orders, orderDetail)
|
||||
if resp.Data[i].Type == "bid" {
|
||||
orderDetail.Side = order.Buy
|
||||
} else if resp.Data[i].Type == "ask" {
|
||||
orderDetail.Side = order.Sell
|
||||
}
|
||||
|
||||
orders = append(orders, orderDetail)
|
||||
}
|
||||
}
|
||||
|
||||
order.FilterOrdersBySide(&orders, req.Side)
|
||||
|
||||
Reference in New Issue
Block a user