From 244cdcb48c11e68edbb5e5b8862001fc7f4ae68e Mon Sep 17 00:00:00 2001 From: Scott Date: Mon, 5 Sep 2016 21:57:23 +1000 Subject: [PATCH] Adds new function to interface to retrieve all enabled currency data from exchange Implements on alphapointhttp.go Adds new page to UI to handle exchange balances --- alphapointhttp.go | 28 +++++++++++++++++++++----- interfaces.go | 2 ++ wallet.go | 13 ++++++++++++ web/app/views/wallets/wallets.html | 28 ++++++++++++++++++++++++++ web/app/views/wallets/wallets.js | 29 +++++++++++++++++++++++++++ web/app/views/wallets/wallets_test.js | 16 +++++++++++++++ 6 files changed, 111 insertions(+), 5 deletions(-) create mode 100644 wallet.go create mode 100644 web/app/views/wallets/wallets.html create mode 100644 web/app/views/wallets/wallets.js create mode 100644 web/app/views/wallets/wallets_test.js diff --git a/alphapointhttp.go b/alphapointhttp.go index 14628c81..2714fa93 100644 --- a/alphapointhttp.go +++ b/alphapointhttp.go @@ -4,10 +4,11 @@ import ( "bytes" "errors" "fmt" - "github.com/gorilla/websocket" "log" "strconv" "time" + + "github.com/gorilla/websocket" ) const ( @@ -203,7 +204,7 @@ func (a *Alphapoint) GetTicker(symbol string) (AlphapointTicker, error) { return response, nil } -func (a *Alphapoint) GetTickerPrice(currency string) TickerPrice { +func (a *Alphapoint) GetTickerPrice(currency string) TickerPrice { var tickerPrice TickerPrice ticker, err := a.GetTicker(currency) if err != nil { @@ -212,12 +213,10 @@ func (a *Alphapoint) GetTickerPrice(currency string) TickerPrice { } tickerPrice.Ask = ticker.Ask tickerPrice.Bid = ticker.Bid - + return tickerPrice } - - func (a *Alphapoint) GetTrades(symbol string, startIndex, count int) (AlphapointTrades, error) { request := make(map[string]interface{}) request["ins"] = symbol @@ -341,6 +340,25 @@ func (a *Alphapoint) GetAccountInfo() (AlphapointAccountInfo, error) { return response, nil } +//GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the Alphapoint exchange +func (a *Alphapoint) GetExchangeAccountInfo() (ExchangeAccountInfo, error) { + var response ExchangeAccountInfo + account, err := a.GetAccountInfo() + if err != nil { + return response, err + } + for i := 0; i < len(account.Currencies); i++ { + var exchangeCurrency ExchangeAccountCurrencyInfo + exchangeCurrency.CurrencyName = account.Currencies[i].Name + exchangeCurrency.TotalValue = account.Currencies[i].Balance + exchangeCurrency.Hold = account.Currencies[i].Hold + + response.Currencies = append(response.Currencies, exchangeCurrency) + } + //If it all works out + return response, nil +} + func (a *Alphapoint) GetAccountTrades(symbol string, startIndex, count int) (AlphapointTrades, error) { request := make(map[string]interface{}) request["ins"] = symbol diff --git a/interfaces.go b/interfaces.go index f6d66d03..c2d7a718 100644 --- a/interfaces.go +++ b/interfaces.go @@ -1,5 +1,6 @@ package main +//IBotExchange : Enforces standard functions for all exchanges supported in gocryptotrader type IBotExchange interface { Setup(exch Exchanges) Start() @@ -8,4 +9,5 @@ type IBotExchange interface { IsEnabled() bool GetTickerPrice(currency string) TickerPrice GetEnabledCurrencies() []string + GetExchangeAccountInfo() ExchangeAccountInfo } diff --git a/wallet.go b/wallet.go new file mode 100644 index 00000000..af6df3e0 --- /dev/null +++ b/wallet.go @@ -0,0 +1,13 @@ +package main + +//ExchangeAccountInfo : Generic type to hold each exchange's holdings in all enabled currencies +type ExchangeAccountInfo struct { + Currencies []ExchangeAccountCurrencyInfo +} + +//ExchangeAccountCurrencyInfo : Sub type to store currency name and value +type ExchangeAccountCurrencyInfo struct { + CurrencyName string + TotalValue int + Hold int +} diff --git a/web/app/views/wallets/wallets.html b/web/app/views/wallets/wallets.html new file mode 100644 index 00000000..b7f11eb4 --- /dev/null +++ b/web/app/views/wallets/wallets.html @@ -0,0 +1,28 @@ +

Dashboard

+

Your current standings

+
+

{{exchange.exchangeName}}

+ + + + + + + + + + + + + + + + + + + +
CurrencyLastHighLowVolumeBidAsk
{{value.CryptoCurrency}}{{value.Last}}{{value.High}}{{value.Low}}{{value.Volume}}{{value.Bid}}{{value.Ask}}
+
+ +
+
\ No newline at end of file diff --git a/web/app/views/wallets/wallets.js b/web/app/views/wallets/wallets.js new file mode 100644 index 00000000..eb4ac885 --- /dev/null +++ b/web/app/views/wallets/wallets.js @@ -0,0 +1,29 @@ +'use strict'; + +angular.module('myApp.home', ['ngRoute']) + +.config(['$routeProvider', function($routeProvider) { + $routeProvider.when('/', { + templateUrl: '/views/home/home.html', + controller: 'HomeController' + }); +}]) + +.controller('HomeController', function ($scope, $http, Notification) { + $scope.getDashboardData = function() { + $http({ + method: 'GET', + url: '/data/all-enabled-currencies' + }). + success(function (data, status, headers, config) { + $scope.exchanges = data.data; + Notification.info("Retrieved latest data"); + }). + error(function (data, status, headers, config) { + console.log('error'); + }); + }; + + $scope.getDashboardData(); + +}); \ No newline at end of file diff --git a/web/app/views/wallets/wallets_test.js b/web/app/views/wallets/wallets_test.js new file mode 100644 index 00000000..14ba79b4 --- /dev/null +++ b/web/app/views/wallets/wallets_test.js @@ -0,0 +1,16 @@ +'use strict'; + +describe('myApp.view1 module', function() { + + beforeEach(module('myApp.view1')); + + describe('view1 controller', function(){ + + it('should ....', inject(function($controller) { + //spec body + var view1Ctrl = $controller('View1Ctrl'); + expect(view1Ctrl).toBeDefined(); + })); + + }); +}); \ No newline at end of file