Skip to content

Commit

Permalink
feat: option for requests using proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
SantiiRepair committed Jan 7, 2024
1 parent 5b244db commit 52f9861
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 70 deletions.
2 changes: 1 addition & 1 deletion example/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __x__(y):
return z


client = Quotex(email="user@email.com", password="password")
client = Quotex(email="email@gmail.com", password="password")
client.debug_ws_enable = False


Expand Down
38 changes: 8 additions & 30 deletions quotexpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import math
import asyncio
import logging
from typing import Union, Dict
from collections import defaultdict
from datetime import datetime, timedelta

Expand All @@ -25,32 +26,14 @@ def truncate(f, n):


class Quotex(object):
__version__ = "1.40.0"

def __init__(self, email, password):
self.size = [
1,
5,
10,
15,
30,
60,
120,
300,
600,
900,
1800,
3600,
7200,
14400,
28800,
43200,
86400,
604800,
2592000,
]
__version__ = "1.40.3"

def __init__(self, email, password, proxy: Union[Dict, None]=None):

self.api = None
self.email = email
self.password = password
self.proxy = proxy
self.set_ssid = None
self.duration = None
self.suspend = 0.5
Expand All @@ -60,7 +43,6 @@ def __init__(self, email, password):
self.websocket_client = None
self.websocket_thread = None
self.debug_ws_enable = False
self.api = None

self.logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -152,11 +134,7 @@ async def get_candle_v2(self, asset, period, size=10):
async def connect(self):
if global_value.check_websocket_if_connect:
self.close()
self.api = QuotexAPI(
"qxbroker.com",
self.email,
self.password,
)
self.api = QuotexAPI("qxbroker.com", self.email, self.password, self.proxy)
self.api.trace_ws = self.debug_ws_enable
check, reason = await self.api.connect()
if check:
Expand Down
14 changes: 10 additions & 4 deletions quotexpy/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import logging
import urllib3
import threading
from urllib.parse import urlparse

from quotexpy import global_value
from quotexpy.http.login import Login
Expand Down Expand Up @@ -57,17 +58,23 @@ class QuotexAPI(object):
timesync = TimeSync()
candles = Candles()

def __init__(self, host, email, password, proxies=None):
def __init__(self, host, email, password, proxy=None):
"""
:param str host: The hostname or ip address of a Quotex server.
:param str email: The email of a Quotex server.
:param str password: The password of a Quotex server.
:param proxies: The proxies of a Quotex server.
"""
self._temp_status = ""
self.settings_list = {}
self.email = email
self.password = password

if proxy is not None and proxy is not "":
if urlparse(proxy).scheme == "":
raise ValueError("Proxy URL does not specify a supported protocol.")

self.proxy = proxy
self._temp_status = ""
self.settings_list = {}
self.signal_data = nested_dict(2, dict)
self.get_candle_data = {}
self.candle_v2_data = {}
Expand All @@ -79,7 +86,6 @@ def __init__(self, host, email, password, proxies=None):
self.set_ssid = None
self.user_agent = None
self.token_login2fa = None
self.proxies = proxies
self.realtime_price = {}
self.profile = Profile()

Expand Down
1 change: 0 additions & 1 deletion quotexpy/global_value.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# python
SSID = None
check_websocket_if_connect = None
ssl_Mutual_exclusion = False
Expand Down
11 changes: 8 additions & 3 deletions quotexpy/http/login.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
from typing import Union, Dict
from quotexpy.http.qxbroker import Browser


class Login(Browser):
"""Class for Quotex login resource."""

url = ""
cookies = None
ssid = None
cookies = None
base_url = "qxbroker.com"
https_base_url = f"https://{base_url}"

async def __call__(self, email, password):
"""Method to get Quotex API login http request.
async def __call__(self, email, password, proxy: Union[Dict, None]=None):
"""
Method to get Quotex API login http request.
:param str username: The username of a Quotex server.
:param str password: The password of a Quotex server.
:returns: The instance of :class:`playwright.cookies`.
"""

self.email = email
self.password = password
self.proxy = proxy

self.ssid, self.cookies = await self.get_cookies_and_ssid()
return self.ssid, self.cookies
4 changes: 2 additions & 2 deletions quotexpy/http/logout.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""Module for Quotex http login resource."""

from quotexpy.http.navigator import Browser
from quotexpy.http.navigator import Navigator


class Logout(Browser):
class Logout(Navigator):
"""Class for Quotex login resource."""

base_url = "qxbroker.com"
Expand Down
13 changes: 11 additions & 2 deletions quotexpy/http/navigator.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import random
import requests
from bs4 import BeautifulSoup
from urllib.parse import urlparse
from urllib3.util.retry import Retry
from requests.adapters import HTTPAdapter

from quotexpy.http.user_agents import agents

retry_strategy = Retry(
Expand All @@ -15,15 +17,22 @@
user_agent_list = agents.split("\n")


class Browser(object):
class Navigator(object):
def __init__(self, api):
"""
Tools for quotexpy navigation.
:param object api: The instance of :class:`quotexpy.api.QuotexAPI`.
"""
self.api = api
self.response = None
self.headers = self.get_headers()
self.session = requests.Session()
self.api.user_agent = self.headers["User-Agent"]
self.session.mount("https://", adapter)
self.session.mount("http://", adapter)
self.session.mount("https://", adapter)

if self.api.proxy:
self.session.proxies.update({urlparse(self.api.proxy).scheme: self.api.proxy["server"]})

def get_headers(self):
self.headers = {
Expand Down
10 changes: 7 additions & 3 deletions quotexpy/http/qxbroker.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,22 @@


class Browser(object):
base_url = "qxbroker.com"
https_base_url = f"https://{base_url}"
email = None
password = None

base_url = "qxbroker.com"
https_base_url = f"https://{base_url}"

proxy = None

def __init__(self, api):
self.api = api

async def run(self, playwright: Playwright) -> Tuple[Any, str]:
browser = await playwright.firefox.launch(headless=True)
browser = await playwright.firefox.launch(headless=True, proxy=self.proxy)
context = await browser.new_context()
page = await context.new_page()

await page.goto(f"{self.https_base_url}/pt/sign-in")
if page.url != f"{self.https_base_url}/pt/trade":
await page.get_by_role("textbox", name="E-mail").click()
Expand Down
24 changes: 0 additions & 24 deletions quotexpy/http/resource.py

This file was deleted.

0 comments on commit 52f9861

Please sign in to comment.