FTX: Add REST staking and basic subaccount functionality (#692)

* Add FTX staking, missing margin APIs and basic subaccount support

* Fix backtester tests and add optional subaccount support to exchange_wrapper_issues tool

* subAccount to subaccount

* Fix TyPo

* Expand test coverage

* Address nitterinos

* Fix typos

* Remove unusued error type
This commit is contained in:
Adrian Gallagher
2021-06-02 15:52:46 +10:00
committed by GitHub
parent 5ea5245afb
commit f234726382
17 changed files with 361 additions and 84 deletions

View File

@@ -652,6 +652,9 @@ func loadLiveData(cfg *config.Config, base *gctexchange.Base) error {
if cfg.DataSettings.LiveData.API2FAOverride != "" {
base.API.Credentials.PEMKey = cfg.DataSettings.LiveData.API2FAOverride
}
if cfg.DataSettings.LiveData.APISubaccountOverride != "" {
base.API.Credentials.Subaccount = cfg.DataSettings.LiveData.APISubaccountOverride
}
validated := base.ValidateAPICredentials()
base.API.AuthenticatedSupport = validated
if !validated && cfg.DataSettings.LiveData.RealOrders {

View File

@@ -228,11 +228,12 @@ func TestLoadData(t *testing.T) {
}
cfg.DataSettings.CSVData = nil
cfg.DataSettings.LiveData = &config.LiveData{
APIKeyOverride: "test",
APISecretOverride: "test",
APIClientIDOverride: "test",
API2FAOverride: "test",
RealOrders: true,
APIKeyOverride: "test",
APISecretOverride: "test",
APIClientIDOverride: "test",
API2FAOverride: "test",
APISubaccountOverride: "test",
RealOrders: true,
}
_, err = bt.loadData(cfg, exch, cp, asset.Spot)
if err != nil {
@@ -305,10 +306,11 @@ func TestLoadLiveData(t *testing.T) {
AuthenticatedWebsocketSupport: false,
PEMKeySupport: false,
Credentials: struct {
Key string
Secret string
ClientID string
PEMKey string
Key string
Secret string
ClientID string
PEMKey string
Subaccount string
}{},
CredentialsValidator: struct {
RequiresPEM bool
@@ -344,6 +346,7 @@ func TestLoadLiveData(t *testing.T) {
cfg.DataSettings.LiveData.APISecretOverride = "1234"
cfg.DataSettings.LiveData.APIClientIDOverride = "1234"
cfg.DataSettings.LiveData.API2FAOverride = "1234"
cfg.DataSettings.LiveData.APISubaccountOverride = "1234"
err = loadLiveData(cfg, b)
if err != nil {
t.Error(err)

View File

@@ -127,6 +127,7 @@ See below for a set of tables and fields, expected values and what they can do
| APISecretOverride | Will set the GoCryptoTrader exchange to use the following API Secret | `5678` |
| APIClientIDOverride | Will set the GoCryptoTrader exchange to use the following API Client ID | `9012` |
| API2FAOverride | Will set the GoCryptoTrader exchange to use the following 2FA seed | `hello-moto` |
| APISubaccountOverride | Will set the GoCryptoTrader exchange to use the following subaccount on supported exchanges | `subzero` |
| RealOrders | Whether to place real orders. You really should never consider using this. Ever ever. | `true` |
##### Leverage Settings

View File

@@ -117,11 +117,12 @@ func TestPrintSettings(t *testing.T) {
FullPath: "fake",
},
LiveData: &LiveData{
APIKeyOverride: "",
APISecretOverride: "",
APIClientIDOverride: "",
API2FAOverride: "",
RealOrders: false,
APIKeyOverride: "",
APISecretOverride: "",
APIClientIDOverride: "",
API2FAOverride: "",
APISubaccountOverride: "",
RealOrders: false,
},
DatabaseData: &DatabaseData{
StartDate: startDate,
@@ -532,11 +533,12 @@ func TestGenerateConfigForDCALiveCandles(t *testing.T) {
Interval: kline.OneHour.Duration(),
DataType: common.CandleStr,
LiveData: &LiveData{
APIKeyOverride: "",
APISecretOverride: "",
APIClientIDOverride: "",
API2FAOverride: "",
RealOrders: false,
APIKeyOverride: "",
APISecretOverride: "",
APIClientIDOverride: "",
API2FAOverride: "",
APISubaccountOverride: "",
RealOrders: false,
},
},
PortfolioSettings: PortfolioSettings{

View File

@@ -131,9 +131,10 @@ type DatabaseData struct {
// LiveData defines all fields to configure live data
type LiveData struct {
APIKeyOverride string `json:"api-key-override"`
APISecretOverride string `json:"api-secret-override"`
APIClientIDOverride string `json:"api-client-id-override"`
API2FAOverride string `json:"api-2fa-override"`
RealOrders bool `json:"real-orders"`
APIKeyOverride string `json:"api-key-override"`
APISecretOverride string `json:"api-secret-override"`
APIClientIDOverride string `json:"api-client-id-override"`
API2FAOverride string `json:"api-2fa-override"`
APISubaccountOverride string `json:"api-subaccount-override"`
RealOrders bool `json:"real-orders"`
}

View File

@@ -426,13 +426,15 @@ func parseLive(reader *bufio.Reader, cfg *config.Config) {
input = quickParse(reader)
if input == y || input == yes {
fmt.Println("What is the API key?")
cfg.DataSettings.DatabaseData.ConfigOverride.Database = quickParse(reader)
cfg.DataSettings.LiveData.APIKeyOverride = quickParse(reader)
fmt.Println("What is the API secret?")
cfg.DataSettings.DatabaseData.ConfigOverride.Database = quickParse(reader)
cfg.DataSettings.LiveData.APISecretOverride = quickParse(reader)
fmt.Println("What is the Client ID?")
cfg.DataSettings.DatabaseData.ConfigOverride.Database = quickParse(reader)
cfg.DataSettings.LiveData.APIClientIDOverride = quickParse(reader)
fmt.Println("What is the 2FA seed?")
cfg.DataSettings.DatabaseData.ConfigOverride.Database = quickParse(reader)
cfg.DataSettings.LiveData.API2FAOverride = quickParse(reader)
fmt.Println("What is the subaccount to use?")
cfg.DataSettings.LiveData.APISubaccountOverride = quickParse(reader)
}
}
}