Skip to content

Commit

Permalink
Cont client implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
tolyo committed Oct 6, 2024
1 parent a695add commit e1d5f4f
Show file tree
Hide file tree
Showing 77 changed files with 143 additions and 78 deletions.
Binary file added demo/demo
Binary file not shown.
3 changes: 2 additions & 1 deletion demo/demo.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ NPM_PREFIX = --prefix demo

setup-demo:
@npm $(NPM_PREFIX) i
@go get ./...

# Run server in dev mode
serve-demo:
@npm $(NPM_PREFIX) run serve
@go run main.go

# Run prettier source
pretty-demo:
Expand Down
11 changes: 11 additions & 0 deletions demo/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package main

import (
"log"
"open-outcry/demo/pkg"
)

func main() {
log.Println("Demo started")
pkg.SetupAll()
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
6 changes: 0 additions & 6 deletions demo/pkg/client/go.mod

This file was deleted.

11 changes: 0 additions & 11 deletions demo/pkg/client/go.sum

This file was deleted.

27 changes: 27 additions & 0 deletions demo/pkg/setup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package pkg

import (
"context"
"open-outcry/demo/pkg/api"
)

type App struct {
Ctx context.Context
ApiClient *api.APIClient
}

var app *App

func SetupAll() error {
ctx := context.Background()
app = &App{Ctx: ctx}

configuration := api.NewConfiguration()
app.ApiClient = api.NewAPIClient(configuration)

return nil
}

func GetApp() *App {
return app
}
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ require (
github.com/shopspring/decimal v1.3.1
github.com/sirupsen/logrus v1.9.3
github.com/spf13/viper v1.16.0
github.com/stretchr/testify v1.8.4
github.com/stretchr/testify v1.9.0
)

require (
github.com/armon/go-proxyproto v0.1.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/net v0.29.0 // indirect
)

require (
Expand All @@ -46,8 +46,8 @@ require (
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/text v0.18.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
9 changes: 9 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/subosito/gotenv v1.4.2 h1:X1TuBLAMDFbaTAChgCBLu3DU3UPyELpnF2jjJ2cz/S8=
github.com/subosito/gotenv v1.4.2/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down Expand Up @@ -296,6 +298,8 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c=
golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U=
golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo=
golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down Expand Up @@ -356,6 +360,8 @@ golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand All @@ -369,6 +375,8 @@ golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4=
golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
Expand Down Expand Up @@ -420,6 +428,7 @@ golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4f
golang.org/x/tools v0.0.0-20210108195828-e2f9c7f1fc8e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
golang.org/x/tools v0.10.0 h1:tvDr/iQoUqNdohiYm0LmmKcBk+q86lb9EprIUFhHHGg=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
9 changes: 5 additions & 4 deletions pkg/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package db

import (
"context"
"fmt"
"open-outcry/pkg/conf"
"reflect"

Expand Down Expand Up @@ -70,14 +71,14 @@ func QueryList[T interface{}](query string, args ...any) []T {
}

func GetCount(tableName string) int {
return QueryVal[int](
"SELECT COUNT(*) FROM " + tableName,
)
query := fmt.Sprintf("SELECT COUNT(*) FROM %s", tableName)
return QueryVal[int](query)
}

func DeleteAll(tableName string) {
query := fmt.Sprintf("DELETE FROM %s", tableName)
_, err := Instance().ExecContext(context.Background(),
"DELETE FROM "+tableName,
query,
)
if err != nil {
log.Fatal(err)
Expand Down
10 changes: 8 additions & 2 deletions pkg/models/payment_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func FindPaymentAccountByAppEntityIdAndCurrencyName(
currencyName CurrencyName,
) *PaymentAccount {
var paymentAccount PaymentAccount
db.Instance().QueryRow(
err := db.Instance().QueryRow(
basePaymentAccountQuery+`WHERE ae.pub_id = $1 AND c.name = $2`,
appEntityId,
currencyName,
Expand All @@ -69,11 +69,17 @@ func FindPaymentAccountByAppEntityIdAndCurrencyName(
&paymentAccount.AmountAvailable,
&paymentAccount.Currency,
)
if err != nil {
log.Fatal(err)
}
return &paymentAccount
}

func CreatePaymentAccount(appEntityId AppEntityId, currencyName CurrencyName) PaymentAccountId {
var id string
db.Instance().QueryRow("SELECT create_payment_account($1, $2)", appEntityId, currencyName).Scan(&id)
err := db.Instance().QueryRow("SELECT create_payment_account($1, $2)", appEntityId, currencyName).Scan(&id)
if err != nil {
log.Fatal(err)
}
return PaymentAccountId(id)
}
10 changes: 8 additions & 2 deletions pkg/models/trade_order.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package models

import "open-outcry/pkg/db"
import (
log "github.com/sirupsen/logrus"
"open-outcry/pkg/db"
)

type OrderTimeInForce string

Expand Down Expand Up @@ -93,7 +96,7 @@ const tradeOrderBaseQuery = `

func GetTradeOrder(id TradeOrderId) TradeOrder {
var order TradeOrder
db.Instance().QueryRow(tradeOrderBaseQuery+`WHERE t.pub_id = $1`, id).Scan(
err := db.Instance().QueryRow(tradeOrderBaseQuery+`WHERE t.pub_id = $1`, id).Scan(
&order.Id,
&order.TradingAccountId,
&order.InstrumentName,
Expand All @@ -106,5 +109,8 @@ func GetTradeOrder(id TradeOrderId) TradeOrder {
&order.TimeInForce,
&order.Created,
)
if err != nil {
log.Fatal(err)
}
return order
}
6 changes: 5 additions & 1 deletion pkg/models/trading_account.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package models

import (
"log"
"open-outcry/pkg/db"

"github.com/shopspring/decimal"
Expand Down Expand Up @@ -40,9 +41,12 @@ func FindTradingAccountByApplicationEntityId(appEntityId AppEntityId) *TradingAc

func helper(query string, arg any) *TradingAccount {
var tradingAccount TradingAccount
db.Instance().QueryRow(
err := db.Instance().QueryRow(
query, arg,
).Scan(&tradingAccount.Id, &tradingAccount.AppEntityId)
if err != nil {
log.Fatal(err)
}

return &tradingAccount
}
1 change: 1 addition & 0 deletions pkg/rest/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
</style>
</head>
<body>
<!--suppress HtmlUnknownTag -->
<redoc spec-url="http://petstore.swagger.io/v2/swagger.json"></redoc>
<script src="https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js"></script>
</body>
Expand Down
29 changes: 29 additions & 0 deletions qodana.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#-------------------------------------------------------------------------------#
# Qodana analysis is configured by qodana.yaml file #
# https://www.jetbrains.com/help/qodana/qodana-yaml.html #
#-------------------------------------------------------------------------------#
version: "1.0"

#Specify inspection profile for code analysis
profile:
name: qodana.starter

#Enable inspections
#include:
# - name: <SomeEnabledInspectionId>

#Disable inspections
#exclude:
# - name: <SomeDisabledInspectionId>
# paths:
# - <path/where/not/run/inspection>

#Execute shell command before Qodana execution (Applied in CI/CD pipeline)
#bootstrap: sh ./prepare-qodana.sh

#Install IDE plugins before Qodana execution (Applied in CI/CD pipeline)
#plugins:
# - id: <plugin.id> #(plugin id can be found at https://plugins.jetbrains.com)

#Specify Qodana linter for analysis (Applied in CI/CD pipeline)
linter: jetbrains/qodana-go:latest
11 changes: 3 additions & 8 deletions sql/0005_trade_order_status.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,17 @@
-- Model of states that a trade order can undergo during its
-- lifecycle. Transitional states hold funds in `payment_account.amount_reserved`
-- Final states should release all reserved funds.
CREATE TYPE trade_order_status AS ENUM (
CREATE TYPE trade_order_status AS ENUM(
-- TRANSITIONAL STATES
-- order remains in the order book and has no fills
'OPEN',

-- order remains in the order book but with partial fill
'PARTIALLY_FILLED',


-- FINAL STATES
-- order has been cancelled by the user without any fills
'CANCELLED',

-- order has been partially filled but then cancelled by user
'PARTIALLY_CANCELLED',

-- order has been partially filled but then rejected.
-- Possible rejection reasons:
-- * IOC
Expand All @@ -26,7 +21,6 @@ CREATE TYPE trade_order_status AS ENUM (
'PARTIALLY_REJECTED',
-- order has been filled and removed from the order book
'FILLED',

-- order rejected from the order book.
-- Possible rejection reasons:
-- * insufficiency of funds
Expand All @@ -35,4 +29,5 @@ CREATE TYPE trade_order_status AS ENUM (
);

-- +goose Down
DROP TYPE trade_order_status CASCADE;
DROP TYPE trade_order_status CASCADE;

Loading

0 comments on commit e1d5f4f

Please sign in to comment.