GithubHelp home page GithubHelp logo

dandiestsquare1 / gemini-python Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mtusman/gemini-python

0.0 2.0 0.0 120 KB

A python client for the Gemini API and Websocket

License: MIT License

Python 100.00%

gemini-python's Introduction

gemini-python

A python client for the Gemini API and Websocket

Getting Started

Installation

pip install gemini_python

PublicClient

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)

PublicClient Methods

r.symbols()
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")

PrivateClient

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)

PrivateClient Methods

r.new_order("BTCUSD", "200", "6000", "buy")
r.cancel_order("866403510")
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()

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.

MarketData Websocket

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)

MarketData Websocket Methods

  • 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')

OrderEvents Websocket

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)

OrderEvents Websocket Methods

  • 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')

Under Development

  • 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

Change Log

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

gemini-python's People

Contributors

mtusman avatar squilter avatar yiwensong avatar

Watchers

James Cloos avatar DandiestSquare1 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.