Giter VIP home page Giter VIP logo

cs-go-ev's Introduction

CSGO-Market

Simplified CSGO skin pricing API

Straight from Steam's community market

Use case:

var csgomarket = require('csgo-market');

csgomarket.getSinglePrice('AK-47', 'Vulcan', 'Factory New', null, function (err, data) {

  if (err) {
    console.error('ERROR', err);
  } else {
    console.log(data);
  }

});

// If you want to disable strictNameMode.
csgomarket.strictNameMode = false;

// Notice the missing '-' in AK 47. With strictNameMode off it will internally swap to 'AK-47'.
csgomarket.getSinglePrice('AK 47', 'Vulcan', 'Factory New', null, function (err, data) {

  if (err) {
    console.error('ERROR', err);
  } else {
    console.log(data);
  }

});

Example output from above code (prices will always return in USD):

{
  "success": true,
  "lowest_price": "$80.50",
  "volume": "48",
  "median_price": "$80.01",
  "wep": "AK-47",
  "skin": "Vulcan",
  "wear": "Factory New",
  "stattrak": false
}
  • Lowest price: $80.50
  • Median price: $80.01
  • 48 sold/bought on the market

Methods

Each function returns data from the Steam market to callback with 2 arguments (err, data) where data is the response if successful, otherwise, err will be populated with a message.

getSinglePrice(wep, skin, wear, stattrak, callback)

  • wep: Name of the weapon to be requested. Ex: 'AK-47'.
  • skin: Name of the skin to be requested. Ex: 'Vulcan'.
  • wear: Wear of the skin to be requested. These options are available: Factory New, Minimal Wear, Field-Tested, Well-Worn, and Battle-Scarred. Defaults to 'Field-Tested' but a Levenshtein distance will be used to ensure a match.
  • stattrak: Boolean which signifies if you want StatTrak to be included in the request or not. Defaults to false
  • callback: Callback function which returns the request data. function(err, data).

getSingleKnifePrice(knife, skin, wear, stattrak, callback)

  • knife: Name of the knife to be requested. Ex: 'Karambit'.
  • skin: Name of the skin to be requested. Ex: 'Crimson Web'. Note: If skin is set to null then it will request the version of the Knife with no skin. example of a knife with no skin
  • wear: Wear of the skin to be requested. These options are available: Factory New, Minimal Wear, Field-Tested, Well-Worn, and Battle-Scarred. Defaults to 'Field-Tested' but a Levenshtein distance will be used to ensure a match. Note: If skin is set to null wear will also be set to null.
  • stattrak: Boolean which signifies if you want StatTrak to be included in the request or not. Defaults to false
  • callback: Callback function which returns the request data. function(err, data).

getSingleStickerPrice(stickerName, foil, callback)

  • stickerName: Name of the Sticker to be requested Note: Do not include the initial 'Sticker | ' infront of the sticker name. Also, do not include '(Foil)' within the name. Ex: 'Robo' or 'kennyS | Cologne 2015'.
  • foil: Boolean which signifies if you want the (Foil) option included in the request. Note: Not all stickers have foil counterparts.
  • callback: Callback function which returns the request data. function(err, data).

getSingleKeyPrice(key, callback)

  • key: Name of the key to be requested. Supports any Case Key and the eSports key. Does not support capsule keys currently. Example strings you can pass in: 'Chroma', 'Winter Offensive' or 'eSports'. 'Key' or 'Case Key' do not need to be added to the name.

  • callback: Callback function which returns the request data. function(err, data).

Asyncrhonous Methods

getSinglePriceAsync(wep, skin, wear, statrak)

Same parameters minus the callback as the non-async version. Promisified version of the getSinglePrice method (Example usage below).

getSingleKnifePriceAsync(knife, skin, wear, stattrak)

Same parameters minus the callback as the non-async version. Promisified version of the getSingleKnifePrice method.

getSingleStickerPriceAsync(stickerName, foil)

Same parameters minus the callback as the non-async version. Promisified version of the getSingleStickerPrice method.

getSingleKeyPriceAsync(key)

Same parameters minus the callback as the non-async version. Promisified version of the getSingleKeyPrice method.

Use case:

var csgomarket = require('csgo-market');
var Q = require('q');

var wears = ['Factory New', 'Minimal Wear',
  'Field-Tested', 'Well-Worn', 'Battle-Scarred'];

var data = {
  prices : [{
    weapon : "AWP",
    cached : false,
    skins : ['Asiimov', 'BOOM', 'Man-o\'-war'],
    skinData : {}
  }]
}

var getPrice = function(theData) {
  var promises = [];
  theData.skins.forEach(function(skin) {
    theData.skinData[skin] = {};
    wears.forEach(function(wear) {
      promises.push(csgomarket.getSinglePriceAsync(theData.weapon, skin, wear, false).then(function(data) {
        theData.skinData[skin][wear] = data;
      }));
    });
  });
  return Q.allSettled(promises).then(function() {
    return theData;
  });
}

getPrice(data.prices[0]).then(function(results) {
  // Do something with returned results here.
})

NOTE:

Capitalization is important for passed in values. If you are unsure of the exact name/spelling/capitilization/punctuation of a weapon and/or skin I highly recommend checking the community market as a reference or turning off strictNameMode by using csgomarket.strictNameMode = false;. Turning strictNameMode off will attempt to match a passed in string with a Weapon or Knife that exists in the game if the string is not formatted correctly. Does not affect passed in Key, Sticker, or Skin names.

Main goals to add in the near future:

  • Method for all wears given a particular gun and skin or knife and skin.

This module is still under-development and this is just the first iteration.

If you have any suggestions I am open to add additional functionality! I'd like to keep it small, but I'd love feedback. Email me at [email protected]

cs-go-ev's People

Contributors

httpnick avatar wilsonhyng avatar balthazar avatar alcadesign avatar

Stargazers

Dmitry Tuzenkov avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.