gocryptotrader
gocryptotrader copied to clipboard
Kraken submit response
I'm trying to sell USDT on EUR on kraken with this code. It works, it does do the job but yet the submit response seems to be wrong or empty.
So it's hard to confirm if my order actually went through. Not sure if this is a known issue or I do something wrong here
func krakenTurboSell() (*order.SubmitResponse, error) {
var orderSubmitResponse = new(order.SubmitResponse)
currencyPair, err := currency.NewPairFromString("USDT-EUR")
if err != nil {
logrus.Warnf("failed to retrieve trading pair: %s\n", currencyPair)
}
info, err := wrappers.GetWrapper().AccountInformation(KRAKEN, asset.Spot)
if err != nil {
logrus.Errorf("failed to retrieve account information: %s\n", err)
}
var USDTBalance bool
sellOrder := order.Submit{
Exchange: KRAKEN,
Type: order.Market,
AssetType: asset.Spot,
Pair: currencyPair,
}
for _, c := range info.Accounts[len(info.Accounts)-1].Currencies {
if c.CurrencyName.String() == "EUR" {
fmt.Printf("Current %s balance is %f\n", c.CurrencyName, c.TotalValue)
}
if c.CurrencyName.String() == "USDT" {
USDTBalance = true
sellOrder.Amount = 10
sellOrder.Side = order.Sell
fmt.Printf("Current %s balance is %f\n", c.CurrencyName, c.TotalValue)
}
}
if USDTBalance {
orderSubmitResponse, err = wrappers.GetWrapper().SubmitOrder(&sellOrder)
fmt.Printf("Selling %f USDT\n", sellOrder.Amount)
if err != nil {
logrus.Errorf("Failed to sell %f USDT to Euro: %s\n", sellOrder.Amount, err)
}
return orderSubmitResponse, nil
}
return orderSubmitResponse, fmt.Errorf("No USDT found in the account\n")
}
in main I use
fmt.Printf("Match %s rate %f with a fee of %f and cost of %f\n", strconv.FormatBool(resp.FullyMatched), resp.Rate, resp.Fee, resp.Cost)
Current Behavior
Current EUR balance is 1130.780900 Current USDT balance is 75.000000 Selling 10.000000 USDT Match false rate 0.000000 with a fee of 0.000000 and cost of 0.000000 Current EUR balance is 1139.242900
Expected Behavior
At least match true
I might be doing something wrong I think?
- Operating System: OS: Arch Linux Kernel: x86_64 Linux 5.11.9-arch1-1 Shell: zsh 5.8
Any tips on how to handle stuff better are welcome. I don't code often and self-taught
Hello and thank you for trying out GoCryptoTrader! I've had a look at Kraken's API documentation here and Kraken does not return much information when placing orders. GoCryptoTrader will return whether the order was placed, any issues encountered, any trades (if returned)
Those fields that you are showing as 0 are not always populated, and as highlighted in the documentation, are not used with Kraken. They are there because they can be populated in other exchanges. FullyMatched
being false is confusing to me, but we'll try the following first:
Since you are placing market orders, I would suggest using the wrapper function QueryOrder
/GetOrderInfo
with the orderID(s) you receive after your order has been placed to get more order information and to confirm its status
Let me know if that resolves or helps your issue, otherwise we can investigate further.
Thanks a lot for the wrapper function. I contacted Kraken about the withdrawal details. Selling works. Kraken documentation is pretty small and lacking info
Surely I do something wrong or could be replaced with a wrapper function I have this piece of code and try to get it running. A bit messy, had some desperate attempts to make it run
func withdrawEuro(amount float64) {
euro, err := getKrakenEuroBalance()
if err != nil {
fmt.Printf("failed to get kraken euro balance: %s\n", err)
}
fmt.Printf("Current EUR balance is %f\n", euro)
cfg := config.GetConfig()
err = cfg.LoadConfig(engine.Bot.Settings.ConfigFile, true)
if err != nil {
logrus.Fatalf("failed loading config: %s\n", err)
}
krakenConfig, err := cfg.GetExchangeConfig(KRAKEN)
if err != nil || krakenConfig == nil {
logrus.Fatal(err)
}
fmt.Printf("spot %x\n", krakenConfig.AssetTypes)
exchange := kraken.Kraken{}
exchange.Enabled = true
kconfig := engine.Bot.GetExchangeByName(KRAKEN).GetBase().Config
engine.Bot.GetExchangeByName(KRAKEN).GetBase().LoadedByConfig = true
fmt.Println("prepare setup")
//*krakenConfig.AssetTypes = asset.Spot.String()
fmt.Println(engine.Bot.GetExchangeByName(KRAKEN).GetEnabledPairs(asset.Spot))
err = exchange.Setup(kconfig)
if err != nil {
logrus.Printf("fail to setup kraken: %s\n\n", err)
}
fmt.Println("done setting up config")
result, err := exchange.Withdraw("EUR", "romanornr_abn_amro", amount)
if err != nil {
logrus.Errorf("Failed to withdraw: %s\n", err)
}
fmt.Println(result)
jsonResp, err := exchange.WithdrawStatus(currency.EUR, result)
if err != nil {
fmt.Println(err)
}
fmt.Println(jsonResp)
fmt.Println("done")
}
Response
Current EUR balance is 39.242900
spot 0
prepare setup
[USDT_EUR] <nil>
INFO[0006] fail to setup kraken: cannot get pair store, asset type futures not supported
done setting up config
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0xbaa44b]
goroutine 1 [running]:
github.com/thrasher-corp/gocryptotrader/exchanges.(*Endpoints).GetURL(0x0, 0xc000db0000, 0x0, 0x0, 0x0, 0x0)
/home/romano/go/pkg/mod/github.com/thrasher-corp/[email protected]/exchanges/exchange.go:1203 +0x4b
github.com/thrasher-corp/gocryptotrader/exchanges/kraken.(*Kraken).SendAuthenticatedHTTPRequest(0xc0002ec380, 0xc000db0000, 0x1678905, 0x8, 0xc000dbbb50, 0x13e3ac0, 0xc000c9c330, 0x0, 0x0)
/home/romano/go/pkg/mod/github.com/thrasher-corp/[email protected]/exchanges/kraken/kraken.go:977 +0x92
github.com/thrasher-corp/gocryptotrader/exchanges/kraken.(*Kraken).Withdraw(0xc0002ec380, 0x166fec5, 0x3, 0x168c5b4, 0x12, 0x402e000000000000, 0x0, 0x0, 0x0, 0x0)
/home/romano/go/pkg/mod/github.com/thrasher-corp/[email protected]/exchanges/kraken/kraken.go:528 +0x350
main.withdrawEuro(0x402e000000000000)
/home/romano/github/toolkit/main.go:261 +0x6b6
main.main()
/home/romano/github/toolkit/main.go:134 +0x150
exit status 2
which leads to this function
// Withdraw withdraws funds
func (k *Kraken) Withdraw(asset, key string, amount float64) (string, error) {
var response struct {
Error []string `json:"error"`
ReferenceID string `json:"refid"`
}
params := url.Values{}
params.Set("asset", asset)
params.Set("key", key)
params.Set("amount", fmt.Sprintf("%f", amount))
if err := k.SendAuthenticatedHTTPRequest(exchange.RestSpot, krakenWithdraw, params, &response); err != nil {
return response.ReferenceID, err
}
return response.ReferenceID, GetError(response.Error)
}