Module: Bitstamper::Rest::Private::Orders
- Included in:
- Client
- Defined in:
- lib/bitstamper/rest/private/orders.rb
Instance Method Summary collapse
- #buy(currency_pair: "btcusd", amount:, price:, limit_price: nil, daily_order: nil) ⇒ Object
- #cancel_all_orders! ⇒ Object
- #cancel_order!(order_id) ⇒ Object
-
#create_order(currency_pair: "btcusd", direction: Bitstamper::Constants::BUY_ORDER, amount:, price:, limit_price: nil, daily_order: nil) ⇒ Object
Request parameters [AUTH] amount - Amount.
- #find_open_order(order_id) ⇒ Object
- #fix_order_direction(direction) ⇒ Object
- #open_orders(currency_pair = nil) ⇒ Object
- #order_status(order_id) ⇒ Object
- #sell(currency_pair: "btcusd", amount:, price:, limit_price: nil, daily_order: nil) ⇒ Object
Instance Method Details
#buy(currency_pair: "btcusd", amount:, price:, limit_price: nil, daily_order: nil) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/bitstamper/rest/private/orders.rb', line 17 def buy(currency_pair: "btcusd", amount:, price:, limit_price: nil, daily_order: nil) create_order( currency_pair: currency_pair, direction: Bitstamper::Constants::BUY_ORDER, amount: amount, price: price, limit_price: limit_price, daily_order: daily_order ) end |
#cancel_all_orders! ⇒ Object
91 92 93 |
# File 'lib/bitstamper/rest/private/orders.rb', line 91 def cancel_all_orders! parse(post('/cancel_all_orders')) end |
#cancel_order!(order_id) ⇒ Object
95 96 97 98 |
# File 'lib/bitstamper/rest/private/orders.rb', line 95 def cancel_order!(order_id) response = parse(post('/v2/cancel_order', data: {id: order_id})) Bitstamper::Models::Order.new(response) if response end |
#create_order(currency_pair: "btcusd", direction: Bitstamper::Constants::BUY_ORDER, amount:, price:, limit_price: nil, daily_order: nil) ⇒ Object
Request parameters
- AUTH
-
amount - Amount. price - Price. limit_price - If the order gets executed, a new sell order will be placed, with “limit_price” as its price. daily_order - (Optional): Opens buy limit order which will be canceled at 0:00 UTC unless it already has been executed. Possible value: True
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/bitstamper/rest/private/orders.rb', line 46 def create_order(currency_pair: "btcusd", direction: Bitstamper::Constants::BUY_ORDER, amount:, price:, limit_price: nil, daily_order: nil) currency_pair = ::Bitstamper::Utilities.fix_currency_pair(currency_pair) direction = fix_order_direction(direction) path = case direction when Bitstamper::Constants::BUY_ORDER "/v2/buy/#{currency_pair}" when Bitstamper::Constants::SELL_ORDER "/v2/sell/#{currency_pair}" end data = { amount: amount, price: price } data[:limit_price] = limit_price if !limit_price.nil? data[:daily_order] = true if daily_order == true response = parse(post(path, data: data)) Bitstamper::Models::Order.new(response.merge("currency_pair" => currency_pair)) if response end |
#find_open_order(order_id) ⇒ Object
12 13 14 |
# File 'lib/bitstamper/rest/private/orders.rb', line 12 def find_open_order(order_id) open_orders.select { |order| order.id == order_id }&.first end |
#fix_order_direction(direction) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/bitstamper/rest/private/orders.rb', line 70 def fix_order_direction(direction) if direction.is_a?(Symbol) direction = case direction when :buy Bitstamper::Constants::BUY_ORDER when :sell Bitstamper::Constants::SELL_ORDER end end return direction end |
#open_orders(currency_pair = nil) ⇒ Object
6 7 8 9 10 |
# File 'lib/bitstamper/rest/private/orders.rb', line 6 def open_orders(currency_pair = nil) path = !currency_pair.to_s.empty? ? "/v2/open_orders/#{::Bitstamper::Utilities.fix_currency_pair(currency_pair)}" : "/v2/open_orders/all" response = post(path) Bitstamper::Models::Order.parse(response) if response end |
#order_status(order_id) ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/bitstamper/rest/private/orders.rb', line 83 def order_status(order_id) response = post("/order_status", data: {id: order_id}) status = response&.fetch("status", nil) transactions = Bitstamper::Models::UserTransaction.parse(response&.fetch("transactions", [])) return {status: status, transactions: transactions} end |
#sell(currency_pair: "btcusd", amount:, price:, limit_price: nil, daily_order: nil) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/bitstamper/rest/private/orders.rb', line 29 def sell(currency_pair: "btcusd", amount:, price:, limit_price: nil, daily_order: nil) create_order( currency_pair: currency_pair, direction: Bitstamper::Constants::SELL_ORDER, amount: amount, price: price, limit_price: limit_price, daily_order: daily_order ) end |