How to use is_simple method in Sure

Best Python code snippet using sure_python

bot_12h.py

Source:bot_12h.py Github

copy

Full Screen

...83 higth_part = candle['high'] - max([candle['open'], candle['close']])84 middle = candle['open'] - candle['close']85 low_part = min([candle['open'], candle['close']]) - candle['low']86 return True if (abs(middle) + (low_part * SWORD_MULTIPLIER)) < higth_part else False87def is_simple(candle):88 return True if not is_dodge(candle) and not is_hummer(candle) and not is_sword(candle) else False89def is_fat(candle):90 if COEF_ALL_CANDLE_MID > (candle['high'] - candle['low']) / (91 abs(candle['close'] - candle['open']) + 0.0001) > COEF_ALL_CANDLE_MIN and COEF_HIGH_LOW_MIN < (92 candle['high'] - max([candle['close'], candle['open']])) / (93 min([candle['close'], candle['open']]) - candle['low'] + 0.0001) < COEF_HIGH_LOW_MAX:94 return True95 else:96 return False97def is_raise_vol(candle1, candle2):98 return True if candle2['volume'] > candle1['volume'] else False99def candle_12h_creator(candles_data):100 for i in range(len(candles_data)):101 if candles_data[0]['date'] % 43200 != 0:102 candles_data = candles_data[1:]103 else:104 break105 if len(candles_data) % 3 == 1:106 candles_data = candles_data[:-1]107 elif len(candles_data) % 3 == 2:108 candles_data = candles_data[:-2]109 elif len(candles_data) % 3 == 0:110 candles_data = candles_data[:-3]111 candles_12h_data = []112 candle_3na4 = []113 for candle in candles_data:114 candle_3na4.append(candle)115 if len(candle_3na4) == 3:116 candle_12h = {'high': (117 max([float(candle_3na4[0]['high']), float(candle_3na4[1]['high']), float(candle_3na4[2]['high'])])),118 'low': (min([float(candle_3na4[0]['low']), float(candle_3na4[1]['low']), float(candle_3na4[2]['low'])])),119 'volume': (sum([float(candle_3na4[0]['volume']), float(candle_3na4[1]['volume']), float(candle_3na4[2]['volume'])])),120 'close': float(candle_3na4[2]['close']), 'open': float(candle_3na4[0]['open']),121 'date': int(candle_3na4[0]['date'])}122 candle_3na4 = []123 candles_12h_data.append(candle_12h)124 return candles_12h_data125def check_hard_condition(candle):126 candle_close = candle['close']127 candle_open = candle['open']128 candle_high = candle['high']129 candle_low = candle['low']130 if candle_close > candle_open:131 close_open = candle_close - candle_open132 high_candle = candle_high - candle_close133 candle_low = candle_open - candle_low if \134 candle_open != candle_low else 0.0001135 elif candle_close < candle_open:136 close_open = candle_open - candle_close137 high_candle = candle_high - candle_open138 candle_low = candle_close - candle_low if \139 candle_close != candle_low else 0.0001140 else:141 close_open = 0.0001142 candle_low = candle_close - candle_low if \143 candle_close != candle_low else 0.0001144 high_candle = candle_high - candle_open145 if high_candle / close_open > HIGHER_COEF \146 and high_candle / candle_low > LOWER_COEF:147 return False148 else:149 return True150def main():151 polo = create_poloniex_connection()152 logging.basicConfig(level=logging.INFO,153 format='%(asctime)s %(levelname)s %(message)s',154 datefmt='%H:%M:%S',155 filename='{}log/logger{}.log'.format(PROJECT_PATH,156 time.strftime('%Y_%m_%d', datetime.datetime.now(157 ).timetuple())))158 with open(PROJECT_PATH + 'bot_daily_btc_pairs.json') as data_file:159 pairs_bought = json.load(data_file)160 with open(PROJECT_PATH + 'bot_daily_btc_date.json') as data_file:161 last_bought_date = json.load(data_file)162 if pairs_bought != '':163 if pairs_bought != 'no pairs':164 balances = polo.returnBalances()165 null_balances_pairs = 0166 for pair in pairs_bought:167 altcoin_amount = float(balances[pair['name'].split('_')[-1]])168 if altcoin_amount > 0:169 current_buy_glass = polo.returnOrderBook(pair['name'], depth=DEPTH_OF_SELLING_GLASS)['bids']170 sum_previous = 0171 sell_price = 0172 for order in current_buy_glass:173 sum_previous += float(order[1])174 if float(sum_previous) >= BUY_ENSURE_COEF * altcoin_amount:175 while True:176 sell_price = float(order[0])177 if sell_price != 0:178 break179 else:180 logging.info('Sell price of {} = 0'.format(pair['name']))181 break182 two_h_data = polo.returnChartData(183 pair['name'], period=CANDLE_2H_PERIOD, start=last_bought_date - CANDLE_2H_PERIOD)[:-1]184 candles_2h_data = [185 {'high': float(candle['high']), 'low': float(candle['low']), 'volume': float(candle['volume']),186 'close': float(candle['close']), 'open': float(candle['open'])}187 for candle in two_h_data188 ]189 first_candle_condition = True if len(candles_2h_data) == 1 and is_green(190 candles_2h_data[0]) and is_hummer(candles_2h_data[0]) else False191 second_candle_condition = False192 if len(candles_2h_data) == 2 and ((is_green(candles_2h_data[0]) and is_green(193 candles_2h_data[1]) and ((is_simple(candles_2h_data[0]) and is_simple(194 candles_2h_data[1]) and not is_raise_vol(candles_2h_data[0], candles_2h_data[1])) or (195 is_simple(candles_2h_data[0]) and is_dodge(candles_2h_data[1])) or (196 is_sword(candles_2h_data[0]) and is_hummer(197 candles_2h_data[1])))) or (not is_green(candles_2h_data[0]) and is_green(198 candles_2h_data[1]) and ((is_simple(candles_2h_data[0]) and is_hummer(199 candles_2h_data[1]) and not is_raise_vol(candles_2h_data[0], candles_2h_data[1])) or (200 is_hummer(candles_2h_data[0]) and is_simple(201 candles_2h_data[1]) and not is_raise_vol(202 candles_2h_data[0], candles_2h_data[1])))) or (203 not is_green(candles_2h_data[0]) and not is_green(204 candles_2h_data[1]) and is_sword(candles_2h_data[0]) and is_simple(205 candles_2h_data[1])) or (is_green(candles_2h_data[0]) and not is_green(206 candles_2h_data[1]) and is_hummer(candles_2h_data[0]) and is_simple(207 candles_2h_data[0]) and not is_raise_vol(candles_2h_data[0], candles_2h_data[1]))):208 second_candle_condition = True209 third_candle_condition = False210 if len(candles_2h_data) == 3 and ((is_green(candles_2h_data[0]) and not is_green(211 candles_2h_data[1]) and not is_green(candles_2h_data[2]) and is_simple(212 candles_2h_data[1]) and ((is_hummer(candles_2h_data[0]) and is_simple(candles_2h_data[2])) or (213 is_sword(candles_2h_data[0]) and is_sword(candles_2h_data[2])))) or (214 is_green(candles_2h_data[0]) and not is_green(215 candles_2h_data[1]) and is_green(candles_2h_data[2]) and is_simple(216 candles_2h_data[0]) and is_simple(candles_2h_data[1]) and is_sword(217 candles_2h_data[2])) or (218 is_green(candles_2h_data[0]) and is_green(219 candles_2h_data[1]) and is_green(candles_2h_data[2]) and is_simple(220 candles_2h_data[0]) and is_hummer(221 candles_2h_data[1]) and is_simple(candles_2h_data[2]))):222 third_candle_condition = True223 224 fourth_candle_condition = False225 if len(candles_2h_data) == 4 and ((is_green(candles_2h_data[0]) and is_green(226 candles_2h_data[1]) and is_green(candles_2h_data[2]) and is_green(227 candles_2h_data[3]) and is_simple(candles_2h_data[0]) and is_simple(228 candles_2h_data[1]) and is_hummer(candles_2h_data[2]) and is_sword(candles_2h_data[3])) or (229 is_green(candles_2h_data[0]) and is_green(230 candles_2h_data[1]) and is_green(231 candles_2h_data[2]) and not is_green(232 candles_2h_data[3]) and is_simple(candles_2h_data[0]) and is_simple(233 candles_2h_data[1]) and is_simple(candles_2h_data[2]) and is_sword(234 candles_2h_data[3])) or (is_green(candles_2h_data[0]) and is_green(235 candles_2h_data[1]) and not is_green(236 candles_2h_data[2]) and not is_green(237 candles_2h_data[3]) and is_simple(candles_2h_data[0]) and is_simple(238 candles_2h_data[1]) and is_simple(candles_2h_data[2]) and is_simple(candles_2h_data[3]))):239 fourth_candle_condition = True240 if (time.time() - last_bought_date >= (CANDLE_4H_PERIOD * PERIOD_MOD) or sell_price < STOP_LOSS *241 pair['price'] or sell_price > TAKE_PROFIT * pair['price']) or first_candle_condition or \242 second_candle_condition or third_candle_condition or fourth_candle_condition:243 polo.sell(pair['name'], sell_price, altcoin_amount)244 logging.info(245 'Selling {} {}. Price: {}'.format(altcoin_amount, pair['name'].split('_')[-1], sell_price))246 gm = Gmail(GMAIL_USER, GMAIL_PASSWORD)247 gm.send_message('SELL_DAILY', 'Selling {} {}. Price: {}. Time: {}'.format(248 altcoin_amount, pair['name'].split('_')[-1], sell_price, datetime.datetime.now()))249 if float(polo.returnBalances()[pair['name'].split('_')[-1]]) > 0:250 null_balances_pairs += 1251 if (time.time() - float(last_bought_date)) >= (CANDLE_4H_PERIOD * PERIOD_MOD) and null_balances_pairs == 0:252 with open(PROJECT_PATH + 'bot_daily_btc_pairs.json', 'w') as f:...

Full Screen

Full Screen

resnet.py

Source:resnet.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2"""3LICENSE: MulanPSL24AUTHOR: cnhemiya@qq.com5DATE: 2022-05-06 22:416文档说明: ResNet 网络模型7"""8import paddle9import paddle.nn as nn10import paddle.nn.functional as F11class ResNetBlock(nn.Layer):12 """13 ResNetBlock 模块14 """15 def __init__(self, channels, stride=1, sample_stride=2, is_sample=False, is_simple=False):16 """17 ResNetBlock 模块18 Args:19 channels (list|tuple): 3个, 0输入通道, 1中间通道, 2输出通道20 stride (int, optional): 模块步幅,默认 1.21 sample_stride (int, optional): 采样模块步幅,默认 222 is_sample (bool, optional): 是否采样模块,默认 False, 默认 不是采样模块23 is_simple (bool, optional): 是否简易模块,默认 False, 默认 不是简易模块24 """25 super(ResNetBlock, self).__init__()26 self.is_sample = is_sample # 是否采样模块27 self.is_simple = is_simple # 是否简易模块28 in_channels = channels[0] # 输入通道29 mid_channels = channels[1] # 中间通道30 out_channels = channels[2] # 输出通道31 # 残差模块32 self.block = nn.Sequential()33 if (is_simple):34 # 简易模块35 self.block = nn.Sequential(36 nn.Conv2D(in_channels=in_channels, out_channels=mid_channels,37 kernel_size=3, stride=stride, padding=1),38 nn.BatchNorm(num_channels=mid_channels),39 nn.ReLU(),40 nn.Conv2D(in_channels=mid_channels, out_channels=out_channels,41 kernel_size=3, stride=1, padding=1),42 nn.BatchNorm(num_channels=out_channels)43 )44 else:45 # 正常模块46 self.block = nn.Sequential(47 nn.Conv2D(in_channels=in_channels, out_channels=mid_channels,48 kernel_size=1, stride=1, padding=0),49 nn.BatchNorm(num_channels=mid_channels),50 nn.ReLU(),51 nn.Conv2D(in_channels=mid_channels, out_channels=mid_channels,52 kernel_size=3, stride=stride, padding=1),53 nn.BatchNorm(num_channels=mid_channels),54 nn.ReLU(),55 nn.Conv2D(in_channels=mid_channels, out_channels=out_channels,56 kernel_size=1, stride=1, padding=0),57 nn.BatchNorm(num_channels=out_channels)58 )59 if (is_sample):60 # 采样模块61 self.sample_block = nn.Sequential(62 nn.Conv2D(in_channels=in_channels, out_channels=out_channels,63 kernel_size=1, stride=sample_stride, padding=0),64 nn.BatchNorm(num_channels=out_channels)65 )66 def forward(self, x):67 residual = x68 y = self.block(x)69 if (self.is_sample):70 residual = self.sample_block(x)71 x = paddle.add(x=residual, y=y)72 x = F.relu(x)73 return x74class ResNet(nn.Layer):75 """76 ResNet 网络模型77 输入图像大小为 224 x 22478 """79 def __init__(self, blocks, num_classes=10, is_simple=False):80 """81 ResNet 网络模型82 Args:83 blocks (list|tuple): 每模块数量84 num_classes (int, optional): 分类数量, 默认 1085 is_simple (bool, optional): 是否简易模块,默认 False, 默认 不是简易模块86 Raises:87 Exception: 分类数量 num_classes < 288 """89 super(ResNet, self).__init__()90 if num_classes < 2:91 raise Exception(92 "分类数量 num_classes 必须大于等于 2: {}".format(num_classes))93 self.num_classes = num_classes # 分类数量94 self.is_simple = is_simple # 是否简易模块95 # 简易模块通道, [0输入通道, 1中间通道, 2输出通道]96 self.simple_channels = [[64, 64, 128],97 [128, 128, 256],98 [256, 256, 512],99 [512, 512, 512]]100 # 正常模块通道, [0输入通道, 1中间通道, 2输出通道]101 self.base_channels = [[64, 64, 256],102 [256, 128, 512],103 [512, 256, 1024],104 [1024, 512, 2048]]105 # 输入模块106 self.in_block = nn.Sequential(107 nn.Conv2D(in_channels=3, out_channels=64,108 kernel_size=7, stride=2, padding=3),109 nn.BatchNorm(num_channels=64),110 nn.ReLU(),111 nn.MaxPool2D(kernel_size=3, stride=2, padding=1)112 )113 # 处理模块114 self.block = self.make_blocks(blocks)115 # 输出模块116 self.avg_pool = nn.AvgPool2D(kernel_size=7, stride=1)117 self.features = 512 if is_simple else 2048118 self.fc = nn.Linear(self.features, num_classes)119 def forward(self, x):120 x = self.in_block(x)121 x = self.block(x)122 x = self.avg_pool(x)123 # flatten 根据给定的 start_axis 和 stop_axis 将连续的维度展平124 x = paddle.flatten(x, start_axis=1, stop_axis=-1)125 x = self.fc(x)126 return x127 def make_blocks(self, blocks):128 """129 生成所有模块130 Args:131 blocks (list|tuple): 每模块数量132 Returns:133 paddle.nn.Sequential: 所有模块顺序连接134 """135 seq = []136 is_in_block = True137 for block_index in range(len(blocks)):138 is_first_block = True139 for i in range(blocks[block_index]):140 seq.append(self.make_one_block(block_index=block_index,141 is_in_block=is_in_block, is_first_block=is_first_block))142 is_first_block = False143 is_in_block = False144 return nn.Sequential(*seq)145 def make_one_block(self, block_index: int, is_in_block: bool, is_first_block: bool):146 """147 生成一个模块148 Args:149 block_index (int): 模块索引150 is_in_block (bool): 是否残差输入模块151 is_first_block (bool): 是否第一模块152 Returns:153 ResNetBlock: 残差模块154 """155 net = None156 stride = 1157 sample_stride = 2158 if is_in_block:159 stride = 1 if is_first_block else 1160 sample_stride = 1 if is_first_block else 2161 else:162 stride = 2 if is_first_block else 1163 sample_stride = 2164 channels1 = self.simple_channels[block_index] if self.is_simple else self.base_channels[block_index]165 if is_first_block:166 net = ResNetBlock(channels=channels1, stride=stride, sample_stride=sample_stride,167 is_sample=is_first_block, is_simple=self.is_simple)168 else:169 channels2 = [channels1[2], channels1[1], channels1[2]]170 net = ResNetBlock(channels=channels2, stride=stride, sample_stride=sample_stride,171 is_sample=is_first_block, is_simple=self.is_simple)172 return net173def get_resnet(num_classes: int, resnet=50):174 """175 获取 ResNet 网络模型176 Args:177 num_classes (int, optional): 分类数量178 resnet (int, optional): ResNet模型选项, 默认 50, 可选 18, 34, 50, 101, 152179 Returns:180 ResNet: ResNet 网络模型181 """182 if resnet not in [18, 34, 50, 101, 152]:183 raise Exception(184 "resnet 可选 18, 34, 50, 101, 152, 实际: {}".format(resnet))185 net = None186 if resnet == 18:187 net = ResNet([2, 2, 2, 2], num_classes, is_simple=True)188 elif resnet == 34:189 net = ResNet([3, 4, 6, 3], num_classes, is_simple=True)190 elif resnet == 50:191 net = ResNet([3, 4, 6, 3], num_classes, is_simple=False)192 elif resnet == 101:193 net = ResNet([3, 4, 23, 3], num_classes, is_simple=False)194 elif resnet == 152:195 net = ResNet([3, 8, 36, 3], num_classes, is_simple=False)...

Full Screen

Full Screen

consumer_groups.py

Source:consumer_groups.py Github

copy

Full Screen

...56 @property57 def id(self) -> str:58 return self.__id59 @property60 def is_simple(self) -> str:61 return self.__is_simple62 @property63 def partition_assignor(self) -> str:64 return self.__partition_assignor65 @property66 def state(self) -> str:67 return self.__state68 @property69 def broker_coordinator(self) -> str:70 return f'{kConn.kafka_rest_api}/{self.__broker_coordinator}'71 @property72 def consumers_url(self) -> str:73 74 return f'{kConn.kafka_rest_api}/{self.__consumers_url}'...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Sure automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful