Skip to content

Instantly share code, notes, and snippets.

Created May 24, 2013
What would you like to do?
Example of how Btce::TradeAPI could be initialized
#<TradeAPI:0x007fd9143fc6c8 @key="YOUR-API-KEY", @secret="YOUR-SECRET-KEY">
#<TradeAPI:0x007fd9144134e0 @key="MY-OTHER-API-KEY", @secret="MY-OTHER-SECRET-KEY">
#<TradeAPI:0x007fd9144129a0 @key="Master key!", @secret="Super S33krit">
#! /usr/bin/env ruby
require 'yaml'
require 'pp'
class TradeAPI < Object
# default to btce-api-key.yml as the key file argument
def initialize(options = {:key_file => 'btce-api-key.yml'})
# process yml file first
data = {}
if options.has_key?(:key_file) && File.exists?(options[:key_file])
data = YAML::load([:key_file])
@key = data.fetch('key', nil)
@secret = data.fetch('secret', nil)
# if :key and/or :secret are explicitly specified, those arguments take
# precedence
@key = options.fetch(:key, @key)
@secret = options.fetch(:secret, @secret)
unless @key && @secret
# throw exception, key and secret must be set, either as args or in yml
# file
raise ArgumentError, "Both :key and :secret must be set."
puts "#{self.inspect}"
t =
t = :key_file => 'other-btce-api-key.yml'
t = :key => "Master key!", :secret => "Super S33krit"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment