class BitexBot::SellOpeningFlow

A workflow for selling bitcoin in Bitex and buying on another exchange. The SellOpeningFlow factory function estimates how much you could buy on the other exchange and calculates a reasonable price taking into account the remote order book and the recent operated volume.

When created, a SellOpeningFlow places an Ask on Bitex for the calculated quantity and price, when the Ask is matched on Bitex an OpenSell is created to buy the same quantity for a lower price on the other exchange.

A SellOpeningFlow can be cancelled at any point, which will cancel the Bitex order and any orders on the remote exchange created from its OpenSell's

@attr order_id The first thing a SellOpeningFlow does is placing an Ask on Bitex, this is its unique id.

Public Class Methods

available_maker_balance() click to toggle source
# File lib/bitex_bot/models/sell_opening_flow.rb, line 110
def self.available_maker_balance
  Robot.maker.balance.crypto.available
end
create_for_market(taker_fiat_balance, taker_asks, taker_transactions, maker_fee, taker_fee, store) click to toggle source

Start a workflow for selling bitcoin on bitex and buying on the other exchange. The quantity to be sold on bitex is retrieved from Settings, if there is not enough BTC on bitex or USD on the other exchange then no order will be placed and an exception will be raised instead.

The amount a SellOpeningFlow will try to sell and the price it will try to charge are derived from these parameters:

@param usd_balance [BigDecimal] amount of usd available in the other exchange that can be spent to balance this sale. @param order_book [[price, quantity]] a list of lists representing an ask 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 our maker exchange. @param taker_fee [BigDecimal] the transaction fee to pay on the taker exchange. @param store [Store] An updated config for this robot, mainly to use for profit.

@return [SellOpeningFlow] The newly created flow. @raise [CannotCreateFlow] If there's any problem creating this flow, for example when you run out of BTC on bitex or out of USD on the other exchange.

# File lib/bitex_bot/models/sell_opening_flow.rb, line 31
def self.create_for_market(taker_fiat_balance, taker_asks, taker_transactions, maker_fee, taker_fee, store)
  super
end
fx_rate() click to toggle source

end: create_for_market helpers

# File lib/bitex_bot/models/sell_opening_flow.rb, line 82
def self.fx_rate
  Settings.selling_fx_rate
end
maker_balance() click to toggle source
# File lib/bitex_bot/models/sell_opening_flow.rb, line 106
def self.maker_balance
  store.maker_crypto
end
maker_price(fiat_to_spend_re_buying) click to toggle source

create_for_market helpers

# File lib/bitex_bot/models/sell_opening_flow.rb, line 52
def self.maker_price(fiat_to_spend_re_buying)
  fiat_to_spend_re_buying * fx_rate / value_to_use * (1 + profit / 100)
end
maker_specie_to_obtain() click to toggle source
# File lib/bitex_bot/models/sell_opening_flow.rb, line 94
def self.maker_specie_to_obtain
  Robot.maker.quote.upcase
end
maker_specie_to_spend() click to toggle source
# File lib/bitex_bot/models/sell_opening_flow.rb, line 90
def self.maker_specie_to_spend
  Robot.maker.base.upcase
end
open_position_class() click to toggle source
# File lib/bitex_bot/models/sell_opening_flow.rb, line 40
def self.open_position_class
  OpenSell
end
order_class() click to toggle source
# File lib/bitex_bot/models/sell_opening_flow.rb, line 56
def self.order_class
  Bitex::Ask
end
order_type() click to toggle source
# File lib/bitex_bot/models/sell_opening_flow.rb, line 61
def self.order_type
  :sell
end
profit() click to toggle source
# File lib/bitex_bot/models/sell_opening_flow.rb, line 65
def self.profit
  store.selling_profit || Settings.selling.profit
end
remote_value_to_use(value_to_use_needed, safest_price) click to toggle source
# File lib/bitex_bot/models/sell_opening_flow.rb, line 69
def self.remote_value_to_use(value_to_use_needed, safest_price)
  value_to_use_needed * safest_price
end
safest_price(transactions, taker_asks, bitcoins_to_use) click to toggle source
# File lib/bitex_bot/models/sell_opening_flow.rb, line 73
def self.safest_price(transactions, taker_asks, bitcoins_to_use)
  OrderBookSimulator.run(Settings.time_to_live, transactions, taker_asks, nil, bitcoins_to_use, nil)
end
taker_specie_to_obtain() click to toggle source
# File lib/bitex_bot/models/sell_opening_flow.rb, line 102
def self.taker_specie_to_obtain
  Robot.taker.base.upcase
end
taker_specie_to_spend() click to toggle source
# File lib/bitex_bot/models/sell_opening_flow.rb, line 98
def self.taker_specie_to_spend
  Robot.taker.quote.upcase
end
transaction_class() click to toggle source

sought_transaction helpers

# File lib/bitex_bot/models/sell_opening_flow.rb, line 46
def self.transaction_class
  Bitex::Sell
end
transaction_order_id(transaction) click to toggle source

sync_open_positions helpers

# File lib/bitex_bot/models/sell_opening_flow.rb, line 36
def self.transaction_order_id(transaction)
  transaction.raw.ask_id
end
value_per_order() click to toggle source
# File lib/bitex_bot/models/sell_opening_flow.rb, line 86
def self.value_per_order
  value_to_use
end
value_to_use() click to toggle source
# File lib/bitex_bot/models/sell_opening_flow.rb, line 77
def self.value_to_use
  store.selling_quantity_to_sell_per_order || Settings.selling.quantity_to_sell_per_order
end