ztizzlegaming / CSGOWinBig

Open-source Counter-Strike: Global Offensive jackpot betting website.
MIT License
174 stars 105 forks source link

Mysql item base #85

Closed Xeroner closed 8 years ago

Xeroner commented 8 years ago

Hello, can anybody update item database ? Becouse it's realy realy old and have a lot of 0 prices. @ztizzlegaming

Stuffa1991 commented 8 years ago

If you delete the 0 prices, it uses the prices directly from the market :)

Xeroner commented 8 years ago

And then for time to time steam blocking connection :)

Stuffa1991 commented 8 years ago

Worked on a method getting prices via www.bitskins.com api, both csgojackpot and csgowild uses it

And it managed to work it out last night, i can tell what to do tomorrow :)

Xeroner commented 8 years ago

Fully free and unlimited?

Stuffa1991 commented 8 years ago

Its free and you can do 8 requests a second :)

Xeroner commented 8 years ago

8 is to small i think for bigger jackpot

Stuffa1991 commented 8 years ago

You can contact them to gain more, but i think that cost extra :) ill release a detailed guide or just the files if people wants it, going to bed soon :)

GreYzZ commented 8 years ago

@Stuffa1991 can you share the implemention of the API with us?

Stuffa1991 commented 8 years ago

Okay i'll make this as detailed as i can :)

I tried making the code i made so versatile so you only have to change the URL in check-items.php

Step by Step

  1. Create an Account on BitSkins.com
  2. Create Two-Factor Authentication - https://bitskins.com/settings In this step its important you write down the "secret" code right under the QR code Write it down or remember it, it will be needed later
  3. Create API access Write down your api-key it will be needed later

Thats it for BitSkins.com, you can close it now :)

Now to the important parts

1. Create a file called GoogleAuthenticator.php Paste this in http://codeshare.io/ROdWA

2. Create a file called price.php Paste this in http://codeshare.io/fRELz

  1. Upload this to a folder on your website.
  2. Change $secret in price.php to the secret from under the QR from bitskins
  3. The same with $api, change that to the api-key provided by bitskins
  4. In php/check-items.php change the URL of $marketObj from
$marketObj = json_decode(file_get_contents("http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=$hash"), true);

to

$marketObj = json_decode(file_get_contents("http://yourwebsite.com/php/price.php$hash"), true);

And thats about it, your bot should now retrieve bitskins prices, which are used by csgowild and csgojackpot :)

rfalkner commented 8 years ago

I followed your guide 100% @Stuffa1991 - how can i check if my prices update? And when will they update?

Best regards

Xeroner commented 8 years ago

@rfalkner you need to replace steamcommunity lines to this script. This will not update your database man. It's should check price when user joining the pot.

Stuffa1991 commented 8 years ago

@rfalkner, to keep the prices you have to add something in the check-items.php

Like so on line 136~

if (isset($medianPrice)) {
            $price = doubleval(substr($medianPrice, 1)) * 100;
            $sql = "INSERT INTO items (marketName, avgPrice30Days) 
                    VALUES (:marketName, :avgPrice30Days)
                    ON DUPLICATE KEY UPDATE avgPrice30Days = :newPrice";
            $stmt = $db->prepare($sql);
            $stmt->bindValue(':marketName', $marketName);
            $stmt->bindValue(':avgPrice30Days', $price);
            $stmt->bindValue(':newPrice', $price);
            $stmt->execute();
        } else {
            $price = doubleval(substr($lowestPrice, 1)) * 100;
            $sql = "INSERT INTO items (marketName, avgPrice30Days) 
                    VALUES (:marketName, :avgPrice30Days)
                    ON DUPLICATE KEY UPDATE avgPrice30Days = :newPrice";
            $stmt = $db->prepare($sql);
            $stmt->bindValue(':marketName', $marketName);
            $stmt->bindValue(':avgPrice30Days', $price);
            $stmt->bindValue(':newPrice', $price);
            $stmt->execute();
        }

And truncate the price tables.

The reason for this is that the check-items works without a timestamp for example that means everytime the bot checks the price, it takes the price in the price table without asking questions, and if it doesnt exist it doesnt add it to the price table but simply return the price.

With this added code it will add the price into the price table instead of only returning the price if the item is non excitence :)

Xeroner commented 8 years ago

@Stuffa1991 script need to check first ,, if item exist do not insert but update ,,

Stuffa1991 commented 8 years ago

Well the update part isnt actually supposed to be there, cause it will never occure, cause the script itself finds if the values exist and if it does it returns the price, therefore an update will never occure and is just there for no reason :D

Xeroner commented 8 years ago

But if table is empty? :dancer:

Stuffa1991 commented 8 years ago

It will update the price only if the price is set to 0, else it will insert

As you can see ON DUPLICATE KEY UPDATE, means that if the thing it tries to insert is already there just update it instead, so its a sort of a fail safe for if the items that exist has a value of 0 :)

Xeroner commented 8 years ago

@Stuffa1991 you're right :)

GreYzZ commented 8 years ago

@Stuffa1991 The GoogleAuthenticator.php is not longer available, can you post it again? Or create a new wiki page

mx0c commented 8 years ago

+1 Would be great!