Initial commit
This commit is contained in:
45
bin/sync_peatio_seed.rb
Normal file
45
bin/sync_peatio_seed.rb
Normal file
@@ -0,0 +1,45 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Sync Alvand-P config/peatio/seed into a running Peatio DB (insert missing rows, refresh IRT).
|
||||
# Usage: bundle exec rails runner ./bin/sync_peatio_seed.rb
|
||||
|
||||
require 'yaml'
|
||||
|
||||
def seed_file(name)
|
||||
Rails.root.join('config/seed', name)
|
||||
end
|
||||
|
||||
puts '--- sync currencies ---'
|
||||
YAML.load_file(seed_file('currencies.yml')).each do |hash|
|
||||
id = hash.fetch('id')
|
||||
currency = Currency.find_by(id: id)
|
||||
if currency
|
||||
currency.update!(hash.except('id'))
|
||||
puts " updated currency #{id}"
|
||||
else
|
||||
Currency.create!(hash)
|
||||
puts " created currency #{id}"
|
||||
end
|
||||
end
|
||||
|
||||
puts '--- sync markets ---'
|
||||
engine = Engine.find_by!(name: 'peatio-default-engine')
|
||||
YAML.load_file(seed_file('markets.yml')).map(&:symbolize_keys).each do |hash|
|
||||
id = hash.fetch(:id)
|
||||
enabled = hash.delete(:enabled)
|
||||
hash[:state] ||= enabled ? :enabled : :disabled
|
||||
hash.delete(:engine_name)
|
||||
hash[:engine_id] = engine.id
|
||||
|
||||
market = Market.find_by(id: id)
|
||||
if market
|
||||
market.update!(hash.except(:id))
|
||||
puts " updated market #{id} (#{hash[:state]})"
|
||||
else
|
||||
Market.create!(hash.except(:id).merge(id: id))
|
||||
puts " created market #{id} (#{hash[:state]})"
|
||||
end
|
||||
end
|
||||
|
||||
puts '--- done ---'
|
||||
puts "Markets by quote: #{Market.group(:quote_unit).count}"
|
||||
Reference in New Issue
Block a user