spec/support/bitstamp_stubs.rb
# Takes all active orders and mockes them as executed in a single transaction.
# If a ratio is provided then each order is only partially executed and added
# as a transaction and the order itself is kept in the order list.
Takes all active orders and mockes them as executed in a single transaction.
If a ratio is provided then each order is only partially executed and added
as a transaction and the order itself is kept in the order list.
Takes all active orders and mockes them as executed in a single transaction . If a ratio is provided then each order is only partially executed and added as a transaction and the order itself is kept in the order list .
def stub_bitstamp_hit_orders_into_transactions(options = {})
    ratio = (options[:ratio] || 1).to_d
    (BitstampStubs.active_bids + BitstampStubs.active_asks).each do |order|
      fiat = order.amount * order.price
      fiat, crypto, trade_type = order.type == :bid ? [-fiat, order.amount, 'buys'] : [fiat, -order.amount, 'sells']
      BitstampStubs.user_transactions << BitexBot::ApiWrappers::UserTransaction.new(
        rand(10).to_s,
        order.id,
        fiat * ratio,
        crypto * ratio,
        order.price,
        0.5.to_d,
        trade_type,
        Time.now.strftime('%F %T'),
        double
      )
    end
    [BitstampStubs.active_bids, BitstampStubs.active_asks].each(&:clear) if ratio == 1
    allow_any_instance_of(BitexBot::ApiWrappers::Bitstamp).to receive(:user_transactions).and_return(BitstampStubs.user_transactions)
  end
def stub_bitstamp_hit_orders_into_transactions ( options = { } ) ratio = ( options [ :ratio ] || 1 ) . to_d ( BitstampStubs . active_bids + BitstampStubs . active_asks ) . each do | order | fiat = order . amount * order . price fiat , crypto , trade_type = order . type == :bid ? [ - fiat , order . amount , 'buys' ] : [ fiat , - order . amount , 'sells' ] BitstampStubs . user_transactions << BitexBot :: ApiWrappers :: UserTransaction . new ( rand ( 10 ) . to_s , order . id , fiat * ratio , crypto * ratio , order . price , 0.5 . to_d , trade_type , Time . now . strftime ( '%F %T' ) , double ) end [ BitstampStubs . active_bids , BitstampStubs . active_asks ] . each ( & :clear ) if ratio == 1 allow_any_instance_of ( BitexBot :: ApiWrappers :: Bitstamp ) . to receive ( :user_transactions ) . and_return ( BitstampStubs . user_transactions ) end
Takes all active orders and mockes them as executed in a single transaction.
Takes all active orders and mockes them as executed in a single transaction .
options
<not_specific>