mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-08 23:16:54 +00:00
Miscellaneous bug fixes (#513)
* Various bug fixes * Deadlink, cleanup plus bug fixes * Various Kraken fixes * Add convert func for decimal unix timestamps * Convert all test times to UTC * Kraken: Make assets a pointer to prevent excessive copying * Docker slash fix * Address nits plus bump ITBit last checked pairs timestamp * Set pairs to enabled pairs when getting active orders * Use asset translator for UpdateAccountInfo and more checks for the exchange template tool * Address MadCozBadd's nits * Make exchange var 2 chars * Make program more user friendly * Project wide comment checks and exchName check * Fix Huobi indexing bug and use correct pair formatting * Address nits + readme change
This commit is contained in:
@@ -42,8 +42,6 @@ const (
|
||||
coinbaseproReports = "reports"
|
||||
coinbaseproTime = "time"
|
||||
coinbaseproMarginTransfer = "profiles/margin-transfer"
|
||||
coinbaseproFunding = "funding"
|
||||
coinbaseproFundingRepay = "funding/repay"
|
||||
coinbaseproPosition = "position"
|
||||
coinbaseproPositionClose = "position/close"
|
||||
coinbaseproPaymentMethod = "payment-methods"
|
||||
@@ -490,37 +488,6 @@ func (c *CoinbasePro) GetFills(orderID, currencyPair string) ([]FillResponse, er
|
||||
c.SendAuthenticatedHTTPRequest(http.MethodGet, uri[1:], nil, &resp)
|
||||
}
|
||||
|
||||
// GetFundingRecords every order placed with a margin profile that draws funding
|
||||
// will create a funding record.
|
||||
//
|
||||
// status - "outstanding", "settled", or "rejected"
|
||||
func (c *CoinbasePro) GetFundingRecords(status string) ([]Funding, error) {
|
||||
var resp []Funding
|
||||
params := url.Values{}
|
||||
params.Set("status", status)
|
||||
|
||||
path := common.EncodeURLValues(c.API.Endpoints.URL+coinbaseproFunding, params)
|
||||
uri := common.GetURIPath(path)
|
||||
|
||||
return resp,
|
||||
c.SendAuthenticatedHTTPRequest(http.MethodGet, uri[1:], nil, &resp)
|
||||
}
|
||||
|
||||
// //////////////////////// Not receiving reply from server /////////////////
|
||||
// RepayFunding repays the older funding records first
|
||||
//
|
||||
// amount - amount of currency to repay
|
||||
// currency - currency, example USD
|
||||
// func (c *CoinbasePro) RepayFunding(amount, currency string) (Funding, error) {
|
||||
// resp := Funding{}
|
||||
// params := make(map[string]interface{})
|
||||
// params["amount"] = amount
|
||||
// params["currency"] = currency
|
||||
//
|
||||
// return resp,
|
||||
// c.SendAuthenticatedHTTPRequest(http.MethodPost, coinbaseproFundingRepay, params, &resp)
|
||||
// }
|
||||
|
||||
// MarginTransfer sends funds between a standard/default profile and a margin
|
||||
// profile.
|
||||
// A deposit will transfer funds from the default profile into the margin
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/thrasher-corp/gocryptotrader/common/convert"
|
||||
"github.com/thrasher-corp/gocryptotrader/config"
|
||||
"github.com/thrasher-corp/gocryptotrader/core"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
@@ -165,10 +166,6 @@ func TestAuthRequests(t *testing.T) {
|
||||
if err == nil {
|
||||
t.Error("Expecting error")
|
||||
}
|
||||
_, err = c.GetFundingRecords("rejected")
|
||||
if err == nil {
|
||||
t.Error("Expecting error")
|
||||
}
|
||||
marginTransferResponse, err := c.MarginTransfer(1, "withdraw", "13371337-1337-1337-1337-133713371337", "BTC")
|
||||
if marginTransferResponse.ID != "" {
|
||||
t.Error("Expecting no data returned")
|
||||
@@ -925,3 +922,17 @@ func TestStatusToStandardStatus(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseTime(t *testing.T) {
|
||||
// Rest examples use 2014-11-07T22:19:28.578544Z" and can be safely
|
||||
// unmarhsalled into time.Time
|
||||
|
||||
// All events except for activate use the above, in the below test
|
||||
// we'll use their API docs example
|
||||
r := convert.TimeFromUnixTimestampDecimal(1483736448.299000).UTC()
|
||||
if r.Year() != 2017 ||
|
||||
r.Month().String() != "January" ||
|
||||
r.Day() != 6 {
|
||||
t.Error("unexpected result")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,11 +30,11 @@ type Ticker struct {
|
||||
|
||||
// Trade holds executed trade information
|
||||
type Trade struct {
|
||||
TradeID int64 `json:"trade_id"`
|
||||
Price float64 `json:"price,string"`
|
||||
Size float64 `json:"size,string"`
|
||||
Time string `json:"time"`
|
||||
Side string `json:"side"`
|
||||
TradeID int64 `json:"trade_id"`
|
||||
Price float64 `json:"price,string"`
|
||||
Size float64 `json:"size,string"`
|
||||
Time time.Time `json:"time"`
|
||||
Side string `json:"side"`
|
||||
}
|
||||
|
||||
// History holds historic rate information
|
||||
@@ -49,10 +49,12 @@ type History struct {
|
||||
|
||||
// Stats holds last 24 hr data for coinbasepro
|
||||
type Stats struct {
|
||||
Open float64 `json:"open,string"`
|
||||
High float64 `json:"high,string"`
|
||||
Low float64 `json:"low,string"`
|
||||
Volume float64 `json:"volume,string"`
|
||||
Open float64 `json:"open,string"`
|
||||
High float64 `json:"high,string"`
|
||||
Low float64 `json:"low,string"`
|
||||
Volume float64 `json:"volume,string"`
|
||||
Last float64 `json:"last,string"`
|
||||
Volume30Day float64 `json:"volume_30day,string"`
|
||||
}
|
||||
|
||||
// Currency holds singular currency product information
|
||||
@@ -64,8 +66,8 @@ type Currency struct {
|
||||
|
||||
// ServerTime holds current requested server time information
|
||||
type ServerTime struct {
|
||||
ISO string `json:"iso"`
|
||||
Epoch float64 `json:"epoch"`
|
||||
ISO time.Time `json:"iso"`
|
||||
Epoch float64 `json:"epoch"`
|
||||
}
|
||||
|
||||
// AccountResponse holds the details for the trading accounts
|
||||
@@ -84,7 +86,7 @@ type AccountResponse struct {
|
||||
// AccountLedgerResponse holds account history information
|
||||
type AccountLedgerResponse struct {
|
||||
ID string `json:"id"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
Amount float64 `json:"amount,string"`
|
||||
Balance float64 `json:"balance,string"`
|
||||
Type string `json:"type"`
|
||||
@@ -93,68 +95,68 @@ type AccountLedgerResponse struct {
|
||||
|
||||
// AccountHolds contains the hold information about an account
|
||||
type AccountHolds struct {
|
||||
ID string `json:"id"`
|
||||
AccountID string `json:"account_id"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
UpdatedAt string `json:"updated_at"`
|
||||
Amount float64 `json:"amount,string"`
|
||||
Type string `json:"type"`
|
||||
Reference string `json:"ref"`
|
||||
ID string `json:"id"`
|
||||
AccountID string `json:"account_id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt string `json:"updated_at"`
|
||||
Amount float64 `json:"amount,string"`
|
||||
Type string `json:"type"`
|
||||
Reference string `json:"ref"`
|
||||
}
|
||||
|
||||
// GeneralizedOrderResponse is the generalized return type across order
|
||||
// placement and information collation
|
||||
type GeneralizedOrderResponse struct {
|
||||
ID string `json:"id"`
|
||||
Price float64 `json:"price,string"`
|
||||
Size float64 `json:"size,string"`
|
||||
ProductID string `json:"product_id"`
|
||||
Side string `json:"side"`
|
||||
Stp string `json:"stp"`
|
||||
Type string `json:"type"`
|
||||
TimeInForce string `json:"time_in_force"`
|
||||
PostOnly bool `json:"post_only"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
FillFees float64 `json:"fill_fees,string"`
|
||||
FilledSize float64 `json:"filled_size,string"`
|
||||
ExecutedValue float64 `json:"executed_value,string"`
|
||||
Status string `json:"status"`
|
||||
Settled bool `json:"settled"`
|
||||
Funds float64 `json:"funds,string"`
|
||||
SpecifiedFunds float64 `json:"specified_funds,string"`
|
||||
DoneReason string `json:"done_reason"`
|
||||
DoneAt string `json:"done_at"`
|
||||
ID string `json:"id"`
|
||||
Price float64 `json:"price,string"`
|
||||
Size float64 `json:"size,string"`
|
||||
ProductID string `json:"product_id"`
|
||||
Side string `json:"side"`
|
||||
Stp string `json:"stp"`
|
||||
Type string `json:"type"`
|
||||
TimeInForce string `json:"time_in_force"`
|
||||
PostOnly bool `json:"post_only"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
FillFees float64 `json:"fill_fees,string"`
|
||||
FilledSize float64 `json:"filled_size,string"`
|
||||
ExecutedValue float64 `json:"executed_value,string"`
|
||||
Status string `json:"status"`
|
||||
Settled bool `json:"settled"`
|
||||
Funds float64 `json:"funds,string"`
|
||||
SpecifiedFunds float64 `json:"specified_funds,string"`
|
||||
DoneReason string `json:"done_reason"`
|
||||
DoneAt string `json:"done_at"`
|
||||
}
|
||||
|
||||
// Funding holds funding data
|
||||
type Funding struct {
|
||||
ID string `json:"id"`
|
||||
OrderID string `json:"order_id"`
|
||||
ProfileID string `json:"profile_id"`
|
||||
Amount float64 `json:"amount,string"`
|
||||
Status string `json:"status"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
Currency string `json:"currency"`
|
||||
RepaidAmount float64 `json:"repaid_amount"`
|
||||
DefaultAmount float64 `json:"default_amount,string"`
|
||||
RepaidDefault bool `json:"repaid_default"`
|
||||
ID string `json:"id"`
|
||||
OrderID string `json:"order_id"`
|
||||
ProfileID string `json:"profile_id"`
|
||||
Amount float64 `json:"amount,string"`
|
||||
Status string `json:"status"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
Currency string `json:"currency"`
|
||||
RepaidAmount float64 `json:"repaid_amount"`
|
||||
DefaultAmount float64 `json:"default_amount,string"`
|
||||
RepaidDefault bool `json:"repaid_default"`
|
||||
}
|
||||
|
||||
// MarginTransfer holds margin transfer details
|
||||
type MarginTransfer struct {
|
||||
CreatedAt string `json:"created_at"`
|
||||
ID string `json:"id"`
|
||||
UserID string `json:"user_id"`
|
||||
ProfileID string `json:"profile_id"`
|
||||
MarginProfileID string `json:"margin_profile_id"`
|
||||
Type string `json:"type"`
|
||||
Amount float64 `json:"amount,string"`
|
||||
Currency string `json:"currency"`
|
||||
AccountID string `json:"account_id"`
|
||||
MarginAccountID string `json:"margin_account_id"`
|
||||
MarginProductID string `json:"margin_product_id"`
|
||||
Status string `json:"status"`
|
||||
Nonce int `json:"nonce"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
ID string `json:"id"`
|
||||
UserID string `json:"user_id"`
|
||||
ProfileID string `json:"profile_id"`
|
||||
MarginProfileID string `json:"margin_profile_id"`
|
||||
Type string `json:"type"`
|
||||
Amount float64 `json:"amount,string"`
|
||||
Currency string `json:"currency"`
|
||||
AccountID string `json:"account_id"`
|
||||
MarginAccountID string `json:"margin_account_id"`
|
||||
MarginProductID string `json:"margin_product_id"`
|
||||
Status string `json:"status"`
|
||||
Nonce int `json:"nonce"`
|
||||
}
|
||||
|
||||
// AccountOverview holds account information returned from position
|
||||
@@ -164,12 +166,12 @@ type AccountOverview struct {
|
||||
MaxFundingValue float64 `json:"max_funding_value,string"`
|
||||
FundingValue float64 `json:"funding_value,string"`
|
||||
OldestOutstanding struct {
|
||||
ID string `json:"id"`
|
||||
OrderID string `json:"order_id"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
Currency string `json:"currency"`
|
||||
AccountID string `json:"account_id"`
|
||||
Amount float64 `json:"amount,string"`
|
||||
ID string `json:"id"`
|
||||
OrderID string `json:"order_id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
Currency string `json:"currency"`
|
||||
AccountID string `json:"account_id"`
|
||||
Amount float64 `json:"amount,string"`
|
||||
} `json:"oldest_outstanding"`
|
||||
} `json:"funding"`
|
||||
Accounts struct {
|
||||
@@ -236,10 +238,10 @@ type LimitInfo struct {
|
||||
|
||||
// DepositWithdrawalInfo holds returned deposit information
|
||||
type DepositWithdrawalInfo struct {
|
||||
ID string `json:"id"`
|
||||
Amount float64 `json:"amount,string"`
|
||||
Currency string `json:"currency"`
|
||||
PayoutAt string `json:"payout_at"`
|
||||
ID string `json:"id"`
|
||||
Amount float64 `json:"amount,string"`
|
||||
Currency string `json:"currency"`
|
||||
PayoutAt time.Time `json:"payout_at"`
|
||||
}
|
||||
|
||||
// CoinbaseAccounts holds coinbase account information
|
||||
@@ -278,16 +280,16 @@ type CoinbaseAccounts struct {
|
||||
|
||||
// Report holds historical information
|
||||
type Report struct {
|
||||
ID string `json:"id"`
|
||||
Type string `json:"type"`
|
||||
Status string `json:"status"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
CompletedAt string `json:"completed_at"`
|
||||
ExpiresAt string `json:"expires_at"`
|
||||
FileURL string `json:"file_url"`
|
||||
ID string `json:"id"`
|
||||
Type string `json:"type"`
|
||||
Status string `json:"status"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
CompletedAt time.Time `json:"completed_at"`
|
||||
ExpiresAt time.Time `json:"expires_at"`
|
||||
FileURL string `json:"file_url"`
|
||||
Params struct {
|
||||
StartDate string `json:"start_date"`
|
||||
EndDate string `json:"end_date"`
|
||||
StartDate time.Time `json:"start_date"`
|
||||
EndDate time.Time `json:"end_date"`
|
||||
} `json:"params"`
|
||||
}
|
||||
|
||||
@@ -336,16 +338,16 @@ type OrderbookResponse struct {
|
||||
|
||||
// FillResponse contains fill information from the exchange
|
||||
type FillResponse struct {
|
||||
TradeID int `json:"trade_id"`
|
||||
ProductID string `json:"product_id"`
|
||||
Price float64 `json:"price,string"`
|
||||
Size float64 `json:"size,string"`
|
||||
OrderID string `json:"order_id"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
Liquidity string `json:"liquidity"`
|
||||
Fee float64 `json:"fee,string"`
|
||||
Settled bool `json:"settled"`
|
||||
Side string `json:"side"`
|
||||
TradeID int `json:"trade_id"`
|
||||
ProductID string `json:"product_id"`
|
||||
Price float64 `json:"price,string"`
|
||||
Size float64 `json:"size,string"`
|
||||
OrderID string `json:"order_id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
Liquidity string `json:"liquidity"`
|
||||
Fee float64 `json:"fee,string"`
|
||||
Settled bool `json:"settled"`
|
||||
Side string `json:"side"`
|
||||
}
|
||||
|
||||
// WebsocketSubscribe takes in subscription information
|
||||
|
||||
@@ -177,12 +177,7 @@ func (c *CoinbasePro) wsHandleData(respRaw []byte) error {
|
||||
}
|
||||
ts := wsOrder.Time
|
||||
if wsOrder.Type == "activate" {
|
||||
var one, two int64
|
||||
one, two, err = convert.SplitFloatDecimals(wsOrder.Timestamp)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ts = time.Unix(one, two)
|
||||
ts = convert.TimeFromUnixTimestampDecimal(wsOrder.Timestamp)
|
||||
}
|
||||
|
||||
var p currency.Pair
|
||||
|
||||
@@ -311,7 +311,7 @@ func (c *CoinbasePro) UpdateTicker(p currency.Pair, assetType asset.Item) (*tick
|
||||
}
|
||||
|
||||
tickerPrice := &ticker.Price{
|
||||
Last: tick.Size,
|
||||
Last: stats.Last,
|
||||
High: stats.High,
|
||||
Low: stats.Low,
|
||||
Bid: tick.Bid,
|
||||
@@ -498,12 +498,8 @@ func (c *CoinbasePro) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
if errTSi != nil {
|
||||
return response, fmt.Errorf("error parsing order Side: %s", errTSi)
|
||||
}
|
||||
td, errTd := time.Parse(time.RFC3339, fillResponse[i].CreatedAt)
|
||||
if errTd != nil {
|
||||
return response, fmt.Errorf("error parsing trade created time: %s", errTd)
|
||||
}
|
||||
response.Trades = append(response.Trades, order.TradeHistory{
|
||||
Timestamp: td,
|
||||
Timestamp: fillResponse[i].CreatedAt,
|
||||
TID: string(fillResponse[i].TradeID),
|
||||
Price: fillResponse[i].Price,
|
||||
Amount: fillResponse[i].Size,
|
||||
@@ -607,22 +603,12 @@ func (c *CoinbasePro) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Deta
|
||||
c.GetPairFormat(asset.Spot, false).Delimiter)
|
||||
orderSide := order.Side(strings.ToUpper(respOrders[i].Side))
|
||||
orderType := order.Type(strings.ToUpper(respOrders[i].Type))
|
||||
orderDate, err := time.Parse(time.RFC3339, respOrders[i].CreatedAt)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys,
|
||||
"Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
|
||||
c.Name,
|
||||
"GetActiveOrders",
|
||||
respOrders[i].ID,
|
||||
respOrders[i].CreatedAt)
|
||||
}
|
||||
|
||||
orders = append(orders, order.Detail{
|
||||
ID: respOrders[i].ID,
|
||||
Amount: respOrders[i].Size,
|
||||
ExecutedAmount: respOrders[i].FilledSize,
|
||||
Type: orderType,
|
||||
Date: orderDate,
|
||||
Date: respOrders[i].CreatedAt,
|
||||
Side: orderSide,
|
||||
Pair: curr,
|
||||
Exchange: c.Name,
|
||||
@@ -654,22 +640,12 @@ func (c *CoinbasePro) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Deta
|
||||
c.GetPairFormat(asset.Spot, false).Delimiter)
|
||||
orderSide := order.Side(strings.ToUpper(respOrders[i].Side))
|
||||
orderType := order.Type(strings.ToUpper(respOrders[i].Type))
|
||||
orderDate, err := time.Parse(time.RFC3339, respOrders[i].CreatedAt)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys,
|
||||
"Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
|
||||
c.Name,
|
||||
"GetActiveOrders",
|
||||
respOrders[i].ID,
|
||||
respOrders[i].CreatedAt)
|
||||
}
|
||||
|
||||
orders = append(orders, order.Detail{
|
||||
ID: respOrders[i].ID,
|
||||
Amount: respOrders[i].Size,
|
||||
ExecutedAmount: respOrders[i].FilledSize,
|
||||
Type: orderType,
|
||||
Date: orderDate,
|
||||
Date: respOrders[i].CreatedAt,
|
||||
Side: orderSide,
|
||||
Pair: curr,
|
||||
Exchange: c.Name,
|
||||
|
||||
Reference in New Issue
Block a user