diff --git a/README.md b/README.md index 00cb15a..6c34e9f 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,10 @@ r.get_auction_history("BTCUSD") # Alternatively, it can be specified for a specific date r.get_auction_history("BTCUSD", since="17/06/2017") ``` +- [get_ticker_v2](https://docs.gemini.com/rest-api/?python#ticker-v2) +```python +r.get_ticker_v2("BTCUSD") +``` ### PrivateClient This endpoint requires both a public and private key to access @@ -129,10 +133,10 @@ r.withdraw_to_address("ETH", "0x0287b1B0032Dc42c16640F71BA06F1A87C3a7101", "20") ```python r.revive_hearbeat() ``` -### Websocket Client +### Websocket Client If you'd prefer to recieve live updates you can either choose to subsribe to the public market data websocket or the private order events websocket. For more information about the difference between the two websockets visit the official [Gemini documentation](https://docs.gemini.com/websocket-api). -### MarketData Websocket +### MarketData Websocket Market data is a public API that streams all the market data on a given symbol. ```python import gemini @@ -140,7 +144,7 @@ r = gemini.MarketDataWS('btcusd') # Alternatively, for a sandbox environment, set sandbox=True r = gemini.MarketDataWS('btcusd', sandbox=True) ``` -#### MarketData Websocket Methods +#### MarketData Websocket Methods - get list of recorded trades ```python r.trades @@ -195,11 +199,11 @@ r = gemini.OrderEventsWS("EXAMPLE_PUBLIC_KEY", "EXAMPLE_PRIVATE_KEY") r = gemini.OrderEventsWS("EXAMPLE_PUBLIC_KEY", "EXAMPLE_PRIVATE_KEY", sandbox=True) ``` -#### OrderEvents Websocket Methods +#### OrderEvents Websocket Methods - get order types ```python -"""All trades are categorised in terms of either subscription_ack', 'heartbeat', -'initial', 'accepted','rejected', 'booked', 'fill', 'cancelled', +"""All trades are categorised in terms of either subscription_ack', 'heartbeat', +'initial', 'accepted','rejected', 'booked', 'fill', 'cancelled', 'cancel_rejected' or 'closed'. The following will print these types""" r.get_order_types ``` @@ -221,7 +225,7 @@ r.export_to_csv(r'/c/Users/user/Documents', 'accepted') ``` - export recorded trades to xml ```python -# Arguments are: directory and type. +# Arguments are: directory and type. # The following will export all 'accepted' orders to a xml format r.export_to_xml(r'/c/Users/user/Documents', 'accepted') ``` @@ -236,12 +240,12 @@ r.export_to_xml(r'/c/Users/user/Documents', 'accepted') # Change Log *0.2.0* -- Created BaseWebsocket class +- Created BaseWebsocket class - Created OrderEventsWS class to interact with the order events websocket -- Created MarketDataWS class to interact with the market data websocket +- Created MarketDataWS class to interact with the market data websocket - Added greater support for heartbeat API's - Improved the Cached metaclass -- Added support for sandbox urls +- Added support for sandbox urls *0.0.1* -- Original release \ No newline at end of file +- Original release diff --git a/gemini/public_client.py b/gemini/public_client.py index 1b61a6a..b156197 100644 --- a/gemini/public_client.py +++ b/gemini/public_client.py @@ -32,7 +32,7 @@ def symbols(self): @typeassert(product_id=str) def symbol_details(self, product_id): """ - This endpoint retrieves extra detail on supported symbols, such as + This endpoint retrieves extra detail on supported symbols, such as minimum order size, tick size, quote increment and more. Args: @@ -51,7 +51,8 @@ def symbol_details(self, product_id): "wrap_enabled":false } """ - r = requests.get(self.public_base_url + '/symbols/details/' + product_id) + r = requests.get(self.public_base_url + + '/symbols/details/' + product_id) return r.json() @typeassert(product_id=str) @@ -174,3 +175,58 @@ def get_auction_history(self, product_id, since=None): r = requests.get(self.public_base_url + '/auction/{}?since={}'.format( product_id, int(self.timestamp))) return r.json() + + @typeassert(product_id=str) + def get_ticker_v2(self, product_id): + """ + This endpoint retrieves information about recent trading + activity for the symbol. + + Args: + product_id(str): Can be any value in self.symbols() + + Returns: + dict: the Open, High, and Low price from 24 hours ago, + the Close price (most recent trade), + Hourly prices descending for past 24 hours, + and the current bid and ask + + example: { + "symbol": "BTCUSD", + "open": "9121.76", + "high": "9440.66", + "low": "9106.51", + "close": "9347.66", + "changes": [ + "9365.1", + "9386.16", + "9373.41", + "9322.56", + "9268.89", + "9265.38", + "9245", + "9231.43", + "9235.88", + "9265.8", + "9295.18", + "9295.47", + "9310.82", + "9335.38", + "9344.03", + "9261.09", + "9265.18", + "9282.65", + "9260.01", + "9225", + "9159.5", + "9150.81", + "9118.6", + "9148.01" + ], + "bid": "9345.70", + "ask": "9347.67" + } + """ + r = requests.get('https://api.gemini.com/v2' + + '/ticker/' + product_id) + return r.json() diff --git a/tests/test_public_client.py b/tests/test_public_client.py index c81c248..e7f0e99 100644 --- a/tests/test_public_client.py +++ b/tests/test_public_client.py @@ -1,6 +1,6 @@ +from gemini import PublicClient import sys sys.path.insert(0, '..') -from gemini import PublicClient def client(): @@ -57,3 +57,16 @@ def test_symbol_details(self): assert "min_order_size" in symbol_details assert "status" in symbol_details assert "wrap_enabled" in symbol_details + + def test_get_ticker_v2(self): + r = client() + ticker_v2 = r.get_ticker_v2("BTCUSD") + assert type(ticker_v2) is dict + assert "symbol" in ticker_v2 + assert "open" in ticker_v2 + assert "high" in ticker_v2 + assert "low" in ticker_v2 + assert "close" in ticker_v2 + assert "changes" in ticker_v2 + assert "bid" in ticker_v2 + assert "ask" in ticker_v2