Skip to content

Commit

Permalink
Clean up the order submission
Browse files Browse the repository at this point in the history
  • Loading branch information
ValentinTrinque committed Apr 30, 2021
1 parent 99e77fc commit 0d25b1b
Show file tree
Hide file tree
Showing 22 changed files with 626 additions and 544 deletions.
66 changes: 66 additions & 0 deletions api/gomock_reflect_889398060/prog.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@

package main

import (
"encoding/gob"
"flag"
"fmt"
"os"
"path"
"reflect"

"github.com/golang/mock/mockgen/model"

pkg_ "code.vegaprotocol.io/vega/api"
)

var output = flag.String("output", "", "The output file name, or empty to use stdout.")

func main() {
flag.Parse()

its := []struct{
sym string
typ reflect.Type
}{

{ "Blockchain", reflect.TypeOf((*pkg_.Blockchain)(nil)).Elem()},

}
pkg := &model.Package{
// NOTE: This behaves contrary to documented behaviour if the
// package name is not the final component of the import path.
// The reflect package doesn't expose the package name, though.
Name: path.Base("code.vegaprotocol.io/vega/api"),
}

for _, it := range its {
intf, err := model.InterfaceFromInterfaceType(it.typ)
if err != nil {
fmt.Fprintf(os.Stderr, "Reflection: %v\n", err)
os.Exit(1)
}
intf.Name = it.sym
pkg.Interfaces = append(pkg.Interfaces, intf)
}

outfile := os.Stdout
if len(*output) != 0 {
var err error
outfile, err = os.Create(*output)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to open output file %q", *output)
}
defer func() {
if err := outfile.Close(); err != nil {
fmt.Fprintf(os.Stderr, "failed to close output file %q", *output)
os.Exit(1)
}
}()
}

if err := gob.NewEncoder(outfile).Encode(pkg); err != nil {
fmt.Fprintf(os.Stderr, "gob encode: %v\n", err)
os.Exit(1)
}
}
10 changes: 5 additions & 5 deletions api/mocks/governance_service_mock.go

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

21 changes: 15 additions & 6 deletions execution/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,15 +422,24 @@ func (e *Engine) removeMarket(mktID string) {
}

// SubmitOrder checks the incoming order and submits it to a Vega market.
func (e *Engine) SubmitOrder(ctx context.Context, order *types.Order) (*types.OrderConfirmation, error) {
func (e *Engine) SubmitOrder(ctx context.Context, orderSubmission *types.OrderSubmission, party string) (confirmation *types.OrderConfirmation, returnedErr error) {
defer func() {
e.notifyFailureOnError(ctx, returnedErr, orderSubmission, party)
}()

if e.log.IsDebug() {
e.log.Debug("submit order", logging.Order(*order))
e.log.Debug("submit order", logging.OrderSubmission(orderSubmission))
}

timer := metrics.NewTimeCounter(order.MarketId, "execution", "SubmitOrder")
timer := metrics.NewTimeCounter(orderSubmission.MarketId, "execution", "SubmitOrder")

order := orderSubmission.IntoOrder(party)

mkt, ok := e.markets[order.MarketId]
mkt, ok := e.markets[orderSubmission.MarketId]
if !ok {
// FIXME(jeremy) We shouldn't define an ID on a failed submission order
// but this is a dirty fix for storage purpose. We'll improve this
// later on.
e.idgen.SetID(order)

// adding rejected order to the buf
Expand Down Expand Up @@ -465,7 +474,7 @@ func (e *Engine) SubmitOrder(ctx context.Context, order *types.Order) (*types.Or
// if it exists and is in a editable state.
func (e *Engine) AmendOrder(ctx context.Context, orderAmendment *types.OrderAmendment) (confirmation *types.OrderConfirmation, returnedErr error) {
defer func() {
e.notifyFailureOnError(ctx, returnedErr, orderAmendment.PartyId, orderAmendment)
e.notifyFailureOnError(ctx, returnedErr, orderAmendment, orderAmendment.PartyId)
}()

if e.log.IsDebug() {
Expand Down Expand Up @@ -902,7 +911,7 @@ func (e *Engine) OnMarketProbabilityOfTradingTauScalingUpdate(ctx context.Contex
return nil
}

func (e *Engine) notifyFailureOnError(ctx context.Context, err error, partyID string, tx interface{}) {
func (e *Engine) notifyFailureOnError(ctx context.Context, err error, tx interface{}, partyID string) {
if err != nil {
e.broker.Send(events.NewTxErrEvent(ctx, err, partyID, tx))
}
Expand Down
66 changes: 66 additions & 0 deletions execution/gomock_reflect_417138063/prog.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@

package main

import (
"encoding/gob"
"flag"
"fmt"
"os"
"path"
"reflect"

"github.com/golang/mock/mockgen/model"

pkg_ "code.vegaprotocol.io/vega/execution"
)

var output = flag.String("output", "", "The output file name, or empty to use stdout.")

func main() {
flag.Parse()

its := []struct{
sym string
typ reflect.Type
}{

{ "TimeService", reflect.TypeOf((*pkg_.TimeService)(nil)).Elem()},

}
pkg := &model.Package{
// NOTE: This behaves contrary to documented behaviour if the
// package name is not the final component of the import path.
// The reflect package doesn't expose the package name, though.
Name: path.Base("code.vegaprotocol.io/vega/execution"),
}

for _, it := range its {
intf, err := model.InterfaceFromInterfaceType(it.typ)
if err != nil {
fmt.Fprintf(os.Stderr, "Reflection: %v\n", err)
os.Exit(1)
}
intf.Name = it.sym
pkg.Interfaces = append(pkg.Interfaces, intf)
}

outfile := os.Stdout
if len(*output) != 0 {
var err error
outfile, err = os.Create(*output)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to open output file %q", *output)
}
defer func() {
if err := outfile.Close(); err != nil {
fmt.Fprintf(os.Stderr, "failed to close output file %q", *output)
os.Exit(1)
}
}()
}

if err := gob.NewEncoder(outfile).Encode(pkg); err != nil {
fmt.Fprintf(os.Stderr, "gob encode: %v\n", err)
os.Exit(1)
}
}
3 changes: 3 additions & 0 deletions execution/market.go
Original file line number Diff line number Diff line change
Expand Up @@ -1148,12 +1148,15 @@ func (m *Market) releaseMarginExcess(ctx context.Context, partyID string) {

// SubmitOrder submits the given order
func (m *Market) SubmitOrder(ctx context.Context, order *types.Order) (*types.OrderConfirmation, error) {
order.CreatedAt = m.currentTime.UnixNano()

if !m.canTrade() {
order.Status = types.Order_STATUS_REJECTED
order.Reason = types.OrderError_ORDER_ERROR_MARKET_CLOSED
m.broker.Send(events.NewOrderEvent(ctx, order))
return nil, ErrTradingNotAllowed
}

conf, err := m.submitOrder(ctx, order, true)
if err != nil {
return nil, err
Expand Down
66 changes: 28 additions & 38 deletions gateway/graphql/generated.go

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

0 comments on commit 0d25b1b

Please sign in to comment.