model

package
v0.0.0-...-2d05010 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 25, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OrderTypeBuy  = "buy"
	OrderTypeSell = "sell"
)
View Source
const (
	BankEndpoint = "bank_endpoint"
	BankAppid    = "bank_appid"
	LogEndpoint  = "log_endpoint"
	LogAppid     = "log_appid"
)

Variables

View Source
var (
	ErrBankUserNotFound   = errors.New("bank user not found")
	ErrBankUserConflict   = errors.New("bank user conflict")
	ErrUserNotFound       = errors.New("user not found")
	ErrOrderNotFound      = errors.New("order not found")
	ErrOrderAlreadyClosed = errors.New("order is already closed")
	ErrCreditInsufficient = errors.New("銀行の残高が足りません")
	ErrParameterInvalid   = errors.New("parameter invalid")
	ErrNoOrderForTrade    = errors.New("no order for trade")
)

Functions

func DeleteOrder

func DeleteOrder(tx *sql.Tx, userID, orderID int64, reason string) error

func FetchOrderRelation

func FetchOrderRelation(d QueryExecutor, order *Order) error

func GetSetting

func GetSetting(d QueryExecutor, k string) (string, error)

func HasTradeChanceByOrder

func HasTradeChanceByOrder(d QueryExecutor, orderID int64) (bool, error)

func InitBenchmark

func InitBenchmark(d QueryExecutor) error

func Isubank

func Isubank(d QueryExecutor) (*isubank.Isubank, error)

func Logger

func Logger(d QueryExecutor) (*isulogger.Isulogger, error)

func RunTrade

func RunTrade(db *sql.DB) error

func SetSetting

func SetSetting(d QueryExecutor, k, v string) error

func UserSignup

func UserSignup(tx *sql.Tx, name, bankID, password string) error

Types

type CandlestickData

type CandlestickData struct {
	Time  time.Time `json:"time"`
	Open  int64     `json:"open"`
	Close int64     `json:"close"`
	High  int64     `json:"high"`
	Low   int64     `json:"low"`
}

func GetCandlestickData

func GetCandlestickData(d QueryExecutor, mt time.Time, tf string) ([]*CandlestickData, error)

type Order

type Order struct {
	ID        int64      `json:"id"`
	Type      string     `json:"type"`
	UserID    int64      `json:"user_id"`
	Amount    int64      `json:"amount"`
	Price     int64      `json:"price"`
	ClosedAt  *time.Time `json:"closed_at"`
	TradeID   int64      `json:"trade_id,omitempty"`
	CreatedAt time.Time  `json:"created_at"`
	User      *User      `json:"user,omitempty"`
	Trade     *Trade     `json:"trade,omitempty"`
}

func AddOrder

func AddOrder(tx *sql.Tx, ot string, userID, amount, price int64) (*Order, error)

func GetHighestBuyOrder

func GetHighestBuyOrder(d QueryExecutor) (*Order, error)

func GetLowestSellOrder

func GetLowestSellOrder(d QueryExecutor) (*Order, error)

func GetOrderByID

func GetOrderByID(d QueryExecutor, id int64) (*Order, error)

func GetOrdersByUserIDAndLastTradeIdWithRelation

func GetOrdersByUserIDAndLastTradeIdWithRelation(d QueryExecutor, userID int64, tradeID int64) ([]*Order, error)

func GetOrdersByUserIDWithRelation

func GetOrdersByUserIDWithRelation(d QueryExecutor, userID int64) ([]*Order, error)

type QueryExecutor

type QueryExecutor interface {
	Exec(string, ...interface{}) (sql.Result, error)
	Query(string, ...interface{}) (*sql.Rows, error)
}

type Setting

type Setting struct {
	Name string
	Val  string
}

type Trade

type Trade struct {
	ID        int64     `json:"id"`
	Amount    int64     `json:"amount"`
	Price     int64     `json:"price"`
	CreatedAt time.Time `json:"created_at"`
}

func GetLatestTrade

func GetLatestTrade(d QueryExecutor) (*Trade, error)

func GetTradeByID

func GetTradeByID(d QueryExecutor, id int64) (*Trade, error)

type User

type User struct {
	ID        int64     `json:"id"`
	BankID    string    `json:"-"`
	Name      string    `json:"name"`
	Password  string    `json:"-"`
	CreatedAt time.Time `json:"-"`
}

func GetUserByID

func GetUserByID(d QueryExecutor, id int64) (*User, error)

func UserLogin

func UserLogin(d QueryExecutor, bankID, password string) (*User, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL