Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
Kelp UI: Move options metadata to the backend and expand options (#208)
Browse files Browse the repository at this point in the history
addresses part of issue #67

* 1 - flux the optionsMetadata structure in preparation to move to backend

* 2 - move v0.1 impl of optionsMetadata to backend

* 3 - builder pattern to create optionsMetadata along with preloading logic when making APIServer

* 4 - add support for fiat via currencylayer API

* 5 - dynamically include whitelisted ccxt markets

* 6 - refactor asset converters, adding custom Display assetConverter and using for CCXT

* 7 - inclide all CCXT exchanges

* 8 - don't log the optionsMetadata json response since it's too verbose

* 9 - blacklist some ccxt exchanges that are not loading for me so startup is faster

* 10 - add all fiat currencies available via currencylayer

* 11 - list all coinmarketcap tokens via their API

* 12 - remove commented out optionsMetadata struct
  • Loading branch information
nikhilsaraf authored Jul 31, 2019
1 parent 002a3d6 commit 1f79bb8
Show file tree
Hide file tree
Showing 16 changed files with 553 additions and 217 deletions.
2 changes: 1 addition & 1 deletion api/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ type OrderbookFetcher interface {

// TradeAPI is the interface we use as a generic API for trading on any crypto exchange
type TradeAPI interface {
GetAssetConverter() *model.AssetConverter
GetAssetConverter() model.AssetConverterInterface

Constrainable

Expand Down
59 changes: 36 additions & 23 deletions gui/backend/api_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@ import (

// APIServer is an instance of the API service
type APIServer struct {
dirPath string
binPath string
configsDir string
logsDir string
kos *kelpos.KelpOS
horizonTestnetURI string
horizonPubnetURI string
apiTestNet *horizonclient.Client
apiPubNet *horizonclient.Client
apiTestNetOld *horizon.Client
apiPubNetOld *horizon.Client
dirPath string
binPath string
configsDir string
logsDir string
kos *kelpos.KelpOS
horizonTestnetURI string
horizonPubnetURI string
apiTestNet *horizonclient.Client
apiPubNet *horizonclient.Client
apiTestNetOld *horizon.Client
apiPubNetOld *horizon.Client
cachedOptionsMetadata metadata
}

// MakeAPIServer is a factory method
Expand Down Expand Up @@ -62,18 +63,24 @@ func MakeAPIServer(kos *kelpos.KelpOS, horizonTestnetURI string, horizonPubnetUR
HTTP: http.DefaultClient,
}

optionsMetadata, e := loadOptionsMetadata()
if e != nil {
return nil, fmt.Errorf("error while loading options metadata when making APIServer: %s", e)
}

return &APIServer{
dirPath: dirPath,
binPath: binPath,
configsDir: configsDir,
logsDir: logsDir,
kos: kos,
horizonTestnetURI: horizonTestnetURI,
horizonPubnetURI: horizonPubnetURI,
apiTestNet: apiTestNet,
apiPubNet: apiPubNet,
apiTestNetOld: apiTestNetOld,
apiPubNetOld: apiPubNetOld,
dirPath: dirPath,
binPath: binPath,
configsDir: configsDir,
logsDir: logsDir,
kos: kos,
horizonTestnetURI: horizonTestnetURI,
horizonPubnetURI: horizonPubnetURI,
apiTestNet: apiTestNet,
apiPubNet: apiPubNet,
apiTestNetOld: apiTestNetOld,
apiPubNetOld: apiPubNetOld,
cachedOptionsMetadata: optionsMetadata,
}, nil
}

Expand Down Expand Up @@ -110,13 +117,19 @@ func (s *APIServer) writeErrorJson(w http.ResponseWriter, message string) {
}

func (s *APIServer) writeJson(w http.ResponseWriter, v interface{}) {
s.writeJsonWithLog(w, v, true)
}

func (s *APIServer) writeJsonWithLog(w http.ResponseWriter, v interface{}, doLog bool) {
marshalledJson, e := json.MarshalIndent(v, "", " ")
if e != nil {
s.writeErrorJson(w, fmt.Sprintf("unable to marshal json with indentation: %s", e))
return
}

log.Printf("responseJson: %s\n", string(marshalledJson))
if doLog {
log.Printf("responseJson: %s\n", string(marshalledJson))
}
w.WriteHeader(http.StatusOK)
w.Write(marshalledJson)
}
Expand Down
Loading

0 comments on commit 1f79bb8

Please sign in to comment.