Whilst Asia are busy discovering microfinance, it seems over here in the West we are adding a new branche to microfinance, micro-investing. Initially that seems to have centered around crowdfunding.

More recently the Bitcoin corner are adding a new form of micro-investing.

Venture capital being scarce in the recession, the branche being rather young, fast maturing since the december 2013 bitcoin price spike, and the coin business being a pure internet branche, has inspired a number of companies to get their venture capital from the customers.

The coins business is rather low threshold. Added to that, transaction cost are far lower than traditional investing.

You can start investing on the exchanges with a dime and buy shares in transaction-fees, that in turn helps the site owners develop the exchange.  In the mining business you can invest in mining from $5,- upwards. The mining operations developed cloud interfaces where you do not have to bother with settings and machines, you can just buy a share in the operation with the newer sites offering a marketplace for these shares, so you can always cash out any time you want. Returns in mining are often between 0.3% and 0.7% per day, with daily payouts, rather risk free. Another example is the Ethereum project which financed its operations with an initial coin release and collected something like 10 million dollars.

One strong advantage of coins, where bearer bonds are not allowed in traditional investment, no such regulation exists for coins. More recent coin launches are experimenting with that, like Supernet Unity, Bleutrade shares, Bter securities.

All in all, where Bitcoin seem to focus on the role of bitcoin as currency, to my opinion it (or  sooner a number of alt-coins) may have a bigger future in micro-investment.

Accessing the Kiva Api with Visual Basic

Kiva list a Dot Net Api class in C# so writing your own in Visual Basic is a tat obsolete were it not that I already had a complete database to process the data dump and I wanted a basic API class that only consumes XML and exposes it as a DataSet to update the main database, and add more user-oriented functionality, so I wrote a quick basic API-client. There, I said it.

The example project is on the server :  KivaVBLibrary Kiva Api example in VB (coded in Visual Basic Express 2010)

About the API

The Kiva API is a HTTP Rest API  using Basic HTTP Auth. I noticed Kiva do not check on credentials on the function I list below here, but I included a basic http authentication anyway. I do expect Kiva to switch to using OAuth somewhere along the line, but for now it is Basic HTTP Auth.

Rate limiting and TOS

Kiva allow 60 calls per minute for unregistered and 500 calls a minute per registered account, Kiva terms are general but Kiva emphasize you should respect the privacy of site users and not misrepresent the data.

The sample

On with the sample, I am going to make a Visual Basic Class to access the Kiva API, retrieve an XML response file, load that into a DataSet object and retrieve and display the data from the DataSet object on a Form.

I took the UrlFactory Class from the Kiva Api Library C# example, and recoded part of it in Visual Basic, one class URLFactory to compose the URL’s accor :

Namespace KivaVBLibrary
  2.     Public Class URLFactory
  4.         Public baseURL As String = "http://api.kivaws.org/v1/"
  5.         Public urlSuffix As String = ".xml"
  6.         //The API returns either html, xml or json depending on the suffix you send in the url.
  8.         Public Function GetLenderURL(ByVal UID As String) As String
  9.             Return baseURL + "lenders/" + UID + urlSuffix
  10.         End Function
  11.     End Class
  12. End NameSpace

With that URL available, let’s get some XML, in this case the basic lender record of Matt (one of the co founders of kiva), retrieved from //api.kivaws.org/v1/lenders/matt.xml

The GetLender function of the KivaAPI class gets the XML data from the API and returns it as Dataset :

Imports System.Net
  1. Imports System.Text
  3. Namespace KivaVBLibrary
  5. Public Class KivaAPI
  7.     Private _UrlFactory As New KivaVBLibrary.URLFactory
  9.     Private _AppID As String = "org.juust.kivareader"
  10.     Private _UserAgent As String = "KivaReader (http://www.juust.org) appid:" & _AppID
  12.     Private _userName As String = ""
  13.     Private _userPassword As String = ""
  15.     Public Property AppID As String
  16.         Get
  17.             Return _AppID
  18.         End Get
  19.         Set(ByVal value As String)
  20.             _AppID = value
  21.         End Set
  22.     End Property
  24.     Public Property userName As String
  25.         Get
  26.             Return _userName
  27.         End Get
  28.         Set(ByVal value As String)
  29.             _userName = value
  30.         End Set
  31.     End Property
  33.     Public Property userPassword As String
  34.         Get
  35.             Return _userPassword
  36.         End Get
  37.         Set(ByVal value As String)
  38.             _userPassword = value
  39.         End Set
  40.     End Property
  42.     Public Sub New()
  43.     End Sub
  45.     Public Sub SetBasicAuthHeader(ByVal request As HttpWebRequest)
  47.         Dim authInfo As String = Me.userName + ":" + Me.userPassword
  48.         authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo))
  49.         With request
  50.             .Headers("Authorization") = "Basic " + authInfo
  51.             .Accept = "application/xml"
  52.             .UserAgent = "KivaReader (juust.org)"
  53.             .AllowAutoRedirect = False
  54.             .Timeout = 5000
  55.             .KeepAlive = False
  56.         End With
  57.     End Sub
  59.     Public Function GetLender(ByVal LenderID As String) As DataSet
  61.         Dim MyRequest As HttpWebRequest
  63.         MyRequest = HttpWebRequest.Create(_UrlFactory.GetLenderURL(LenderID))
  64.         With MyRequest
  65.             .Method = "GET"
  66.         End With
  68.         SetBasicAuthHeader(MyRequest)
  70.         Dim DataSetLender As DataSet
  71.         DataSetLender = New DataSet()
  72.         Using MyResponse As HttpWebResponse = MyRequest.GetResponse()
  73.             DataSetLender.ReadXml(MyResponse.GetResponseStream())
  74.         End Using
  75.         MyRequest = Nothing
  77.         Return DataSetLender
  79.     End Function
  81. End Class
  82. End NameSpace

Now we have the code to retrieve the DataSet object from the Kiva API, so let’s make a quick Form, with three texboxes (username, password and the id of the lender you want to retrieve data for), two rich format boxes to display data from the dataset and a button to run the API Test :

…and in the form module we add some basic code that creates an instance of KivaVBLibrary.KivaAPI, sets our basic authorization, and calls the GetLender function to retrieve the Lender data for the ID we fill in in the form :

Public Class Form1
  2.     Private myApi As New KivaVBLibrary.KivaAPI
  4.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btntestApi.Click
  5.         myApi.userName = TxtUsername.Text
  6.         myApi.userPassword = TxtPassword.Text
  8.         Dim ds As DataSet
  9.         ds = myApi.GetLender(TxtLender.Text)
  11.         PrintDataRecords(ds)
  12.         PrintDataSet(ds)
  14.     End Sub

Click the button on the form, and after a second, we get our first data :

The Dataset is processed twice, one for general Table set data, and one for the content using the two rich text boxes (RtLender and RTTableSet) to display data on the form :

Public Sub PrintDataRecords(ByVal ds As DataSet)
  2.         // Print out all tables and their columns
  3.         Dim iRow As DataRow
  4.         Dim iCol As DataColumn
  5.         For Each table As DataTable In ds.Tables
  6.             For Each iRow In table.Rows
  7.                 For Each iCol In table.Columns
  8.                     RTLender.AppendText(iCol.ToString)
  9.                     RTLender.AppendText(vbTab & iRow(iCol.ToString).ToString)
  10.                     RTLender.AppendText(vbCrLf)
  11.                 Next
  12.             Next
  13.         Next  // For Each table  
  15.     End Sub
  17.     Public Sub PrintDataSet(ByVal ds As DataSet)
  19.         // Print out all tables and their columns
  20.         For Each table As DataTable In ds.Tables
  21.             RTTableSet.AppendText(vbCrLf & "TABLE " & table.TableName)
  22.             RTTableSet.AppendText(vbCrLf & "Total # of rows: " & table.Rows.Count)
  23.             RTTableSet.AppendText(vbCrLf & "—————————————————————")
  25.             For Each column As DataColumn In table.Columns
  26.                 RTTableSet.AppendText(vbCrLf & column.ColumnName & " " & column.DataType.ToString())
  27.             Next  // For Each column
  28.             RTTableSet.AppendText(vbCrLf)
  30.         Next  // For Each table  
  32.         // Print out table relations
  33.         For Each relation As DataRelation In ds.Relations
  34.             RTTableSet.AppendText(vbCrLf & "RELATION: " & relation.RelationName)
  35.             RTTableSet.AppendText(vbCrLf & "—————————————————————")
  36.             RTTableSet.AppendText(vbCrLf & "Parent: " & relation.ParentTable.TableName)
  37.             RTTableSet.AppendText(vbCrLf & "Child: " & relation.ChildTable.TableName)
  38.             RTTableSet.AppendText(vbCrLf)
  39.         Next  // For Each relation  
  41.     End Sub

さよなら (=goodbye)