Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -129,18 +133,18 @@ 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
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
Expand Down Expand Up @@ -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
```
Expand All @@ -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')
```
Expand All @@ -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
- Original release
60 changes: 58 additions & 2 deletions gemini/public_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand Down Expand Up @@ -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()
15 changes: 14 additions & 1 deletion tests/test_public_client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from gemini import PublicClient
import sys
sys.path.insert(0, '..')
from gemini import PublicClient


def client():
Expand Down Expand Up @@ -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