Skip to content

Commit

Permalink
Minor optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
tolyo committed Jan 11, 2024
1 parent dbb7437 commit a29a98d
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 34 deletions.
19 changes: 9 additions & 10 deletions pkg/conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import (

log "github.com/sirupsen/logrus"

"github.com/spf13/viper"

// Loads yaml config files
_ "embed"

"github.com/spf13/viper"
)

//go:embed dev.env
Expand All @@ -30,18 +29,18 @@ var mapper = map[EnvName]string{
DEV: dev,
}

// configuration - structure that contains configuration information from config variables
type configuration struct {
// Configuration - structure that contains Configuration information from config variables
type Configuration struct {
DBDsn string
UpdateFees bool
RestPort string
}

var config *configuration
var config *Configuration
var envName EnvName

// LoadConfig - loads configurations from config variables into Environment struct
func LoadConfig(conf string) (*configuration, error) {
func LoadConfig(conf string) (*Configuration, error) {
envName = EnvName(conf)
switch envName {
case DEV:
Expand All @@ -58,7 +57,7 @@ func LoadConfig(conf string) (*configuration, error) {
log.Fatal("Environment variable not supplied")
}

config = &configuration{
config = &Configuration{
DBDsn: fmt.Sprintf(
"host=%s user=%s password=%s dbname=%s port=%s sslmode=disable",
viper.GetString("POSTGRES_HOST"),
Expand All @@ -75,15 +74,15 @@ func LoadConfig(conf string) (*configuration, error) {
}

// Get config
func Get() *configuration {
func Get() *Configuration {
if config == nil {
log.Fatal("Env not initialized")
}
return config
}

// LoadTestConfig - Helper for calling in tests
func LoadTestConfig() (*configuration, error) {
func LoadTestConfig() (*Configuration, error) {
return LoadConfig(string(DEV))
}

Expand Down
28 changes: 14 additions & 14 deletions pkg/fix/fix.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,62 +13,62 @@ import (
)

// FixServer implements the main quickfix interface
type FixServer struct {
type Server struct {
*quickfix.MessageRouter
}

func New() *FixServer {
server := &FixServer{}
func New() *Server {
server := &Server{}
server.AddRoute(marketdatarequest.Route(server.NewMarketDataReq))
server.AddRoute(newordersingle.Route(server.NewOrder))
server.AddRoute(ordercancelrequest.Route(server.CancelOrder))
server.AddRoute(neworderlist.Route(server.NewOrderList))
return server
}

func (s *FixServer) OnCreate(sessionID quickfix.SessionID) {
func (s *Server) OnCreate(sessionID quickfix.SessionID) {
log.Println("Session created:", sessionID)
}

func (s *FixServer) OnLogon(sessionID quickfix.SessionID) {
func (s *Server) OnLogon(sessionID quickfix.SessionID) {
fmt.Println("Session logged on:", sessionID)
}

func (s *FixServer) OnLogout(sessionID quickfix.SessionID) {
func (s *Server) OnLogout(sessionID quickfix.SessionID) {
fmt.Println("Session logged out:", sessionID)
}

func (s *FixServer) ToAdmin(message quickfix.Message, sessionID quickfix.SessionID) {
func (s *Server) ToAdmin(message quickfix.Message, sessionID quickfix.SessionID) {
fmt.Println("Sending admin message to", sessionID, ":", message)
}

func (s *FixServer) ToApp(message quickfix.Message, sessionID quickfix.SessionID) error {
func (s *Server) ToApp(message quickfix.Message, sessionID quickfix.SessionID) error {
fmt.Println("Sending app message to", sessionID, ":", message)
return nil
}

func (s *FixServer) FromAdmin(message quickfix.Message, sessionID quickfix.SessionID) quickfix.MessageRejectError {
func (s *Server) FromAdmin(message quickfix.Message, sessionID quickfix.SessionID) quickfix.MessageRejectError {
fmt.Println("Receiving admin message from", sessionID, ":", message)
return quickfix.InvalidMessageType()
}

func (s *FixServer) FromApp(message quickfix.Message, sessionID quickfix.SessionID) quickfix.MessageRejectError {
func (s *Server) FromApp(message quickfix.Message, sessionID quickfix.SessionID) quickfix.MessageRejectError {
fmt.Println("Receiving app message from", sessionID, ":", message)
return quickfix.InvalidMessageType()
}

func (s *FixServer) NewOrder(msg newordersingle.NewOrderSingle, id quickfix.SessionID) quickfix.MessageRejectError {
func (s *Server) NewOrder(msg newordersingle.NewOrderSingle, id quickfix.SessionID) quickfix.MessageRejectError {
return nil
}

func (s *FixServer) CancelOrder(msg ordercancelrequest.OrderCancelRequest, id quickfix.SessionID) quickfix.MessageRejectError {
func (s *Server) CancelOrder(msg ordercancelrequest.OrderCancelRequest, id quickfix.SessionID) quickfix.MessageRejectError {
return nil
}

func (s *FixServer) NewOrderList(msg neworderlist.NewOrderList, id quickfix.SessionID) quickfix.MessageRejectError {
func (s *Server) NewOrderList(msg neworderlist.NewOrderList, id quickfix.SessionID) quickfix.MessageRejectError {
return nil
}

func (s *FixServer) NewMarketDataReq(msg marketdatarequest.MarketDataRequest, id quickfix.SessionID) quickfix.MessageRejectError {
func (s *Server) NewMarketDataReq(msg marketdatarequest.MarketDataRequest, id quickfix.SessionID) quickfix.MessageRejectError {
return nil
}
2 changes: 1 addition & 1 deletion pkg/services/matching_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
log "github.com/sirupsen/logrus"
)

// Main entry point for processing a trade order.
// ProcessTradeOrder Main entry point for processing a trade order.
// - For BUY side, the amount must be alocated in quote currency.
// - For SELL side the amount must be allocared in base currency
func ProcessTradeOrder(
Expand Down
2 changes: 1 addition & 1 deletion pkg/services/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type MatchingServiceTestCase struct {
steps []TestStep
}

// // shorthand methods
// Acc shorthand methods
func Acc(v string) (models.AppEntityId, models.TradingAccountId) {
appEntityId := CreateAppEntity(models.AppEntityExternalId(v))
models.CreatePaymentAccount(appEntityId, models.CurrencyName("BTC"))
Expand Down
1 change: 1 addition & 0 deletions pkg/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
</style>
</head>
<body>
<!--suppress HtmlUnknownTag -->
<redoc spec-url='/static/api.yaml'></redoc>
<script src="https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js"> </script>
</body>
Expand Down
8 changes: 4 additions & 4 deletions sql/0190_get_crossing_limit_orders.sql
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ BEGIN
AND t.trading_account_id != trade_account_id_param
AND t.order_type = 'LIMIT'::order_type
-- order first by price then by date created
ORDER BY t.price ASC, t.created_at ASC;
ORDER BY t.price, t.created_at;
ELSE
RETURN QUERY SELECT b.id, b.pub_id, b.trade_order_id FROM book_order b
INNER JOIN trade_order t
Expand All @@ -45,7 +45,7 @@ BEGIN
AND t.trading_account_id != trade_account_id_param
AND t.order_type = 'LIMIT'::order_type
-- order first by price then by date created
ORDER BY t.price DESC, t.created_at ASC;
ORDER BY t.price DESC, t.created_at;
END IF;
ELSE
-- handle limit order
Expand All @@ -59,7 +59,7 @@ BEGIN
AND t.order_type = 'LIMIT'::order_type
AND t.price <= price_param
-- order first by price then by date created
ORDER BY t.price ASC, t.created_at ASC;
ORDER BY t.price, t.created_at;
ELSE
RETURN QUERY SELECT b.id, b.pub_id, b.trade_order_id FROM book_order b
INNER JOIN trade_order t
Expand All @@ -70,7 +70,7 @@ BEGIN
AND t.order_type = 'LIMIT'::order_type
AND t.price >= price_param
-- order first by price then by date created
ORDER BY t.price DESC, t.created_at ASC;
ORDER BY t.price DESC, t.created_at;
END IF;
END IF;
END;
Expand Down
2 changes: 1 addition & 1 deletion sql/0210_get_best_limit_price.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ BEGIN
WHERE side = side_param
AND instrument_id = instrument_id_param
AND price > 0
ORDER BY price ASC
ORDER BY price
LIMIT 1
INTO acc;
ELSEIF side_param = 'BUY'::order_side THEN
Expand Down
2 changes: 1 addition & 1 deletion sql/0290_process_trade_order.sql
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ BEGIN
AND t.trading_account_id != trading_account_instance.id
AND t.side = opposite_side_var
AND t.order_type = 'MARKET'::order_type
ORDER BY t.created_at ASC
ORDER BY t.created_at

LOOP
trade_price_var = get_trade_price(
Expand Down
4 changes: 2 additions & 2 deletions sql/0340_get_market_orders.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ BEGIN
AND side = side_param
AND order_type = 'MARKET'::order_type
-- order first by price then by date created
ORDER BY created_at ASC;
ORDER BY created_at;
ELSE
RETURN QUERY SELECT * FROM book_order
WHERE instrument_id = instrument_id_param
AND side = side_param
AND order_type = 'MARKET'::order_type
-- order first by price then by date created
ORDER BY created_at ASC;
ORDER BY created_at;
END IF;
END;
$$;
Expand Down

0 comments on commit a29a98d

Please sign in to comment.