Skip to content

An unofficial CSGOEmpire's API Wrapper for JavaScript

License

Notifications You must be signed in to change notification settings

tavindev/csgoempire-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

69 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Unofficial CSGOEmpire API Wrapper

The unofficial CSGOEmpire API JavaScript Wrapper

You can find the Official CSGOEmpire Api documentation here

You can also find the change log file here

This wrapper is not complete yet. If you feel like contributing, open a pull request proposing a change :)

Installation

With npm:

npm install csgoempire-api

With Yarn:

yarn add csgoempire-api

Usage

import { CSGOEmpire } from "csgoempire-api"

const empire = new CSGOEmpire(YOUR_API_KEY)

empire.getActiveTrades()
empire.getActiveAuctions()
...

Initializing websocket:

import { CSGOEmpire } from "csgoempire-api"

const empire = new CSGOEmpire(YOUR_API_KEY)

empire.initSocket((socket) => {
    socket.on("new_item", (data) => {
        // ...
    })
})

// empire.socket can be undefined
const socket = empire.socket

Note: Not running initSocket will result in a undefined socket instance

initSocket(fn)

Option Type Default Value Description
fn Function? - A callback function that gets executed when the socket is initialized and authenticated

Documentation

Api

const empire = new CSGOEmpire(apiKey)
  • apiKey: string (required)
  • webSocketEnabled: boolean (optional) (true by default)

Socket

Extends socket.io-client's class. Can be undefined if not initialized

const socket = empire.socket

on(event, fn)

socket.on is a io().on wrapper that provides typings support for CSGOEmpire's events

socket.on(event, fn)
  • event: string (required)
    • "new_item"
    • "updated_item"
    • "auction_update"
    • "deleted_item"
    • "trade_status"
    • "timesync"
  • fn: Function (required)

Each event function has typings support.

socket.on("new_item", (data) => {
    /**
     * data extends NewItemSocketData interface
     * 
     * Available properties: 
     * { 
     *      id: number,
     *      name: string,
     *      ...
     * }
     */
    const { id, name } = data
})

You can check all events example responses here


getMetadata

Returns the user object, which is used to identify via websocket, as well as socket token (authorizationToken) & socket signature (signature) which are used to authenticate on websocket.

Option Type Default Value Description
- - - -
empire.getMetadata().then(res => {
    ...
})

You can find the response Object interface here


getActiveTrades

Returns an array of all items currently being deposited or withdrawn by this account. This does not include bids placed on active items until the auction ends.

Option Type Default Value Description
- - - -
empire.getActiveTrades().then(res => {
    ...
})

You can find the response Object interface here


getActiveAuctions

Returns an array of all auctions currently being bid on by this account.

Option Type Default Value Description
- - - -
empire.getActiveAuctions().then(res => {
    ...
})

You can find the response Object interface here


updateSettings

Used to update your tradelink and/or Steam API key

Option Type Default Value Description
data Object - An object containing a trade_url (required) and a steam_api_key (optional)
empire.updateSettings().then(res => {
    ...
})

You can find the response Object interface here


Deposits

Deposit related methods

getCSGOInventory

Fetch your inventory from steam and caches it to the database for 1 hour.

Option Type Default Value Description
invalid boolean false Filters invalid items, defaults to no filtering
empire.getCSGOInventory().then(res => {
    ...
})

You can find the response Object interface here

getUniqueInfo

Get inspected unique info for items in user inventory. Examples include float/sticker data

Option Type Default Value Description
- - - -
empire.getUniqueInfo().then(res => {
    ...
})

You can find the response Object interface here

createDeposit

Creates an item deposit

Notes: coin_value is in coin cents, so 100.01 coins is represented as 10001

Option Type Default Value Description
data Object - An object containing an array of items to deposit
empire.createDeposit({
    items: [
        {
            "id": 3731677704,
            "custom_price_percentage": 32,
            "coin_value": 576811
        }
    ]
}).then(res => {
    ...
})

You can find the response Object interface here

cancelDeposit

Cancels processing deposit without any bids. Once a bid has been placed items are no longer eligible to be cancelled.

Option Type Default Value Description
deposit_id number - The deposited item's id
empire.cancelDeposit(28391470).then(res => {
    ...
})

You can find the response Object interface here

sellNow

Sells an on going auction item to the current auction highest bidder

Option Type Default Value Description
deposit_id number - The deposited item's id
empire.sellNow(28391470).then(res => {
    ...
})

You can find the response Object interface here


Withdraw

Withdraw related methods

getListedItems

Get a list of all items listed on the withdrawals page

Option Type Default Value Description
page number - The page to fetch the data from
per_page number - The ammount of items to be fetched per page
options Object? - An object containing filtering options
empire.getListedItems(1, 50, { sort: "asc" }).then(res => {
    ...
})

You can find the response Object interface here

getDepositorStats

Get the depositing users stats from a unique deposit ID

Option Type Default Value Description
deposit_id number - The deposited item's id
empire.getDepositorStats(28391470).then(res => {
    ...
})

You can find the response Object interface here

createWithdrawal

Withdraw item directly if the auction has expired without being won.

Option Type Default Value Description
deposit_id number - The deposited item's id
empire.createWithdrawal(28391470).then(res => {
    ...
})

You can find the response Object interface here

placeBid

Place a bid on an auction.

Option Type Default Value Description
deposit_id number - The deposited item's id
bid_value number - The ammount to bid
empire.placeBid(28391470, 60).then(res => {
    ...
})

You can find the response Object interface here


Misc

Other api methods

getSeeds

Get roulette seeds

Option Type Default Value Description
page number - The page to fetch the data from
per_page number? 15 The ammount of items to be fetched per page
empire.getSeeds(1, 20).then(res => {
    ...
})

You can find the response Object interface here

getHistory

Returns rolls history

Option Type Default Value Description
seed number - The seed to fetch the data from
empire.getHistory(2543).then(res => {
    ...
})

You can find the response Object interface here