First/last trade
This commit is contained in:
parent
67a5d3abc0
commit
eb0c79942c
@ -17,6 +17,10 @@ const (
|
||||
trades_in_date_range = `SELECT id, trade_id, product, price, size, buy, ` +
|
||||
`sell, timestamp FROM trades WHERE product = $1 AND timestamp >= $2 ` +
|
||||
`AND timestamp < $3;`
|
||||
trade_first = `SELECT id, trade_id, product, price, size, buy, sell, timestamp ` +
|
||||
`FROM trades WHERE product = $1 ORDER BY trade_id ASC LIMIT 1;`
|
||||
trade_last = `SELECT id, trade_id, product, price, size, buy, sell, timestamp ` +
|
||||
`FROM trades WHERE product = $1 ORDER BY trade_id DESC LIMIT 1;`
|
||||
)
|
||||
|
||||
type TradeService struct {
|
||||
@ -94,3 +98,29 @@ func (t *TradeService) TradesInDateRange(product string, start,
|
||||
|
||||
return trades, nil
|
||||
}
|
||||
|
||||
func (t *TradeService) FirstTrade(product string) (*tacitus.Trade, error) {
|
||||
var tr tacitus.Trade
|
||||
|
||||
row := t.client.db.QueryRow(trade_first, product)
|
||||
if err := row.Scan(&tr.Id, &tr.TradeId, &tr.Product, &tr.Price, &tr.Size, &tr.Buy,
|
||||
&tr.Sell, &tr.Timestamp); err != nil {
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &tr, nil
|
||||
}
|
||||
|
||||
func (t *TradeService) LastTrade(product string) (*tacitus.Trade, error) {
|
||||
var tr tacitus.Trade
|
||||
|
||||
row := t.client.db.QueryRow(trade_last, product)
|
||||
if err := row.Scan(&tr.Id, &tr.TradeId, &tr.Product, &tr.Price, &tr.Size, &tr.Buy,
|
||||
&tr.Sell, &tr.Timestamp); err != nil {
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &tr, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user