1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-23 15:19:38 +02:00
Maybe/db/seeds/exchanges.rb
Josh Pigford 73e184ad3d
Stock Exchanges with seed (#1351)
* Stock Exchanges with seed

* Run the seed file on migration

* Fix for enum column
2024-10-22 14:30:57 -05:00

31 lines
1 KiB
Ruby

# Load exchanges from YAML configuration
exchanges_config = YAML.load_file(Rails.root.join('config', 'exchanges.yml'))
exchanges_config.each do |exchange|
next unless exchange['mic'].present? # Skip any invalid entries
StockExchange.find_or_create_by!(mic: exchange['mic']) do |ex|
ex.name = exchange['name']
ex.acronym = exchange['acronym']
ex.country = exchange['country']
ex.country_code = exchange['country_code']
ex.city = exchange['city']
ex.website = exchange['website']
# Timezone details
if exchange['timezone']
ex.timezone_name = exchange['timezone']['timezone']
ex.timezone_abbr = exchange['timezone']['abbr']
ex.timezone_abbr_dst = exchange['timezone']['abbr_dst']
end
# Currency details
if exchange['currency']
ex.currency_code = exchange['currency']['code']
ex.currency_symbol = exchange['currency']['symbol']
ex.currency_name = exchange['currency']['name']
end
end
end
puts "Created #{StockExchange.count} stock exchanges"