Beispiel #1
0
def get_sell_condition(symbol_value):
    period_value = misc.getConfigKeyValueByKeyName('config.ini', 'config', 'period_value')
    price_buy = float(misc.getConfigKeyValueByKeyName('config.ini', symbol_value, 'price_buy'))
    price_max = float(misc.getConfigKeyValueByKeyName('config.ini', symbol_value, 'price_max'))
    k_line = api.get_k_line(symbol_value, period_value, 11)
    k_line_0_close = k_line[0]['close']
    price_low = price_max * (1 - down_percent)
    price_min = price_buy * (1 - down_percent_max)
    print('price_buy = %s' % price_buy)
    #print('price_max = %s' % price_max)
    #print('price_low = %s' % price_low)
    #print('price_min = %s' % price_min)
    print('close = %s' % k_line_0_close)
    print('percent = %.4f%%' % ((k_line_0_close / price_buy - 1) * 100))
    condition1 = k_line_0_close < k_line[0]['open']#阴线
    print('阴线 = %s' % condition1)
    if k_line_0_close > price_max:
        misc.setConfigKeyValue('config.ini', symbol_value, 'price_max', k_line_0_close)
        price_max = k_line_0_close
    if price_min > k_line_0_close:
        return True
    if price_low > k_line_0_close:
        return True
    else:
        return False
Beispiel #2
0
def base_fun(symbol_value, period_value='1day', n=20, j=100):
    k_line = api.get_k_line(symbol_value, period_value, 200)

    roc_list = []
    time_list = []
    close_list = []
    ma_list = []

    for index in np.arange(0, len(k_line) - n):
        roc = (k_line[index].close -
               k_line[index + n].close) / k_line[index + n].close * 100
        roc_list.append(roc * j)

    # print(roc_list[::-1])

    for index in np.arange(0, len(k_line) - n):
        timestamp = k_line[index].id
        temp = datetime.datetime.fromtimestamp(timestamp + 8 * 3600)
        # time_list.append(time.strftime("%Y-%m-%d %H:%M:%S", temp))
        time_list.append(temp)

    # print(time_list[::-1])

    for index in np.arange(0, len(k_line) - n):
        close_list.append(k_line[index].close)

    # print(close_list)

    for index in np.arange(0, len(k_line) - n):
        ma_list.append(misc.getMALine(k_line, n)[index])
    # 收盘价
    close = Scatter(x=time_list[::-1], y=close_list[::-1], name="收盘价")
    # 均线
    ma = Scatter(x=time_list[::-1], y=ma_list[::-1], name="均线({})".format(n))
    # roc线
    roc = Scatter(x=time_list[::-1],
                  y=roc_list[::-1],
                  name="roc({})".format(n))

    layout = Layout(xaxis=dict(range=[
        time_list[-1].timestamp() * 1000, time_list[0].timestamp() * 1000
    ]),
                    title=symbol_value)

    return Figure(data=[close, ma, roc], layout=layout)
Beispiel #3
0
def get_condition():
    operationType = misc.getConfigKeyValueByKeyName('config.ini', symbol_value,
                                                    'type')
    k_line = api.get_k_line(symbol_value, period_value, 8)
    last_close_value = k_line[0]['close']
    ma_line = api.get_ma_line(k_line, 4)
    last_ma_value = ma_line[0]
    slope_list = api.get_slope_line(ma_line)
    print(slope_list)
    slope_list[0] = slope_list[0] * 1.075
    print(slope_list)
    slope_sum = 0
    for slope in slope_list:
        slope_sum = slope_sum + slope
    slope_sum = round(slope_sum, 6)
    slope_sum_last = slope_list[0] + slope_list[1]  # + slope_list[2]
    slope_sum_early = slope_list[3] + slope_list[2]  # + slope_list[5]

    condition1 = operationType == 'sell'
    condition2 = last_close_value > last_ma_value  #true为买入机会,false为卖出机会
    condition3 = slope_sum > 0  #true为斜率之和大于0,目前趋势向上,反之向下
    time_value = 0.0150
    condition4 = abs(slope_sum) > (float(last_close_value) * time_value
                                   )  #true为波动幅度大于市价的100.75%,波动幅度较大,非横盘震荡、谷底、山顶
    condition5 = slope_sum_last > slope_sum_early  #斜率后半段大于前半段
    condition6 = last_close_value > k_line[0]['open']  #true收盘价大于开盘价,阳线
    condition7 = slope_sum_last > 0  #后半段斜率之和为正
    condition8 = slope_sum_early < 0  #前半段斜率之和为负
    print('均线 = %s' % last_ma_value)
    print('市价 = %s' % last_close_value)
    print('斜率之和 = %s' % slope_sum)
    print('斜率之和(前半段) = %s' % slope_sum_early)
    print('斜率之和(后半段) = %s' % slope_sum_last)
    print('斜率波动幅度要求 = %s' % (last_close_value * time_value))
    print('1-最后一次操作为卖出 = %s' % condition1)
    print('2-市价高于均线 = %s' % condition2)
    print('3-斜率之和大于0 = %s' % condition3)
    print('4-波动幅度足够大 = %s' % condition4)
    print('5-后半段斜率之和大于前半段三斜率之和 = %s' % condition5)
    print('8-前半段斜率之和小于0 = %s' % condition8)
    print('7-后半段斜率之和大于0 = %s' % condition7)
    print('6-是否阳线 = %s' % condition6)
    return condition1, condition2, condition3, condition4, condition5, condition6, condition7, condition8
Beispiel #4
0
def get_sell_condition(symbol_value):
    period_value = misc.getConfigKeyValueByKeyName('config.ini', 'config',
                                                   'period_value')
    k_line = api.get_k_line(symbol_value, period_value, 11)
    k_line_0_close = k_line[0]['close']
    condition1 = k_line_0_close < k_line[0]['open']  #阴线
    k_line_1_close = k_line[1]['close']
    k_line_1_time = k_line[1]['id']
    k_line_time = int(
        misc.getConfigKeyValueByKeyName('config.ini', symbol_value,
                                        'k_line_time'))
    x_value = (k_line_1_time - k_line_time) / 60 / 60
    k_value = float(
        misc.getConfigKeyValueByKeyName('config.ini', symbol_value, 'k_value'))
    b_value = float(
        misc.getConfigKeyValueByKeyName('config.ini', symbol_value, 'b_value'))
    y_value = k_value * x_value + b_value
    if (k_line_1_close > y_value * up_point and x_value > 0):
        y_value_repair = y_value + (k_line_1_close - y_value) / 10
        k_value_repair = (y_value_repair - b_value) / x_value
        print('原始k k_value=%s' % k_value)
        print('斜率k修正 k_value_repair=%s' % k_value_repair)
        misc.setConfigKeyValue('config.ini', symbol_value, 'k_value',
                               str(k_value_repair))
        #return False and condition1
    k_value = float(
        misc.getConfigKeyValueByKeyName('config.ini', symbol_value, 'k_value'))
    x_value = x_value + 1
    y_value = k_value * x_value + b_value
    print('k_line_1时间 x=%s' % x_value)
    print('直线斜率 k=%s' % k_value)
    print('常数项 b=%s' % b_value)
    print('理想市价 y=%s' % y_value)
    print('实际市价 close=%s' % k_line_0_close)
    if (k_line_0_close < y_value * down_point):
        return True and condition1
    else:
        return False and condition1
Beispiel #5
0
def get_buy_condition(symbol_value):
    period_value = misc.getConfigKeyValueByKeyName('config.ini', 'config', 'period_value')
    k_line = api.get_k_line(symbol_value, period_value, 8)
    last_close_value = k_line[0]['close']
    ma_line = api.get_ma_line(k_line, 4)
    print(ma_line)
    last_ma_value = ma_line[0]
    slope_list = api.get_slope_line(ma_line)
    print(slope_list)
    slope_sum = 0
    for slope in slope_list:
        slope_sum = slope_sum + slope
    slope_sum = round(slope_sum, 6)
    slope_sum_last = slope_list[0] + slope_list[1]
    slope_sum_early = slope_list[3] + slope_list[2]

    condition1 = last_close_value > last_ma_value #市价在均线之上
    condition2 = last_close_value > k_line[0]['open'] #true收盘价大于开盘价,阳线
    #condition3 = slope_sum_last > slope_sum_early and slope_sum_last > 0 #斜率后半段大于前半段,且大于0
    condition3 = slope_list[0] > 0
    print('市价在均线之上 = %s' % condition1)
    print('阳线 = %s' % condition2)
    print('斜率后半段大于前半段,且大于0 = %s' % condition3)
    return condition1, condition2, condition3
Beispiel #6
0
import huo_bi_api as api
import misc
import time
from person import mailPass as mail_pass

mail_host = misc.getConfigKeyValueByKeyName('config.ini', 'mail', 'mailHost')
mail_user = misc.getConfigKeyValueByKeyName('config.ini', 'mail', 'mailUser')
receivers = misc.getConfigKeyValueByKeyName('config.ini', 'mail',
                                            'receivers').split(',')
#交易对
symbol_value = 'qspbtc'
money_name = 'usdt'
coin_name = 'btc'
account_id = api.get_account_id()
global buy_signal
global sell_signal
buy_signal = 0
sell_signal = 0
buy_signal_max = 4
sell_signal_max = 4

usdt = api.get_balance(account_id, 'usdt')
btc = api.get_balance(account_id, 'btc')
bcc = api.get_balance(account_id, 'bcc')
print('usdt = %s' % usdt)
print('btc  = %s' % btc)
print('bcc  = %s' % bcc)

k_line = api.get_k_line(symbol_value)
print(k_line)
Beispiel #7
0
import numpy as np

mail_host = misc.getConfigKeyValueByKeyName('config.ini', 'mail', 'mailHost')
mail_user = misc.getConfigKeyValueByKeyName('config.ini', 'mail', 'mailUser')
receivers = misc.getConfigKeyValueByKeyName('config.ini', 'mail',
                                            'receivers').split(',')

#交易对
symbol_value = 'btcusdt'
money_name = 'usdt'
coin_name = 'btc'
period_value = '1day'  #60min/1day
n = 20  #回看时间窗口
j = 100  #缩小倍数

k_line = api.get_k_line(symbol_value, period_value, 200)

roc_list = []
time_list = []
close_list = []
ma_list = []

for index in np.arange(0, len(k_line) - n):
    roc = (k_line[index].close -
           k_line[index + n].close) / k_line[index + n].close * 100
    roc_list.append(roc)

#print(roc_list[::-1])

for index in np.arange(0, len(k_line) - n):
    timestamp = k_line[index].id