Module: CBX::Trading

Includes:
Pagination
Defined in:
lib/cbx/trading.rb

Overview

Provides an interface to the Trading section of the Coinbase Exchange API.

Instance Method Summary collapse

Instance Method Details

#accounts(account_id = nil, &block) ⇒ Object

Account methods



8
9
10
11
12
13
14
# File 'lib/cbx/trading.rb', line 8

def accounts( = nil, &block)
  if .nil?
    get('accounts', nil, &block)
  else
    get('accounts/' + .to_s, nil, &block)
  end
end

#cancel_order(order_id, &block) ⇒ Object



38
39
40
# File 'lib/cbx/trading.rb', line 38

def cancel_order(order_id, &block)
  delete('orders/' + order_id.to_s, nil, &block)
end

#create_report(start_date = nil, end_date = nil, type = 'fill', &block) ⇒ Object

Create a report



82
83
84
85
86
87
88
89
# File 'lib/cbx/trading.rb', line 82

def create_report(start_date = nil, end_date = nil, type = 'fill', &block)
  params = {
    'type' => type,
    'start_date' => start_date,
    'end_date' => end_date
  }
  post('reports', params, &block)
end

#deposit(amount, coinbase_account_id, &block) ⇒ Object

Deposit funds into your Exchange account from a Coinbase wallet.



54
55
56
57
58
59
60
61
# File 'lib/cbx/trading.rb', line 54

def deposit(amount, , &block)
  order = { 
    'type' => 'deposit',
    'amount' => amount,
    'coinbase_account_id' => 
  }
  post('orders', order, &block)
end

#fills(pagination = {}, &block) ⇒ Object

Fill methods



76
77
78
# File 'lib/cbx/trading.rb', line 76

def fills(pagination = {}, &block)
  get('fills' + paginate(pagination), nil, &block)
end

#holds(account_id, pagination = {}, &block) ⇒ Object



20
21
22
# File 'lib/cbx/trading.rb', line 20

def holds(, pagination = {}, &block)
  get('accounts/' + .to_s + '/holds' + paginate(pagination), nil, &block)
end

#ledger(account_id, pagination = {}, &block) ⇒ Object



16
17
18
# File 'lib/cbx/trading.rb', line 16

def ledger(, pagination = {}, &block)
  get('accounts/' + .to_s + '/ledger' + paginate(pagination), nil, &block)
end

#order(order_id = nil, &block) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/cbx/trading.rb', line 30

def order(order_id = nil, &block)
  if order_id.nil?
    get('orders', nil, &block)
  else
    get('orders/' + order_id.to_s, nil, &block)
  end
end

#orders(pagination = {}, &block) ⇒ Object

Order methods



26
27
28
# File 'lib/cbx/trading.rb', line 26

def orders(pagination = {}, &block)
  get('orders' + paginate(pagination), nil, &block)
end

#place_order(size, price, side, product_id = 'BTC-USD', &block) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/cbx/trading.rb', line 42

def place_order(size, price, side, product_id = 'BTC-USD', &block)
  order = { 
    'size' => size,
    'price' => price,
    'side' => side,
    'product_id' => product_id
  }
  post('orders', order, &block)
end

#report_info(report_id, &block) ⇒ Object

Get info about a report



93
94
95
# File 'lib/cbx/trading.rb', line 93

def report_info(report_id, &block)
  get('reports/' + report_id)
end

#withdraw(amount, coinbase_account_id, &block) ⇒ Object

Withdraw funds to your Coinbase wallet.



65
66
67
68
69
70
71
72
# File 'lib/cbx/trading.rb', line 65

def withdraw(amount, , &block)
  order = {
    'type' => 'withdraw',
    'amount' => amount,
    'coinbase_account_id' => 
  }
  post('orders', order, &block)
end