Skip to content

Commit

Permalink
Workflow. REST API actualize
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky committed Oct 4, 2021
1 parent 9a2547e commit d956495
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 84 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Tests
on: push

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/[email protected]
with:
version: v1.34
args: --timeout=2m
test:
runs-on: ubuntu-latest
steps:
- name: install Go
uses: actions/setup-go@v2
with:
go-version: 1.15.x
- name: checkout code
uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: golang tests
env:
GO111MODULE: on
run: |
go mod download
go test ./...
7 changes: 7 additions & 0 deletions rest/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,10 @@ const (
StatusCancelled = "canceled"
StatusExpired = "expired"
)

// modes
const (
OrderModeGTC = "GTC"
OrderModeIOC = "IOC"
OrderModeGTD = "GTD"
)
8 changes: 4 additions & 4 deletions rest/methods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ func TestKraken_AssetPairs(t *testing.T) {
PairDecimals: 6,
LotDecimals: 8,
LotMultiplier: 1,
LeverageBuy: []float64{},
LeverageSell: []float64{},
LeverageBuy: []int{},
LeverageSell: []int{},
Fees: [][]float64{{0, 0.26}, {50000, 0.24}, {100000, 0.22}, {250000, 0.2}, {500000, 0.18}, {1000000, 0.16}, {2500000, 0.14}, {5000000, 0.12}, {10000000, 0.1}},
FeesMaker: [][]float64{{0, 0.16}, {50000, 0.14}, {100000, 0.12}, {250000, 0.1}, {500000, 0.08}, {1000000, 0.06}, {2500000, 0.04}, {5000000, 0.02}, {10000000, 0}},
FeeVolumeCurrency: "ZUSD",
Expand Down Expand Up @@ -236,8 +236,8 @@ func TestKraken_AssetPairs(t *testing.T) {
PairDecimals: 6,
LotDecimals: 8,
LotMultiplier: 1,
LeverageBuy: []float64{},
LeverageSell: []float64{},
LeverageBuy: []int{},
LeverageSell: []int{},
Fees: [][]float64{{0, 0.26}, {50000, 0.24}, {100000, 0.22}, {250000, 0.2}, {500000, 0.18}, {1000000, 0.16}, {2500000, 0.14}, {5000000, 0.12}, {10000000, 0.1}},
FeesMaker: [][]float64{{0, 0.16}, {50000, 0.14}, {100000, 0.12}, {250000, 0.1}, {500000, 0.08}, {1000000, 0.06}, {2500000, 0.04}, {5000000, 0.02}, {10000000, 0}},
FeeVolumeCurrency: "ZUSD",
Expand Down
33 changes: 13 additions & 20 deletions rest/private_methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import (
"net/url"
"strconv"
"strings"

"github.com/shopspring/decimal"
)

// GetAccountBalances - methods returns account balances
func (api *Kraken) GetAccountBalances() (BalanceResponse, error) {
response := BalanceResponse{}
func (api *Kraken) GetAccountBalances() (map[string]decimal.Decimal, error) {
response := make(map[string]decimal.Decimal)
if err := api.request("Balance", true, nil, &response); err != nil {
return response, err
}
Expand Down Expand Up @@ -252,7 +254,7 @@ func (api *Kraken) GetTradeVolume(needFeeInfo bool, pairs ...string) (TradeVolum
}

// AddOrder - method sends order to exchange
func (api *Kraken) AddOrder(pair string, side string, orderType string, volume float64, args map[string]interface{}) (AddOrderResponse, error) {
func (api *Kraken) AddOrder(pair string, side string, orderType string, volume float64, args map[string]interface{}) (response AddOrderResponse, err error) {
data := url.Values{
"pair": {pair},
"volume": {strconv.FormatFloat(volume, 'f', 8, 64)},
Expand All @@ -274,30 +276,21 @@ func (api *Kraken) AddOrder(pair string, side string, orderType string, volume f
}
}

response := AddOrderResponse{}
if err := api.request("AddOrder", true, data, &response); err != nil {
return response, err
}
return response, nil
err = api.request("AddOrder", true, data, &response)
return
}

// Cancel - method cancels order
func (api *Kraken) Cancel(orderID string) (CancelResponse, error) {
func (api *Kraken) Cancel(orderID string) (response CancelResponse, err error) {
data := url.Values{
"txid": {orderID},
}
response := CancelResponse{}
if err := api.request("CancelOrder", true, data, &response); err != nil {
return response, err
}
return response, nil
err = api.request("CancelOrder", true, data, &response)
return
}

// GetWebSocketsToken - WebSockets authentication
func (api *Kraken) GetWebSocketsToken() (GetWebSocketTokenResponse, error) {
response := GetWebSocketTokenResponse{}
if err := api.request("GetWebSocketsToken", true, nil, &response); err != nil {
return response, err
}
return response, nil
func (api *Kraken) GetWebSocketsToken() (response GetWebSocketTokenResponse, err error) {
err = api.request("GetWebSocketsToken", true, nil, &response)
return
}
25 changes: 17 additions & 8 deletions rest/private_methods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import (
"net/http"
"reflect"
"testing"

"github.com/shopspring/decimal"
"github.com/stretchr/testify/assert"
)

var (
Expand Down Expand Up @@ -122,14 +125,14 @@ func TestKraken_GetAccountBalances(t *testing.T) {
name string
err error
resp *http.Response
want BalanceResponse
want map[string]decimal.Decimal
wantErr bool
}{
{
name: "Kraken returns error",
err: ErrSomething,
resp: &http.Response{},
want: BalanceResponse{},
want: make(map[string]decimal.Decimal),
wantErr: true,
}, {
name: "Get Account Balances",
Expand All @@ -138,10 +141,10 @@ func TestKraken_GetAccountBalances(t *testing.T) {
StatusCode: 200,
Body: ioutil.NopCloser(bytes.NewReader(balancesJSON)),
},
want: BalanceResponse{
BSV: 0.0000053898,
ZUSD: 435.9135,
USDT: 2,
want: map[string]decimal.Decimal{
"BSV": decimal.NewFromFloat(0.0000053898),
"ZUSD": decimal.NewFromFloat(435.9135),
"USDT": decimal.NewFromInt(2),
},
wantErr: false,
},
Expand All @@ -159,8 +162,14 @@ func TestKraken_GetAccountBalances(t *testing.T) {
t.Errorf("Kraken.GetAccountBalances() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("Kraken.GetAccountBalances() = %v, want %v", got, tt.want)
assert.Len(t, got, len(tt.want))
for name, balance := range got {
wantBalance, ok := tt.want[name]
if !ok {
t.Errorf("Kraken.GetAccountBalances() unknown asset: %s", name)
return
}
assert.Equal(t, wantBalance.String(), balance.String())
}
})
}
Expand Down
70 changes: 18 additions & 52 deletions rest/responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,24 @@ type Asset struct {

// AssetPair - asset pair information
type AssetPair struct {
Altname string `json:"altname"`
AssetClassBase string `json:"aclass_base"`
Base string `json:"base"`
AssetClassQuote string `json:"aclass_quote"`
Quote string `json:"quote"`
Lot string `json:"lot"`
PairDecimals int `json:"pair_decimals"`
LotDecimals int `json:"lot_decimals"`
LotMultiplier int `json:"lot_multiplier"`
LeverageBuy []float64 `json:"leverage_buy"`
LeverageSell []float64 `json:"leverage_sell"`
Fees [][]float64 `json:"fees"`
FeesMaker [][]float64 `json:"fees_maker"`
FeeVolumeCurrency string `json:"fee_volume_currency"`
MarginCall int `json:"margin_call"`
MarginStop int `json:"margin_stop"`
WSName string `json:"wsname"`
Altname string `json:"altname"`
AssetClassBase string `json:"aclass_base"`
Base string `json:"base"`
AssetClassQuote string `json:"aclass_quote"`
Quote string `json:"quote"`
Lot string `json:"lot"`
PairDecimals int `json:"pair_decimals"`
LotDecimals int `json:"lot_decimals"`
LotMultiplier int `json:"lot_multiplier"`
LeverageBuy []int `json:"leverage_buy"`
LeverageSell []int `json:"leverage_sell"`
Fees [][]float64 `json:"fees"`
FeesMaker [][]float64 `json:"fees_maker"`
FeeVolumeCurrency string `json:"fee_volume_currency"`
MarginCall int `json:"margin_call"`
MarginStop int `json:"margin_stop"`
WSName string `json:"wsname"`
OrderMin decimal.Decimal `json:"ordermin"`
}

// Level - ticker structure for Ask and Bid
Expand Down Expand Up @@ -529,41 +530,6 @@ type SpreadResponse struct {
XZECZUSD []Spread
}

// BalanceResponse - response on account balance request
type BalanceResponse struct {
ADA float64 `json:",string"`
BCH float64 `json:",string"`
BSV float64 `json:",string"`
DASH float64 `json:",string"`
EOS float64 `json:",string"`
GNO float64 `json:",string"`
KFEE float64 `json:",string"`
QTUM float64 `json:",string"`
USDT float64 `json:",string"`
XDAO float64 `json:",string"`
XETC float64 `json:",string"`
XETH float64 `json:",string"`
XICN float64 `json:",string"`
XLTC float64 `json:",string"`
XMLN float64 `json:",string"`
XNMC float64 `json:",string"`
XREP float64 `json:",string"`
XXBT float64 `json:",string"`
XXDG float64 `json:",string"`
XXLM float64 `json:",string"`
XXMR float64 `json:",string"`
XXRP float64 `json:",string"`
XXTZ float64 `json:",string"`
XXVN float64 `json:",string"`
XZEC float64 `json:",string"`
ZCAD float64 `json:",string"`
ZEUR float64 `json:",string"`
ZGBP float64 `json:",string"`
ZJPY float64 `json:",string"`
ZKRW float64 `json:",string"`
ZUSD float64 `json:",string"`
}

// TradeBalanceResponse - response of get trade balance request
type TradeBalanceResponse struct {
EquivalentBalance float64 `json:"eb,string"`
Expand Down

0 comments on commit d956495

Please sign in to comment.