This repository has been archived on 2022-11-30. You can view files and clone it, but cannot push or open issues or pull requests.
tacitus/trade.go

45 lines
1.1 KiB
Go

package tacitus
import (
"github.com/shopspring/decimal"
"strings"
"time"
)
var PRODUCTS = [...]string{"BTC-USD", "ETH-USD"}
type Trade struct {
Id int `json:"-"`
TradeId int `json:"trade_id,"`
Product string `json:"product,"`
Price decimal.Decimal `json:"price,"`
Size decimal.Decimal `json:"size,"`
Buy bool `json:"buy,"`
Sell bool `json:"sell,"`
Timestamp time.Time `json:"timestamp,"`
}
type TradeService interface {
Trade(id int) (*Trade, error)
TradeByTradeId(id int, prod string) (*Trade, error)
CreateTrade(t *Trade) error
DeleteTrade(id int)
TradesInDateRange(product string, start, end time.Time) ([]Trade, error)
FirstTrades(product string, limit int) ([]Trade, error)
LastTrades(product string, limit int) ([]Trade, error)
TradesAfter(product string, id, limit int) ([]Trade, error)
TradesBefore(product string, id, limit int) ([]Trade, error)
}
func ValidProduct(prod string) bool {
prod = strings.ToUpper(prod)
for _, p := range PRODUCTS {
if p == prod {
return true
}
}
return false
}