<commit_before>namespace :btc do
  desc 'Record stats about each market'
  task :snapshot => :environment do
    #autoloader hack
    require 'exchanges/base'
    # exchanges with internal markets
    super_http = Faraday.new(request:{timeout:SETTINGS["net"]["timeout"]})

    snapshot = Snapshot.create
    snapshot.poll(super_http, Exchange.with_markets('btc','usd'))
    snapshot.poll(super_http, Exchange.with_markets('ltc','btc'))
    snapshot.poll(super_http, Exchange.with_markets('doge','btc'))
  end

  desc 'Compute strategy'
  task :strategy, [:markets] => :environment do |task, args|
    snapshot = Snapshot.order('created_at desc').first
    if snapshot
      puts "Snapshot ##{snapshot.id} #{snapshot.created_at} #{snapshot.exchange_runs.map{|er|er.exchange.name}}"
      snapshot.strategies << Strategy.opportunity('btc', 'usd', snapshot)
      snapshot.strategies << Strategy.opportunity('ltc', 'btc', snapshot)
      snapshot.strategies << Strategy.opportunity('doge', 'btc', snapshot)
    else
      puts "No snapshots in system"
    end
  end

  desc 'Backfill Total opportunity'
  task :backfill, [:markets] => :environment do |task, args|
    snapshots = Snapshot.where('strategy_id is null')
    snapshots.each do |snapshot|
      Strategy.opportunity('btc', 'usd', snapshot)
    end
  end

  desc 'Best pair of markets'<commit_msg>allow for empty strategies<commit_after>namespace :btc do
  desc 'Record stats about each market'
  task :snapshot => :environment do
    #autoloader hack
    require 'exchanges/base'
    # exchanges with internal markets
    super_http = Faraday.new(request:{timeout:SETTINGS["net"]["timeout"]})

    snapshot = Snapshot.create
    snapshot.poll(super_http, Exchange.with_markets('btc','usd'))
    snapshot.poll(super_http, Exchange.with_markets('ltc','btc'))
    snapshot.poll(super_http, Exchange.with_markets('doge','btc'))
  end

  desc 'Compute strategy'
  task :strategy, [:markets] => :environment do |task, args|
    snapshot = Snapshot.order('created_at desc').first
    if snapshot
      puts "** Snapshot ##{snapshot.id} #{snapshot.created_at} #{snapshot.exchange_runs.map{|er|er.exchange.name}}"
      puts "** BTC/USD run"
      btc_strategy = Strategy.opportunity('btc', 'usd', snapshot)
      snapshot.strategies << btc_strategy if btc_strategy
      puts "** LTC/BTC run"
      ltc_strategy = Strategy.opportunity('ltc', 'btc', snapshot)
      snapshot.strategies <<  ltc_strategy if ltc_strategy
      puts "** DOGE/BTC run"
      doge_strategy = Strategy.opportunity('doge', 'btc', snapshot)
      snapshot.strategies << doge_strategy if doge_strategy
    else
      puts "No snapshots in system"
    end
  end

  desc 'Backfill Total opportunity'
  task :backfill, [:markets] => :environment do |task, args|
    snapshots = Snapshot.where('strategy_id is null')
    snapshots.each do |snapshot|
      Strategy.opportunity('btc', 'usd', snapshot)
    end
  end

  desc 'Best pair of markets'
{'fraction_non_alphanumeric': 0.12951096121416525, 'fraction_numerical': 0.0, 'mean_word_length': 4.078767123287672, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7204344', 'n_tokens_mistral': 966, 'n_tokens_neox': 960, 'n_words': 223}