Skip to content

Commit

Permalink
Query for instruments
Browse files Browse the repository at this point in the history
  • Loading branch information
tolyo committed Dec 5, 2023
1 parent 7115882 commit 3fd25dc
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
16 changes: 13 additions & 3 deletions pkg/models/instrument.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package models

import "open-outcry/pkg/db"

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

Expand All @@ -13,9 +15,17 @@ type InstrumentBaseCurrency CurrencyName
type InstrumentQuoteCurrency CurrencyName

type Instrument struct {
Id InstrumentId
Id InstrumentId `db:"pub_id"`
Name InstrumentName
BaseCurrency InstrumentBaseCurrency
QuoteCurrency InstrumentQuoteCurrency
BaseCurrency InstrumentBaseCurrency `db:"base_currency"`
QuoteCurrency InstrumentQuoteCurrency `db:"quote_currency"`
Active bool
}

func GetInstruments() []Instrument {
return db.QueryList[Instrument](`SELECT pub_id, name, quote_currency FROM instrument WHERE fx_instrument = FALSE`)
}

func GetFxInstruments() []Instrument {
return db.QueryList[Instrument](`SELECT pub_id, name, base_currency, quote_currency FROM instrument WHERE fx_instrument = TRUE`)
}
9 changes: 9 additions & 0 deletions pkg/models/instrument_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package models

func (assert *ModelsTestSuite) TestGetInstruments() {
assert.GreaterOrEqual(1, len(GetInstruments()))
}

func (assert *ModelsTestSuite) TestGetFxInstruments() {
assert.GreaterOrEqual(1, len(GetFxInstruments()))
}
4 changes: 2 additions & 2 deletions pkg/models/models_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ func TestModelSuite(t *testing.T) {
suite.Run(t, &ModelsTestSuite{})
}

func (suite *ModelsTestSuite) SetupTest() {
func (assert *ModelsTestSuite) SetupTest() {
err := db.SetupInstance()
if err != nil {
panic(err)
}
db.MigrateUp()
}

func (suite *ModelsTestSuite) TearDownTest() {
func (assert *ModelsTestSuite) TearDownTest() {
db.MigrateDown()
db.Instance().Close()
}

0 comments on commit 3fd25dc

Please sign in to comment.