class BitexBot::BuyOpeningFlow
A workflow for buying bitcoin in Bitex
and selling on another exchange. The BuyOpeningFlow
factory function estimates how much you could sell on the other exchange and calculates a reasonable price taking into account the remote order book and the recent operated volume.
When created, a BuyOpeningFlow
places a Bid on Bitex
for the calculated amount and price, when the Bid is matched on Bitex
an OpenBuy
is created to sell the matched amount for a higher price on the other exchange.
A BuyOpeningFlow
can be cancelled at any point, which will cancel the Bitex
order and any orders on the remote exchange created from its OpenBuy's
@attr order_id The first thing a BuyOpeningFlow
does is placing a Bid on Bitex
, this is its unique id.
Public Class Methods
# File lib/bitex_bot/models/buy_opening_flow.rb, line 110 def self.available_maker_balance Robot.maker.balance.fiat.available end
Start a workflow for buying bitcoin on bitex and selling on the other exchange. The amount to be spent on bitex is retrieved from Settings, if there is not enough USD on bitex or BTC on the other exchange then no order will be placed and an exception will be raised instead.
The amount a BuyOpeningFlow
will try to buy and the price it will try to buy at are derived from these parameters:
@param btc_balance [BigDecimal] amount of btc available in the other exchange that can be sold to balance this purchase. @param order_book [[price, quantity]] a list of lists representing a bid order book in the other exchange. @param transactions [Hash] a list of hashes representing all transactions in the other exchange:
Each hash contains 'date', 'tid', 'price' and 'amount', where 'amount' is the BTC transacted.
@param maker_fee [BigDecimal] the transaction fee to pay on maker exchange. @param taker_fee [BigDecimal] the transaction fee to pay on taker exchange. @param store [Store] An updated config for this robot, mainly to use for profit.
@return [BuyOpeningFlow] The newly created flow. @raise [CannotCreateFlow] If there's any problem creating this flow, for example when you run out of USD on bitex or out
of BTC on the other exchange.
# File lib/bitex_bot/models/buy_opening_flow.rb, line 31 def self.create_for_market(taker_crypto_balance, taker_bids, taker_transactions, maker_fee, taker_fee, store) super end
end: create_for_market
helpers
# File lib/bitex_bot/models/buy_opening_flow.rb, line 82 def self.fx_rate Settings.buying_fx_rate end
# File lib/bitex_bot/models/buy_opening_flow.rb, line 106 def self.maker_balance store.maker_fiat end
create_for_market
helpers
# File lib/bitex_bot/models/buy_opening_flow.rb, line 52 def self.maker_price(crypto_to_resell) value_to_use * fx_rate / crypto_to_resell * (1 - profit / 100) end
# File lib/bitex_bot/models/buy_opening_flow.rb, line 94 def self.maker_specie_to_obtain Robot.maker.base.upcase end
# File lib/bitex_bot/models/buy_opening_flow.rb, line 90 def self.maker_specie_to_spend Robot.maker.quote.upcase end
# File lib/bitex_bot/models/buy_opening_flow.rb, line 40 def self.open_position_class OpenBuy end
# File lib/bitex_bot/models/buy_opening_flow.rb, line 56 def self.order_class Bitex::Bid end
# File lib/bitex_bot/models/buy_opening_flow.rb, line 61 def self.order_type :buy end
# File lib/bitex_bot/models/buy_opening_flow.rb, line 65 def self.profit store.buying_profit || Settings.buying.profit end
# File lib/bitex_bot/models/buy_opening_flow.rb, line 69 def self.remote_value_to_use(value_to_use_needed, safest_price) value_to_use_needed / safest_price end
# File lib/bitex_bot/models/buy_opening_flow.rb, line 73 def self.safest_price(transactions, taker_bids, amount_to_use) OrderBookSimulator.run(Settings.time_to_live, transactions, taker_bids, amount_to_use, nil, fx_rate) end
# File lib/bitex_bot/models/buy_opening_flow.rb, line 102 def self.taker_specie_to_obtain Robot.taker.quote.upcase end
# File lib/bitex_bot/models/buy_opening_flow.rb, line 98 def self.taker_specie_to_spend Robot.taker.base.upcase end
sought_transaction helpers
# File lib/bitex_bot/models/buy_opening_flow.rb, line 46 def self.transaction_class Bitex::Buy end
sync_open_positions helpers
# File lib/bitex_bot/models/buy_opening_flow.rb, line 36 def self.transaction_order_id(transaction) transaction.raw.bid_id end
# File lib/bitex_bot/models/buy_opening_flow.rb, line 86 def self.value_per_order value_to_use * fx_rate end
# File lib/bitex_bot/models/buy_opening_flow.rb, line 77 def self.value_to_use store.buying_amount_to_spend_per_order || Settings.buying.amount_to_spend_per_order end