-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
70 lines (58 loc) · 2.32 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const Skincrib = require('./index.js');
const market = new Skincrib({
key: '', //skincrib merchant api key
reconnect: true, //auto-reconnect to websocket if disconnected
memory: true //store listings and active client deposits/withdraws in memory
});
let bought = false;
market.on('authenticated', (message)=>{
console.log(message);
});
market.on('disconnect', (message)=>{ //disconnected from socket
console.log(message);
});
market.on('error', (error)=>{
console.error(error);
});
market.on('listing.added', async (listing)=>{ //new listing on market, send to clients when this is recieved
if(!bought){
bought = true;
console.log('Listing Added:', listing);
let purchaseData = await market.purchaseListing({steamid: buyer.steamId, tradeUrl: buyer.tradeUrl, id: listing.id});
console.log('Purchase Data:', purchaseData);
}
});
market.on('listing.removed', (listing)=>{ //listing removed from market
console.log('Listing Removed:', listing);
});
market.on('listing.updated', async (listing)=>{ //one of your client's active listings has had a status update
console.log('Listing Updated:', listing);
if(listing.status == 'sell_confirmation'){
let confirmData = await market.confirmListing({steamid: seller.steamId, id: listing.id});
console.log('Confirm Data:', confirmData);
}
});
market.authenticate()
.then(async (success)=>{
return console.log(success); //successfully authenticated
let activeListings = await market.getClientActiveListings(seller.steamId);
console.log(activeListings);
if(activeListings.deposits.length > 0){
let [cancelErr, cancelData] = await market.cancelListings({steamid: seller.steamId, ids: activeListings.deposits.map(x => x.id)});
console.log([cancelErr, cancelData]);
}
let inventory = await market.loadInventory(seller.steamId);
let toList = inventory.map(x => {
if(x.accepted){
return {
...x,
percentIncrease: 0
}
}
}).filter(x => x);
console.log('Inventory:', toList.length);
let [err, data] = await market.createListings({steamid: seller.steamId, apiKey: seller.apiKey, tradeUrl: seller.tradeUrl, items: toList});
console.log([err, data]);
}, (err)=>{
console.error(err); //error authenticating
});