Class: Bitshares::Trader

Inherits:
Object
  • Object
show all
Defined in:
lib/bitshares/trader.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

WMSA =
'wallet_market_submit_ask'
WMSB =
'wallet_market_submit_bid'
WMOL =
'wallet_market_order_list'
WMCO =
'wallet_market_cancel_orders'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(account, market) ⇒ Trader

Returns a new instance of Trader.



14
15
16
17
18
19
20
21
# File 'lib/bitshares/trader.rb', line 14

def initialize(, market)
  @account = 
  @wallet = .wallet
  @name = .name
  @market = market
  @base = market.base
  @quote = market.quote
end

Instance Attribute Details

#accountObject (readonly)

Returns the value of attribute account.



12
13
14
# File 'lib/bitshares/trader.rb', line 12

def 
  @account
end

#marketObject (readonly)

Returns the value of attribute market.



12
13
14
# File 'lib/bitshares/trader.rb', line 12

def market
  @market
end

Instance Method Details

#cancel_allObject



45
46
47
# File 'lib/bitshares/trader.rb', line 45

def cancel_all
  cancel_orders all_order_ids
end

#cancel_orders(*id_list) ⇒ Object



39
40
41
42
43
# File 'lib/bitshares/trader.rb', line 39

def cancel_orders(*id_list)
  @wallet.unlock if @wallet.locked?
  confirm = CLIENT.request(WMCO, id_list)
  confirm['ledger_entries'].map { |e| e['memo'] } # returns 'cancel ASK-xxxxxxxx' first 8 chars of order id
end

#order_list(limit = '-1') ⇒ Object



35
36
37
# File 'lib/bitshares/trader.rb', line 35

def order_list(limit = '-1')
  CLIENT.request(WMOL, [@quote, @base, limit, @name])
end

#submit_ask(quantity, price, stupid = false) ⇒ Object



23
24
25
26
27
# File 'lib/bitshares/trader.rb', line 23

def submit_ask(quantity, price, stupid = false)
  @wallet.unlock if @wallet.locked?
  o = CLIENT.request(WMSA, [@name, quantity, @base, price, @quote, stupid])
  o['record_id'] # return order id
end

#submit_bid(quantity, price, stupid = false) ⇒ Object



29
30
31
32
33
# File 'lib/bitshares/trader.rb', line 29

def submit_bid(quantity, price, stupid = false)
  @wallet.unlock if @wallet.locked?
  o = CLIENT.request(WMSB, [@name, quantity, @base, price, @quote, stupid])
  o['record_id'] # return order id
end