1const Apify = require('apify');
2const axios = require('axios');
3const moment = require('moment');
4const lodash = require('lodash');
5Apify.main(async () => {
6 let positions = [];
7 try {
8 var config = {
9 method: 'post',
10 url: 'https://www.binance.com/bapi/futures/v1/public/future/leaderboard/getOtherPosition',
11 headers: {
12 'authority': 'www.binance.com',
13 'accept': '*/*',
14 'accept-language': 'tr,en;q=0.9,tr-TR;q=0.8',
15 'clienttype': 'web',
16 'content-type': 'application/json',
17 'lang': 'en',
18 'origin': 'https://www.binance.com',
19 'referer': 'https://www.binance.com/en/futures-activity/leaderboard?type=myProfile&encryptedUid=EE0CE3F95107DE82428E8744053E85D3',
20 'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="100", "Google Chrome";v="100"',
21 'sec-ch-ua-mobile': '?0',
22 'sec-ch-ua-platform': '"Windows"',
23 'sec-fetch-dest': 'empty',
24 'sec-fetch-mode': 'cors',
25 'sec-fetch-site': 'same-origin',
26 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36',
27 'Cookie': 'cid=4C4kmgsb'
28 },
29 data: "{}"
30 };
31 const tradersConfig = config;
32 tradersConfig.data = {
33 "limit": 50,
34 "sortType": "ROI",
35 "isShared": true,
36 "periodType": "MONTHLY",
37 "pnlGainType": null,
38 "roiGainType": null,
39 "symbol": "",
40 "tradeType": "PERPETUAL"
41 };
42 tradersConfig.url = "https://www.binance.com/bapi/futures/v1/public/future/leaderboard/searchLeaderboard";
43 const tradersData = await axios(config);
44
45 const allRequests = [];
46 const traders = [];
47 if (tradersData && tradersData.data && tradersData.data.data && tradersData.data.data.length > 0) {
48 tradersData.data.data.forEach(async (trader) => {
49 const roi = trader.roiValue * 100;
50 if (trader.followerCount > 20 && roi > 100) {
51 var data = JSON.stringify({
52 "encryptedUid": trader.encryptedUid,
53 "tradeType": "PERPETUAL"
54 });
55 config.data = data;
56 config.url = "https://www.binance.com/bapi/futures/v1/public/future/leaderboard/getOtherPosition";
57 allRequests.push(axios(config));
58 traders.push(trader);
59 }
60 });
61 const response = await axios.all(allRequests);
62 response.forEach((res, index) => {
63 if (res && res.data && res.data.data && res.data.data.otherPositionRetList && res.data.data.otherPositionRetList.length > 0) {
64 var otherPositionRetList = res.data.data.otherPositionRetList;
65 var trader = traders[index];
66 otherPositionRetList.forEach(otherPositionRet => {
67 let positionType = "--";
68 const { symbol, amount, entryPrice, markPrice, pnl, roe, updateTimeStamp } = otherPositionRet;
69 var _roe = roe * 100;
70
71 if (markPrice > entryPrice && pnl > 0) {
72 positionType = "LONG";
73 }
74 else if (entryPrice > markPrice && pnl > 0) {
75 positionType = "SHORT";
76 }
77 else if (entryPrice > markPrice && pnl < 0) {
78 positionType = "LONG";
79 }
80 else if (entryPrice < markPrice && pnl < 0) {
81 positionType = "SHORT";
82 }
83 _roe = _roe.toFixed(2);
84 if (pnl && pnl !== 0) {
85 positions.push({
86 traderName: trader.nickName,
87 traderWebPage: "https://www.binance.com/en/futures-activity/leaderboard?type=myProfile&encryptedUid=" + trader.encryptedUid,
88 symbol: symbol,
89 positionType,
90 entryPrice: entryPrice,
91 markPrice: markPrice,
92 roe: _roe + "%",
93 enteringTime: moment(updateTimeStamp).format('YYYY-DD-MM HH:mm:ss')
94 });
95 }
96
97 });
98 }
99 });
100 }
101 } catch (error) {
102 console.log("error", error.message);
103 }
104 if (positions && positions.length > 0) {
105 positions = lodash.orderBy(positions, ['symbol', 'positionType'],
106 ['asc', 'asc']);
107 }
108 await Apify.pushData(positions);
109});