-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
139 lines (123 loc) · 3.6 KB
/
index.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
'use strict'
const bitApi = require('./bin/bitskins');
const steamapi = require('./bin/steamapi');
const tradebot = require('./bin/tradebot');
const cron = require('node-cron');
const config = require('config');
const Pusher = require('pusher-client');
const minPrice = config.get("Prices.MIN_PRICE");
const maxPrice = config.get("Prices.MAX_PRICE");
const min_discount = config.get("Prices.MIN_DISCOUNT");
const crawlExtPriceTime = 30000
, crawlSaleTime = 120000
, crawlWithdrawTime = 120000
, logMoneyTime = 3600000
, app_ids = [570, 730, 578080, 440, 252490, 218620, 232090];
var skinObj = {}
, extPrices = {}, pusher = undefined
, pusherOnline = false
, skinCounter = 0
, saleChannelSubscribe = undefined;
let processSaleData = (skin) => {
try {
skinCounter++;
var extPrice = extPrices[skin.app_id][skin.market_hash_name];
var intPrice = skin.price;
var percent = Math.round(100 - ((intPrice / extPrice) * 100));
skin.state = "idle";
skinObj[skin.item_id] = skin;
if (((extPrice >= 0.06) && (extPrice <= 0.10)) && (percent >= 85.0)) {
skinObj[skin.item_id].state = "buying";
bitApi.buySkin(skin.item_id, intPrice, skin.app_id);
}
else if ((extPrice >= 0.11) && (extPrice <= 4.99) && (percent >= 70.0)) {
skinObj[skin.item_id].state = "buying";
bitApi.buySkin(skin.item_id, intPrice, skin.app_id);
}
else if ((extPrice >= 5) && (extPrice <= 80) && (percent >= 55.0)) {
skinObj[skin.item_id].state = "buying";
bitApi.buySkin(skin.item_id, intPrice, skin.app_id);
}
else if ((extPrice >= 81) && (percent >= 50.0)) {
skinObj[skin.item_id].state = "buying";
bitApi.buySkin(skin.item_id, intPrice, skin.app_id);
} else if (percent >= 98.0) {
skinObj[skin.item_id].state = "buying";
bitApi.buySkin(skin.item_id, intPrice, skin.app_id);
} else {
delete skinObj[skin.item_id];
}
} catch (e) {
console.error("Couldn't find item: "+ skin.market_hash_name);
}
}
let initiatePusher = () => {
let socket = new Pusher('c0eef4118084f8164bec65e6253bf195', {
host: "notifier.bitskins.com"
, ws_port: 443
, wss_port: 443
, encrypted: true
, disabledTransports: ['sockjs']
, disableStats: true
});
socket.connection.bind('connected', function () {
console.log("Pusher connected!")
pusherOnline = true;
subscribeToSaleChannel(socket);
});
socket.connection.bind('disconnected', function () {
console.log("Pusher disconnected!")
pusherOnline = false;
});
}
let subscribeToSaleChannel = (socket) => {
if (pusherOnline && saleChannelSubscribe === undefined) {
saleChannelSubscribe = socket.subscribe('inventory_changes');
saleChannelSubscribe.bind('listed', function (data) {
processSaleData(data);
});
console.log("Subbed to new item channel");
saleChannelSubscribe.bind('price_changed', function (data) {
processSaleData(data);
});
console.log("Subbed to price change channel");
}
else if (saleChannelSubscribe === undefined) {
console.log("Sale notices are offline");
}
else if (saleChannelSubscribe !== undefined) {
console.log("Already subscribed to sale channel");
}
}
let createPriceObj = async () => {
for (let i in app_ids) {
extPrices[app_ids[i]] = await steamapi.getExternalPrices(app_ids[i]);
}
}
let printInfo = () => {
console.log(skinObj);
console.log(skinCounter);
}
(async () => {
try {
tradebot.init(bitApi);
await createPriceObj();
initiatePusher();
} catch (err) {
console.log(err);
}
})();
cron.schedule('*/1 * * * *', async () => {
try {
printInfo();
} catch (err) {
console.log(err);
}
});
cron.schedule('0 */2 * * *', async () => {
try {
await createPriceObj();
} catch (err) {
console.log(err);
}
});