Skip to content

Commit

Permalink
Initial enpoint implementation for user
Browse files Browse the repository at this point in the history
  • Loading branch information
tolyo committed Dec 11, 2023
1 parent dbab848 commit c25c642
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 66 deletions.
36 changes: 36 additions & 0 deletions api/endpoints/user/trade_orders_by_id.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
get:
tags:
- user
summary: Get trade order
description: Returns user's trade order
operationId: getTradeOrderById
parameters:
- $ref: '../../models/trading_account.yaml#/components/parameters/TradingAccountId'
- $ref: '../../models/trade_order.yaml#/components/parameters/TradeOrderId'

responses:
"200":
description: Success
content:
application/json:
schema:
$ref: '../../models/trade_order.yaml#/components/schemas/TradeOrder'
"404":
description: Error


delete:
tags:
- user
summary: Cancel trade order
description: Cancels a trade order by id
operationId: deleteTradeOrderById
parameters:
- $ref: '../../models/trading_account.yaml#/components/parameters/TradingAccountId'
- $ref: '../../models/trade.yaml#/components/parameters/TradeId'
responses:
"204":
description: Success

"404":
description: Error
15 changes: 0 additions & 15 deletions api/endpoints/user/trades_by_id.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,3 @@ get:
"404":
description: Error

delete:
tags:
- user
summary: Cancel trade
description: Cancels a trade order by id
operationId: deleteTradeById
parameters:
- $ref: '../../models/trading_account.yaml#/components/parameters/TradingAccountId'
- $ref: '../../models/trade.yaml#/components/parameters/TradeId'
responses:
"204":
description: Success

"404":
description: Error
11 changes: 10 additions & 1 deletion api/models/trade_order.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
components:
schemas:
TradeOrderId:
$ref: './shared.yaml#/components/schemas/Id'

TradeOrderSide:
type: string
Expand Down Expand Up @@ -42,7 +44,7 @@ components:
type: object
properties:
id:
$ref: './shared.yaml#/components/schemas/Id'
$ref: '#/components/schemas/TradeOrderId'
instrument:
$ref: './instrument.yaml#/components/schemas/InstrumentName'
side:
Expand All @@ -62,6 +64,13 @@ components:
created:
$ref: './shared.yaml#/components/schemas/DateTime'

parameters:
TradingAccountId:
name: trade_order_id
in: path
required: true
schema:
$ref: '#/components/schemas/TradeOrderId'



Expand Down
2 changes: 2 additions & 0 deletions api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ 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}:
$ref: ./endpoints/user/trade_orders_by_id.yaml
/trading_account/{trading_account_id}:
$ref: ./endpoints/user/trading_account_by_id.yaml

Expand Down
9 changes: 4 additions & 5 deletions pkg/models/application_entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@ package models

import "open-outcry/pkg/db"

// `app_entity.pub_id` db reference
// AppEntityId `app_entity.pub_id` db reference
type AppEntityId string

// `app_entity.pub_id` db reference
// AppEntityExternalId `app_entity.pub_id` db reference
type AppEntityExternalId string

// Type of application entity
// AppEntityType Type of application entity
type AppEntityType string

const (
Client AppEntityType = "CLIENT"
Master AppEntityType = "MASTER"
)

// Application entity is any generic enity capable of being an
// actor in financial transaction
// AppEntity Application entity is any generic entity capable of being an actor in financial transaction
type AppEntity struct {
Id AppEntityId
Type AppEntityType
Expand Down
8 changes: 4 additions & 4 deletions pkg/models/instrument.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ package models

import "open-outcry/pkg/db"

// `instrument.pub_id` db reference
// InstrumentId `instrument.pub_id` db reference
type InstrumentId string

// Ticker-like name of the instrument. For monetary instruments, a currency pair is used.
// InstrumentName Ticker-like name of the instrument. For monetary instruments, a currency pair is used.
type InstrumentName string

// The underlying currency of the FX instrument
// InstrumentBaseCurrency The underlying currency of the FX instrument
type InstrumentBaseCurrency CurrencyName

// The default currency for market quotes of the instrument
// InstrumentQuoteCurrency The default currency for market quotes of the instrument
type InstrumentQuoteCurrency CurrencyName

type Instrument struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/models/trade_order.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const (
Rejected OrderStatus = "REJECTED"
)

// See SQL for atom funcinitions
// OrderType See SQL for atom funcinitions
type OrderType string

const (
Expand Down
44 changes: 25 additions & 19 deletions pkg/rest/api/api_public_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ package api

import (
"context"
"errors"
"net/http"
"open-outcry/pkg/models"
"open-outcry/pkg/services"
Expand Down Expand Up @@ -46,30 +45,37 @@ func (s *PublicAPIService) GetCurrencies(ctx context.Context) (ImplResponse, err

// GetFxInstruments - Fx instrument list
func (s *PublicAPIService) GetFxInstruments(ctx context.Context) (ImplResponse, error) {
// 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, []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
instruments := models.GetFxInstruments()
res := make([]FxInstrument, 0)

for _, item := range instruments {
res = append(res, FxInstrument{
Id: string(item.Id),
Name: string(item.Name),
QuoteCurrency: string(item.QuoteCurrency),
BaseCurrency: string(item.BaseCurrency),
Enabled: false,
})
}

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

// GetInstruments - Instrument list
func (s *PublicAPIService) GetInstruments(ctx context.Context) (ImplResponse, error) {
// 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, []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
instruments := models.GetInstruments()
res := make([]Instrument, 0)

for _, item := range instruments {
res = append(res, Instrument{
Id: string(item.Id),
Name: string(item.Name),
QuoteCurrency: string(item.QuoteCurrency),
Enabled: false,
})
}

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

// GetOrderBook - Get order book
Expand Down
56 changes: 35 additions & 21 deletions pkg/rest/api/api_user_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import (
"context"
"errors"
"net/http"
"open-outcry/pkg/models"
"open-outcry/pkg/services"

log "github.com/sirupsen/logrus"
)

// UserAPIService is a service that implements the logic for the UserAPIServicer
Expand All @@ -27,31 +31,41 @@ func NewUserAPIService() UserAPIServicer {
}

// CreateTrade - Create trade order
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.

// 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("CreateTrade method not implemented")
func (s *UserAPIService) CreateTrade(ctx context.Context, tradingAccountId string, req CreateTradeRequest) (ImplResponse, error) {
// TODO add validation
res, err := services.ProcessTradeOrder(
models.TradingAccountId(tradingAccountId),
models.InstrumentName(req.Instrument),
models.OrderType(req.Type),
models.OrderSide(req.Side),
models.OrderPrice(req.Price),
req.Amount,
models.OrderTimeInForce(req.TimeInForce),
)

if err != nil {
log.Error(err)
// TODO implement error handling
return Response(http.StatusUnprocessableEntity, err), err
}

return Response(http.StatusOK, res), nil
}

// DeleteTradeById - Cancel trade
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.

// TODO: Uncomment the next line to return response Response(204, {}) or use other options such as http.Ok ...
// return Response(204, nil),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("DeleteTradeById method not implemented")
// TODO add validation
err := services.CancelTradeOrder(
models.TradeOrderId(tradeId),
)

if err != nil {
log.Error(err)
// TODO implement error handling
return Response(http.StatusUnprocessableEntity, err), err
}

return Response(http.StatusOK, nil), nil
}

// GetBookOrders - Get book orders
Expand Down

0 comments on commit c25c642

Please sign in to comment.