Skip to content

Commit

Permalink
Merge pull request #48 from ricardospinoza/main
Browse files Browse the repository at this point in the history
Melhorias na estrategia de exemplo
  • Loading branch information
ricardospinoza authored Dec 11, 2023
2 parents d96dff3 + 761a39a commit e1acbb7
Show file tree
Hide file tree
Showing 3 changed files with 381 additions and 21 deletions.
55 changes: 36 additions & 19 deletions example/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import time
import shutup
import random
import sys
import asyncio
import schedule
from termcolor import colored
Expand All @@ -20,6 +21,7 @@
last_action = None
count_sequence_loss = 1
is_trade_open = False
result_trade = None
# countSequenceLossTrend = 0

# management risk
Expand Down Expand Up @@ -132,9 +134,9 @@ async def trade_and_check():
global count_sequence_loss
while balance >= 1:
amount = 1
if count_sequence_loss > 0:
# amount = countSequenceLoss + countSequenceLoss #martigale
amount = 2
#if count_sequence_loss > 0:
# # amount = countSequenceLoss + countSequenceLoss #martigale
# amount = 2

if last_action is None:
action = random.choice([OperationType.CALL_GREEN, OperationType.PUT_RED])
Expand Down Expand Up @@ -185,7 +187,7 @@ async def trade_and_check():
client.close()


async def management_risk(result_trade):
async def management_risk():
global valor_entrada_em_operacao
global valor_entrada_inicial
global limite_wins_sequencias
Expand All @@ -198,8 +200,9 @@ async def management_risk(result_trade):
global valor_total_credito_win
global valor_total_debito_loss
global count_gale
global result_trade

if result_trade: # win
if result_trade is not None and result_trade: # win
valor_total_credito_win = valor_total_credito_win + valor_entrada_em_operacao
count_win = count_win + 1
count_loss = 0
Expand Down Expand Up @@ -228,7 +231,7 @@ async def management_risk(result_trade):

#Qndo der loss mantém o valor
#Próxima entrada = entrada inicial
if not result_trade: #loss
if result_trade is not None and not result_trade: #loss
valor_total_debito_loss = valor_total_debito_loss - valor_entrada_em_operacao
count_loss = count_loss + 1
count_loss_print = count_loss_print + 1
Expand All @@ -242,11 +245,23 @@ async def management_risk(result_trade):

print(f'\nPróxima entrada: {valor_entrada_em_operacao}\nLucro atual: {lucro}\nWins: {count_win_print}\nLoss: {count_loss_print}\n')

balance = await client.get_balance()
#valida disponibilidade de saldo para entrada
if balance <= valor_entrada_em_operacao:
print(colored("[INFO]: ", "blue"), "Balance: ", balance, " <= ", valor_entrada_em_operacao)

async def wait_for_input_exceeding_30_seconds_limit():
if balance >= valor_entrada_inicial:
print(colored("[INFO]: ", "blue"), "Balance: ", balance, " >= ", valor_entrada_inicial)
valor_entrada_em_operacao = valor_entrada_inicial
if balance < valor_entrada_inicial:
print(colored("[INFO]: ", "blue"), "Balance: ", balance, " < ", valor_entrada_inicial)
valor_entrada_em_operacao = 1 #minimo de entrada


async def wait_for_input_exceeding_x_seconds_limit(secounds=30):
while True:
now = datetime.datetime.now()
if now.second < 30:
if now.second < secounds:
return # Returns when it's the right time to proceed
await asyncio.sleep(0.5)

Expand All @@ -258,10 +273,11 @@ async def strategy_random():
balance = await client.get_balance()
print(colored("[INFO]: ", "blue"), "Balance: ", balance)
global last_action
global count_sequence_loss
#global count_sequence_loss
global count_gale
global valor_entrada_em_operacao
global is_trade_open
global result_trade

while balance >= 1:
if last_action is None:
Expand All @@ -273,10 +289,11 @@ async def strategy_random():
global CONST_ASSET
asset, asset_open = check_asset(CONST_ASSET)

await wait_for_input_exceeding_30_seconds_limit()
await wait_for_input_exceeding_x_seconds_limit(30) #waiting for secounds

if asset_open[2] and not is_trade_open:
print(colored("[INFO]: "), "OK: Asset is open")
await management_risk()
status, trade_info = await client.trade(
action, valor_entrada_em_operacao, asset, DurationTime.ONE_MINUTE
)
Expand All @@ -290,19 +307,18 @@ async def strategy_random():
is_trade_open = False
print(colored("[INFO]: ", "green"), f"Win -> Profit: {client.get_profit()}")
last_action = action
count_sequence_loss = 0
#count_sequence_loss = 0
else:
is_trade_open = False
print(colored("[INFO]: ", "light_red"), f"Loss -> Loss: {client.get_profit()}")
count_sequence_loss += 1
#count_sequence_loss += 1
count_gale += 1
if count_sequence_loss > 1:
if last_action == OperationType.CALL_GREEN:
last_action = OperationType.PUT_RED
else:
last_action = OperationType.CALL_GREEN
count_sequence_loss = 0
await management_risk(result_trade=result_trade)
#if count_sequence_loss > 1:
if last_action == OperationType.CALL_GREEN:
last_action = OperationType.PUT_RED
else:
last_action = OperationType.CALL_GREEN
#count_sequence_loss = 0
else:
if is_trade_open:
print(colored("[INFO]: ", "blue"), "Trade in progress. Not permited open new trade. waiting current operation.")
Expand All @@ -314,6 +330,7 @@ async def strategy_random():
pass
else:
print(colored("[WARN]: ", "light_red"), "No balance available :(")
sys.exit(2)
client.close()


Expand Down
3 changes: 1 addition & 2 deletions quotexpy/expiration.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
import pytz
from datetime import datetime, timedelta

TIME_ZONE = "Etc/GMT+3"

TIME_ZONE = "Etc/GMT+0"

# def get_timestamp() -> int:
# return calendar.timegm(time.gmtime())
Expand Down
Loading

0 comments on commit e1acbb7

Please sign in to comment.