Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
use better assetConverter for KrakenExchange#GetOpenOrders, closes #143
Browse files Browse the repository at this point in the history
… (#144)
  • Loading branch information
nikhilsaraf authored Apr 2, 2019
1 parent 761e114 commit 258f1d6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
29 changes: 25 additions & 4 deletions model/tradingPair.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,35 @@ func (p TradingPair) ToString(c *AssetConverter, delim string) (string, error) {

// TradingPairFromString makes a TradingPair out of a string
func TradingPairFromString(codeSize int8, c *AssetConverter, p string) (*TradingPair, error) {
base, e := c.FromString(p[0:codeSize])
return TradingPairFromString2(codeSize, []*AssetConverter{c}, p)
}

// TradingPairFromString2 makes a TradingPair out of a string
func TradingPairFromString2(codeSize int8, converters []*AssetConverter, p string) (*TradingPair, error) {
var base Asset
var quote Asset
var e error

baseString := p[0:codeSize]
for _, c := range converters {
base, e = c.FromString(baseString)
if e == nil {
break
}
}
if e != nil {
return nil, fmt.Errorf("base asset could not be converted: %s", e)
return nil, fmt.Errorf("base asset could not be converted using any of the converters in the list of %d converters: %s", len(converters), baseString)
}

quote, e := c.FromString(p[codeSize : codeSize*2])
quoteString := p[codeSize : codeSize*2]
for _, c := range converters {
quote, e = c.FromString(quoteString)
if e == nil {
break
}
}
if e != nil {
return nil, fmt.Errorf("quote asset could not be converted: %s", e)
return nil, fmt.Errorf("quote asset could not be converted using any of the converters in the list of %d converters: %s", len(converters), quoteString)
}

return &TradingPair{Base: base, Quote: quote}, nil
Expand Down
6 changes: 4 additions & 2 deletions plugins/ieif.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package plugins
import (
"fmt"
"log"
"strings"

"github.com/stellar/go/clients/horizon"
"github.com/stellar/kelp/api"
Expand Down Expand Up @@ -168,15 +169,16 @@ func (ieif *IEIF) LogAllLiabilities(assetBase horizon.Asset, assetQuote horizon.
}

func (ieif *IEIF) logLiabilities(asset horizon.Asset, assetStr string) {
trimmedAssetStr := strings.TrimSpace(assetStr)
l, e := ieif.assetLiabilities(asset)
if e != nil {
log.Printf("could not fetch liability for asset '%s', error = %s\n", assetStr, e)
log.Printf("could not fetch liability for %s asset, error = %s\n", trimmedAssetStr, e)
return
}

balance, e := ieif.assetBalance(asset)
if e != nil {
log.Printf("cannot fetch balance for asset '%s', error = %s\n", assetStr, e)
log.Printf("cannot fetch balance for %s asset, error = %s\n", trimmedAssetStr, e)
return
}
// TODO don't break out into vars
Expand Down
7 changes: 4 additions & 3 deletions plugins/krakenExchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,13 @@ func (k *krakenExchange) GetOpenOrders(pairs []*model.TradingPair) (map[model.Tr
return nil, e
}

assetConverters := []*model.AssetConverter{k.assetConverterOpenOrders, model.Display}
m := map[model.TradingPair][]model.OpenOrder{}
for ID, o := range openOrdersResponse.Open {
// kraken uses different symbols when fetching open orders!
pair, e := model.TradingPairFromString(3, k.assetConverterOpenOrders, o.Description.AssetPair)
pair, e := model.TradingPairFromString2(3, assetConverters, o.Description.AssetPair)
if e != nil {
return nil, e
return nil, fmt.Errorf("error parsing trading pair '%s' in krakenExchange#GetOpenOrders: %s", o.Description.AssetPair, e)
}

if _, ok := pairsMap[*pair]; !ok {
Expand Down Expand Up @@ -376,7 +377,7 @@ func (k *krakenExchange) getTradeHistory(tradingPair model.TradingPair, maybeCur
var pair *model.TradingPair
pair, e = model.TradingPairFromString(4, k.assetConverter, _pair)
if e != nil {
return nil, e
return nil, fmt.Errorf("error parsing trading pair '%s' in krakenExchange#getTradeHistory: %s", _pair, e)
}
orderConstraints := k.GetOrderConstraints(pair)
// for now use the max precision between price and volume for fee and cost
Expand Down

0 comments on commit 258f1d6

Please sign in to comment.