Class: BitexBot::SellOpeningFlow
- Inherits:
-
OpeningFlow
- Object
- ActiveRecord::Base
- OpeningFlow
- BitexBot::SellOpeningFlow
- Defined in:
- lib/bitex_bot/models/sell_opening_flow.rb
Overview
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
Instance Attribute Summary collapse
-
#order_id ⇒ Object
The first thing a SellOpeningFlow does is placing an Ask on Bitex, this is its unique id.
Class Method Summary collapse
-
.create_for_market(usd_balance, order_book, transactions, maker_fee, taker_fee, store) ⇒ SellOpeningFlow
Start a workflow for selling bitcoin on bitex and buying on the other exchange.
-
.fx_rate ⇒ Object
end: create_for_market helpers.
-
.maker_price(fiat_to_spend_re_buying) ⇒ Object
create_for_market helpers.
- .open_position_class ⇒ Object
- .order_class ⇒ Object
- .profit ⇒ Object
- .remote_value_to_use(value_to_use_needed, safest_price) ⇒ Object
- .safest_price(transactions, order_book, bitcoins_to_use) ⇒ Object
-
.transaction_class ⇒ Object
sought_transaction helpers.
-
.transaction_order_id(transaction) ⇒ Object
sync_open_positions helpers.
- .value_to_use ⇒ Object
Methods inherited from OpeningFlow
active, active_transaction?, calc_remote_value, create_open_position!, create_order!, enough_funds?, enough_remote_funds?, expected_order_book?, #finalise!, maker_plus, old_active, open_position?, sought_transaction?, #statuses, sync_open_positions
Instance Attribute Details
#order_id ⇒ Object
The first thing a SellOpeningFlow does is placing an Ask on Bitex, this is its unique id.
13 14 15 |
# File 'lib/bitex_bot/models/sell_opening_flow.rb', line 13 def order_id @order_id end |
Class Method Details
.create_for_market(usd_balance, order_book, transactions, maker_fee, taker_fee, store) ⇒ SellOpeningFlow
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:
of USD on the other exchange.
31 32 33 |
# File 'lib/bitex_bot/models/sell_opening_flow.rb', line 31 def self.create_for_market(usd_balance, order_book, transactions, maker_fee, taker_fee, store) super end |
.fx_rate ⇒ Object
end: create_for_market helpers
77 78 79 |
# File 'lib/bitex_bot/models/sell_opening_flow.rb', line 77 def self.fx_rate Settings.selling_fx_rate end |
.maker_price(fiat_to_spend_re_buying) ⇒ Object
create_for_market helpers
52 53 54 |
# File 'lib/bitex_bot/models/sell_opening_flow.rb', line 52 def self.maker_price() * fx_rate / value_to_use * (1 + profit / 100) end |
.open_position_class ⇒ Object
40 41 42 |
# File 'lib/bitex_bot/models/sell_opening_flow.rb', line 40 def self.open_position_class OpenSell end |
.order_class ⇒ Object
56 57 58 |
# File 'lib/bitex_bot/models/sell_opening_flow.rb', line 56 def self.order_class Bitex::Ask end |
.profit ⇒ Object
60 61 62 |
# File 'lib/bitex_bot/models/sell_opening_flow.rb', line 60 def self.profit store.selling_profit || Settings.selling.profit end |
.remote_value_to_use(value_to_use_needed, safest_price) ⇒ Object
64 65 66 |
# File 'lib/bitex_bot/models/sell_opening_flow.rb', line 64 def self.remote_value_to_use(value_to_use_needed, safest_price) value_to_use_needed * safest_price end |
.safest_price(transactions, order_book, bitcoins_to_use) ⇒ Object
68 69 70 |
# File 'lib/bitex_bot/models/sell_opening_flow.rb', line 68 def self.safest_price(transactions, order_book, bitcoins_to_use) OrderBookSimulator.run(Settings.time_to_live, transactions, order_book, nil, bitcoins_to_use) end |
.transaction_class ⇒ Object
sought_transaction helpers
46 47 48 |
# File 'lib/bitex_bot/models/sell_opening_flow.rb', line 46 def self.transaction_class Bitex::Sell end |
.transaction_order_id(transaction) ⇒ Object
sync_open_positions helpers
36 37 38 |
# File 'lib/bitex_bot/models/sell_opening_flow.rb', line 36 def self.transaction_order_id(transaction) transaction.ask_id end |
.value_to_use ⇒ Object
72 73 74 |
# File 'lib/bitex_bot/models/sell_opening_flow.rb', line 72 def self.value_to_use store.selling_quantity_to_sell_per_order || Settings.selling.quantity_to_sell_per_order end |