Skip to content

Commit

Permalink
Update and sync api
Browse files Browse the repository at this point in the history
  • Loading branch information
tolyo committed Dec 11, 2023
1 parent c25c642 commit 6a02a7d
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 39 deletions.
2 changes: 1 addition & 1 deletion api/endpoints/user/trade_orders_by_id.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ delete:
operationId: deleteTradeOrderById
parameters:
- $ref: '../../models/trading_account.yaml#/components/parameters/TradingAccountId'
- $ref: '../../models/trade.yaml#/components/parameters/TradeId'
- $ref: '../../models/trade_order.yaml#/components/parameters/TradeOrderId'
responses:
"204":
description: Success
Expand Down
2 changes: 1 addition & 1 deletion api/models/trade_order.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ components:
$ref: './shared.yaml#/components/schemas/DateTime'

parameters:
TradingAccountId:
TradeOrderId:
name: trade_order_id
in: path
required: true
Expand Down
2 changes: 1 addition & 1 deletion api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ paths:
$ref: ./endpoints/user/trades.yaml
/trade_orders/{trading_account_id}:
$ref: ./endpoints/user/trade_orders.yaml
/trade_orders/{trading_account_id}/id/{trade_id}:
/trade_orders/{trading_account_id}/id/{trade_order_id}:
$ref: ./endpoints/user/trade_orders_by_id.yaml
/trading_account/{trading_account_id}:
$ref: ./endpoints/user/trading_account_by_id.yaml
Expand Down
2 changes: 1 addition & 1 deletion pkg/rest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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-08T19:14:53.772694+02:00[Europe/Riga]
- Build date: 2023-12-11T18:26:27.902618+02:00[Europe/Riga]


### Running the server
Expand Down
6 changes: 4 additions & 2 deletions pkg/rest/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ type PublicAPIRouter interface {
// pass the data to a UserAPIServicer to perform the required actions, then write the service results to the http response.
type UserAPIRouter interface {
CreateTrade(http.ResponseWriter, *http.Request)
DeleteTradeById(http.ResponseWriter, *http.Request)
DeleteTradeOrderById(http.ResponseWriter, *http.Request)
GetBookOrders(http.ResponseWriter, *http.Request)
GetPaymentAccounts(http.ResponseWriter, *http.Request)
GetTradeById(http.ResponseWriter, *http.Request)
GetTradeOrderById(http.ResponseWriter, *http.Request)
GetTradeOrders(http.ResponseWriter, *http.Request)
GetTrades(http.ResponseWriter, *http.Request)
GetTradingAccount(http.ResponseWriter, *http.Request)
Expand Down Expand Up @@ -76,10 +77,11 @@ type PublicAPIServicer interface {
// and updated with the logic required for the API.
type UserAPIServicer interface {
CreateTrade(context.Context, string, CreateTradeRequest) (ImplResponse, error)
DeleteTradeById(context.Context, string, string) (ImplResponse, error)
DeleteTradeOrderById(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)
GetTradeOrderById(context.Context, string, string) (ImplResponse, error)
GetTradeOrders(context.Context, string) (ImplResponse, error)
GetTrades(context.Context, string) (ImplResponse, error)
GetTradingAccount(context.Context, string) (ImplResponse, error)
Expand Down
46 changes: 37 additions & 9 deletions pkg/rest/api/api_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ func (c *UserAPIController) Routes() Routes {
"/trade_orders/{trading_account_id}",
c.CreateTrade,
},
"DeleteTradeById": Route{
"DeleteTradeOrderById": Route{
strings.ToUpper("Delete"),
"/trades/{trading_account_id}/id/{trade_id}",
c.DeleteTradeById,
"/trade_orders/{trading_account_id}/id/{trade_order_id}",
c.DeleteTradeOrderById,
},
"GetBookOrders": Route{
strings.ToUpper("Get"),
Expand All @@ -75,6 +75,11 @@ func (c *UserAPIController) Routes() Routes {
"/trades/{trading_account_id}/id/{trade_id}",
c.GetTradeById,
},
"GetTradeOrderById": Route{
strings.ToUpper("Get"),
"/trade_orders/{trading_account_id}/id/{trade_order_id}",
c.GetTradeOrderById,
},
"GetTradeOrders": Route{
strings.ToUpper("Get"),
"/trade_orders/{trading_account_id}",
Expand Down Expand Up @@ -126,20 +131,20 @@ func (c *UserAPIController) CreateTrade(w http.ResponseWriter, r *http.Request)
EncodeJSONResponse(result.Body, &result.Code, w)
}

// DeleteTradeById - Cancel trade
func (c *UserAPIController) DeleteTradeById(w http.ResponseWriter, r *http.Request) {
// DeleteTradeOrderById - Cancel trade order
func (c *UserAPIController) DeleteTradeOrderById(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)
tradeOrderIdParam := params["trade_order_id"]
if tradeOrderIdParam == "" {
c.errorHandler(w, r, &RequiredError{"trade_order_id"}, nil)
return
}
result, err := c.service.DeleteTradeById(r.Context(), tradingAccountIdParam, tradeIdParam)
result, err := c.service.DeleteTradeOrderById(r.Context(), tradingAccountIdParam, tradeOrderIdParam)
// If an error occurred, encode the error with the status code
if err != nil {
c.errorHandler(w, r, err, &result)
Expand Down Expand Up @@ -208,6 +213,29 @@ func (c *UserAPIController) GetTradeById(w http.ResponseWriter, r *http.Request)
EncodeJSONResponse(result.Body, &result.Code, w)
}

// GetTradeOrderById - Get trade order
func (c *UserAPIController) GetTradeOrderById(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
}
tradeOrderIdParam := params["trade_order_id"]
if tradeOrderIdParam == "" {
c.errorHandler(w, r, &RequiredError{"trade_order_id"}, nil)
return
}
result, err := c.service.GetTradeOrderById(r.Context(), tradingAccountIdParam, tradeOrderIdParam)
// If an error occurred, encode the error with the status code
if err != nil {
c.errorHandler(w, r, err, &result)
return
}
// If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, w)
}

// GetTradeOrders - Get trade orders
func (c *UserAPIController) GetTradeOrders(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
Expand Down
20 changes: 17 additions & 3 deletions pkg/rest/api/api_user_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ func (s *UserAPIService) CreateTrade(ctx context.Context, tradingAccountId strin
return Response(http.StatusOK, res), nil
}

// DeleteTradeById - Cancel trade
func (s *UserAPIService) DeleteTradeById(ctx context.Context, tradingAccountId string, tradeId string) (ImplResponse, error) {
// DeleteTradeOrderById - Cancel trade order
func (s *UserAPIService) DeleteTradeOrderById(ctx context.Context, tradingAccountId string, tradeOrderId string) (ImplResponse, error) {
// TODO add validation
err := services.CancelTradeOrder(
models.TradeOrderId(tradeId),
models.TradeOrderId(tradeOrderId),
)

if err != nil {
Expand Down Expand Up @@ -110,6 +110,20 @@ func (s *UserAPIService) GetTradeById(ctx context.Context, tradingAccountId stri
return Response(http.StatusNotImplemented, nil), errors.New("GetTradeById method not implemented")
}

// GetTradeOrderById - Get trade order
func (s *UserAPIService) GetTradeOrderById(ctx context.Context, tradingAccountId string, tradeOrderId string) (ImplResponse, error) {
// TODO - update GetTradeOrderById 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, 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

return Response(http.StatusNotImplemented, nil), errors.New("GetTradeOrderById method not implemented")
}

// GetTradeOrders - Get trade orders
func (s *UserAPIService) GetTradeOrders(ctx context.Context, tradingAccountId string) (ImplResponse, error) {
// TODO - update GetTradeOrders with the required logic for this service method.
Expand Down
6 changes: 3 additions & 3 deletions pkg/rest/api/model_fx_instrument.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ type FxInstrument struct {
// ISO 4217 Currency symbol
QuoteCurrency string `json:"quote_currency,omitempty"`

// Availability for trading
Enabled bool `json:"enabled,omitempty"`

// ISO 4217 Currency symbol
BaseCurrency string `json:"base_currency,omitempty"`

// Availability for trading
Enabled bool `json:"enabled,omitempty"`
}

// AssertFxInstrumentRequired checks if the required fields are not zero-ed
Expand Down
63 changes: 45 additions & 18 deletions pkg/rest/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -139,20 +139,6 @@ paths:
tags:
- user
/trades/{trading_account_id}/id/{trade_id}:
delete:
description: Cancels a trade order by id
operationId: deleteTradeById
parameters:
- $ref: '#/components/parameters/TradingAccountId'
- $ref: '#/components/parameters/TradeId'
responses:
"204":
description: Success
"404":
description: Error
summary: Cancel trade
tags:
- user
get:
description: Returns a trade by id
operationId: getTradeById
Expand Down Expand Up @@ -237,6 +223,39 @@ paths:
summary: Create trade order
tags:
- user
/trade_orders/{trading_account_id}/id/{trade_order_id}:
delete:
description: Cancels a trade order by id
operationId: deleteTradeOrderById
parameters:
- $ref: '#/components/parameters/TradingAccountId'
- $ref: '#/components/parameters/TradeOrderId'
responses:
"204":
description: Success
"404":
description: Error
summary: Cancel trade order
tags:
- user
get:
description: Returns user's trade order
operationId: getTradeOrderById
parameters:
- $ref: '#/components/parameters/TradingAccountId'
- $ref: '#/components/parameters/TradeOrderId'
responses:
"200":
content:
application/json:
schema:
$ref: '#/components/schemas/TradeOrder'
description: Success
"404":
description: Error
summary: Get trade order
tags:
- user
/trading_account/{trading_account_id}:
get:
description: Returns user's trading account
Expand Down Expand Up @@ -359,6 +378,14 @@ components:
schema:
$ref: '#/components/schemas/Id'
style: simple
TradeOrderId:
explode: false
in: path
name: trade_order_id
required: true
schema:
$ref: '#/components/schemas/Id'
style: simple
schemas:
CurrencyName:
description: ISO 4217 Currency symbol
Expand Down Expand Up @@ -422,14 +449,14 @@ components:
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
enabled:
description: Availability for trading
example: true
type: boolean
FxInstrumentList:
items:
$ref: '#/components/schemas/FxInstrument'
Expand Down

0 comments on commit 6a02a7d

Please sign in to comment.