From b6ff596ce0ee889499c5c3c51d1e8e0ab1d358e6 Mon Sep 17 00:00:00 2001 From: Anatoly Ostrovsky Date: Fri, 8 Dec 2023 19:18:15 +0200 Subject: [PATCH] Decouple API from pkg --- Makefile | 31 +---- api/api.mk | 26 ++++ {pkg/api => api}/endpoints/admin/apps.yaml | 0 .../endpoints/admin/apps_by_id.yaml | 0 .../api => api}/endpoints/admin/auctions.yaml | 0 .../endpoints/admin/instruments.yaml | 0 .../api => api}/endpoints/admin/payments.yaml | 0 .../endpoints/admin/payments_by_id.yaml | 0 .../endpoints/public/currencies.yaml | 0 .../endpoints/public/fx-instruments.yaml | 0 .../endpoints/public/instruments.yaml | 0 .../order_books_by_instrument_name.yaml | 0 .../endpoints/user/book_orders.yaml | 0 .../endpoints/user/payment_accounts.yaml | 0 .../endpoints/user/trade_orders.yaml | 0 {pkg/api => api}/endpoints/user/trades.yaml | 0 .../endpoints/user/trades_by_id.yaml | 0 .../endpoints/user/trading_account_by_id.yaml | 0 {pkg/api => api}/models/app_entity.yaml | 0 {pkg/api => api}/models/currency.yaml | 0 {pkg/api => api}/models/instrument.yaml | 0 {pkg/api => api}/models/order_book.yaml | 0 {pkg/api => api}/models/payment.yaml | 0 {pkg/api => api}/models/payment_account.yaml | 0 {pkg/api => api}/models/shared.yaml | 0 {pkg/api => api}/models/trade.yaml | 0 {pkg/api => api}/models/trade_order.yaml | 1 - {pkg/api => api}/models/trading_account.yaml | 0 {pkg/api => api}/openapi.yaml | 0 package.json => api/package.json | 0 openapitools.json | 2 +- pkg/rest/.openapi-generator-ignore | 2 +- pkg/rest/.openapi-generator/FILES | 1 + pkg/rest/.openapi-generator/VERSION | 2 +- pkg/rest/README.md | 2 +- pkg/rest/api/api.go | 22 ++-- pkg/rest/api/api_admin.go | 8 ++ pkg/rest/api/api_admin_service.go | 8 +- pkg/rest/api/api_public.go | 4 + pkg/rest/api/api_public_service.go | 14 +- pkg/rest/api/api_user.go | 40 ++++++ pkg/rest/api/api_user_service.go | 28 ++-- pkg/rest/api/model_app_entity.go | 4 +- pkg/rest/api/model_create_trade_request.go | 6 +- pkg/rest/api/model_currency.go | 4 +- pkg/rest/api/model_currency_list.go | 7 +- pkg/rest/api/model_fx_instrument.go | 10 +- pkg/rest/api/model_instrument.go | 8 +- pkg/rest/api/model_order_book.go | 7 +- pkg/rest/api/model_payment.go | 20 +-- pkg/rest/api/model_payment_account.go | 10 +- pkg/rest/api/model_payment_account_list.go | 7 +- pkg/rest/api/model_payment_type.go | 52 +++++++- pkg/rest/api/model_price_volume.go | 4 +- pkg/rest/api/model_trade.go | 2 +- pkg/rest/api/model_trade_order.go | 16 ++- pkg/rest/api/model_trade_order_side.go | 40 +++++- pkg/rest/api/model_trade_order_status.go | 52 +++++++- .../api/model_trade_order_time_in_force.go | 49 ++++++- pkg/rest/api/model_trade_order_type.go | 46 ++++++- pkg/rest/api/model_trading_account.go | 9 +- .../api/model_trading_account_instrument.go | 12 +- pkg/rest/api/openapi.yaml | 120 ++++++++++++++++-- 63 files changed, 544 insertions(+), 132 deletions(-) create mode 100644 api/api.mk rename {pkg/api => api}/endpoints/admin/apps.yaml (100%) rename {pkg/api => api}/endpoints/admin/apps_by_id.yaml (100%) rename {pkg/api => api}/endpoints/admin/auctions.yaml (100%) rename {pkg/api => api}/endpoints/admin/instruments.yaml (100%) rename {pkg/api => api}/endpoints/admin/payments.yaml (100%) rename {pkg/api => api}/endpoints/admin/payments_by_id.yaml (100%) rename {pkg/api => api}/endpoints/public/currencies.yaml (100%) rename {pkg/api => api}/endpoints/public/fx-instruments.yaml (100%) rename {pkg/api => api}/endpoints/public/instruments.yaml (100%) rename {pkg/api => api}/endpoints/public/order_books_by_instrument_name.yaml (100%) rename {pkg/api => api}/endpoints/user/book_orders.yaml (100%) rename {pkg/api => api}/endpoints/user/payment_accounts.yaml (100%) rename {pkg/api => api}/endpoints/user/trade_orders.yaml (100%) rename {pkg/api => api}/endpoints/user/trades.yaml (100%) rename {pkg/api => api}/endpoints/user/trades_by_id.yaml (100%) rename {pkg/api => api}/endpoints/user/trading_account_by_id.yaml (100%) rename {pkg/api => api}/models/app_entity.yaml (100%) rename {pkg/api => api}/models/currency.yaml (100%) rename {pkg/api => api}/models/instrument.yaml (100%) rename {pkg/api => api}/models/order_book.yaml (100%) rename {pkg/api => api}/models/payment.yaml (100%) rename {pkg/api => api}/models/payment_account.yaml (100%) rename {pkg/api => api}/models/shared.yaml (100%) rename {pkg/api => api}/models/trade.yaml (100%) rename {pkg/api => api}/models/trade_order.yaml (98%) rename {pkg/api => api}/models/trading_account.yaml (100%) rename {pkg/api => api}/openapi.yaml (100%) rename package.json => api/package.json (100%) diff --git a/Makefile b/Makefile index 2effe69..4a44a87 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,4 @@ +include api/api.mk .DEFAULT_GOAL := help .PHONY: help @@ -27,43 +28,19 @@ lint: go vet ./... include ./pkg/conf/dev.env -DBDSN:="host=$(POSTGRES_HOST) user=$(POSTGRES_USER) password=$(POSTGRES_PASSWORD) dbname=$(POSTGRES_DB) port=$(POSTGRES_PORT) sslmode=disable" +DB_DSN:="host=$(POSTGRES_HOST) user=$(POSTGRES_USER) password=$(POSTGRES_PASSWORD) dbname=$(POSTGRES_DB) port=$(POSTGRES_PORT) sslmode=disable" MIGRATE_OPTIONS=-allow-missing -dir="./sql" db-up: ## Migrate down on database - goose -v $(MIGRATE_OPTIONS) postgres $(DBDSN) up + goose -v $(MIGRATE_OPTIONS) postgres $(DB_DSN) up db-down: ## Migrate up on database - goose -v $(MIGRATE_OPTIONS) postgres $(DBDSN) reset + goose -v $(MIGRATE_OPTIONS) postgres $(DB_DSN) reset db-rebuild: ## Reset the database make db-down make db-up -OUTPUT_YAML:="./pkg/static/api.yaml" - -bundle-api: - npx @redocly/cli bundle \ - pkg/api/openapi.yaml \ - --output $(OUTPUT_YAML) - -validate-api: - make bundle-api - npx @redocly/cli lint \ - $(OUTPUT_YAML) \ - --format=checkstyle - -generate-api: ## Generate server bindings, move model files, fix imports - make validate-api - npx @openapitools/openapi-generator-cli generate \ - -i $(OUTPUT_YAML) \ - -g go-server \ - -o pkg/rest \ - --additional-properties=packageName=api \ - --additional-properties=sourceFolder=api \ - --additional-properties=outputAsLibrary=true - make lint - help: grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) \ | sed -n 's/^\(.*\): \(.*\)##\(.*\)/\1\3/p' diff --git a/api/api.mk b/api/api.mk new file mode 100644 index 0000000..382a4b8 --- /dev/null +++ b/api/api.mk @@ -0,0 +1,26 @@ +# API management make + +INPUT_YAML:="./api/openapi.yaml" +OUTPUT_YAML:="../pkg/static/api.yaml" + +bundle-api: + npx @redocly/cli bundle \ + $(INPUT_YAML) \ + --output $(OUTPUT_YAML) + +validate-api: + make bundle-api + npx @redocly/cli lint \ + $(OUTPUT_YAML) \ + --format=checkstyle + +generate-api: ## Generate server bindings, move model files, fix imports + make validate-api + npx @openapitools/openapi-generator-cli generate \ + -i $(OUTPUT_YAML) \ + -g go-server \ + -o pkg/rest \ + --additional-properties=packageName=api \ + --additional-properties=sourceFolder=api \ + --additional-properties=outputAsLibrary=true + make lint \ No newline at end of file diff --git a/pkg/api/endpoints/admin/apps.yaml b/api/endpoints/admin/apps.yaml similarity index 100% rename from pkg/api/endpoints/admin/apps.yaml rename to api/endpoints/admin/apps.yaml diff --git a/pkg/api/endpoints/admin/apps_by_id.yaml b/api/endpoints/admin/apps_by_id.yaml similarity index 100% rename from pkg/api/endpoints/admin/apps_by_id.yaml rename to api/endpoints/admin/apps_by_id.yaml diff --git a/pkg/api/endpoints/admin/auctions.yaml b/api/endpoints/admin/auctions.yaml similarity index 100% rename from pkg/api/endpoints/admin/auctions.yaml rename to api/endpoints/admin/auctions.yaml diff --git a/pkg/api/endpoints/admin/instruments.yaml b/api/endpoints/admin/instruments.yaml similarity index 100% rename from pkg/api/endpoints/admin/instruments.yaml rename to api/endpoints/admin/instruments.yaml diff --git a/pkg/api/endpoints/admin/payments.yaml b/api/endpoints/admin/payments.yaml similarity index 100% rename from pkg/api/endpoints/admin/payments.yaml rename to api/endpoints/admin/payments.yaml diff --git a/pkg/api/endpoints/admin/payments_by_id.yaml b/api/endpoints/admin/payments_by_id.yaml similarity index 100% rename from pkg/api/endpoints/admin/payments_by_id.yaml rename to api/endpoints/admin/payments_by_id.yaml diff --git a/pkg/api/endpoints/public/currencies.yaml b/api/endpoints/public/currencies.yaml similarity index 100% rename from pkg/api/endpoints/public/currencies.yaml rename to api/endpoints/public/currencies.yaml diff --git a/pkg/api/endpoints/public/fx-instruments.yaml b/api/endpoints/public/fx-instruments.yaml similarity index 100% rename from pkg/api/endpoints/public/fx-instruments.yaml rename to api/endpoints/public/fx-instruments.yaml diff --git a/pkg/api/endpoints/public/instruments.yaml b/api/endpoints/public/instruments.yaml similarity index 100% rename from pkg/api/endpoints/public/instruments.yaml rename to api/endpoints/public/instruments.yaml diff --git a/pkg/api/endpoints/public/order_books_by_instrument_name.yaml b/api/endpoints/public/order_books_by_instrument_name.yaml similarity index 100% rename from pkg/api/endpoints/public/order_books_by_instrument_name.yaml rename to api/endpoints/public/order_books_by_instrument_name.yaml diff --git a/pkg/api/endpoints/user/book_orders.yaml b/api/endpoints/user/book_orders.yaml similarity index 100% rename from pkg/api/endpoints/user/book_orders.yaml rename to api/endpoints/user/book_orders.yaml diff --git a/pkg/api/endpoints/user/payment_accounts.yaml b/api/endpoints/user/payment_accounts.yaml similarity index 100% rename from pkg/api/endpoints/user/payment_accounts.yaml rename to api/endpoints/user/payment_accounts.yaml diff --git a/pkg/api/endpoints/user/trade_orders.yaml b/api/endpoints/user/trade_orders.yaml similarity index 100% rename from pkg/api/endpoints/user/trade_orders.yaml rename to api/endpoints/user/trade_orders.yaml diff --git a/pkg/api/endpoints/user/trades.yaml b/api/endpoints/user/trades.yaml similarity index 100% rename from pkg/api/endpoints/user/trades.yaml rename to api/endpoints/user/trades.yaml diff --git a/pkg/api/endpoints/user/trades_by_id.yaml b/api/endpoints/user/trades_by_id.yaml similarity index 100% rename from pkg/api/endpoints/user/trades_by_id.yaml rename to api/endpoints/user/trades_by_id.yaml diff --git a/pkg/api/endpoints/user/trading_account_by_id.yaml b/api/endpoints/user/trading_account_by_id.yaml similarity index 100% rename from pkg/api/endpoints/user/trading_account_by_id.yaml rename to api/endpoints/user/trading_account_by_id.yaml diff --git a/pkg/api/models/app_entity.yaml b/api/models/app_entity.yaml similarity index 100% rename from pkg/api/models/app_entity.yaml rename to api/models/app_entity.yaml diff --git a/pkg/api/models/currency.yaml b/api/models/currency.yaml similarity index 100% rename from pkg/api/models/currency.yaml rename to api/models/currency.yaml diff --git a/pkg/api/models/instrument.yaml b/api/models/instrument.yaml similarity index 100% rename from pkg/api/models/instrument.yaml rename to api/models/instrument.yaml diff --git a/pkg/api/models/order_book.yaml b/api/models/order_book.yaml similarity index 100% rename from pkg/api/models/order_book.yaml rename to api/models/order_book.yaml diff --git a/pkg/api/models/payment.yaml b/api/models/payment.yaml similarity index 100% rename from pkg/api/models/payment.yaml rename to api/models/payment.yaml diff --git a/pkg/api/models/payment_account.yaml b/api/models/payment_account.yaml similarity index 100% rename from pkg/api/models/payment_account.yaml rename to api/models/payment_account.yaml diff --git a/pkg/api/models/shared.yaml b/api/models/shared.yaml similarity index 100% rename from pkg/api/models/shared.yaml rename to api/models/shared.yaml diff --git a/pkg/api/models/trade.yaml b/api/models/trade.yaml similarity index 100% rename from pkg/api/models/trade.yaml rename to api/models/trade.yaml diff --git a/pkg/api/models/trade_order.yaml b/api/models/trade_order.yaml similarity index 98% rename from pkg/api/models/trade_order.yaml rename to api/models/trade_order.yaml index 6b9087f..c46b847 100644 --- a/pkg/api/models/trade_order.yaml +++ b/api/models/trade_order.yaml @@ -32,7 +32,6 @@ components: - PARTIALLY_CANCELLED - PARTIALLY_REJECTED - FILLED - - REJECTED TradeOrderList: type: array diff --git a/pkg/api/models/trading_account.yaml b/api/models/trading_account.yaml similarity index 100% rename from pkg/api/models/trading_account.yaml rename to api/models/trading_account.yaml diff --git a/pkg/api/openapi.yaml b/api/openapi.yaml similarity index 100% rename from pkg/api/openapi.yaml rename to api/openapi.yaml diff --git a/package.json b/api/package.json similarity index 100% rename from package.json rename to api/package.json diff --git a/openapitools.json b/openapitools.json index 3015568..15fef60 100644 --- a/openapitools.json +++ b/openapitools.json @@ -2,6 +2,6 @@ "$schema": "./node_modules/@openapitools/openapi-generator-cli/config.schema.json", "spaces": 2, "generator-cli": { - "version": "7.0.0" + "version": "7.1.0" } } diff --git a/pkg/rest/.openapi-generator-ignore b/pkg/rest/.openapi-generator-ignore index f7b7430..44bfae3 100644 --- a/pkg/rest/.openapi-generator-ignore +++ b/pkg/rest/.openapi-generator-ignore @@ -22,5 +22,5 @@ # Then explicitly reverse the ignore rule for a single file: #!docs/README.md # -**/api_public_service.go +#**/api_public_service.go #**/helpers.go \ No newline at end of file diff --git a/pkg/rest/.openapi-generator/FILES b/pkg/rest/.openapi-generator/FILES index 1bd5322..f956357 100644 --- a/pkg/rest/.openapi-generator/FILES +++ b/pkg/rest/.openapi-generator/FILES @@ -3,6 +3,7 @@ api/api.go api/api_admin.go api/api_admin_service.go api/api_public.go +api/api_public_service.go api/api_user.go api/api_user_service.go api/error.go diff --git a/pkg/rest/.openapi-generator/VERSION b/pkg/rest/.openapi-generator/VERSION index 4122521..3769235 100644 --- a/pkg/rest/.openapi-generator/VERSION +++ b/pkg/rest/.openapi-generator/VERSION @@ -1 +1 @@ -7.0.0 \ No newline at end of file +7.1.0 \ No newline at end of file diff --git a/pkg/rest/README.md b/pkg/rest/README.md index fe4d7cf..30be51e 100644 --- a/pkg/rest/README.md +++ b/pkg/rest/README.md @@ -24,7 +24,7 @@ To see how to make this your own, look here: [README](https://openapi-generator.tech) - API version: 1.0.0 -- Build date: 2023-12-07T21:19:37.002526+02:00[Europe/Riga] +- Build date: 2023-12-08T19:14:53.772694+02:00[Europe/Riga] ### Running the server diff --git a/pkg/rest/api/api.go b/pkg/rest/api/api.go index af02887..20eaf3f 100644 --- a/pkg/rest/api/api.go +++ b/pkg/rest/api/api.go @@ -54,9 +54,9 @@ type UserAPIRouter interface { // and updated with the logic required for the API. type AdminAPIServicer interface { CreateAdminPayment(context.Context) (ImplResponse, error) - GetAdminPaymentById(context.Context, interface{}) (ImplResponse, error) + GetAdminPaymentById(context.Context, string) (ImplResponse, error) GetAppEntities(context.Context) (ImplResponse, error) - GetAppEntity(context.Context, interface{}) (ImplResponse, error) + GetAppEntity(context.Context, string) (ImplResponse, error) } // PublicAPIServicer defines the api actions for the PublicAPI service @@ -67,7 +67,7 @@ type PublicAPIServicer interface { GetCurrencies(context.Context) (ImplResponse, error) GetFxInstruments(context.Context) (ImplResponse, error) GetInstruments(context.Context) (ImplResponse, error) - GetOrderBook(context.Context, interface{}) (ImplResponse, error) + GetOrderBook(context.Context, string) (ImplResponse, error) } // UserAPIServicer defines the api actions for the UserAPI service @@ -75,12 +75,12 @@ type PublicAPIServicer interface { // while the service implementation can be ignored with the .openapi-generator-ignore file // and updated with the logic required for the API. type UserAPIServicer interface { - CreateTrade(context.Context, interface{}, CreateTradeRequest) (ImplResponse, error) - DeleteTradeById(context.Context, interface{}, interface{}) (ImplResponse, error) - GetBookOrders(context.Context, interface{}) (ImplResponse, error) - GetPaymentAccounts(context.Context, interface{}) (ImplResponse, error) - GetTradeById(context.Context, interface{}, interface{}) (ImplResponse, error) - GetTradeOrders(context.Context, interface{}) (ImplResponse, error) - GetTrades(context.Context, interface{}) (ImplResponse, error) - GetTradingAccount(context.Context, interface{}) (ImplResponse, error) + CreateTrade(context.Context, string, CreateTradeRequest) (ImplResponse, error) + DeleteTradeById(context.Context, string, string) (ImplResponse, error) + GetBookOrders(context.Context, string) (ImplResponse, error) + GetPaymentAccounts(context.Context, string) (ImplResponse, error) + GetTradeById(context.Context, string, string) (ImplResponse, error) + GetTradeOrders(context.Context, string) (ImplResponse, error) + GetTrades(context.Context, string) (ImplResponse, error) + GetTradingAccount(context.Context, string) (ImplResponse, error) } diff --git a/pkg/rest/api/api_admin.go b/pkg/rest/api/api_admin.go index 412d1e3..0e26357 100644 --- a/pkg/rest/api/api_admin.go +++ b/pkg/rest/api/api_admin.go @@ -88,6 +88,10 @@ func (c *AdminAPIController) CreateAdminPayment(w http.ResponseWriter, r *http.R func (c *AdminAPIController) GetAdminPaymentById(w http.ResponseWriter, r *http.Request) { params := mux.Vars(r) paymentIdParam := params["payment_id"] + if paymentIdParam == "" { + c.errorHandler(w, r, &RequiredError{"payment_id"}, nil) + return + } result, err := c.service.GetAdminPaymentById(r.Context(), paymentIdParam) // If an error occurred, encode the error with the status code if err != nil { @@ -114,6 +118,10 @@ func (c *AdminAPIController) GetAppEntities(w http.ResponseWriter, r *http.Reque func (c *AdminAPIController) GetAppEntity(w http.ResponseWriter, r *http.Request) { params := mux.Vars(r) appEntityIdParam := params["app_entity_id"] + if appEntityIdParam == "" { + c.errorHandler(w, r, &RequiredError{"app_entity_id"}, nil) + return + } result, err := c.service.GetAppEntity(r.Context(), appEntityIdParam) // If an error occurred, encode the error with the status code if err != nil { diff --git a/pkg/rest/api/api_admin_service.go b/pkg/rest/api/api_admin_service.go index 42e0e5c..91fbc7b 100644 --- a/pkg/rest/api/api_admin_service.go +++ b/pkg/rest/api/api_admin_service.go @@ -41,7 +41,7 @@ func (s *AdminAPIService) CreateAdminPayment(ctx context.Context) (ImplResponse, } // GetAdminPaymentById - Get payment -func (s *AdminAPIService) GetAdminPaymentById(ctx context.Context, paymentId interface{}) (ImplResponse, error) { +func (s *AdminAPIService) GetAdminPaymentById(ctx context.Context, paymentId string) (ImplResponse, error) { // TODO - update GetAdminPaymentById with the required logic for this service method. // Add api_admin_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. @@ -59,8 +59,8 @@ func (s *AdminAPIService) GetAppEntities(ctx context.Context) (ImplResponse, err // TODO - update GetAppEntities with the required logic for this service method. // Add api_admin_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. - // TODO: Uncomment the next line to return response Response(200, interface{}{}) or use other options such as http.Ok ... - // return Response(200, interface{}{}), nil + // TODO: Uncomment the next line to return response Response(200, []AppEntity{}) or use other options such as http.Ok ... + // return Response(200, []AppEntity{}), nil // TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ... // return Response(404, nil),nil @@ -69,7 +69,7 @@ func (s *AdminAPIService) GetAppEntities(ctx context.Context) (ImplResponse, err } // GetAppEntity - Get application entity -func (s *AdminAPIService) GetAppEntity(ctx context.Context, appEntityId interface{}) (ImplResponse, error) { +func (s *AdminAPIService) GetAppEntity(ctx context.Context, appEntityId string) (ImplResponse, error) { // TODO - update GetAppEntity with the required logic for this service method. // Add api_admin_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. diff --git a/pkg/rest/api/api_public.go b/pkg/rest/api/api_public.go index 83dfb44..07f6cdc 100644 --- a/pkg/rest/api/api_public.go +++ b/pkg/rest/api/api_public.go @@ -112,6 +112,10 @@ func (c *PublicAPIController) GetInstruments(w http.ResponseWriter, r *http.Requ func (c *PublicAPIController) GetOrderBook(w http.ResponseWriter, r *http.Request) { params := mux.Vars(r) instrumentNameParam := params["instrument_name"] + if instrumentNameParam == "" { + c.errorHandler(w, r, &RequiredError{"instrument_name"}, nil) + return + } result, err := c.service.GetOrderBook(r.Context(), instrumentNameParam) // If an error occurred, encode the error with the status code if err != nil { diff --git a/pkg/rest/api/api_public_service.go b/pkg/rest/api/api_public_service.go index 5531fd6..e9aa241 100644 --- a/pkg/rest/api/api_public_service.go +++ b/pkg/rest/api/api_public_service.go @@ -33,8 +33,8 @@ func (s *PublicAPIService) GetCurrencies(ctx context.Context) (ImplResponse, err res := make([]Currency, 0) for _, v := range currencies { cur := Currency{ - Name: NewInterface(v.Name), - Precision: NewInterface(v.Precision), + Name: string(v.Name), + Precision: int32(v.Precision), } res = append(res, cur) } @@ -47,8 +47,8 @@ func (s *PublicAPIService) GetFxInstruments(ctx context.Context) (ImplResponse, // TODO - update GetFxInstruments with the required logic for this service method. // Add api_public_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. - // TODO: Uncomment the next line to return response Response(200, interface{}{}) or use other options such as http.Ok ... - // return Response(200, interface{}{}), nil + // TODO: Uncomment the next line to return response Response(200, []FxInstrument{}) or use other options such as http.Ok ... + // return Response(200, []FxInstrument{}), nil // TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ... // return Response(404, nil),nil @@ -61,8 +61,8 @@ func (s *PublicAPIService) GetInstruments(ctx context.Context) (ImplResponse, er // TODO - update GetInstruments with the required logic for this service method. // Add api_public_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. - // TODO: Uncomment the next line to return response Response(200, interface{}{}) or use other options such as http.Ok ... - // return Response(200, interface{}{}), nil + // TODO: Uncomment the next line to return response Response(200, []Instrument{}) or use other options such as http.Ok ... + // return Response(200, []Instrument{}), nil // TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ... // return Response(404, nil),nil @@ -71,7 +71,7 @@ func (s *PublicAPIService) GetInstruments(ctx context.Context) (ImplResponse, er } // GetOrderBook - Get order book -func (s *PublicAPIService) GetOrderBook(ctx context.Context, instrumentName interface{}) (ImplResponse, error) { +func (s *PublicAPIService) GetOrderBook(ctx context.Context, instrumentName string) (ImplResponse, error) { // TODO - update GetOrderBook with the required logic for this service method. // Add api_public_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. diff --git a/pkg/rest/api/api_user.go b/pkg/rest/api/api_user.go index 2946f24..b05db1f 100644 --- a/pkg/rest/api/api_user.go +++ b/pkg/rest/api/api_user.go @@ -97,6 +97,10 @@ func (c *UserAPIController) Routes() Routes { func (c *UserAPIController) CreateTrade(w http.ResponseWriter, r *http.Request) { params := mux.Vars(r) tradingAccountIdParam := params["trading_account_id"] + if tradingAccountIdParam == "" { + c.errorHandler(w, r, &RequiredError{"trading_account_id"}, nil) + return + } createTradeRequestParam := CreateTradeRequest{} d := json.NewDecoder(r.Body) d.DisallowUnknownFields() @@ -126,7 +130,15 @@ func (c *UserAPIController) CreateTrade(w http.ResponseWriter, r *http.Request) func (c *UserAPIController) DeleteTradeById(w http.ResponseWriter, r *http.Request) { params := mux.Vars(r) tradingAccountIdParam := params["trading_account_id"] + if tradingAccountIdParam == "" { + c.errorHandler(w, r, &RequiredError{"trading_account_id"}, nil) + return + } tradeIdParam := params["trade_id"] + if tradeIdParam == "" { + c.errorHandler(w, r, &RequiredError{"trade_id"}, nil) + return + } result, err := c.service.DeleteTradeById(r.Context(), tradingAccountIdParam, tradeIdParam) // If an error occurred, encode the error with the status code if err != nil { @@ -141,6 +153,10 @@ func (c *UserAPIController) DeleteTradeById(w http.ResponseWriter, r *http.Reque func (c *UserAPIController) GetBookOrders(w http.ResponseWriter, r *http.Request) { params := mux.Vars(r) tradingAccountIdParam := params["trading_account_id"] + if tradingAccountIdParam == "" { + c.errorHandler(w, r, &RequiredError{"trading_account_id"}, nil) + return + } result, err := c.service.GetBookOrders(r.Context(), tradingAccountIdParam) // If an error occurred, encode the error with the status code if err != nil { @@ -155,6 +171,10 @@ func (c *UserAPIController) GetBookOrders(w http.ResponseWriter, r *http.Request func (c *UserAPIController) GetPaymentAccounts(w http.ResponseWriter, r *http.Request) { params := mux.Vars(r) appEntityIdParam := params["app_entity_id"] + if appEntityIdParam == "" { + c.errorHandler(w, r, &RequiredError{"app_entity_id"}, nil) + return + } result, err := c.service.GetPaymentAccounts(r.Context(), appEntityIdParam) // If an error occurred, encode the error with the status code if err != nil { @@ -169,7 +189,15 @@ func (c *UserAPIController) GetPaymentAccounts(w http.ResponseWriter, r *http.Re func (c *UserAPIController) GetTradeById(w http.ResponseWriter, r *http.Request) { params := mux.Vars(r) tradingAccountIdParam := params["trading_account_id"] + if tradingAccountIdParam == "" { + c.errorHandler(w, r, &RequiredError{"trading_account_id"}, nil) + return + } tradeIdParam := params["trade_id"] + if tradeIdParam == "" { + c.errorHandler(w, r, &RequiredError{"trade_id"}, nil) + return + } result, err := c.service.GetTradeById(r.Context(), tradingAccountIdParam, tradeIdParam) // If an error occurred, encode the error with the status code if err != nil { @@ -184,6 +212,10 @@ func (c *UserAPIController) GetTradeById(w http.ResponseWriter, r *http.Request) func (c *UserAPIController) GetTradeOrders(w http.ResponseWriter, r *http.Request) { params := mux.Vars(r) tradingAccountIdParam := params["trading_account_id"] + if tradingAccountIdParam == "" { + c.errorHandler(w, r, &RequiredError{"trading_account_id"}, nil) + return + } result, err := c.service.GetTradeOrders(r.Context(), tradingAccountIdParam) // If an error occurred, encode the error with the status code if err != nil { @@ -198,6 +230,10 @@ func (c *UserAPIController) GetTradeOrders(w http.ResponseWriter, r *http.Reques func (c *UserAPIController) GetTrades(w http.ResponseWriter, r *http.Request) { params := mux.Vars(r) tradingAccountIdParam := params["trading_account_id"] + if tradingAccountIdParam == "" { + c.errorHandler(w, r, &RequiredError{"trading_account_id"}, nil) + return + } result, err := c.service.GetTrades(r.Context(), tradingAccountIdParam) // If an error occurred, encode the error with the status code if err != nil { @@ -212,6 +248,10 @@ func (c *UserAPIController) GetTrades(w http.ResponseWriter, r *http.Request) { func (c *UserAPIController) GetTradingAccount(w http.ResponseWriter, r *http.Request) { params := mux.Vars(r) tradingAccountIdParam := params["trading_account_id"] + if tradingAccountIdParam == "" { + c.errorHandler(w, r, &RequiredError{"trading_account_id"}, nil) + return + } result, err := c.service.GetTradingAccount(r.Context(), tradingAccountIdParam) // If an error occurred, encode the error with the status code if err != nil { diff --git a/pkg/rest/api/api_user_service.go b/pkg/rest/api/api_user_service.go index 86c73b9..7518963 100644 --- a/pkg/rest/api/api_user_service.go +++ b/pkg/rest/api/api_user_service.go @@ -27,7 +27,7 @@ func NewUserAPIService() UserAPIServicer { } // CreateTrade - Create trade order -func (s *UserAPIService) CreateTrade(ctx context.Context, tradingAccountId interface{}, createTradeRequest CreateTradeRequest) (ImplResponse, error) { +func (s *UserAPIService) CreateTrade(ctx context.Context, tradingAccountId string, createTradeRequest CreateTradeRequest) (ImplResponse, error) { // TODO - update CreateTrade with the required logic for this service method. // Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. @@ -41,7 +41,7 @@ func (s *UserAPIService) CreateTrade(ctx context.Context, tradingAccountId inter } // DeleteTradeById - Cancel trade -func (s *UserAPIService) DeleteTradeById(ctx context.Context, tradingAccountId interface{}, tradeId interface{}) (ImplResponse, error) { +func (s *UserAPIService) DeleteTradeById(ctx context.Context, tradingAccountId string, tradeId string) (ImplResponse, error) { // TODO - update DeleteTradeById with the required logic for this service method. // Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. @@ -55,12 +55,12 @@ func (s *UserAPIService) DeleteTradeById(ctx context.Context, tradingAccountId i } // GetBookOrders - Get book orders -func (s *UserAPIService) GetBookOrders(ctx context.Context, tradingAccountId interface{}) (ImplResponse, error) { +func (s *UserAPIService) GetBookOrders(ctx context.Context, tradingAccountId string) (ImplResponse, error) { // TODO - update GetBookOrders with the required logic for this service method. // Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. - // TODO: Uncomment the next line to return response Response(200, interface{}{}) or use other options such as http.Ok ... - // return Response(200, interface{}{}), nil + // TODO: Uncomment the next line to return response Response(200, []TradeOrder{}) or use other options such as http.Ok ... + // return Response(200, []TradeOrder{}), nil // TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ... // return Response(404, nil),nil @@ -69,7 +69,7 @@ func (s *UserAPIService) GetBookOrders(ctx context.Context, tradingAccountId int } // GetPaymentAccounts - Get payment accounts -func (s *UserAPIService) GetPaymentAccounts(ctx context.Context, appEntityId interface{}) (ImplResponse, error) { +func (s *UserAPIService) GetPaymentAccounts(ctx context.Context, appEntityId string) (ImplResponse, error) { // TODO - update GetPaymentAccounts with the required logic for this service method. // Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. @@ -83,7 +83,7 @@ func (s *UserAPIService) GetPaymentAccounts(ctx context.Context, appEntityId int } // GetTradeById - Get trade -func (s *UserAPIService) GetTradeById(ctx context.Context, tradingAccountId interface{}, tradeId interface{}) (ImplResponse, error) { +func (s *UserAPIService) GetTradeById(ctx context.Context, tradingAccountId string, tradeId string) (ImplResponse, error) { // TODO - update GetTradeById with the required logic for this service method. // Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. @@ -97,12 +97,12 @@ func (s *UserAPIService) GetTradeById(ctx context.Context, tradingAccountId inte } // GetTradeOrders - Get trade orders -func (s *UserAPIService) GetTradeOrders(ctx context.Context, tradingAccountId interface{}) (ImplResponse, error) { +func (s *UserAPIService) GetTradeOrders(ctx context.Context, tradingAccountId string) (ImplResponse, error) { // TODO - update GetTradeOrders with the required logic for this service method. // Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. - // TODO: Uncomment the next line to return response Response(200, interface{}{}) or use other options such as http.Ok ... - // return Response(200, interface{}{}), nil + // TODO: Uncomment the next line to return response Response(200, []TradeOrder{}) or use other options such as http.Ok ... + // return Response(200, []TradeOrder{}), nil // TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ... // return Response(404, nil),nil @@ -111,12 +111,12 @@ func (s *UserAPIService) GetTradeOrders(ctx context.Context, tradingAccountId in } // GetTrades - Trades list -func (s *UserAPIService) GetTrades(ctx context.Context, tradingAccountId interface{}) (ImplResponse, error) { +func (s *UserAPIService) GetTrades(ctx context.Context, tradingAccountId string) (ImplResponse, error) { // TODO - update GetTrades with the required logic for this service method. // Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. - // TODO: Uncomment the next line to return response Response(200, interface{}{}) or use other options such as http.Ok ... - // return Response(200, interface{}{}), nil + // TODO: Uncomment the next line to return response Response(200, []Trade{}) or use other options such as http.Ok ... + // return Response(200, []Trade{}), nil // TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ... // return Response(404, nil),nil @@ -125,7 +125,7 @@ func (s *UserAPIService) GetTrades(ctx context.Context, tradingAccountId interfa } // GetTradingAccount - Get trading account -func (s *UserAPIService) GetTradingAccount(ctx context.Context, tradingAccountId interface{}) (ImplResponse, error) { +func (s *UserAPIService) GetTradingAccount(ctx context.Context, tradingAccountId string) (ImplResponse, error) { // TODO - update GetTradingAccount with the required logic for this service method. // Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. diff --git a/pkg/rest/api/model_app_entity.go b/pkg/rest/api/model_app_entity.go index 727d50c..1eb95c0 100644 --- a/pkg/rest/api/model_app_entity.go +++ b/pkg/rest/api/model_app_entity.go @@ -11,10 +11,10 @@ package api // AppEntity - Registered user type AppEntity struct { - Id *interface{} `json:"id,omitempty"` + Id string `json:"id,omitempty"` // External id - ExternalId *interface{} `json:"external_id,omitempty"` + ExternalId string `json:"external_id,omitempty"` } // AssertAppEntityRequired checks if the required fields are not zero-ed diff --git a/pkg/rest/api/model_create_trade_request.go b/pkg/rest/api/model_create_trade_request.go index 6a490aa..68f2f66 100644 --- a/pkg/rest/api/model_create_trade_request.go +++ b/pkg/rest/api/model_create_trade_request.go @@ -12,7 +12,7 @@ package api type CreateTradeRequest struct { // Ticker-like name of the instrument. For monetary instruments, a currency pair is used. - Instrument *interface{} `json:"instrument"` + Instrument string `json:"instrument"` Side TradeOrderSide `json:"side"` @@ -20,9 +20,9 @@ type CreateTradeRequest struct { TimeInForce TradeOrderTimeInForce `json:"timeInForce"` - Amount *interface{} `json:"amount"` + Amount float64 `json:"amount"` - Price *interface{} `json:"price,omitempty"` + Price float64 `json:"price,omitempty"` } // AssertCreateTradeRequestRequired checks if the required fields are not zero-ed diff --git a/pkg/rest/api/model_currency.go b/pkg/rest/api/model_currency.go index a075794..1bb2d78 100644 --- a/pkg/rest/api/model_currency.go +++ b/pkg/rest/api/model_currency.go @@ -13,10 +13,10 @@ package api type Currency struct { // ISO 4217 Currency symbol - Name *interface{} `json:"name,omitempty"` + Name string `json:"name,omitempty"` // Currency precision as number of decimal points - Precision *interface{} `json:"precision,omitempty"` + Precision int32 `json:"precision,omitempty"` } // AssertCurrencyRequired checks if the required fields are not zero-ed diff --git a/pkg/rest/api/model_currency_list.go b/pkg/rest/api/model_currency_list.go index 972ab5f..9b5d3c3 100644 --- a/pkg/rest/api/model_currency_list.go +++ b/pkg/rest/api/model_currency_list.go @@ -11,11 +11,16 @@ package api // CurrencyList - List of currencies supported by app type CurrencyList struct { - Data *interface{} `json:"data,omitempty"` + Data []Currency `json:"data,omitempty"` } // AssertCurrencyListRequired checks if the required fields are not zero-ed func AssertCurrencyListRequired(obj CurrencyList) error { + for _, el := range obj.Data { + if err := AssertCurrencyRequired(el); err != nil { + return err + } + } return nil } diff --git a/pkg/rest/api/model_fx_instrument.go b/pkg/rest/api/model_fx_instrument.go index d4bdb13..a5ea0fd 100644 --- a/pkg/rest/api/model_fx_instrument.go +++ b/pkg/rest/api/model_fx_instrument.go @@ -10,19 +10,19 @@ package api type FxInstrument struct { - Id *interface{} `json:"id,omitempty"` + Id string `json:"id,omitempty"` // Ticker-like name of the instrument. For monetary instruments, a currency pair is used. - Name *interface{} `json:"name,omitempty"` + Name string `json:"name,omitempty"` // ISO 4217 Currency symbol - QuoteCurrency *interface{} `json:"quote_currency,omitempty"` + QuoteCurrency string `json:"quote_currency,omitempty"` // Availability for trading - Enabled *interface{} `json:"enabled,omitempty"` + Enabled bool `json:"enabled,omitempty"` // ISO 4217 Currency symbol - BaseCurrency *interface{} `json:"base_currency,omitempty"` + BaseCurrency string `json:"base_currency,omitempty"` } // AssertFxInstrumentRequired checks if the required fields are not zero-ed diff --git a/pkg/rest/api/model_instrument.go b/pkg/rest/api/model_instrument.go index 0f2115c..aed7b84 100644 --- a/pkg/rest/api/model_instrument.go +++ b/pkg/rest/api/model_instrument.go @@ -10,16 +10,16 @@ package api type Instrument struct { - Id *interface{} `json:"id,omitempty"` + Id string `json:"id,omitempty"` // Ticker-like name of the instrument. For monetary instruments, a currency pair is used. - Name *interface{} `json:"name,omitempty"` + Name string `json:"name,omitempty"` // ISO 4217 Currency symbol - QuoteCurrency *interface{} `json:"quote_currency,omitempty"` + QuoteCurrency string `json:"quote_currency,omitempty"` // Availability for trading - Enabled *interface{} `json:"enabled,omitempty"` + Enabled bool `json:"enabled,omitempty"` } // AssertInstrumentRequired checks if the required fields are not zero-ed diff --git a/pkg/rest/api/model_order_book.go b/pkg/rest/api/model_order_book.go index 91ad0dc..67dcd43 100644 --- a/pkg/rest/api/model_order_book.go +++ b/pkg/rest/api/model_order_book.go @@ -10,13 +10,18 @@ package api type OrderBook struct { - Sell *interface{} `json:"sell,omitempty"` + Sell []PriceVolume `json:"sell,omitempty"` Buy *interface{} `json:"buy,omitempty"` } // AssertOrderBookRequired checks if the required fields are not zero-ed func AssertOrderBookRequired(obj OrderBook) error { + for _, el := range obj.Sell { + if err := AssertPriceVolumeRequired(el); err != nil { + return err + } + } return nil } diff --git a/pkg/rest/api/model_payment.go b/pkg/rest/api/model_payment.go index b4f230d..8a17924 100644 --- a/pkg/rest/api/model_payment.go +++ b/pkg/rest/api/model_payment.go @@ -10,28 +10,28 @@ package api type Payment struct { - Id *interface{} `json:"id"` + Id string `json:"id"` Type PaymentType `json:"type"` - Amount *interface{} `json:"amount"` + Amount float64 `json:"amount"` // ISO 4217 Currency symbol - Currency *interface{} `json:"currency"` + Currency string `json:"currency"` - SenderAccountId *interface{} `json:"senderAccountId"` + SenderAccountId string `json:"senderAccountId"` - BeneficiaryAccountId *interface{} `json:"beneficiaryAccountId"` + BeneficiaryAccountId string `json:"beneficiaryAccountId"` - Details *interface{} `json:"details"` + Details string `json:"details"` - ExternalReferenceNumber *interface{} `json:"externalReferenceNumber"` + ExternalReferenceNumber string `json:"externalReferenceNumber"` - Status *interface{} `json:"status"` + Status string `json:"status"` - DebitBalanceAmount *interface{} `json:"debitBalanceAmount,omitempty"` + DebitBalanceAmount float64 `json:"debitBalanceAmount,omitempty"` - CreditBalanceAmount *interface{} `json:"creditBalanceAmount,omitempty"` + CreditBalanceAmount float64 `json:"creditBalanceAmount,omitempty"` } // AssertPaymentRequired checks if the required fields are not zero-ed diff --git a/pkg/rest/api/model_payment_account.go b/pkg/rest/api/model_payment_account.go index 474ce9d..5873ad7 100644 --- a/pkg/rest/api/model_payment_account.go +++ b/pkg/rest/api/model_payment_account.go @@ -11,16 +11,16 @@ package api // PaymentAccount - Payment account available to user type PaymentAccount struct { - Id *interface{} `json:"id,omitempty"` + Id string `json:"id,omitempty"` // ISO 4217 Currency symbol - Currency *interface{} `json:"currency,omitempty"` + Currency string `json:"currency,omitempty"` - Amount *interface{} `json:"amount,omitempty"` + Amount float64 `json:"amount,omitempty"` - AmountReserved *interface{} `json:"amountReserved,omitempty"` + AmountReserved float64 `json:"amountReserved,omitempty"` - AmountAvailable *interface{} `json:"amountAvailable,omitempty"` + AmountAvailable float64 `json:"amountAvailable,omitempty"` } // AssertPaymentAccountRequired checks if the required fields are not zero-ed diff --git a/pkg/rest/api/model_payment_account_list.go b/pkg/rest/api/model_payment_account_list.go index 1cdf203..2cd2617 100644 --- a/pkg/rest/api/model_payment_account_list.go +++ b/pkg/rest/api/model_payment_account_list.go @@ -11,11 +11,16 @@ package api // PaymentAccountList - List of payment accounts available to user type PaymentAccountList struct { - Data *interface{} `json:"data,omitempty"` + Data []PaymentAccount `json:"data,omitempty"` } // AssertPaymentAccountListRequired checks if the required fields are not zero-ed func AssertPaymentAccountListRequired(obj PaymentAccountList) error { + for _, el := range obj.Data { + if err := AssertPaymentAccountRequired(el); err != nil { + return err + } + } return nil } diff --git a/pkg/rest/api/model_payment_type.go b/pkg/rest/api/model_payment_type.go index 031870e..554778a 100644 --- a/pkg/rest/api/model_payment_type.go +++ b/pkg/rest/api/model_payment_type.go @@ -9,7 +9,57 @@ package api -type PaymentType struct { +import ( + "fmt" +) + +type PaymentType string + +// List of PaymentType +const ( + DEPOSIT PaymentType = "DEPOSIT" + WITHDRAWAL PaymentType = "WITHDRAWAL" + TRANSFER PaymentType = "TRANSFER" + INSTRUMENT_BUY PaymentType = "INSTRUMENT_BUY" + INSTRUMENT_SELL PaymentType = "INSTRUMENT_SELL" + CHARGE PaymentType = "CHARGE" +) + +// AllowedPaymentTypeEnumValues is all the allowed values of PaymentType enum +var AllowedPaymentTypeEnumValues = []PaymentType{ + "DEPOSIT", + "WITHDRAWAL", + "TRANSFER", + "INSTRUMENT_BUY", + "INSTRUMENT_SELL", + "CHARGE", +} + +// validPaymentTypeEnumValue provides a map of PaymentTypes for fast verification of use input +var validPaymentTypeEnumValues = map[PaymentType]struct{}{ + "DEPOSIT": {}, + "WITHDRAWAL": {}, + "TRANSFER": {}, + "INSTRUMENT_BUY": {}, + "INSTRUMENT_SELL": {}, + "CHARGE": {}, +} + +// IsValid return true if the value is valid for the enum, false otherwise +func (v PaymentType) IsValid() bool { + _, ok := validPaymentTypeEnumValues[v] + return ok +} + +// NewPaymentTypeFromValue returns a pointer to a valid PaymentType +// for the value passed as argument, or an error if the value passed is not allowed by the enum +func NewPaymentTypeFromValue(v string) (PaymentType, error) { + ev := PaymentType(v) + if ev.IsValid() { + return ev, nil + } else { + return "", fmt.Errorf("invalid value '%v' for PaymentType: valid values are %v", v, AllowedPaymentTypeEnumValues) + } } // AssertPaymentTypeRequired checks if the required fields are not zero-ed diff --git a/pkg/rest/api/model_price_volume.go b/pkg/rest/api/model_price_volume.go index 615b163..ffea120 100644 --- a/pkg/rest/api/model_price_volume.go +++ b/pkg/rest/api/model_price_volume.go @@ -10,9 +10,9 @@ package api type PriceVolume struct { - Price *interface{} `json:"price,omitempty"` + Price float32 `json:"price,omitempty"` - Volume *interface{} `json:"volume,omitempty"` + Volume float32 `json:"volume,omitempty"` } // AssertPriceVolumeRequired checks if the required fields are not zero-ed diff --git a/pkg/rest/api/model_trade.go b/pkg/rest/api/model_trade.go index 1c35b8d..f96c861 100644 --- a/pkg/rest/api/model_trade.go +++ b/pkg/rest/api/model_trade.go @@ -11,7 +11,7 @@ package api // Trade - Executed trade type Trade struct { - Id *interface{} `json:"id,omitempty"` + Id string `json:"id,omitempty"` } // AssertTradeRequired checks if the required fields are not zero-ed diff --git a/pkg/rest/api/model_trade_order.go b/pkg/rest/api/model_trade_order.go index 019cb38..c79962f 100644 --- a/pkg/rest/api/model_trade_order.go +++ b/pkg/rest/api/model_trade_order.go @@ -9,11 +9,15 @@ package api +import ( + "time" +) + type TradeOrder struct { - Id *interface{} `json:"id,omitempty"` + Id string `json:"id,omitempty"` // Ticker-like name of the instrument. For monetary instruments, a currency pair is used. - Instrument *interface{} `json:"instrument,omitempty"` + Instrument string `json:"instrument,omitempty"` Side TradeOrderSide `json:"side,omitempty"` @@ -23,13 +27,13 @@ type TradeOrder struct { Status TradeOrderStatus `json:"status,omitempty"` - Price *interface{} `json:"price,omitempty"` + Price float64 `json:"price,omitempty"` - Amount *interface{} `json:"amount,omitempty"` + Amount float64 `json:"amount,omitempty"` - OpenAmount *interface{} `json:"openAmount,omitempty"` + OpenAmount float64 `json:"openAmount,omitempty"` - Created *interface{} `json:"created,omitempty"` + Created time.Time `json:"created,omitempty"` } // AssertTradeOrderRequired checks if the required fields are not zero-ed diff --git a/pkg/rest/api/model_trade_order_side.go b/pkg/rest/api/model_trade_order_side.go index 82c716f..92d7b70 100644 --- a/pkg/rest/api/model_trade_order_side.go +++ b/pkg/rest/api/model_trade_order_side.go @@ -9,7 +9,45 @@ package api -type TradeOrderSide struct { +import ( + "fmt" +) + +type TradeOrderSide string + +// List of TradeOrderSide +const ( + SELL TradeOrderSide = "SELL" + BUY TradeOrderSide = "BUY" +) + +// AllowedTradeOrderSideEnumValues is all the allowed values of TradeOrderSide enum +var AllowedTradeOrderSideEnumValues = []TradeOrderSide{ + "SELL", + "BUY", +} + +// validTradeOrderSideEnumValue provides a map of TradeOrderSides for fast verification of use input +var validTradeOrderSideEnumValues = map[TradeOrderSide]struct{}{ + "SELL": {}, + "BUY": {}, +} + +// IsValid return true if the value is valid for the enum, false otherwise +func (v TradeOrderSide) IsValid() bool { + _, ok := validTradeOrderSideEnumValues[v] + return ok +} + +// NewTradeOrderSideFromValue returns a pointer to a valid TradeOrderSide +// for the value passed as argument, or an error if the value passed is not allowed by the enum +func NewTradeOrderSideFromValue(v string) (TradeOrderSide, error) { + ev := TradeOrderSide(v) + if ev.IsValid() { + return ev, nil + } else { + return "", fmt.Errorf("invalid value '%v' for TradeOrderSide: valid values are %v", v, AllowedTradeOrderSideEnumValues) + } } // AssertTradeOrderSideRequired checks if the required fields are not zero-ed diff --git a/pkg/rest/api/model_trade_order_status.go b/pkg/rest/api/model_trade_order_status.go index 297d745..0fad15b 100644 --- a/pkg/rest/api/model_trade_order_status.go +++ b/pkg/rest/api/model_trade_order_status.go @@ -9,7 +9,57 @@ package api -type TradeOrderStatus struct { +import ( + "fmt" +) + +type TradeOrderStatus string + +// List of TradeOrderStatus +const ( + OPEN TradeOrderStatus = "OPEN" + REJECTED TradeOrderStatus = "REJECTED" + CANCELLED TradeOrderStatus = "CANCELLED" + PARTIALLY_CANCELLED TradeOrderStatus = "PARTIALLY_CANCELLED" + PARTIALLY_REJECTED TradeOrderStatus = "PARTIALLY_REJECTED" + FILLED TradeOrderStatus = "FILLED" +) + +// AllowedTradeOrderStatusEnumValues is all the allowed values of TradeOrderStatus enum +var AllowedTradeOrderStatusEnumValues = []TradeOrderStatus{ + "OPEN", + "REJECTED", + "CANCELLED", + "PARTIALLY_CANCELLED", + "PARTIALLY_REJECTED", + "FILLED", +} + +// validTradeOrderStatusEnumValue provides a map of TradeOrderStatuss for fast verification of use input +var validTradeOrderStatusEnumValues = map[TradeOrderStatus]struct{}{ + "OPEN": {}, + "REJECTED": {}, + "CANCELLED": {}, + "PARTIALLY_CANCELLED": {}, + "PARTIALLY_REJECTED": {}, + "FILLED": {}, +} + +// IsValid return true if the value is valid for the enum, false otherwise +func (v TradeOrderStatus) IsValid() bool { + _, ok := validTradeOrderStatusEnumValues[v] + return ok +} + +// NewTradeOrderStatusFromValue returns a pointer to a valid TradeOrderStatus +// for the value passed as argument, or an error if the value passed is not allowed by the enum +func NewTradeOrderStatusFromValue(v string) (TradeOrderStatus, error) { + ev := TradeOrderStatus(v) + if ev.IsValid() { + return ev, nil + } else { + return "", fmt.Errorf("invalid value '%v' for TradeOrderStatus: valid values are %v", v, AllowedTradeOrderStatusEnumValues) + } } // AssertTradeOrderStatusRequired checks if the required fields are not zero-ed diff --git a/pkg/rest/api/model_trade_order_time_in_force.go b/pkg/rest/api/model_trade_order_time_in_force.go index 6416519..5b8f0fd 100644 --- a/pkg/rest/api/model_trade_order_time_in_force.go +++ b/pkg/rest/api/model_trade_order_time_in_force.go @@ -9,7 +9,54 @@ package api -type TradeOrderTimeInForce struct { +import ( + "fmt" +) + +type TradeOrderTimeInForce string + +// List of TradeOrderTimeInForce +const ( + GTC TradeOrderTimeInForce = "GTC" + IOC TradeOrderTimeInForce = "IOC" + FOK TradeOrderTimeInForce = "FOK" + GTD TradeOrderTimeInForce = "GTD" + GTT TradeOrderTimeInForce = "GTT" +) + +// AllowedTradeOrderTimeInForceEnumValues is all the allowed values of TradeOrderTimeInForce enum +var AllowedTradeOrderTimeInForceEnumValues = []TradeOrderTimeInForce{ + "GTC", + "IOC", + "FOK", + "GTD", + "GTT", +} + +// validTradeOrderTimeInForceEnumValue provides a map of TradeOrderTimeInForces for fast verification of use input +var validTradeOrderTimeInForceEnumValues = map[TradeOrderTimeInForce]struct{}{ + "GTC": {}, + "IOC": {}, + "FOK": {}, + "GTD": {}, + "GTT": {}, +} + +// IsValid return true if the value is valid for the enum, false otherwise +func (v TradeOrderTimeInForce) IsValid() bool { + _, ok := validTradeOrderTimeInForceEnumValues[v] + return ok +} + +// NewTradeOrderTimeInForceFromValue returns a pointer to a valid TradeOrderTimeInForce +// for the value passed as argument, or an error if the value passed is not allowed by the enum +func NewTradeOrderTimeInForceFromValue(v string) (TradeOrderTimeInForce, error) { + ev := TradeOrderTimeInForce(v) + if ev.IsValid() { + return ev, nil + } else { + return "", fmt.Errorf("invalid value '%v' for TradeOrderTimeInForce: valid values are %v", v, AllowedTradeOrderTimeInForceEnumValues) + } } // AssertTradeOrderTimeInForceRequired checks if the required fields are not zero-ed diff --git a/pkg/rest/api/model_trade_order_type.go b/pkg/rest/api/model_trade_order_type.go index a3a72c3..49410e4 100644 --- a/pkg/rest/api/model_trade_order_type.go +++ b/pkg/rest/api/model_trade_order_type.go @@ -9,7 +9,51 @@ package api -type TradeOrderType struct { +import ( + "fmt" +) + +type TradeOrderType string + +// List of TradeOrderType +const ( + LIMIT TradeOrderType = "LIMIT" + MARKET TradeOrderType = "MARKET" + STOPLOSS TradeOrderType = "STOPLOSS" + STOPLIMIT TradeOrderType = "STOPLIMIT" +) + +// AllowedTradeOrderTypeEnumValues is all the allowed values of TradeOrderType enum +var AllowedTradeOrderTypeEnumValues = []TradeOrderType{ + "LIMIT", + "MARKET", + "STOPLOSS", + "STOPLIMIT", +} + +// validTradeOrderTypeEnumValue provides a map of TradeOrderTypes for fast verification of use input +var validTradeOrderTypeEnumValues = map[TradeOrderType]struct{}{ + "LIMIT": {}, + "MARKET": {}, + "STOPLOSS": {}, + "STOPLIMIT": {}, +} + +// IsValid return true if the value is valid for the enum, false otherwise +func (v TradeOrderType) IsValid() bool { + _, ok := validTradeOrderTypeEnumValues[v] + return ok +} + +// NewTradeOrderTypeFromValue returns a pointer to a valid TradeOrderType +// for the value passed as argument, or an error if the value passed is not allowed by the enum +func NewTradeOrderTypeFromValue(v string) (TradeOrderType, error) { + ev := TradeOrderType(v) + if ev.IsValid() { + return ev, nil + } else { + return "", fmt.Errorf("invalid value '%v' for TradeOrderType: valid values are %v", v, AllowedTradeOrderTypeEnumValues) + } } // AssertTradeOrderTypeRequired checks if the required fields are not zero-ed diff --git a/pkg/rest/api/model_trading_account.go b/pkg/rest/api/model_trading_account.go index 18b0d05..d9f9a40 100644 --- a/pkg/rest/api/model_trading_account.go +++ b/pkg/rest/api/model_trading_account.go @@ -10,9 +10,9 @@ package api type TradingAccount struct { - Id *interface{} `json:"id"` + Id string `json:"id"` - Instruments *interface{} `json:"instruments"` + Instruments []TradingAccountInstrument `json:"instruments"` } // AssertTradingAccountRequired checks if the required fields are not zero-ed @@ -27,6 +27,11 @@ func AssertTradingAccountRequired(obj TradingAccount) error { } } + for _, el := range obj.Instruments { + if err := AssertTradingAccountInstrumentRequired(el); err != nil { + return err + } + } return nil } diff --git a/pkg/rest/api/model_trading_account_instrument.go b/pkg/rest/api/model_trading_account_instrument.go index 8f0c258..d855655 100644 --- a/pkg/rest/api/model_trading_account_instrument.go +++ b/pkg/rest/api/model_trading_account_instrument.go @@ -12,18 +12,18 @@ package api type TradingAccountInstrument struct { // Ticker-like name of the instrument. For monetary instruments, a currency pair is used. - Name *interface{} `json:"name"` + Name string `json:"name"` - Amount *interface{} `json:"amount"` + Amount float64 `json:"amount"` - AmountReserved *interface{} `json:"amountReserved"` + AmountReserved float64 `json:"amountReserved"` - AmountAvailable *interface{} `json:"amountAvailable"` + AmountAvailable float64 `json:"amountAvailable"` - Value *interface{} `json:"value"` + Value float64 `json:"value"` // ISO 4217 Currency symbol - Currency *interface{} `json:"currency"` + Currency string `json:"currency"` } // AssertTradingAccountInstrumentRequired checks if the required fields are not zero-ed diff --git a/pkg/rest/api/openapi.yaml b/pkg/rest/api/openapi.yaml index 1a12f80..2e4ffdb 100644 --- a/pkg/rest/api/openapi.yaml +++ b/pkg/rest/api/openapi.yaml @@ -363,15 +363,18 @@ components: CurrencyName: description: ISO 4217 Currency symbol example: USD + type: string Currency: description: Currency of payment account properties: name: description: ISO 4217 Currency symbol example: USD + type: string precision: description: Currency precision as number of decimal points example: 2 + type: integer CurrencyList: description: List of currencies supported by app example: @@ -384,69 +387,105 @@ components: data: items: $ref: '#/components/schemas/Currency' + type: array Id: example: 29b6e916-0d74-41c3-b004-eb8373bca606 format: uuid + type: string InstrumentName: description: "Ticker-like name of the instrument. For monetary instruments,\ \ a currency pair is used." example: BTC-EUR + type: string InstrumentAvailability: description: Availability for trading example: true + type: boolean FxInstrument: + example: + base_currency: USD + name: BTC-EUR + id: 29b6e916-0d74-41c3-b004-eb8373bca606 + quote_currency: USD + enabled: true properties: id: example: 29b6e916-0d74-41c3-b004-eb8373bca606 format: uuid + type: string name: description: "Ticker-like name of the instrument. For monetary instruments,\ \ a currency pair is used." example: BTC-EUR + type: string quote_currency: description: ISO 4217 Currency symbol example: USD + type: string enabled: description: Availability for trading example: true + type: boolean base_currency: description: ISO 4217 Currency symbol example: USD + type: string FxInstrumentList: items: $ref: '#/components/schemas/FxInstrument' + type: array Instrument: + example: + name: BTC-EUR + id: 29b6e916-0d74-41c3-b004-eb8373bca606 + quote_currency: USD + enabled: true properties: id: example: 29b6e916-0d74-41c3-b004-eb8373bca606 format: uuid + type: string name: description: "Ticker-like name of the instrument. For monetary instruments,\ \ a currency pair is used." example: BTC-EUR + type: string quote_currency: description: ISO 4217 Currency symbol example: USD + type: string enabled: description: Availability for trading example: true + type: boolean InstrumentList: items: $ref: '#/components/schemas/Instrument' + type: array PriceVolume: + example: + volume: 80 + price: 120 properties: price: example: 120 + type: number volume: example: 80 + type: number OrderBook: example: - sell: "" + sell: + - volume: 80 + price: 120 + - volume: 80 + price: 120 buy: "" properties: sell: items: $ref: '#/components/schemas/PriceVolume' + type: array buy: items: $ref: '#/components/schemas/PriceVolume' @@ -454,12 +493,14 @@ components: enum: - SELL - BUY + type: string TradeOrderType: enum: - LIMIT - MARKET - STOPLOSS - STOPLIMIT + type: string TradeOrderTimeInForce: enum: - GTC @@ -467,6 +508,7 @@ components: - FOK - GTD - GTT + type: string TradeOrderStatus: enum: - OPEN @@ -475,13 +517,15 @@ components: - PARTIALLY_CANCELLED - PARTIALLY_REJECTED - FILLED - - REJECTED + type: string MoneyAmount: example: "100.50" format: decimal + type: string DateTime: example: 2017-07-21T17:32:28Z format: date-time + type: string TradeOrder: example: side: null @@ -498,10 +542,12 @@ components: id: example: 29b6e916-0d74-41c3-b004-eb8373bca606 format: uuid + type: string instrument: description: "Ticker-like name of the instrument. For monetary instruments,\ \ a currency pair is used." example: BTC-EUR + type: string side: $ref: '#/components/schemas/TradeOrderSide' type: @@ -513,36 +559,46 @@ components: price: example: "100.50" format: decimal + type: string amount: example: "100.50" format: decimal + type: string openAmount: example: "100.50" format: decimal + type: string created: example: 2017-07-21T17:32:28Z format: date-time + type: string TradeOrderList: items: $ref: '#/components/schemas/TradeOrder' + type: array PaymentAccount: description: Payment account available to user properties: id: example: 29b6e916-0d74-41c3-b004-eb8373bca606 format: uuid + type: string currency: description: ISO 4217 Currency symbol example: USD + type: string amount: example: "100.50" format: decimal + type: string amountReserved: example: "100.50" format: decimal + type: string amountAvailable: example: "100.50" format: decimal + type: string PaymentAccountList: description: List of payment accounts available to user example: @@ -555,6 +611,7 @@ components: data: items: $ref: '#/components/schemas/PaymentAccount' + type: array Trade: description: Executed trade example: @@ -563,31 +620,45 @@ components: id: example: 29b6e916-0d74-41c3-b004-eb8373bca606 format: uuid + type: string TradeList: - description: List of executed trades items: $ref: '#/components/schemas/Trade' + type: array TradingAccountInstrument: + example: + amount: "100.50" + amountAvailable: "100.50" + name: BTC-EUR + amountReserved: "100.50" + currency: USD + value: "100.50" properties: name: description: "Ticker-like name of the instrument. For monetary instruments,\ \ a currency pair is used." example: BTC-EUR + type: string amount: example: "100.50" format: decimal + type: string amountReserved: example: "100.50" format: decimal + type: string amountAvailable: example: "100.50" format: decimal + type: string value: example: "100.50" format: decimal + type: string currency: description: ISO 4217 Currency symbol example: USD + type: string required: - amount - amountAvailable @@ -597,35 +668,52 @@ components: - value TradingAccount: example: - instruments: "" + instruments: + - amount: "100.50" + amountAvailable: "100.50" + name: BTC-EUR + amountReserved: "100.50" + currency: USD + value: "100.50" + - amount: "100.50" + amountAvailable: "100.50" + name: BTC-EUR + amountReserved: "100.50" + currency: USD + value: "100.50" id: 29b6e916-0d74-41c3-b004-eb8373bca606 properties: id: example: 29b6e916-0d74-41c3-b004-eb8373bca606 format: uuid + type: string instruments: items: $ref: '#/components/schemas/TradingAccountInstrument' + type: array required: - id - instruments AppEntityExternalId: description: External id + type: string AppEntity: description: Registered user example: - external_id: "" + external_id: external_id id: 29b6e916-0d74-41c3-b004-eb8373bca606 properties: id: example: 29b6e916-0d74-41c3-b004-eb8373bca606 format: uuid + type: string external_id: description: External id + type: string AppEntityList: - description: List of registered users items: $ref: '#/components/schemas/AppEntity' + type: array PaymentType: enum: - DEPOSIT @@ -634,10 +722,13 @@ components: - INSTRUMENT_BUY - INSTRUMENT_SELL - CHARGE + type: string PaymentDetails: example: Bank deposit Bank REF123456 + type: string PaymentExternalReferenceNumber: example: REF123456 + type: string Payment: example: amount: "100.50" @@ -650,36 +741,46 @@ components: id: 29b6e916-0d74-41c3-b004-eb8373bca606 type: null senderAccountId: 29b6e916-0d74-41c3-b004-eb8373bca606 - status: "" + status: status properties: id: example: 29b6e916-0d74-41c3-b004-eb8373bca606 format: uuid + type: string type: $ref: '#/components/schemas/PaymentType' amount: example: "100.50" format: decimal + type: string currency: description: ISO 4217 Currency symbol example: USD + type: string senderAccountId: example: 29b6e916-0d74-41c3-b004-eb8373bca606 format: uuid + type: string beneficiaryAccountId: example: 29b6e916-0d74-41c3-b004-eb8373bca606 format: uuid + type: string details: example: Bank deposit Bank REF123456 + type: string externalReferenceNumber: example: REF123456 - status: {} + type: string + status: + type: string debitBalanceAmount: example: "100.50" format: decimal + type: string creditBalanceAmount: example: "100.50" format: decimal + type: string required: - amount - beneficiaryAccountId @@ -696,6 +797,7 @@ components: description: "Ticker-like name of the instrument. For monetary instruments,\ \ a currency pair is used." example: BTC-EUR + type: string side: $ref: '#/components/schemas/TradeOrderSide' type: @@ -705,9 +807,11 @@ components: amount: example: "100.50" format: decimal + type: string price: example: "100.50" format: decimal + type: string required: - amount - instrument