lib/coinsetter.rb in coinsetter-0.0.8 vs lib/coinsetter.rb in coinsetter-0.0.9

- old
+ new

@@ -36,11 +36,12 @@ def self.configured? configuration.username && configuration.password && configuration.ip_address end - def self.with_session + def self.with_new_session + destroy_client_session! if client_session.kind_of? ClientSession yield client_session if block_given? else destroy_client_session! {error: 'No Client Session available.'} @@ -54,11 +55,15 @@ def self.get_account(account_uuid) Customer::Accounts.new(client_session.uuid).get(account_uuid) end def self.destroy_client_session! + begin client_session.destroy! + rescue e + # TODO: Add error responses. + end @client_session = nil end def self.orders(uuid=nil) Orders.new(uuid || client_session.uuid) @@ -78,25 +83,16 @@ def self.get_order(order_uuid) orders.get(order_uuid) end - def self.add_order_with_new_session(side='BUY', options={}) - order = with_session do |client_session| + def self.add_order(side='BUY', options={}) + with_new_session do |client_session| params = default_options.merge(options) params.merge!(side: side, customerUuid: client_session.customer_uuid) orders.create(params) end - - order.kind_of?(Order) ? Coinsetter.get_order(order.uuid) : nil - end - - def self.add_order(side='BUY', options={}) - params = default_options.merge(options) - params.merge!(side: side, - customerUuid: client_session.customer_uuid) - orders.create(params) end # Required Order Params # requestedQuantity, requestedPrice, accountUuid def self.buy_order(amount, price, account_uuid, options={})