A python client for the Gemini API and Websocket
pip install gemini_python
This endpoint doesn't require an api-key and can be used without having a Gemini account. This README will document some of the methods and features of the class.
import gemini
r = gemini.PublicClient()
# Alternatively, for a sandbox environment, set sandbox=True
r = gemini.PublicClient(sandbox=True)
r.symbols()
r.symbol_details("BTCUSD")
r.get_ticker("BTCUSD")
r.get_current_order_book("BTCUSD")
# Will get the latest 500 trades
r.get_trade_history("BTCUSD")
# Alternatively, it can be specified for a specific date
r.get_trade_history("BTCUSD", since="17/06/2017")
# Will get the latest 500 auctions
r.get_auction_history("BTCUSD")
# Alternatively, it can be specified for a specific date
r.get_auction_history("BTCUSD", since="17/06/2017")
This endpoint requires both a public and private key to access the API. Hence, one must have an account with Gemini and register an application. So far, if the 'heartbeat' option is enabled for the API, the user must manually revive the heartbeat. Further options will be added in the future in order to avoid doing this manually.
The payload of the requests will be a JSON object. Rather than being sent as the body of the POST request, Gemini requires it to be base-64 encoded and stored as a header in the request. Adding a 'nonce' is optional for the API but is highly recommended. That's why the class will always send each request with a unique 'nonce'. An important point to note is that every argument for the methods of PrivateClient must be strings with the exception of 'options'.
import gemini
r = gemini.PrivateClient("EXAMPLE_PUBLIC_KEY", "EXAMPLE_PRIVATE_KEY")
# Alternatively, for a sandbox environment, set sandbox=True
r = gemini.PrivateClient("EXAMPLE_PUBLIC_KEY", "EXAMPLE_PRIVATE_KEY", sandbox=True)
r.new_order("BTCUSD", "200", "6000", "buy")
r.cancel_order("866403510")
r.wrap_order("GUSDUSD", "10", "buy")
r.cancel_session_orders()
r.cancel_all_orders()
r.status_of_order("866403510")
r.active_orders()
# Will get the last 500 past trades
r.get_past_trades("BTCUSD")
# Alternatively, you can set the limit_trades number to your liking
r.get_past_trades("BTCUSD", limit_trades="200")
r.get_trade_volume()
r.get_balance()
# This will create a new currency address
r.create_deposit_address("BTCUSD")
# Alternatively, you can specify the label
r.create_deposit_address("BTCUSD", label="Main Bitcoin Address")
r.withdraw_to_address("ETH", "0x0287b1B0032Dc42c16640F71BA06F1A87C3a7101", "20")
r.revive_hearbeat()
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.
Market data is a public API that streams all the market data on a given symbol.
import gemini
r = gemini.MarketDataWS('btcusd')
# Alternatively, for a sandbox environment, set sandbox=True
r = gemini.MarketDataWS('btcusd', sandbox=True)
- get list of recorded trades
r.trades
- get recorded bids
r.bids
- get recorded asks
r.asks
- get market book
r.get_market_book()
- remove a recorded price from bids or asks
# To remove a price from bids
r.remove_from_bids('10000')
# To remove a price from asks
r.remove_from_asks('10000')
- search for a particular price recorded
r.search_price('10000')
- export recorded trades to csv
r.export_to_csv(r'/c/Users/user/Documents')
- export recorded trades to xml
r.export_to_xml(r'/c/Users/user/Documents')
Order events is a private API that gives you information about your orders in real time.When you connect, you get a book of your active orders. Then in real time you'll get information about order events like:
- when your orders are accepted by the exchange
- when your orders first appear on the book
- fills
- cancels
- and more.
Support for subscription filters is currently under development
import gemini
r = gemini.OrderEventsWS("EXAMPLE_PUBLIC_KEY", "EXAMPLE_PRIVATE_KEY")
# Alternatively, for a sandbox environment, set sandbox=True
r = gemini.OrderEventsWS("EXAMPLE_PUBLIC_KEY", "EXAMPLE_PRIVATE_KEY", sandbox=True)
- get order types
"""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
- get order book
# Will return all recorded orders
r.get_order_book
- remove a recorded price from the order book
# Arguments are: type and order_id
r.remove_order('accepted', '12321123')
- export recorded trades to csv
# Arguments are: directory and type
# The following will export all 'accepted' orders to a csv format
r.export_to_csv(r'/c/Users/user/Documents', 'accepted')
- export recorded trades to xml
# 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')
- Add filter options to order events websocket
- Improve options to add and remove orders from market data websocket
- Add options to choose whether a particular class is cached or not
- Export recorded data from market data or order events websocket into a matplotlib graph
- Export recorded data from market data or order events websocket into a sqlite, postgresl or sql database
- Add test for the cached metaclass
0.2.0
- Created BaseWebsocket class
- Created OrderEventsWS class to interact with the order events 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
0.0.1
- Original release