BitShares Forum

Main => General Discussion => Topic started by: bulletproof on August 17, 2015, 03:43:51 pm

Title: bitshares Ruby API (Ruby gem)
Post by: bulletproof on August 17, 2015, 03:43:51 pm
After some experimentation since here (https://bitsharestalk.org/index.php/topic,17835.0.html), I've now released a Ruby gem for the bitshares client (v0.x). The gem is called bitshares (https://github.com/MatzFan/bitshares-ruby).

Inspiration from & credit to @xeroc's Python API (https://github.com/xeroc/python-bitsharesrpc) and the web-services Ruby API code (https://github.com/bitshares/web_services/blob/master/faucet/lib/BitShares/bitshares_api.rb)

I've used this as an exercise to teach myself how the bitshares client actually works (lots to learn!). At this stage I'd appreciate any feedback on this project so I can judge whether it is worth continuing with the initiative and maintaining the gem. In any case, pointers to the changes in graphene's JSON RPC API, so I can update the code to be 2.0 compatible, would be great. Feature requests/ideas/collaborators all most welcome  :)

Executive summary

Code: [Select]
client = Bitshares::Client.init
Bitshares.configure(:wallet => {'my_wallet' => 'wallet_password'})
wallet = Bitshares::Wallet.new 'my_wallet'
account = wallet.account 'my_account_name'

# a Market object, representing an asset-pair:-
cny_bts = Bitshares::Market.new('CNY', 'BTS')
cny_bts.order_book # gets order book for this market
etc...

# trading in a market from an account
cny_bts_trader = Bitshares::Trader.new(account, cny_bts)
cny_bts_trader.submit_ask(1000, 0.03) # sell order for 1,000 BTS @ 0.03 CNY/BTS
etc...
Title: Re: bitshares Ruby API (Ruby gem)
Post by: roadscape on August 17, 2015, 04:54:23 pm
 +5% Awesome.. I'll test it out this week!
Title: Re: bitshares Ruby API (Ruby gem)
Post by: xeroc on August 17, 2015, 05:11:15 pm
+5%
Title: Re: bitshares Ruby API (Ruby gem)
Post by: bytemaster on August 17, 2015, 09:23:48 pm
After some experimentation since here (https://bitsharestalk.org/index.php/topic,17835.0.html), I've now released a Ruby gem for the bitshares client (v0.x). The gem is called bitshares (https://github.com/MatzFan/bitshares-ruby).

Inspiration from & credit to @xeroc's Python API (https://github.com/xeroc/python-bitsharesrpc) and the web-services Ruby API code (https://github.com/bitshares/web_services/blob/master/faucet/lib/BitShares/bitshares_api.rb)

I've used this as an exercise to teach myself how the bitshares client actually works (lots to learn!). At this stage I'd appreciate any feedback on this project so I can judge whether it is worth continuing with the initiative and maintaining the gem. In any case, pointers to the changes in graphene's JSON RPC API, so I can update the code to be 2.0 compatible, would be great. Feature requests/ideas/collaborators all most welcome  :)

Executive summary
  • it is designed to work with < v1.0 CLI client running the RPC server
  • this version detects the running JSON RPC server ports and can thus be integrated into any Ruby/Rails project running the bitshares_client server
  • multiple wallets/accounts are supported with stored passwords - so functions requiring these may be automated
  • the docs (https://github.com/MatzFan/bitshares-ruby/blob/master/README.md) list the functionality, which includes automated trading (long-only so far). Here is a flavour:-

Code: [Select]
client = Bitshares::Client.init
Bitshares.configure(:wallet => {'my_wallet' => 'wallet_password'})
wallet = Bitshares::Wallet.new 'my_wallet'
account = wallet.account 'my_account_name'

# a Market object, representing an asset-pair:-
cny_bts = Bitshares::Market.new('CNY', 'BTS')
cny_bts.order_book # gets order book for this market
etc...

# trading in a market from an account
cny_bts_trader = Bitshares::Trader.new(account, cny_bts)
cny_bts_trader.submit_ask(1000, 0.03) # sell order for 1,000 BTS @ 0.03 CNY/BTS
etc...

Great work!   I will throw some brownies your way for this, and hope you do the same for BTS 2.0
Title: Re: bitshares Ruby API (Ruby gem)
Post by: abit on August 18, 2015, 12:44:12 am
Great! +5%
2.0 supports (and prefers?) websocket, will you implement with it as well?
Title: Re: bitshares Ruby API (Ruby gem)
Post by: bulletproof on August 18, 2015, 12:49:12 am
2.0 supports (and prefers?) websocket, will you implement with it as well?

Yup, that's the intention.
Title: Re: bitshares Ruby API (Ruby gem)
Post by: ebit on August 18, 2015, 01:21:55 am
 +5%
Title: Re: bitshares Ruby API (Ruby gem)
Post by: roadscape on August 20, 2015, 11:04:40 pm
I keep getting a 'Bad credentials' error..does that refer to RPC or wallet?

I understand these are RPC credentials. Would it be possible to have these be part of the configuration and not globals?
$BITSHARES_ACCOUNT
$BITSHARES_PASSWORD
Title: Re: bitshares Ruby API (Ruby gem)
Post by: bulletproof on August 21, 2015, 12:24:25 am
Done. v0.1.6 - see latest README

Let me know if you still have trouble
Title: Re: bitshares Ruby API (Ruby gem)
Post by: roadscape on August 21, 2015, 05:13:40 pm
Cool, works now :)
Title: Re: bitshares Ruby API (Ruby gem)
Post by: bulletproof on September 03, 2015, 09:59:46 am
Update:

Started work on graphene version of the Gem, with websockets too. Got basic ws calls working, so to aid my understanding of why ws is used/preferred, can someone point me at the docs which describe how graphene handles async/statefull API calls - or maybe just provide one or two examples - i.e. where stateless (JSON RPC) API can't be used & why?

Thx

EDIT: Nothing heard as of 9/04, so will focus on JSON RPC only for now