VB.net Unable to cast object of type System.Collections.Generic.list to type string

325 Views Asked by At

Please forgive me in advanced for my lack of coding knowledge.

I'm using a NuGet package called KuCoin.Net and have everything setup and connected. I can run the command and Place a Buy order so I know my Api settings are correct. The issue I'm having is when I run the following code:

Public Async Function GetBalancesAsync() As Task
    Dim kucoinClient = New KucoinClient(New KucoinClientOptions() With {
        .ApiCredentials = New KucoinApiCredentials("xxx", "xxx", "xxx"),
        .LogLevel = LogLevel.Debug,
        .RequestTimeout = TimeSpan.FromSeconds(60),
.FuturesApiOptions = New KucoinRestApiClientOptions With {
    .ApiCredentials = New KucoinApiCredentials("xxx", "xxx", "xxx"),
    .AutoTimestamp = False
}})

    Dim accountData = Await kucoinClient.SpotApi.Account.GetAccountsAsync()

    MessageBox.show(accountData.data)
    End Function

I guess I'm needing to convert the list to a string so I can display it into a Messagebox.

The Error I recieve is as follows:

Unable to cast object of type 'System.Collections.Generic.List`1[Kucoin.Net.Objects.Models.Spot.KucoinAccount]' to type 'System.String'

Here is some additional info if this helps

Error

accountData

Any help is much appreciated

1

There are 1 best solutions below

2
On

You can generate your String yourself using a StringBuilder while enumerating through accountData.Data:

Dim sb As New System.Text.StringBuilder

For Each account As Kucoin.Net.Objects.Models.Spot.KucoinAccount In accountData.data
    sb.AppendLine(account.ToString)
Next

MessageBox(sb.ToString())

You can change account.ToString to something more appropriate like accout.Number perhaps (see the properties the KucoinAccount object has).