Virtex
A thin wrapper around the CaVirtex API
Usage
See the CaVirtex API docs and source code for more information
Unauthenticated requests
require 'virtex'
@virtex = Virtex::Client.new
Orderbook
book = @virtex.orderbook('BTCCAD').orderbook
best_bid = book.bids.first
expect(best_bid[0]).to eq(631.481850000) # Price
expect(best_bid[1]).to eq(1.367900000) # Size
best_ask = asks.last
expect(best_ask[0]).to eq(634.974840000)
expect(best_ask[1]).to eq(9.727400000)
Tradebook
trades = @virtex.tradebook('BTCCAD').trades
latest = trades.first
Ticker
ticker = @virtex.ticker("BTCCAD").ticker.BTCCAD
Authenticated requests
require 'virtex'
@virtex = Virtex::Client.new(ENV['VIRTEX_API_KEY'], ENV['VIRTEX_API_SECRET'])
View Balance
expect(@virtex.balance.balance.CAD).to eq(0.0385)
View Transactions
transactions = @virtex.transactions("BTC").transactions
View trades
recent_trades = @virtex.trades.trades
View orders
recent_orders = @virtex.orders.orders
Place an order
# Place a new order to sell 0.1 BTC/CAD at 1000.00
new_order = @virtex.new_order!('sell', 0.1, 'BTCCAD', 1000.00).order
Cancel an order
@virtex.cancel_order! 543468
Withdraw to an external wallet
withdrawal = @virtex.withdraw!(0.01, 'BTC', '1DWYffTxhXgBtbswMjNViw9nNCvx3Drpvn').result
Testing
If you'd like to contribute code or modify this gem, you can run the test suite with:
gem install virtex --dev
bundle exec rspec
Contributing
- Fork this repo and make changes in your own copy
- Add a test if applicable and run the existing tests with
rspec
to make sure they pass - Commit your changes and push to your fork
git push origin master
- Create a new pull request and submit it back to me
Credits
Thanks to @Skizzk for providing an example of correctly authenticating with Virtex
Thanks to @barmstrong on whose coinbase gem I based this library