mtgban

package
v0.0.0-...-882b071 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package mtgban defines interfaces for scrapers and utility functions to obtain pricing information from various vendors.

Index

Constants

View Source
const DefaultArbitMinDiff = 0.2
View Source
const DefaultArbitMinSpread = 25.0
View Source
const DefaultMismatchMinDiff = 1.0
View Source
const DefaultMismatchMinSpread = 100.0

Variables

View Source
var (
	// The canonical header that will be present in all inventory files
	InventoryHeader = []string{
		"Key", "Name", "Set", "F/NF", "Conditions", "Price", "Quantity",
	}
	// The canonical header that will be present in all buylist files
	BuylistHeader = []string{
		"Key", "Name", "Set", "F/NF", "Conditions", "Buy Price", "Trade Price", "Quantity", "Price Ratio", "Quantity Ratio",
	}

	ArbitHeader = []string{
		"Key", "Name", "Edition", "F/NF", "Conditions", "Sell Price", "Buy Price", "Trade Price", "Difference", "Spread", "Price Ratio", "Quantity Ratio",
	}
	MismatchHeader = []string{
		"Key", "Name", "Edition", "F/NF", "Conditions", "Price", "Difference", "Spread",
	}
)
View Source
var EditionTable = map[string]string{}/* 198 elements not displayed */
View Source
var NewPrereleaseDate = time.Date(2014, time.September, 1, 0, 0, 0, 0, time.UTC)
View Source
var VariantsTable = map[string]map[string]map[string]string{
	"Alliances":                     allVariants,
	"Anthologies":                   athVariants,
	"Antiquities":                   atqVariants,
	"Arena League 2001":             pal01Variants,
	"Asia Pacific Land Program":     palpVariants,
	"Battle Royale Box Set":         brbVariants,
	"Champions of Kamigawa":         chkVariants,
	"Chronicles":                    chrVariants,
	"Collectors’ Edition":           oldLandVariants,
	"Conspiracy: Take the Crown":    cn2Variants,
	"Deckmasters":                   dkmVariants,
	"European Land Program":         pelpVariants,
	"Fallen Empires":                femVariants,
	"Fifth Edition":                 ed5Variants,
	"Fourth Edition":                ed4Variants,
	"GRN Ravnica Weekend":           prwkVariants,
	"Homelands":                     hmlVariants,
	"Ice Age":                       iceVariants,
	"Intl. Collectors’ Edition":     oldLandVariants,
	"Introductory Two-Player Set":   itpVariants,
	"Limited Edition Alpha":         leaVariants,
	"Limited Edition Beta":          oldLandVariants,
	"Magic Premiere Shop 2005":      pmpsVariants,
	"Mirage":                        mirVariants,
	"Oath of the Gatewatch":         ogwVariants,
	"Planeshift":                    plsVariants,
	"Portal Second Age":             po2Variants,
	"Portal":                        porVariants,
	"Pro Tour Collector Set":        ptcVariants,
	"Rinascimento":                  rinVariants,
	"RNA Ravnica Weekend":           prw2Variants,
	"Revised Edition":               ed3Variants,
	"Secret Lair Drop":              sldVariants,
	"Shadows over Innistrad":        soiVariants,
	"Shadows over Innistrad Promos": psoiVariants,
	"Tempest":                       tmpVariants,
	"Unlimited Edition":             oldLandVariants,
	"Unstable":                      ustVariants,
	"World Championship Decks 1999": wc99Variants,
	"World Championship Decks 2000": wc00Variants,
	"World Championship Decks 2001": wc01Variants,
	"World Championship Decks 2002": wc02Variants,
}

Functions

func BuylistAdd

func BuylistAdd(buylist map[string]BuylistEntry, card BuylistEntry) error

func GetExchangeRate

func GetExchangeRate(currency string) (float64, error)

func InventoryAdd

func InventoryAdd(inventory map[string][]InventoryEntry, card InventoryEntry) error

func SplitVariants

func SplitVariants(str string) []string

SplitVariants returns an array of strings from the parentheses-defined fields commonly used to distinguish some cards across editions.

func WriteArbitrageToCSV

func WriteArbitrageToCSV(arbitrage []ArbitEntry, w io.Writer) error

func WriteBuylistToCSV

func WriteBuylistToCSV(vendor Vendor, w io.Writer) error

func WriteCombineToCSV

func WriteCombineToCSV(root *CombineRoot, w io.Writer) error

func WriteInventoryToCSV

func WriteInventoryToCSV(seller Seller, w io.Writer) error

func WriteMismatchToCSV

func WriteMismatchToCSV(mismatch []MismatchEntry, w io.Writer) error

Types

type ArbitEntry

type ArbitEntry struct {
	BuylistEntry
	InventoryEntry

	Difference float64
	Spread     float64
}

func Arbit

func Arbit(opts *ArbitOpts, vendor Vendor, seller Seller) (result []ArbitEntry, err error)

type ArbitOpts

type ArbitOpts struct {
	MinDiff   float64
	MinSpread float64

	UseTrades bool
}

type BanClient

type BanClient struct {
	// contains filtered or unexported fields
}

BanClient abstracts some common operations that can be performed on both Seller and Vendor types, as well as offering a way to retrieve any given Scaper.

func NewClient

func NewClient() *BanClient

Return an empty BanClient

func (*BanClient) Load

func (bc *BanClient) Load() error

Load inventory and buylist content for each scraper registered in the client

func (*BanClient) Register

func (bc *BanClient) Register(scraper Scraper)

Add a Scraper to the client

func (*BanClient) ScraperByName

func (bc *BanClient) ScraperByName(shorthand string) (Scraper, error)

Return the scraper with a matching name from the ones registered in the client

func (*BanClient) Scrapers

func (bc *BanClient) Scrapers() (scrapers []Scraper)

Return a new slice containing all the scrapers registers in the client

func (*BanClient) Sellers

func (bc *BanClient) Sellers() (sellers []Seller)

Return a new slice containing all the sellers registers in the client

func (*BanClient) Vendors

func (bc *BanClient) Vendors() (vendors []Vendor)

Return a new slice containing all the vendors registers in the client

type BaseBuylist

type BaseBuylist struct {
	// contains filtered or unexported fields
}

func (*BaseBuylist) Buylist

func (bl *BaseBuylist) Buylist() (map[string]BuylistEntry, error)

func (*BaseBuylist) Grading

func (bl *BaseBuylist) Grading(entry BuylistEntry) map[string]float64

func (*BaseBuylist) Info

func (inv *BaseBuylist) Info() (info ScraperInfo)

type BaseInventory

type BaseInventory struct {
	// contains filtered or unexported fields
}

func (*BaseInventory) Info

func (inv *BaseInventory) Info() (info ScraperInfo)

func (*BaseInventory) Inventory

func (inv *BaseInventory) Inventory() (map[string][]InventoryEntry, error)

type BuylistEntry

type BuylistEntry struct {
	Card

	Quantity   int
	Conditions string
	BuyPrice   float64
	TradePrice float64

	PriceRatio    float64
	QuantityRatio float64

	Notes string
}

BuylistEntry represents an entry for buying a particular Card

func LoadBuylistFromCSV

func LoadBuylistFromCSV(r io.Reader) ([]BuylistEntry, error)

type Card

type Card struct {
	// The unique identifier of a card. When the UUID can be used to associate
	// two versions of the same card (for example because one is foil), `_f`
	// suffix is appended to it.
	Id string `json:"id"`

	// The official name of the card
	Name string `json:"name"`

	// The set the card comes from
	Set string `json:"set"`

	// Whether the card is foil or not
	Foil bool `json:"foil"`
}

Card is a generic card representation using fields defined by the MTGJSON project.

type CombineEntry

type CombineEntry struct {
	ScraperName string
	Price       float64
	Ratio       float64
	Quantity    int
	Notes       string
}

type CombineRoot

type CombineRoot struct {
	Names     []string
	Entries   map[Card][]CombineEntry
	BestOffer map[Card]CombineEntry
}

func CombineBuylists

func CombineBuylists(vendors []Vendor, useCredit bool) (*CombineRoot, error)

func CombineInventories

func CombineInventories(sellers []Seller) (*CombineRoot, error)

type InventoryEntry

type InventoryEntry struct {
	Card

	Quantity   int
	Conditions string
	Price      float64

	Notes string
}

InventoryEntry represents an entry for selling a particular Card

func LoadInventoryFromCSV

func LoadInventoryFromCSV(r io.Reader) ([]InventoryEntry, error)

type LogCallbackFunc

type LogCallbackFunc func(format string, a ...interface{})

type MismatchEntry

type MismatchEntry struct {
	InventoryEntry

	Difference float64
	Spread     float64
}

func Mismatch

func Mismatch(opts *ArbitOpts, reference Seller, probe Seller) (result []MismatchEntry, err error)

type Normalizer

type Normalizer struct {
	// contains filtered or unexported fields
}

Type to normalize the various name differences across vendors

func NewNormalizer

func NewNormalizer() *Normalizer

NewNormalizer initializes a Normalizer with default rules.

func (*Normalizer) Normalize

func (n *Normalizer) Normalize(str string) string

Normalize uses the rules defined in NewNormalized to replace uncommon elements of card names, producing an easy to compare string.

type NumberCheckFunc

type NumberCheckFunc func(set mtgjson.Set, card mtgjson.Card) bool

type Scraper

type Scraper interface {
	Info() ScraperInfo
}

Scraper is the interface both Sellers and Vendors need to implement

type ScraperInfo

type ScraperInfo struct {
	Name               string
	Shorthand          string
	InventoryTimestamp time.Time
	BuylistTimestamp   time.Time
}

ScraperInfo contains

type Seller

type Seller interface {
	// Return the inventory for a Seller. If not already loaded, it will start
	// scraping the seller gathering the necessary data.
	Inventory() (map[string][]InventoryEntry, error)

	// Return some information about the seller
	Info() ScraperInfo
}

Seller is the interface describing actions to be performed on an seller inventory

func NewSellerFromCSV

func NewSellerFromCSV(r io.Reader) (Seller, error)

type SetCheckFunc

type SetCheckFunc func(set mtgjson.Set) bool

type Vendor

type Vendor interface {
	// Return the buylist for a Vendor. If not already loaded, it will start
	// scraping the vendor gathering the necessary data.
	Buylist() (map[string]BuylistEntry, error)

	// Return the grading scale for adjusting prices according to conditions
	Grading(BuylistEntry) map[string]float64

	// Return some information about the vendor
	Info() ScraperInfo
}

Vendor is the interface describing actions to be performed on an vendor buylist

func NewVendorFromCSV

func NewVendorFromCSV(r io.Reader, grade map[string]float64) (Vendor, error)

Jump to

Keyboard shortcuts

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