当前位置: 首页>>代码示例>>Python>>正文


Python client.RemoteDisconnected方法代码示例

本文整理汇总了Python中http.client.RemoteDisconnected方法的典型用法代码示例。如果您正苦于以下问题:Python client.RemoteDisconnected方法的具体用法?Python client.RemoteDisconnected怎么用?Python client.RemoteDisconnected使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在http.client的用法示例。


在下文中一共展示了client.RemoteDisconnected方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_ord_book

# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import RemoteDisconnected [as 别名]
def get_ord_book(self, pair):
        error_count = 0
        book_returned = False
        ord_book = {}
        fail = False
        self.lg.log('Getting order book for pair ' + pair)

        while not book_returned and not fail:
            try:
                ord_book = client.depth(pair, limit=5)
            except (MalformedRequest, InternalError, StatusUnknown,
                    ConnectionError, RemoteDisconnected, ProtocolError, HTTPException) as e:
                self.lg.log(str(e) + ' ' + str(e.__traceback__) + ' ' + 'Order book retrieve for ' + pair +
                            ' failed, keep trying')
                error_count += 1
                time.sleep(1)
                client.set_offset()
            else:
                book_returned = True
            finally:
                if error_count >= 5:
                    self.lg.log("Tried to get order book 5 times and failed")
                    fail = True
        return {"ord_book": ord_book, "fail_flag": fail} 
开发者ID:Reidmcc,项目名称:Binance-bot,代码行数:26,代码来源:mult_arbit.py

示例2: get_open_ords

# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import RemoteDisconnected [as 别名]
def get_open_ords(self, pair):
        error_count = 0
        got_ords = False
        open_ords = {}
        # self.lg.log('Getting open orders for pair ' + pair)
        while not got_ords and error_count < 10:
            try:
                open_ords = client.openOrders(pair)
            except (
            MalformedRequest, InternalError, StatusUnknown, ConnectionError, RemoteDisconnected, ProtocolError,
            HTTPException) as e:
                self.lg.log(str(e) + ' ' + str(e.__traceback__) + ' ' + 'Open order request failed try again')
                error_count += 1
                time.sleep(1)
                client.set_offset()
            else:
                got_ords = True
            finally:
                if error_count >= 10:
                    self.lg.log('Open orders check failed 10 times')
        return open_ords 
开发者ID:Reidmcc,项目名称:Binance-bot,代码行数:23,代码来源:mult_arbit.py

示例3: route_check_altfirst

# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import RemoteDisconnected [as 别名]
def route_check_altfirst(self, pair_1, pair_2, pair_3, pair_1_pip, pair_2_pip, pair_3_pip):
        calc_done = False
        route_gain = -1
        bid_p1 = -1
        ask_p2 = -1
        bid_p3 = -1
        while calc_done == False:
            try:
                bid_p1 = float(client.depth(pair_1, limit = 5)['bids'][0][0])
                ask_p2 = float(client.depth(pair_2, limit = 5)['asks'][0][0])
                bid_p3 = float(client.depth(pair_3, limit = 5)['bids'][0][0])
            except (MalformedRequest, InternalError, StatusUnknown, ConnectionError, RemoteDisconnected, ProtocolError, HTTPException) as e:
                self.lg.log(str(e) + ' ' + str(e.__traceback__))
                client.set_offset()
            else:
                route_gain = (1 / (bid_p1 + pair_1_pip)) * (ask_p2 - pair_2_pip)  / (bid_p3 + pair_3_pip)
                calc_done = True

        return (route_gain, bid_p1, ask_p2, bid_p3) 
开发者ID:Reidmcc,项目名称:Binance-bot,代码行数:21,代码来源:data_checks.py

示例4: route_check_altlast

# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import RemoteDisconnected [as 别名]
def route_check_altlast(self, pair_1, pair_2, pair_3, pair_1_pip, pair_2_pip, pair_3_pip):
        calc_done = False
        route_gain = -1
        bid_p2 = -1
        ask_p3 = -1
        ask_p1 = -1
        while calc_done == False:
            try:
                ask_p1 = float(client.depth(pair_1, limit = 5)['asks'][0][0]) - float(pair_1_pip)
                bid_p2 = float(client.depth(pair_2, limit = 5)['bids'][0][0]) + float(pair_2_pip)
                ask_p3 = float(client.depth(pair_3, limit = 5)['asks'][0][0]) - float(pair_3_pip)
            except (MalformedRequest, InternalError, StatusUnknown, ConnectionError, RemoteDisconnected, ProtocolError, HTTPException) as e:
                self.lg.log(str(e) + ' ' + str(e.__traceback__))
                client.set_offset()
            else:
                # route_gain = ((ask_p1 - pair_1_pip) / ((bid_p2 + pair_2_pip)) * (ask_p3 - pair_3_pip))
                route_gain = ask_p1  / bid_p2 * ask_p3
                calc_done = True
        return (route_gain, ask_p1, bid_p2, ask_p3) 
开发者ID:Reidmcc,项目名称:Binance-bot,代码行数:21,代码来源:data_checks.py

示例5: route_check_alt_last_lastprice

# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import RemoteDisconnected [as 别名]
def route_check_alt_last_lastprice(self, pair_1, pair_2, pair_3, pair_1_pip, pair_2_pip, pair_3_pip):
        route_gain = -1
        calc_done = False
        t_1_price = -1
        t_2_price = -1
        t_3_price = -1
        while calc_done == False:
            try:
                prices = client.allPrices()
                for p in prices:
                    symbol = p['symbol']
                    if symbol == pair_1:
                        t_1_price =  float(p['price'])
                    if symbol == pair_2:
                        t_2_price =  float(p['price'])
                    if symbol == pair_3:
                        t_3_price =  float(p['price'])
            except (MalformedRequest, InternalError, StatusUnknown, ConnectionError, RemoteDisconnected, ProtocolError, HTTPException) as e:
                self.lg.log(str(e) + ' ' + str(e.__traceback__))
                client.set_offset()
            else:
                route_gain = (t_1_price / (t_2_price) * t_3_price)
                calc_done = True

        return route_gain 
开发者ID:Reidmcc,项目名称:Binance-bot,代码行数:27,代码来源:data_checks.py

示例6: route_check_t3_ask_oth_lastprice

# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import RemoteDisconnected [as 别名]
def route_check_t3_ask_oth_lastprice(self, pair_1, pair_2, pair_3, pair_1_pip, pair_2_pip, pair_3_pip):
        route_gain = -1
        ask_p3 = -1
        calc_done = False
        t_1_price = -1
        t_2_price = -1
        while calc_done == False:
            try:
                prices = client.allPrices()
                for p in prices:
                    symbol = p['symbol']
                    if symbol == pair_1:
                        t_1_price = float(p['price']) - pair_1_pip
                    if symbol == pair_2:
                        t_2_price = float(p['price']) + pair_2_pip

                ask_p3 = float(client.depth(pair_3, limit=5)['asks'][0][0]) - pair_3_pip
            except (MalformedRequest, InternalError, StatusUnknown, ConnectionError, RemoteDisconnected, ProtocolError, HTTPException) as e:
                self.lg.log(str(e) + ' ' + str(e.__traceback__))
                client.set_offset()
            else:
                route_gain = t_1_price / t_2_price * ask_p3
                calc_done = True

        return (route_gain, t_1_price, t_2_price, ask_p3) 
开发者ID:Reidmcc,项目名称:Binance-bot,代码行数:27,代码来源:data_checks.py

示例7: set_offset

# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import RemoteDisconnected [as 别名]
def set_offset(self):
        got_time = False
        while not got_time:
            try:
                cur_time = int(time.time() * 1000)
                bintime = int(self.time()['serverTime'])
                time_diff = cur_time - bintime
                if time_diff > 0:
                    self.time_offset = time_diff
                else:
                    self.time_offset = 500
            except (InternalError, StatusUnknown,
                        ConnectionError, RemoteDisconnected, ProtocolError, HTTPException) as e:
                print(str(e) + ' ' + str(e.__traceback__) + 'Time check failed, retry')
                time.sleep(.5)
            else:
                got_time = True 
开发者ID:Reidmcc,项目名称:Binance-bot,代码行数:19,代码来源:api.py

示例8: get_entries_from_api

# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import RemoteDisconnected [as 别名]
def get_entries_from_api(word, url):
    if "YOUR_KEY_HERE" in url:
        return []
    try:
        req = urllib.request.Request(url, headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:62.0)'
                                                                 ' Gecko/20100101 Firefox/62.0'})
        returned = urllib.request.urlopen(req).read()
        if "Invalid API key" in returned.decode("UTF-8"):
            showInfo("API key '%s' is invalid. Please double-check you are using the key labeled \"Key (Dictionary)\". "
                     "A web browser with the web page that lists your keys will open." % url.split("?key=")[1])
            webbrowser.open("https://www.dictionaryapi.com/account/my-keys.htm")
            return []
        if "Results not found" in returned.decode("UTF-8"):
            return []
        etree = ET.fromstring(returned)
        return etree.findall("entry")
    except URLError:
        return []
    except (ET.ParseError, RemoteDisconnected):
        showInfo("Couldn't parse API response for word '%s'. "
                 "Please submit an issue to the AutoDefine GitHub (a web browser window will open)." % word)
        webbrowser.open("https://github.com/z1lc/AutoDefine/issues/new?title=Parse error for word '%s'"
                        "&body=Anki Version: %s%%0APlatform: %s %s%%0AURL: %s%%0AStack Trace: %s"
                        % (word, version, platform.system(), platform.release(), url, traceback.format_exc()), 0, False) 
开发者ID:z1lc,项目名称:AutoDefine,代码行数:26,代码来源:autodefine.py

示例9: test_closes_connection_without_content_length

# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import RemoteDisconnected [as 别名]
def test_closes_connection_without_content_length(self):
        """
        The server doesn't support keep-alive because Python's http.server
        module that it uses hangs if a Content-Length header isn't set (for
        example, if CommonMiddleware isn't enabled or if the response is a
        StreamingHttpResponse) (#28440 / https://bugs.python.org/issue31076).
        """
        conn = HTTPConnection(LiveServerViews.server_thread.host, LiveServerViews.server_thread.port, timeout=1)
        try:
            conn.request('GET', '/example_view/', headers={'Connection': 'keep-alive'})
            response = conn.getresponse().read()
            conn.request('GET', '/example_view/', headers={'Connection': 'close'})
            # macOS may give ConnectionResetError.
            with self.assertRaises((RemoteDisconnected, ConnectionResetError)):
                try:
                    conn.getresponse()
                except ConnectionAbortedError:
                    if sys.platform == 'win32':
                        self.skipTest('Ignore nondeterministic failure on Windows.')
        finally:
            conn.close()
        self.assertEqual(response, b'example view') 
开发者ID:nesdis,项目名称:djongo,代码行数:24,代码来源:tests.py

示例10: _submit_request

# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import RemoteDisconnected [as 别名]
def _submit_request(self, url, params=None, data=None,
                        headers=None, method="GET"):
        """Submits the given request, and handles the errors appropriately.

        Args:
            url (str): the request to send.
            params (dict): params to be passed along to get/post
            data (bytes): the data to include in the request.
            headers (dict): the headers to include in the request.
            method (str): the method to use for the request, "POST" or "GET".

        Returns:
            tuple of (int, str): The response status code and the json parsed
                body, or the error message.

        Raises:
            `Exception`: If any issues occur with the URL.
        """
        try:
            if method == 'POST':
                result = requests.post(
                    url, params=params, data=data, headers=headers)
            elif method == 'GET':
                result = requests.get(
                    url, params=params, data=data, headers=headers)
            result.raise_for_status()
            return (result.status_code, result.json())
        except requests.exceptions.HTTPError as excp:
            return (excp.response.status_code, excp.response.reason)
        except RemoteDisconnected as excp:
            raise Exception(excp)
        except requests.exceptions.ConnectionError as excp:
            raise Exception(
                ('Unable to connect to "{}": '
                 'make sure URL is correct').format(self.url)) 
开发者ID:hyperledger,项目名称:sawtooth-core,代码行数:37,代码来源:integration_tools.py

示例11: test_disconnected

# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import RemoteDisconnected [as 别名]
def test_disconnected(self):

        def make_reset_reader(text):
            """Return BufferedReader that raises ECONNRESET at EOF"""
            stream = io.BytesIO(text)
            def readinto(buffer):
                size = io.BytesIO.readinto(stream, buffer)
                if size == 0:
                    raise ConnectionResetError()
                return size
            stream.readinto = readinto
            return io.BufferedReader(stream)

        tests = (
            (io.BytesIO, client.RemoteDisconnected),
            (make_reset_reader, ConnectionResetError),
        )
        for stream_factory, exception in tests:
            with self.subTest(exception=exception):
                conn = FakeSocketHTTPConnection(b'', stream_factory)
                conn.request('GET', '/eof-response')
                self.assertRaises(exception, conn.getresponse)
                self.assertIsNone(conn.sock)
                # HTTPConnection.connect() should be automatically invoked
                conn.request('GET', '/reconnect')
                self.assertEqual(conn.connections, 2) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:28,代码来源:test_httplib.py

示例12: test_100_close

# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import RemoteDisconnected [as 别名]
def test_100_close(self):
        conn = FakeSocketHTTPConnection(
            b'HTTP/1.1 100 Continue\r\n'
            b'\r\n'
            # Missing final response
        )
        conn.request('GET', '/', headers={'Expect': '100-continue'})
        self.assertRaises(client.RemoteDisconnected, conn.getresponse)
        self.assertIsNone(conn.sock)
        conn.request('GET', '/reconnect')
        self.assertEqual(conn.connections, 2) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:13,代码来源:test_httplib.py

示例13: place_order_onetry

# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import RemoteDisconnected [as 别名]
def place_order_onetry(self, pair, quant, price, side, test=False):
        status = 'not_placed'
        orderID = '0'
        trade = {}

        if test:
            self.lg.log('Would have placed order as: pair = ' + pair + ', quant = ' + str(quant) + ', price = '
                        + str(price) + ', side = ' + side)
            status = 'was_tested'
        elif not test:
            self.lg.log('Placing order as pair = ' + pair + ', quant = ' + str(quant) + ', price = '
                        + str(price) + ', side = ' + side)
            try:
                if side == 'sell':
                    trade = client.newLimitSellOrder(pair, quant, price)
                elif side == 'buy':
                    trade = client.newLimitBuyOrder(pair, quant, price)
            except MalformedRequest as e:
                self.lg.log(
                    str(e) + ' ' + str(e.__traceback__) + ' Tried to place order as pair = ' + pair + ', quant = '
                    + str(quant) + ', price = ' + str(price) + ', side = ' + side)
                client.set_offset()
            except StatusUnknown as e:
                self.lg.log(
                    str(e) + ' ' + str(e.__traceback__) + 'API returned StatusUnknown, checking for placed order')
                order = self.check_for_open(pair)
                fail = order["fail_flag"]
                if not fail:
                    orderID = order["order_ID"]
                    status = order["status"]
            except (InternalError, ConnectionError, RemoteDisconnected, ProtocolError, HTTPException) as e:
                self.lg.log(
                    str(e) + ' ' + str(e.__traceback__) + " Some sort of connection or internal error occured")
            else:
                status = trade["status"]
                orderID = trade["orderId"]
        self.lg.log('Returning: orderID = ' + str(orderID) + ', status = ' + status)
        return {"orderID": orderID, "status": status} 
开发者ID:Reidmcc,项目名称:Binance-bot,代码行数:40,代码来源:mult_arbit.py

示例14: get_order_stat_remaining

# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import RemoteDisconnected [as 别名]
def get_order_stat_remaining(self, pair, Order_id):
        error_count = 0
        info_returned = False
        status = 'not_found'
        remaining = -1
        executed = -1
        fail = False

        if Order_id == 0:
            self.lg.log("Tried to check an unplaced order")
            fail = True

        while info_returned == False and not fail:
            try:
                stat_get = client.queryOrder(pair, orderId=Order_id)
            except MalformedRequest as e:
                self.lg.log(str(e) + ' ' + str(e.__traceback__) +
                            ' Order ID not found on status + remain check, keep trying')
                error_count += 1
                time.sleep(5)
                client.set_offset()
            except (
            InternalError, StatusUnknown, ConnectionError, RemoteDisconnected, ProtocolError, HTTPException) as e:
                self.lg.log(str(e) + ' ' + str(e.__traceback__))
                error_count += 1
                time.sleep(1)
            else:
                status = stat_get['status']
                remaining = float(stat_get['origQty']) - float(stat_get['executedQty'])
                executed = float(stat_get['executedQty'])
                info_returned = True
            finally:
                if error_count >= 5:
                    self.lg.log("Tried to get status/remaining 5 times and failed")
                    fail = True

        # self.lg.log('Returning: status = ' + status + ' remaining = ' + str(remaining))
        return {"status": status, "remaining": remaining, "executed": executed, "fail_flag": fail} 
开发者ID:Reidmcc,项目名称:Binance-bot,代码行数:40,代码来源:mult_arbit.py

示例15: ord_cancel

# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import RemoteDisconnected [as 别名]
def ord_cancel(self, pair, Order_id):
        ord_cancelled = False
        error_count = 0
        self.lg.log('Cancelling order ' + str(Order_id))
        while not ord_cancelled and error_count < 10:
            try:
                client.deleteOrder(pair, orderId=Order_id)
            except MalformedRequest as e:
                self.lg.log(str(e) + ' ' + str(
                    e.__traceback__) + ' ' + 'Order ID not found on cancel, try cancelling all open orders for the pair')
                client.set_offset()
                cur_open = self.get_open_ords(pair)
                if cur_open == []:
                    self.lg.log('Could not find the order, but no order open for the pair so must be cancelled')
                    ord_cancelled = True
                else:
                    for o in cur_open:
                        try:
                            client.deleteOrder(pair, orderId=o['orderId'])
                        except (MalformedRequest, InternalError, StatusUnknown, ConnectionError, RemoteDisconnected,
                                ProtocolError, HTTPException) as e:
                            self.lg.log(str(e) + ' ' + str(
                                e.__traceback__) + ' ' + 'Trying to cancel open orders after single cancel fails, wtf')
                            client.set_offset()
                    ord_cancelled = True
                error_count += 1
                time.sleep(1)
            except (
            InternalError, StatusUnknown, ConnectionError, RemoteDisconnected, ProtocolError, HTTPException) as e:
                self.lg.log(str(e) + ' ' + str(
                    e.__traceback__) + 'Internal or Unknown error while cancelling order, keep trying')
                error_count += 1
                time.sleep(1)
            else:
                ord_cancelled = True
            finally:
                if error_count >= 10:
                    self.lg.log('Order cancel failed 10 times, Order ID was: ' + str(Order_id)) 
开发者ID:Reidmcc,项目名称:Binance-bot,代码行数:40,代码来源:mult_arbit.py


注:本文中的http.client.RemoteDisconnected方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。