csfloat

package module
v0.0.0-...-a4e1952 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2025 License: BSD-3-Clause Imports: 10 Imported by: 0

README

Unofficial CSFloat API wrapper

This is a work in progress API wrapper for CSFloat.

It is not 100% feature complete. If you need any additional endpoints, either make a PR or create an issue.

The API might not be 100% stable and could change at any time.

There's no extensive test suite, as it is hard to test this without potentially causing chaos in my own account.

Given that there is NO documentation for CSFloat, everything here was reversed through the browser.

Concepts

Ratelimits

CSFloat has two types of ratelimiting:

  1. IP-based (separate for IPv4 and IPv6)

N request per 5 minutes 2. Account-based per endpoint (includes API Key) Each endpoint will tell you

This wrapepr does not respect ratelimits on its own, but exposes a Ratelimits field on every endpoint, which you can use to respect them yourself.

Errors

CSFloat uses a generic error format. These errors are exposed in the Error field of each response and need to be checked for nil before accessing.

I do NOT know all error codes yet, so there are only constants for the ones I stumbled upon.

Known issues

Timeouts

Sometimes CSFloat will have very slow reponse times, where you don't even receive the headers. This can cause timeouts sometimes, even though the actual action behind the request is already done.

For example you click buy on an item and it gives you a timeout error, but the purchase has alreadt completed / will keep completing in the background.

Documentation

Index

Constants

View Source
const (
	ErrorCodeAlreadySold = 4
	// ErrorCodeInvalidPurchaseState is thrown along HTTP status code 422. It
	// is unclear when exactly, but it seems similar to AlreadySold. It might
	// be unlisted.
	ErrorCodeInvalidPurchaseState = 6
	ErrorCodePriceChanged         = 15
	// ErrorCodeSalesHistoryNotAvailable implies that the history for a certain
	// item was disabled. This is done for cases for example.
	ErrorCodeSalesHistoryNotAvailable = 200
)
View Source
const (
	Normal   = 1
	StatTrak = 2
	Souvenir = 3
)
View Source
const Fee float64 = 2

Fee is a constant fee. Technically the profile has a setting, but it seems its unachievable to reduce the fee, so this is fine for now.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuctionRequest

type AuctionRequest struct {
	DurationDays uint `json:"duration_days,omitempty"`
	ReservePrice uint `json:"reserve_price,omitempty"`
}

type BlueGem

type BlueGem struct {
	PlaysideBlue   float64 `json:"playside_blue"`
	PlaysideGold   float64 `json:"playside_gold"`
	PlaysidePurple float64 `json:"playside_purple"`
	BacksideBlue   float64 `json:"backside_blue"`
	BacksideGold   float64 `json:"backside_gold"`
	BacksidePurple float64 `json:"backside_purple"`
}

type BuyNowRequest

type BuyNowRequest struct {
	Price uint `json:"price,omitempty"`
}

type BuyRequestPayload

type BuyRequestPayload struct {
	ContractIds []string `json:"contract_ids"`
	TotalPrice  uint     `json:"total_price"`
}

type BuyResponse

type BuyResponse struct {
	GenericResponse
}

type CSFloat

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

func New

func New() *CSFloat

func NewWithHTTPClient

func NewWithHTTPClient(client *http.Client) *CSFloat

func (*CSFloat) Buy

func (api *CSFloat) Buy(apiKey string, payload BuyRequestPayload) (*BuyResponse, error)

func (*CSFloat) FloatRange

func (api *CSFloat) FloatRange(f float32) (float32, float32)

FloatRange returns the float range for the given quality (fn, mw, ...).

func (*CSFloat) History

func (api *CSFloat) History(apiKey string, payload HistoryRequestPayload) (*HistoryResponse, error)

func (*CSFloat) Inventory

func (api *CSFloat) Inventory(apiKey string) (*InventoryResponse, error)

Inventory returns all visible (tradable) items from the Steam inventory. This includes items already listed in the stall, those will have a `listing_id` set.

func (*CSFloat) ItemBuyOrders

func (api *CSFloat) ItemBuyOrders(apiKey string, item *Item) (*ItemBuyOrdersResponse, error)

func (*CSFloat) List

func (api *CSFloat) List(apiKey string, payload ListRequest) (*ListResponse, error)

func (*CSFloat) Listing

func (api *CSFloat) Listing(apiKey string, listingId string) (*ListingResponse, error)

Listing returns an existing listing.

func (*CSFloat) ListingBuyOrders

func (api *CSFloat) ListingBuyOrders(apiKey, listingId string) (*ItemBuyOrdersResponse, error)

func (*CSFloat) Listings

func (api *CSFloat) Listings(apiKey string, query ListingsRequest) (*ListingsResponse, error)

func (*CSFloat) Me

func (api *CSFloat) Me(apiKey string) (*MeResponse, error)

func (*CSFloat) Similar

func (api *CSFloat) Similar(apiKey, listingId string) (*SimilarResponse, error)

func (*CSFloat) SimpleItemBuyOrders

func (api *CSFloat) SimpleItemBuyOrders(apiKey string, item *Item) (*SimpleItemBuyOrdersResponse, error)

func (*CSFloat) Stall

func (api *CSFloat) Stall(apiKey, steamId string) (*StallResponse, error)

func (*CSFloat) Trades

func (api *CSFloat) Trades(apiKey string, payload TradesRequest) (*TradesResponse, error)

func (*CSFloat) Transactions

func (api *CSFloat) Transactions(apiKey string, payload TransactionsRequest) (*TransactionsResponse, error)

func (*CSFloat) Unlist

func (api *CSFloat) Unlist(apiKey, listingId string) (*UnlistResponse, error)

func (*CSFloat) UpdateListing

func (api *CSFloat) UpdateListing(apiKey, id string, payload UpdateListingRequest) (*UpdateListingResponse, error)

type Category

type Category uint

type Charm

type Charm struct {
	// CharmId is called stickerId, not a typo.
	Index     uint      `json:"stickerId"`
	Pattern   uint      `json:"pattern"`
	Name      string    `json:"name"`
	Reference Reference `json:"reference"`
}

type Error

type Error struct {
	HttpStatus uint   `json:"-"`
	Code       uint   `json:"code"`
	Message    string `json:"message"`
}

type Fade

type Fade struct {
	// Seed sems to be the same as the paintseed so far.
	Seed       uint    `json:"seed"`
	Percentage float64 `json:"percentage"`
	Rank       uint    `json:"rank"`
	Type       string  `json:"type"`
}

type GenericResponse

type GenericResponse struct {
	// Ratelimits will have zero values if the request fails completly.
	Ratelimits Ratelimits `json:"-"`
	// Error will only be set if an error happened after successfully reaching
	// the server. However, there might still be other errors, for example when
	// decoding the server response.
	Error *Error `json:"-"`
}

type HistoryEntry

type HistoryEntry struct {
	Price  uint      `json:"price"`
	Item   Item      `json:"item"`
	SoldAt time.Time `json:"sold_at"`
}

type HistoryRequestPayload

type HistoryRequestPayload struct {
	MarketHashName string
	PaintIndex     uint
}

type HistoryResponse

type HistoryResponse struct {
	GenericResponse
	Data []HistoryEntry
}

type InventoryItem

type InventoryItem struct {
	Item
	// ListingID is only filled for items that are already in the stall.
	ListingID string        `json:"listing_id"`
	Reference ItemReference `json:"reference"`
}

type InventoryResponse

type InventoryResponse struct {
	GenericResponse
	Data []InventoryItem
}

type Item

type Item struct {
	ID             string   `json:"asset_id"`
	Rarity         Rarity   `json:"rarity"`
	Type           ItemType `jsob:"type"`
	MarketHashName string   `json:"market_hash_name"`
	IconURL        string   `json:"icon_url"`

	// InspectLink is used to open CS. However, CSFloat also uses it as a key to
	// filter buy orders for a concrete asset.
	InspectLink string  `json:"inspect_link"`
	Float       float64 `json:"float_value"`
	IsStattrak  bool    `json:"is_stattrak"`
	IsSouvenir  bool    `json:"is_souvenir"`
	// DefIndex is the weapon type
	DefIndex     uint `json:"def_index"`
	StickerIndex uint `json:"sticker_index"`
	// PaintIndex is the skin type
	PaintIndex uint `json:"paint_index"`
	// PaintSeed determines the skin pattern
	PaintSeed  uint      `json:"paint_seed"`
	Stickers   []Sticker `json:"stickers,omitempty"`
	Charms     []Charm   `json:"keychains,omitempty"`
	Fade       *Fade     `json:"fade,omitempty"`
	BlueGem    *BlueGem  `json:"blue_gem,omitempty"`
	Collection string    `json:"collection"`

	CharmIndex   uint `json:"keychain_index"`
	CharmPattern uint `json:"keychain_pattern"`
}

func (*Item) Category

func (item *Item) Category() Category

Category will map to the query category matching this item. This is required for listing similar items.

type ItemBuyOrder

type ItemBuyOrder struct {
	// MarketHashName is only used for simple buy orders.
	MarketHashName string `json:"market_hash_name"`
	// Expression is only used for advanced buy orders.
	Expression string `json:"expression"`
	Quantity   uint   `json:"qty"`
	Price      uint   `json:"price"`
}

type ItemBuyOrdersResponse

type ItemBuyOrdersResponse struct {
	GenericResponse
	Data []ItemBuyOrder `json:"data"`
}

type ItemReference

type ItemReference struct {
	BasePrice      int  `json:"base_price"`
	PredictedPrice int  `json:"predicted_price"`
	Quantity       uint `json:"quantity"`
}

type ItemType

type ItemType string
const (
	TypeCharm ItemType = "charm"
	TypeSkin  ItemType = "skin"
)

type ListRequest

type ListRequest struct {
	*BuyNowRequest
	*AuctionRequest

	AssetId     string      `json:"asset_id"`
	AuctionType ListingType `json:"type"`
	Description string      `json:"description"`
}

type ListResponse

type ListResponse struct {
	GenericResponse
	Item ListedItem
}

type ListedItem

type ListedItem struct {
	ID               string        `json:"id"`
	Price            int           `json:"price"`
	Item             Item          `json:"item"`
	Reference        ItemReference `json:"reference"`
	Type             ListingType   `json:"type"`
	Description      string        `json:"description"`
	Private          bool          `json:"private"`
	MaxOfferDiscount uint          `json:"max_offer_discount"`
	Watchers         uint          `json:"watchers"`
}

type ListingResponse

type ListingResponse struct {
	GenericResponse
	Item ListedItem
}

type ListingType

type ListingType string
const (
	BuyNow  ListingType = "buy_now"
	Auction ListingType = "auction"
)

type ListingsRequest

type ListingsRequest struct {
	MinPrice    int
	MaxPrice    int
	MinFloat    float32
	MaxFloat    float32
	ExcludeRare bool
	Category    Category
	DefIndex    uint
	PaintIndex  uint
	PaintSeed   []uint
	CharmIndex  uint
}

type ListingsResponse

type ListingsResponse struct {
	GenericResponse
	Data []ListedItem `json:"data"`
}

type MeResponse

type MeResponse struct {
	GenericResponse
	User MeUser `json:"user"`
}

type MeUser

type MeUser struct {
	SteamId        string `json:"steam_id"`
	Balance        uint   `json:"balance"`
	PendingBalance uint   `json:"pending_balance"`
}

type Order

type Order string
const (
	OrderDesc Order = "desc"
	OrderAsc  Order = "asc"
)

type Rarity

type Rarity uint8
const (
	Consumer   Rarity = 0
	Industrial Rarity = 1
	MilSpec    Rarity = 2
	Restricted Rarity = 3
	Classified Rarity = 4
	Covert     Rarity = 5
	Contraband Rarity = 6
)

type Ratelimits

type Ratelimits struct {
	Limit         uint
	Remaining     uint
	Reset         time.Time
	SuggestedWait time.Time
}

type Reference

type Reference struct {
	Price    uint `json:"price"`
	Quantity uint `json:"quantity"`
}

type Response

type Response interface {
	// contains filtered or unexported methods
}

type SimilarResponse

type SimilarResponse struct {
	GenericResponse
	Data []*ListedItem
}

type SimpleItemBuyOrdersResponse

type SimpleItemBuyOrdersResponse struct {
	GenericResponse
	Data []ItemBuyOrder `json:"data"`
}

type Stall

type Stall struct {
	Items []ListedItem `json:"data"`
	Count int          `json:"total_count"`
}

type StallResponse

type StallResponse struct {
	GenericResponse
	Stall
}

type Sticker

type Sticker struct {
	Index     uint      `json:"stickerId"`
	Name      string    `json:"name"`
	Reference Reference `json:"reference"`
	ItemURL   string    `json:"item_url"`
	Wear      float32   `json:"wear"`
	Rotation  float32   `json:"rotation"`
}

type Trade

type Trade struct {
	ID string `json:"id"`
	// BuyerId is the steam ID, which can be your own ID if you are the buyer.
	BuyerId  string     `json:"buyer_id"`
	Contract ListedItem `json:"contract"`
	// CreatedAt is the time at which the sale was made, either through a buy
	// order or manually.
	CreatedAt time.Time `json:"created_at"`
	// AcceptedAt, is the time where the trade accepted the trade on CSFloat.
	AcceptedAt time.Time `json:"accepted_at"`
	// TradeProtectionEndsAt is the time at which the Steam trade protection
	// ends. Only after this, we can verify.
	TradeProtectionEndsAt time.Time `json:"trade_protection_ends_at"`
	// VerifySaleAt is the time after which the traede protection runs out.
	VerifySaleAt time.Time `json:"verify_sale_at"`
	// VerifiedAt is the time at which escrow ended.
	VerifiedAt       time.Time        `json:"verified_at"`
	State            TradeState       `json:"state"`
	VerificationMode VerificationMode `json:"verification_mode"`
}

type TradeState

type TradeState string
const (
	// Queued means it was just bought, step 1.
	Queued TradeState = "queued"
	// Pending is the stage after queued, meaning the sale was accepted, but
	// has not been verified yet. You can also be in this state if the item
	// is still in trade protection, but would otherwise be verified. In this
	// state it is relevant to check for all the different timestamp fields on
	// the trade object. The verification mode will also already be escrow at
	// this point in time.
	Pending TradeState = "pending"
	// Verified means both sides have received the goods.
	Verified TradeState = "verified"
	// Cancelled means the buyer decided not to buy afterall.
	Cancelled TradeState = "cancelled"
	// Failed means the buyer failed to accept.
	Failed TradeState = "failed"
)

type TradesRequest

type TradesRequest struct {
	// Page, default 0 (latest)
	Page uint `json:"page"`
	// Limit, default 100
	Limit uint `json:"limit"`
	// States, empty by default, not filtering
	States []TradeState
}

type TradesResponse

type TradesResponse struct {
	GenericResponse
	Trades []Trade `json:"trades"`
	Count  uint    `json:"count"`
}

type Transaction

type Transaction struct {
	ID            string             `json:"id"`
	CreatedAt     time.Time          `json:"created_at"`
	UserID        string             `json:"user_id"`
	Type          TransactionType    `json:"type"`
	Details       TransactionDetails `json:"details"`
	BalanceOffset int                `json:"balance_offset"`
	PendingOffset int                `json:"pending_offset"`
}

type TransactionDetailType

type TransactionDetailType string
const (
	TransactionDetailTypeBuyerConfirm TransactionDetailType = "buyer_confirm"
	TransactionDetailTypeBuyerPing    TransactionDetailType = "buyer_ping"
	TransactionDetailTypeLink         TransactionDetailType = "link"
	TransactionDetailTypeFloatDB      TransactionDetailType = "floatdb"
)

type TransactionDetails

type TransactionDetails struct {
	ContractID string `json:"contract_id"`
	TradeID    string `json:"trade_id"`
	BidID      string `json:"bid_id"`
	// ListingID is used for BidPosted
	ListingID             string                `json:"listing_id"`
	BuyOrderID            string                `json:"buy_order_id"`
	OriginalTransactionId string                `json:"original_tx"`
	Type                  TransactionDetailType `json:"type"`
	// FeeAmountString should not be used, use the FeeAmount function instead.
	FeeAmountString string `json:"fee_amount"`
	// Reason is used for fines and others.
	Reason string `json:"reason"`

	// Fee is used for Deposits. God knows why its a seperate field and not
	// FeeAmountString.
	FeeString        string `json:"fee"`
	PaymentMethod    string `json:"payment_method"`
	PaymentProcessor string `json:"payment_processor"`
	// SessionID is for strip deposits.
	SessionID string `json:"session_id"`
}

func (TransactionDetails) Fee

func (details TransactionDetails) Fee() int

func (TransactionDetails) FeeAmount

func (details TransactionDetails) FeeAmount() int

type TransactionType

type TransactionType string
const (
	TransactionTypeDeposit                TransactionType = "deposit"
	TransactionTypeWithdrawal             TransactionType = "withdrawal"
	TransactionTypeContractSold           TransactionType = "contract_sold"
	TransactionTypeContractSaleRefund     TransactionType = "contract_sale_refund"
	TransactionTypeContractPurchased      TransactionType = "contract_purchased"
	TransactionTypeContractPurchaseRefund TransactionType = "contract_purchase_refund"
	TransactionTypeTradeVerified          TransactionType = "trade_verified"
	TransactionTypeFine                   TransactionType = "fine"
	TransactionTypeBidDeclined            TransactionType = "bid_declined"
	TransactionTypeBidPosted              TransactionType = "bid_posted"
)

type TransactionsRequest

type TransactionsRequest struct {
	// Page, default 0 (latest)
	Page uint
	// Limit, default 100
	Limit uint
	Order Order
}

type TransactionsResponse

type TransactionsResponse struct {
	GenericResponse
	Transactions []Transaction `json:"transactions"`
	Count        uint          `json:"count"`
}

type UnlistResponse

type UnlistResponse struct {
	GenericResponse
}

type UpdateListingRequest

type UpdateListingRequest struct {
	MaxOfferDiscount uint `json:"max_offer_discount"`
}

type UpdateListingResponse

type UpdateListingResponse struct {
	GenericResponse
}

type VerificationMode

type VerificationMode string
const (
	// Inventory is the mode right after purchase, before anyone has
	// accepted anything until the seller accepted the sale.
	Inventory VerificationMode = "inventory"
	// Escrow means both sides have accepted everything, but the balance isn't
	// usable yet.
	Escrow VerificationMode = "escrow"
)

type WearName

type WearName string
const (
	BattleScarred WearName = "Battle-Scarred"
	WellWorn      WearName = "Well-Worn"
	FieldTested   WearName = "Field-Tested"
	MinimalWear   WearName = "Minimal Wear"
	FactoryNew    WearName = "Factory New"
)

Jump to

Keyboard shortcuts

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