Esempio n. 1
0
    def __init__(self, product_id: str, expiry: int):
        assert(isinstance(product_id, str))
        assert(isinstance(expiry, int))

        self.gdax_price_client = GdaxPriceClient(ws_url=GDAX_WS_URL,
                                                 product_id=product_id,
                                                 expiry=expiry)
Esempio n. 2
0
class GdaxPriceFeed(PriceFeed):
    logger = logging.getLogger()

    def __init__(self, product_id: str, expiry: int):
        assert (isinstance(product_id, str))
        assert (isinstance(expiry, int))

        self.gdax_price_client = GdaxPriceClient(ws_url=GDAX_WS_URL,
                                                 product_id=product_id,
                                                 expiry=expiry)

    def get_price(self) -> Price:
        gdax_price = self.gdax_price_client.get_price()

        if gdax_price:
            return Price(buy_price=Wad.from_number(gdax_price),
                         sell_price=Wad.from_number(gdax_price))

        else:
            return Price(buy_price=None, sell_price=None)

    def get_midpoint_price(self) -> Price:
        gdax_midpoint_price = self.gdax_price_client.get_obook_price()

        if gdax_midpoint_price:
            return Price(buy_price=Wad.from_number(gdax_midpoint_price),
                         sell_price=Wad.from_number(gdax_midpoint_price))

        else:
            return Price(buy_price=None, sell_price=None)
Esempio n. 3
0
def test_gdax_price_feed_client():

    logging.basicConfig(format='%(asctime)-15s %(levelname)-8s %(message)s', level=logging.DEBUG)
    logging.getLogger('urllib3.connectionpool').setLevel(logging.INFO)
    logging.getLogger('requests.packages.urllib3.connectionpool').setLevel(logging.INFO)

    price_client = GdaxPriceClient(GDAX_WS_URL, "ETH-USD", 120)

    while True:
        price = price_client.get_price()
        logging.info(f"Current price is: {price}")
        if price is not None:
            break

        time.sleep(1)