2017-09-07 23:04:47 -07:00
|
|
|
package tacitus
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/shopspring/decimal"
|
|
|
|
|
2017-09-09 10:14:50 -07:00
|
|
|
"strings"
|
2017-09-07 23:04:47 -07:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2017-09-21 10:26:29 -07:00
|
|
|
var PRODUCTS = [...]string{"BTC-USD", "ETH-USD"}
|
2017-09-09 10:14:50 -07:00
|
|
|
|
2017-09-07 23:04:47 -07:00
|
|
|
type Trade struct {
|
2017-09-09 10:14:50 -07:00
|
|
|
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,"`
|
2017-09-07 23:04:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
type TradeService interface {
|
2017-09-23 16:52:47 -07:00
|
|
|
CreateTrade(t Trade) (Trade, error)
|
2017-09-07 23:04:47 -07:00
|
|
|
DeleteTrade(id int)
|
2017-09-27 20:38:25 -07:00
|
|
|
|
|
|
|
Trade(id int) (Trade, error)
|
|
|
|
TradeByTradeId(id int, prod string) (Trade, error)
|
2017-09-07 23:04:47 -07:00
|
|
|
TradesInDateRange(product string, start, end time.Time) ([]Trade, error)
|
2017-09-09 10:14:50 -07:00
|
|
|
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)
|
2017-09-27 20:38:25 -07:00
|
|
|
|
2017-09-27 23:23:34 -07:00
|
|
|
TradesAfterAll(product string, id int) (Results, error)
|
2017-10-13 09:34:35 -07:00
|
|
|
TradesWhereResults(sql string, params ...interface{}) (Results, error)
|
2017-09-09 10:14:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func ValidProduct(prod string) bool {
|
|
|
|
prod = strings.ToUpper(prod)
|
|
|
|
for _, p := range PRODUCTS {
|
|
|
|
if p == prod {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
2017-09-07 23:04:47 -07:00
|
|
|
}
|