| 69 | |
| 70 | @classmethod |
| 71 | async def create( |
| 72 | cls, |
| 73 | api_key: Optional[str] = None, |
| 74 | api_secret: Optional[str] = None, |
| 75 | requests_params: Optional[Dict[str, Any]] = None, |
| 76 | tld: str = "com", |
| 77 | base_endpoint: str = BaseClient.BASE_ENDPOINT_DEFAULT, |
| 78 | testnet: bool = False, |
| 79 | demo: bool = False, |
| 80 | loop=None, |
| 81 | session_params: Optional[Dict[str, Any]] = None, |
| 82 | private_key: Optional[Union[str, Path]] = None, |
| 83 | private_key_pass: Optional[str] = None, |
| 84 | https_proxy: Optional[str] = None, |
| 85 | time_unit: Optional[str] = None, |
| 86 | verbose: bool = False, |
| 87 | ): |
| 88 | self = cls( |
| 89 | api_key, |
| 90 | api_secret, |
| 91 | requests_params, |
| 92 | tld, |
| 93 | base_endpoint, |
| 94 | testnet, |
| 95 | demo, |
| 96 | loop, |
| 97 | session_params, |
| 98 | private_key, |
| 99 | private_key_pass, |
| 100 | https_proxy, |
| 101 | time_unit, |
| 102 | verbose |
| 103 | ) |
| 104 | self.https_proxy = https_proxy # move this to the constructor |
| 105 | |
| 106 | try: |
| 107 | await self.ping() |
| 108 | |
| 109 | # calculate timestamp offset between local and binance server |
| 110 | res = await self.get_server_time() |
| 111 | self.timestamp_offset = res["serverTime"] - int(time.time() * 1000) |
| 112 | |
| 113 | return self |
| 114 | except Exception: |
| 115 | # If ping throw an exception, the current self must be cleaned |
| 116 | # else, we can receive a "asyncio:Unclosed client session" |
| 117 | await self.close_connection() |
| 118 | raise |
| 119 | |
| 120 | def _init_session(self) -> aiohttp.ClientSession: |
| 121 | session = aiohttp.ClientSession( |