VB.NET and IEnumerable

0

I'm new to VB.NET and am not getting the syntax like I want.

Using this library: https://github.com/jjxtra/ExchangeSharp

I'm trying to iterate through open orders.

Dim openOrders As IEnumerable(Of ExchangeOrderResult) = api.GetOpenOrderDetails()

This doesn't give me an error, but anything I try and do with the variable it just says "invalid command" All of these don't work and I'm not sure how to iterate over this.

Console.WriteLine(openOrders.Count)
'also tried this

    Dim enumerator As IEnumerator(Of ExchangeOrderResult) = openOrders.GetEnumerator
    While (enumerator.MoveNext) 'crashes here
    End While

I don't understand VB syntax and I've been searching for an hour or two, so I've given up for now. Any help appreciated!

Edit

I'm using the poloniex API.

This is the stack trace I'm getting from any example/attempt at this:

ExchangeSharp.APIException occurred HResult=0x80131500 Message=Invalid command. Source=ExchangeSharp StackTrace: at ExchangeSharp.ExchangePoloniexAPI.CheckError(JToken result) at ExchangeSharp.ExchangePoloniexAPI.MakePrivateAPIRequest(Stri‌​ng command, Object[] parameters) at ExchangeSharp.ExchangePoloniexAPI.d__26‌​.MoveNext() at ConsoleApp3.Module1.Main() in C:\Users\KMS10\source\repos\ConsoleApp3\ConsoleApp3\Module1.‌​vb:line 42

vb.net
ienumerable
ienumerator
exchange-sharp
asked on Stack Overflow Jan 21, 2018 by Touchy Clan • edited Jan 21, 2018 by NightOwl888

2 Answers

0

Use For Each to iterate over an IEnumerable. Make sure you've imported System.Collections.Generic:

Dim openOrders As IEnumerable(Of ExchangeOrderResult) = api.GetOpenOrderDetails()

For Each openOrder In openOrders
    ...
Next
answered on Stack Overflow Jan 21, 2018 by zola25
0

An enumerable is similar to a collection, except the only way to read the contents is to loop through it. VB.NET has the For Each...Next structure that can be used for this.

For Each item As ExchangeOrderResult In openOrders
    ' Do something with item variable
Next
answered on Stack Overflow Jan 21, 2018 by NightOwl888

User contributions licensed under CC BY-SA 3.0