美文网首页
交易爬虫和分析脚本

交易爬虫和分析脚本

作者: smg666 | 来源:发表于2018-12-27 02:50 被阅读0次

此脚本用于EOS链上获取鲸交所2018年12月26日0点0分0秒到12月26日59分59秒的数据。

const axios = require('axios');
const fs = require('fs');

const start = 3996731;
const to = 4056774;
let now = start;

let allActions = [];

let total = to - start;
async function fetchData() {
  let offset = 99;
  if (now + offset >= to) {
    offset = to - now;
  }
  let startTime = Date.now();
  let waitTime = 5;
  try {
    let response = await axios.post('https://eos.greymass.com/v1/history/get_actions', {
      account_name: 'whaleextrust',
      pos: now,
      offset: offset
    });
    if (response.status == 200) {
      var actions = response.data.actions;
      allActions.push.apply(allActions, actions);
      now += 100;
      console.log('('+Math.ceil((now - start) / 100)+'/'+Math.ceil(total / 100)+')fetch success in ' + (Date.now() - startTime) + 'ms');
      if (now > to) {
        console.log('data fetch complete.');
        var finalData = JSON.stringify(allActions);
        fs.writeFile('actions.json', finalData, function(){
          console.log('actions saved.');
        });
        return;
      }
    } else {
      console.log('fetch error.');
      waitTime = 1000;
    }
  } catch (e) {
    console.log('fetch failure.');
    waitTime = 1000;
  }

  setTimeout(() => {
    fetchData();
  }, 10);
}

//start
fetchData();

以下脚本用于采集数据的分析

function parseData() {
  console.log('start analyze...');
  const startTime = Date.now();
  let data = fs.readFileSync('actions.json');
  const actions = JSON.parse(data);
  data = null;
  let trades = 0;
  let mineTrades = 0;
  let accounts = [];
  let mineAccounts = [];
  let candyAccounts = [];
  for (const action of actions) {
    const act = action.action_trace.act;
    if (act.name == 'verifytrade') {
      trades++;
      if (!accounts.includes(act.data.buyer)) {
        accounts.push(act.data.buyer);
      }
      if (!accounts.includes(act.data.seller)) {
        accounts.push(act.data.seller);
      }
      if (act.data.buyer == act.data.seller) {
        mineTrades++;
        if (!mineAccounts.includes(act.data.buyer)) {
          mineAccounts.push(act.data.buyer);
        }
      }
    }
    if (act.name == 'verifyad') {
      if (!candyAccounts.includes(act.data.to)) {
        candyAccounts.push(act.data.to);
      }
    }
  }
 
  let mineAmount = 0;
  let totalAmount = 0;
  let actionMaps = {};
  for (const action of actions) {
    const act = action.action_trace.act;
    if (typeof actionMaps[act.name] == 'undefined') {
      actionMaps[act.name] = 0;
    }
    actionMaps[act.name]++;
    if (act.name == 'verifytrade') {
      if (mineAccounts.includes(act.data.buyer) || mineAccounts.includes(act.data.seller)) {
        mineAmount += act.data.quote_amount;
      }
      totalAmount  += act.data.quote_amount;
    }
  }
  for (const action in actionMaps) {
    console.log('action: '+ action + ':' + actionMaps[action]);
  }
  console.log('--------------------');
  console.log('action count:' + actions.length);
  console.log('trade count:' + trades);
  console.log('account count:' + accounts.length);
  console.log('total amount:' + (totalAmount / 10000));
  console.log('candy account count:' + candyAccounts.length);
  console.log('--------------------');
  console.log('mine trade count:' + mineTrades);
  console.log('mine account count:' +  mineAccounts.length);
  console.log('mine amount:' + (mineAmount / 10000));
  console.log('--------------------');
  console.log('cost time: ' + (Date.now() - startTime) + 'ms');
}

parseData();

相关文章

  • 交易爬虫和分析脚本

    此脚本用于EOS链上获取鲸交所2018年12月26日0点0分0秒到12月26日59分59秒的数据。 以下脚本用于采...

  • 隔离见证后的区块数据结构

    Segwit之前和之后的交易 • 在Segwit之前:每个交易都有一个交易哈希值、输入脚本、脚本签名和输出脚本。 ...

  • 爬虫基础

    1.爬虫概述 爬虫又称为网络爬虫,主要指代从互联网是上进行数据采集的脚本程序,是进行数据分析和数据挖掘的基础爬虫首...

  • 交易函数

    交易处理函数,用于EA和脚本中。指标不能直接调用这些函数进行交易。为了在EA和脚本中进行交易,在程序交易环境(智能...

  • 爬虫理论概述

    1. 爬虫概述     爬虫,又称为网络爬虫,主要指代从互联网上进行数据采集的脚本后端程序,是进行数据分析和数据挖...

  • python爬虫基础

    1、爬虫概述 爬虫、又被称为网路爬虫,主要指从互联网上进行数据采集的脚本——后者程序,是进行数据分析和数据挖掘的基...

  • python爬虫入门-学习urllib和requests使用,模

    前言 python爬虫入门-通过茅台脚本讲些爬虫知识,应用和价值[https://www.jianshu.com/...

  • 今天开始记录算法之旅

    今天算是正式启程啦,从数据分析到爬虫脚本算法等等。用这个来记录自己每天的进步

  • python 爬虫基础

    爬虫,也就是分析网站的各种请求,用脚本模拟网页登陆、获取数据,套路也就是get,post,cookies,head...

  • 爬虫01:概述

    爬虫概述 1.目录清单 爬虫简介 通用爬虫和聚焦爬虫 网络请求那些事儿 网络数据抓包分析 2.章节内容 2.1爬虫...

网友评论

      本文标题:交易爬虫和分析脚本

      本文链接:https://www.haomeiwen.com/subject/sjyllqtx.html