mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-09 15:11:10 +00:00
codebase: Remove web frontend and related services (#2067)
* codebase: Remove web frontend and related services * refactor: Update StartPPROF to accept context and adjust related tests * refactor: Simplify SetIfZero functions and update related tests * config: Clarify DowngradeConfig method documentation regarding permanent removal of deprecated fields * refactor: Rename setIfZeroAndWarn to setDefaultIfZeroWarn for clarity and update related calls * refactor: Update error handling in DataHistoryManager and remove redundant error variable
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# GoCryptoTrader dbseed tool
|
||||
|
||||
<img src="https://github.com/thrasher-corp/gocryptotrader/blob/master/web/src/assets/page-logo.png?raw=true" width="350px" height="350px" hspace="70">
|
||||
<img src="/docs/assets/page-logo.png" width="350px" height="350px" hspace="70">
|
||||
|
||||
|
||||
[](https://github.com/thrasher-corp/gocryptotrader/actions/workflows/tests.yml)
|
||||
@@ -103,7 +103,7 @@ btc markets,
|
||||
|
||||
## Donations
|
||||
|
||||
<img src="https://github.com/thrasher-corp/gocryptotrader/blob/master/web/src/assets/donate.png?raw=true" hspace="70">
|
||||
<img src="/docs/assets/donate.png" hspace="70">
|
||||
|
||||
If this framework helped you in any way, or you would like to support the developers working on it, please donate Bitcoin to:
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ upper := strings.ToUpper(testString)
|
||||
|
||||
## Donations
|
||||
|
||||
<img src="https://github.com/thrasher-corp/gocryptotrader/blob/master/web/src/assets/donate.png?raw=true" hspace="70">
|
||||
<img src="/docs/assets/donate.png" hspace="70">
|
||||
|
||||
If this framework helped you in any way, or you would like to support the developers working on it, please donate Bitcoin to:
|
||||
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
{{define "engine apiserver" -}}
|
||||
{{template "header" .}}
|
||||
## Current Features for {{.CapitalName}}
|
||||
+ The API server subsystem is a deprecated service used to host a REST or websocket server to interact with some functions of GoCryptoTrader
|
||||
+ This subsystem is no longer maintained and it is highly encouraged to interact with GRPC endpoints directly where possible
|
||||
+ In order to modify the behaviour of the API server subsystem, you can edit the following inside your config file:
|
||||
|
||||
### deprecatedRPC
|
||||
|
||||
| Config | Description | Example |
|
||||
| ------ | ----------- | ------- |
|
||||
| enabled | If enabled will create a REST server which will listen to commands on the listen address | `true` |
|
||||
| listenAddress | If enabled will listen for REST requests on this address and return a JSON response | `localhost:9050` |
|
||||
|
||||
### websocketRPC
|
||||
|
||||
| Config | Description | Example |
|
||||
| ------ | ----------- | ------- |
|
||||
| enabled | If enabled will create a REST server which will listen to commands on the listen address | `true` |
|
||||
| listenAddress | If enabled will listen for requests on this address and return a JSON response | `localhost:9051` |
|
||||
| connectionLimit | Defines how many connections the websocket RPC server can handle simultanesoly | `1` |
|
||||
| maxAuthFailures | For authenticated endpoints, the amount of failed attempts allowed before disconnection | `3` |
|
||||
| allowInsecureOrigin | Allows use of insecure connections | `true` |
|
||||
|
||||
{{template "donations" .}}
|
||||
{{end}}
|
||||
@@ -74,7 +74,6 @@ However, we welcome pull requests for any exchange which does not match this cri
|
||||
+ Scripting support. See [gctscript](/gctscript/README.md).
|
||||
+ Recent and historic trade processing. See [trades](/exchanges/trade/README.md).
|
||||
+ Backtesting application. An event-driven backtesting tool to test and iterate trading strategies using historical or custom data. See [backtester](/backtester/README.md).
|
||||
+ WebGUI (discontinued).
|
||||
+ Exchange HTTP mock testing. See [mock](/exchanges/mock/README.md).
|
||||
+ Exchange multichain deposits and withdrawals for specific exchanges. See [multichain transfer support](/docs/MULTICHAIN_TRANSFER_SUPPORT.md).
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{{define "donations" -}}
|
||||
## Donations
|
||||
|
||||
<img src="https://github.com/thrasher-corp/gocryptotrader/blob/master/web/src/assets/donate.png?raw=true" hspace="70">
|
||||
<img src="/docs/assets/donate.png" hspace="70">
|
||||
|
||||
If this framework helped you in any way, or you would like to support the developers working on it, please donate Bitcoin to:
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# GoCryptoTrader gRPC client
|
||||
|
||||
<img src="https://github.com/thrasher-corp/gocryptotrader/blob/master/web/src/assets/page-logo.png?raw=true" width="350px" height="350px" hspace="70">
|
||||
<img src="/docs/assets/page-logo.png" width="350px" height="350px" hspace="70">
|
||||
|
||||
[](https://github.com/thrasher-corp/gocryptotrader/actions/workflows/tests.yml)
|
||||
[](https://github.com/thrasher-corp/gocryptotrader/blob/master/LICENSE)
|
||||
|
||||
@@ -1,200 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
gws "github.com/gorilla/websocket"
|
||||
"github.com/thrasher-corp/gocryptotrader/common"
|
||||
"github.com/thrasher-corp/gocryptotrader/config"
|
||||
"github.com/thrasher-corp/gocryptotrader/encoding/json"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
)
|
||||
|
||||
// Vars for the websocket client
|
||||
var (
|
||||
WSConn *gws.Conn
|
||||
)
|
||||
|
||||
// WebsocketEvent is the struct used for websocket events
|
||||
type WebsocketEvent struct {
|
||||
Exchange string `json:"exchange,omitempty"`
|
||||
AssetType string `json:"assetType,omitempty"`
|
||||
Event string
|
||||
Data any
|
||||
}
|
||||
|
||||
// WebsocketAuth is the struct used for a websocket auth request
|
||||
type WebsocketAuth struct {
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
}
|
||||
|
||||
// WebsocketEventResponse is the struct used for websocket event responses
|
||||
type WebsocketEventResponse struct {
|
||||
Event string `json:"event"`
|
||||
Data any `json:"data"`
|
||||
Error string `json:"error"`
|
||||
}
|
||||
|
||||
// WebsocketOrderbookTickerRequest is a struct used for ticker and orderbook
|
||||
// requests
|
||||
type WebsocketOrderbookTickerRequest struct {
|
||||
Exchange string `json:"exchangeName"`
|
||||
Currency string `json:"currency"`
|
||||
AssetType asset.Item `json:"assetType"`
|
||||
}
|
||||
|
||||
// SendWebsocketEvent sends a websocket event message
|
||||
func SendWebsocketEvent(event string, reqData any, result *WebsocketEventResponse) error {
|
||||
req := WebsocketEvent{
|
||||
Event: event,
|
||||
}
|
||||
|
||||
if reqData != nil {
|
||||
req.Data = reqData
|
||||
}
|
||||
|
||||
err := WSConn.WriteJSON(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = WSConn.ReadJSON(&result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if result.Error != "" {
|
||||
return errors.New(result.Error)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
cfg := config.GetConfig()
|
||||
err := cfg.LoadConfig(config.File, true)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to load config file: %s", err)
|
||||
}
|
||||
|
||||
listenAddr := cfg.RemoteControl.WebsocketRPC.ListenAddress
|
||||
wsHost := fmt.Sprintf("ws://%s/ws", net.JoinHostPort(common.ExtractHostOrDefault(listenAddr),
|
||||
strconv.Itoa(common.ExtractPortOrDefault(listenAddr))))
|
||||
log.Printf("Connecting to websocket host: %s", wsHost)
|
||||
|
||||
var dialer gws.Dialer
|
||||
var resp *http.Response
|
||||
WSConn, resp, err = dialer.Dial(wsHost, http.Header{})
|
||||
if err != nil {
|
||||
log.Println("Unable to connect to websocket server")
|
||||
return
|
||||
}
|
||||
resp.Body.Close()
|
||||
log.Println("Connected to websocket!")
|
||||
|
||||
log.Println("Authenticating..")
|
||||
shasum := sha256.Sum256([]byte(cfg.RemoteControl.Password))
|
||||
reqData := WebsocketAuth{
|
||||
Username: cfg.RemoteControl.Username,
|
||||
Password: hex.EncodeToString(shasum[:]),
|
||||
}
|
||||
var wsResp WebsocketEventResponse
|
||||
err = SendWebsocketEvent("auth", reqData, &wsResp)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
log.Println("Authenticated successfully")
|
||||
|
||||
log.Println("Getting config..")
|
||||
err = SendWebsocketEvent("GetConfig", nil, &wsResp)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
log.Printf("Fetched config.")
|
||||
|
||||
dataJSON, err := json.Marshal(&wsResp.Data)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
var resultCfg config.Config
|
||||
err = json.Unmarshal(dataJSON, &resultCfg)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
log.Println("Saving config..")
|
||||
origBotName := resultCfg.Name
|
||||
resultCfg.Name = "TEST"
|
||||
err = SendWebsocketEvent("SaveConfig", resultCfg, &wsResp)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
log.Println("Saved config!")
|
||||
resultCfg.Name = origBotName
|
||||
err = SendWebsocketEvent("SaveConfig", resultCfg, &wsResp)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
log.Println("Saved config (restored original bot name)!")
|
||||
|
||||
log.Println("Getting account info..")
|
||||
err = SendWebsocketEvent("GetAccountInfo", nil, &wsResp)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
log.Println("Got account info!")
|
||||
|
||||
log.Println("Getting tickers..")
|
||||
err = SendWebsocketEvent("GetTickers", nil, &wsResp)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
log.Println("Got tickers!")
|
||||
|
||||
log.Println("Getting specific ticker..")
|
||||
dataReq := WebsocketOrderbookTickerRequest{
|
||||
Exchange: "Bitfinex",
|
||||
Currency: "BTCUSD",
|
||||
AssetType: asset.Spot,
|
||||
}
|
||||
|
||||
err = SendWebsocketEvent("GetTicker", dataReq, &wsResp)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
log.Println("Got ticker!")
|
||||
|
||||
log.Println("Getting orderbooks..")
|
||||
err = SendWebsocketEvent("GetOrderbooks", nil, &wsResp)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
log.Println("Got orderbooks!")
|
||||
|
||||
log.Println("Getting specific orderbook..")
|
||||
err = SendWebsocketEvent("GetOrderbook", dataReq, &wsResp)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
log.Println("Got orderbook!")
|
||||
|
||||
for {
|
||||
var wsEvent WebsocketEvent
|
||||
err = WSConn.ReadJSON(&wsEvent)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
|
||||
log.Printf("Recv'd: %s", wsEvent.Event)
|
||||
}
|
||||
WSConn.Close()
|
||||
}
|
||||
Reference in New Issue
Block a user