lowest price for the last 24h
[" BTC-NXT", " BTC-CRW", " BTC-MONA", " BTC-NEOS", " BTC-BYC", " BTC-AGRS", " BTC-XWC", " BTC-MLN", " BTC-START", " BTC-SBD"
created a robot that trades crypto pairs
I will further develop it
first version
def choice_order_and_sell(pairs)
pairs.each do |pair|
pair="BTC-#{pair}" unless pair.start_with?("BTC-")
bid = TradeUtil.get_bid_ask(pair)
if bid && bid[0]
sell_order(pair,bid[0])
end
sleep 0.5
end
end
def find_last_hist_order_not_sold(hist_orders)
last_indx=0
orders=[]
##find last not solded
hist_orders.each do|ord|
last_indx +=1 if ord[:OrderType]=='LIMIT_SELL'
if last_indx==0
orders<
end
last_indx -=1 if ord[:OrderType]=='LIMIT_BUY' && last_indx>0
#p "order #{ord[:OrderType]} last_indx #{last_indx}"
end
orders
end
def sell_order(pair,bid)
#ord = DB[:bot_trading].filter(name:pair, finished:0).order(:ppu).first
from = date_now(24)
#hist_orders = DB[:my_hst_orders].filter( pid:get_profile, Exchange:pair).reverse_order(:Closed).limit(
.all
hist_orders = DB[:my_hst_orders].filter( Sequel.lit("(pid=? and Exchange=? and Closed > ? )", get_profile, pair, from) ).reverse_order(:Closed).all
last_orders = find_last_hist_order_not_sold(hist_orders)
if last_orders.size>0
ord = last_orders.first
else
ord = hist_orders.select{|ord| ord[:OrderType]=='LIMIT_BUY'}.max_by{|ord| ord[:PricePerUnit] }
end
if ord && ord[:PricePerUnit] && ord[:OrderType]=='LIMIT_BUY'
finished = DB[:bot_trading].first(ord_uuid: ord[:OrderUuid],finished:1)
return if finished
q = ord[:Quantity]
ppu = ord[:PricePerUnit]
factor = DB[:my_trade_pairs].first(pid:get_profile, name:pair)[:sell_factor] rescue 105
return if factor<101
diff = bid/ppu*100
p "--sell #{pair.ljust(10,' ')} factor #{factor} bid: #{'%0.8f' % bid} ppu #{'%0.8f' % ppu} diff #{'%0.0f' % diff} closed #{ord[:Closed].strftime("%F %k:%M ")}"
if diff>factor #|| diff< 90
uuid=TradeUtil.sell_curr(pair, q, bid)
if uuid
p "SOLD bid #{'%0.8f' % bid} diff #{'%0.8f' % diff} closed #{ord[:Closed].strftime("%F %k:%M ")}"
DB[:bot_trading].filter(ord_uuid: ord[:OrderUuid]).update(finished:1, s_ppu:bid, bot_sold_at:date_now)
end
end
end
end