Skip to content

Commit

Permalink
Fixed linter issues for Coinut exchange.
Browse files Browse the repository at this point in the history
  • Loading branch information
shazbert committed Feb 25, 2018
1 parent 111c678 commit 6962f84
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 99 deletions.
75 changes: 45 additions & 30 deletions exchanges/coinut/coinut.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ func (c *COINUT) Setup(exch config.ExchangeConfig) {
}

// GetInstruments returns instruments
func (c *COINUT) GetInstruments() (CoinutInstruments, error) {
var result CoinutInstruments
func (c *COINUT) GetInstruments() (Instruments, error) {
var result Instruments
params := make(map[string]interface{})
params["sec_type"] = "SPOT"
err := c.SendHTTPRequest(coinutInstruments, params, false, &result)
Expand All @@ -95,8 +95,9 @@ func (c *COINUT) GetInstruments() (CoinutInstruments, error) {
return result, nil
}

func (c *COINUT) GetInstrumentTicker(instrumentID int) (CoinutTicker, error) {
var result CoinutTicker
// GetInstrumentTicker returns a ticker for a specific instrument
func (c *COINUT) GetInstrumentTicker(instrumentID int) (Ticker, error) {
var result Ticker
params := make(map[string]interface{})
params["inst_id"] = instrumentID
err := c.SendHTTPRequest(coinutTicker, params, false, &result)
Expand All @@ -106,8 +107,9 @@ func (c *COINUT) GetInstrumentTicker(instrumentID int) (CoinutTicker, error) {
return result, nil
}

func (c *COINUT) GetInstrumentOrderbook(instrumentID, limit int) (CoinutOrderbook, error) {
var result CoinutOrderbook
// GetInstrumentOrderbook returns the orderbooks for a specific instrument
func (c *COINUT) GetInstrumentOrderbook(instrumentID, limit int) (Orderbook, error) {
var result Orderbook
params := make(map[string]interface{})
params["inst_id"] = instrumentID
if limit > 0 {
Expand All @@ -120,8 +122,9 @@ func (c *COINUT) GetInstrumentOrderbook(instrumentID, limit int) (CoinutOrderboo
return result, nil
}

func (c *COINUT) GetTrades(instrumentID int) (CoinutTrades, error) {
var result CoinutTrades
// GetTrades returns trade information
func (c *COINUT) GetTrades(instrumentID int) (Trades, error) {
var result Trades
params := make(map[string]interface{})
params["inst_id"] = instrumentID
err := c.SendHTTPRequest(coinutTrades, params, false, &result)
Expand All @@ -131,15 +134,17 @@ func (c *COINUT) GetTrades(instrumentID int) (CoinutTrades, error) {
return result, nil
}

func (c *COINUT) GetUserBalance() (CoinutUserBalance, error) {
result := CoinutUserBalance{}
// GetUserBalance returns the full user balance
func (c *COINUT) GetUserBalance() (UserBalance, error) {
result := UserBalance{}
err := c.SendHTTPRequest(coinutBalance, nil, true, &result)
if err != nil {
return result, err
}
return result, nil
}

// NewOrder places a new order on the exchange
func (c *COINUT) NewOrder(instrumentID int, quantity, price float64, buy bool, orderID uint32) (interface{}, error) {
var result interface{}
params := make(map[string]interface{})
Expand All @@ -159,8 +164,9 @@ func (c *COINUT) NewOrder(instrumentID int, quantity, price float64, buy bool, o
return result, nil
}

func (c *COINUT) NewOrders(orders []CoinutOrder) ([]CoinutOrdersBase, error) {
var result CoinutOrdersResponse
// NewOrders places multiple orders on the exchange
func (c *COINUT) NewOrders(orders []Order) ([]OrdersBase, error) {
var result OrdersResponse
params := make(map[string]interface{})
params["orders"] = orders
err := c.SendHTTPRequest(coinutOrders, params, true, &result.Data)
Expand All @@ -170,8 +176,9 @@ func (c *COINUT) NewOrders(orders []CoinutOrder) ([]CoinutOrdersBase, error) {
return result.Data, nil
}

func (c *COINUT) GetOpenOrders(instrumentID int) ([]CoinutOrdersResponse, error) {
var result []CoinutOrdersResponse
// GetOpenOrders returns a list of open order and relevant information
func (c *COINUT) GetOpenOrders(instrumentID int) ([]OrdersResponse, error) {
var result []OrdersResponse
params := make(map[string]interface{})
params["inst_id"] = instrumentID
err := c.SendHTTPRequest(coinutOrdersOpen, params, true, &result)
Expand All @@ -181,8 +188,9 @@ func (c *COINUT) GetOpenOrders(instrumentID int) ([]CoinutOrdersResponse, error)
return result, nil
}

// CancelOrder cancels a specific order and returns if it was actioned
func (c *COINUT) CancelOrder(instrumentID, orderID int) (bool, error) {
var result CoinutGenericResponse
var result GenericResponse
params := make(map[string]interface{})
params["inst_id"] = instrumentID
params["order_id"] = orderID
Expand All @@ -193,8 +201,9 @@ func (c *COINUT) CancelOrder(instrumentID, orderID int) (bool, error) {
return true, nil
}

func (c *COINUT) CancelOrders(orders []CoinutCancelOrders) (CoinutCancelOrdersResponse, error) {
var result CoinutCancelOrdersResponse
// CancelOrders cancels multiple orders
func (c *COINUT) CancelOrders(orders []CancelOrders) (CancelOrdersResponse, error) {
var result CancelOrdersResponse
params := make(map[string]interface{})
params["entries"] = orders
err := c.SendHTTPRequest(coinutOrdersCancel, params, true, &result)
Expand All @@ -204,8 +213,9 @@ func (c *COINUT) CancelOrders(orders []CoinutCancelOrders) (CoinutCancelOrdersRe
return result, nil
}

func (c *COINUT) GetTradeHistory(instrumentID, start, limit int) (CoinutTradeHistory, error) {
var result CoinutTradeHistory
// GetTradeHistory returns trade history for a specific instrument.
func (c *COINUT) GetTradeHistory(instrumentID, start, limit int) (TradeHistory, error) {
var result TradeHistory
params := make(map[string]interface{})
params["inst_id"] = instrumentID
if start >= 0 && start <= 100 {
Expand All @@ -221,8 +231,9 @@ func (c *COINUT) GetTradeHistory(instrumentID, start, limit int) (CoinutTradeHis
return result, nil
}

func (c *COINUT) GetIndexTicker(asset string) (CoinutIndexTicker, error) {
var result CoinutIndexTicker
// GetIndexTicker returns the index ticker for an asset
func (c *COINUT) GetIndexTicker(asset string) (IndexTicker, error) {
var result IndexTicker
params := make(map[string]interface{})
params["asset"] = asset
err := c.SendHTTPRequest(coinutIndexTicker, params, false, &result)
Expand All @@ -232,6 +243,7 @@ func (c *COINUT) GetIndexTicker(asset string) (CoinutIndexTicker, error) {
return result, nil
}

// GetDerivativeInstruments returns a list of derivative instruments
func (c *COINUT) GetDerivativeInstruments(secType string) (interface{}, error) {
var result interface{} //to-do
params := make(map[string]interface{})
Expand All @@ -243,8 +255,9 @@ func (c *COINUT) GetDerivativeInstruments(secType string) (interface{}, error) {
return result, nil
}

func (c *COINUT) GetOptionChain(asset, secType string, expiry int64) (CoinutOptionChainResponse, error) {
var result CoinutOptionChainResponse
// GetOptionChain returns option chain
func (c *COINUT) GetOptionChain(asset, secType string, expiry int64) (OptionChainResponse, error) {
var result OptionChainResponse
params := make(map[string]interface{})
params["asset"] = asset
params["sec_type"] = secType
Expand All @@ -255,8 +268,9 @@ func (c *COINUT) GetOptionChain(asset, secType string, expiry int64) (CoinutOpti
return result, nil
}

func (c *COINUT) GetPositionHistory(secType string, start, limit int) (CoinutPositionHistory, error) {
var result CoinutPositionHistory
// GetPositionHistory returns position history
func (c *COINUT) GetPositionHistory(secType string, start, limit int) (PositionHistory, error) {
var result PositionHistory
params := make(map[string]interface{})
params["sec_type"] = secType
if start >= 0 {
Expand All @@ -272,9 +286,10 @@ func (c *COINUT) GetPositionHistory(secType string, start, limit int) (CoinutPos
return result, nil
}

func (c *COINUT) GetOpenPositions(instrumentID int) ([]CoinutOpenPosition, error) {
// GetOpenPositions returns all your current opened positions
func (c *COINUT) GetOpenPositions(instrumentID int) ([]OpenPosition, error) {
type Response struct {
Positions []CoinutOpenPosition `json:"positions"`
Positions []OpenPosition `json:"positions"`
}
var result Response
params := make(map[string]interface{})
Expand All @@ -289,6 +304,7 @@ func (c *COINUT) GetOpenPositions(instrumentID int) ([]CoinutOpenPosition, error

//to-do: user position update via websocket

// SendHTTPRequest sends an authenticated HTTP request
func (c *COINUT) SendHTTPRequest(apiRequest string, params map[string]interface{}, authenticated bool, result interface{}) (err error) {
if !c.AuthenticatedAPISupport && authenticated {
return fmt.Errorf(exchange.WarningAuthenticatedRequestWithoutCredentialsSet, c.Name)
Expand All @@ -299,15 +315,14 @@ func (c *COINUT) SendHTTPRequest(apiRequest string, params map[string]interface{
} else {
c.Nonce.Inc()
}
payload := []byte("")

if params == nil {
params = map[string]interface{}{}
}
params["nonce"] = c.Nonce.Get()
params["request"] = apiRequest

payload, err = common.JSONEncode(params)
payload, err := common.JSONEncode(params)
if err != nil {
return errors.New("SenddHTTPRequest: Unable to JSON request")
}
Expand All @@ -333,7 +348,7 @@ func (c *COINUT) SendHTTPRequest(apiRequest string, params map[string]interface{
log.Printf("Received raw: \n%s", resp)
}

genResp := CoinutGenericResponse{}
genResp := GenericResponse{}
err = common.JSONDecode([]byte(resp), &genResp)
if err != nil {
return errors.New("unable to JSON Unmarshal generic response")
Expand Down
1 change: 0 additions & 1 deletion exchanges/coinut/coinut_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ func TestSetDefaults(t *testing.T) {

func TestSetup(t *testing.T) {
t.Parallel()
c := COINUT{}
c.Name = "Coinut"
cfg := config.GetConfig()
cfg.LoadConfig("../../testdata/configtest.json")
Expand Down
Loading

0 comments on commit 6962f84

Please sign in to comment.