• This repository has been archived on 03/Apr/2019
  • Stars
    star
    608
  • Rank 72,123 (Top 2 %)
  • Language
    Python
  • License
    MIT License
  • Created over 8 years ago
  • Updated about 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐Ÿ’ฐ Cryptocurrency trading bot library with a simple example strategy (trading via Gemini).

Crypto Trading Bot Framework using the Gemini Exchange

๐Ÿ’ฐ Python bindings for trading Bitcoin, Ethereum, & USD on the Gemini.com Exchange API.


ARCHIVED: Use https://github.com/ccxt/ccxt

Quickstart

  1. Download & install
git clone https://github.com/pirate/cryto-trader.git
cd crypto-trader
pip3 install -r requirements.txt
  1. Open https://exchange.gemini.com/settings/api and get an API key & secret
cp secrets_default.py secrets.py
nano secrets.py  # add key & secret here
  1. Start hacking!
import gemini_api as api
from symbols import Order, ETH, USD

current_price = USD(api.ticker('ethusd')['last'])
if current_price > USD(950.00):
    buy_order = Order(api.new_order('buy', 'ethusd', ETH(0.001), current_price))

    for event in order_events(buy_order.id):
        print(event)
  1. (Optional) run the example bot
nano settings.py                   # Confirm your bot parameters
python3 ./example.py ethusd        # Run the example theshold bot

Configuration

  • API Key Secrets: secrets.py
  • Bot Settings: settings.py

API Documentation

import gemini_api as api
from symbols import Order, USD, BTC, ETH

Data Types

Currencies:

  • symbols.USD: US Dollar USD(1.25)
  • symbols.BTC: Bitcoin BTC(0.000001)
  • symbols.ETH: Ethereum ETH(0.0001)

All currency symbols are based on the base type symbols.Currency.

Order: All API functions that deal with order data like new_order or order_status return a raw json dict from Gemini with the schema below. It can be converted to a type-checked python object by using Order(order_json).

order_json = {
    "order_id": "44375901",
    "id": "44375901",
    "symbol": "btcusd",
    "exchange": "gemini",
    "avg_execution_price": "400.00",
    "side": "buy",
    "type": "exchange limit",
    "timestamp": "1494870642",
    "timestampms": 1494870642156,
    "is_live": False,
    "is_cancelled": False,
    "is_hidden": False,
    "was_forced": False,
    "executed_amount": "3",
    "remaining_amount": "0",
    "options": [],
    "price": "400.00",
    "original_amount": "3",
}
buy_order = Order(order_json)
order_id = buy_order.id       # values can be accessed as properties

REST API Functions

The Gemini REST API functions documentation can be found here:
https://docs.gemini.com/rest-api/#requests

api.ticker(symbol: str) -> dict:
Get the ticker price info for a given symbol, e.g.:

ticker_info = api.ticker('ethusd')
# {'bid': '914.00', 'ask': '914.44', 'volume': {'ETH': '94530.56656129', 'USD': '83955829.9730076926', 'timestamp': 1515014100000}, 'last': '915.39'}
last_price = USD(ticker_info['last'])

api.new_order(side: str, symbol: str, amt: Currency, price: Currency) -> dict:
Submit a new order to Gemini, e.g:

buy_order = Order(api.new_order('buy', 'ethusd', ETH(0.01), USD(965)))
sell_order = Order(api.new_order('sell', 'ethusd', ETH(0.01), USD(965)))

api.order_status(order_id: str) -> dict:
Get the updated order info json from Gemini for a given order_id, e.g.:

buy_order = Order(api.order_status('44375901'))
print(buy_order.filled_amt)

WebSocket API Functions

The Gemini WebSocket API functions documentation can be found here:
https://docs.gemini.com/websocket-api/#websocket-request

api.order_events(order_id: str) -> Generator[dict]:
Get a live-updating stream of order events via WebSocket e.g.:

for event in api.order_events('44375901'):
    print(event)

Example Bot

example.py is a simple example bot that randomly creates some initial buys, then sells the moment it makes a certain threshold percentage of profit.

It might profit if the market is trending upwards, but generally this strategy doesn't work if you want to make any real money. This code serves as a boilerplate example upon which to build other, more advanced bots.

This type of tight, risk-averse bot will only make small profits because it never waits for big upward trends to max out, it sells as soon as it goes in the green. The days where it starts in the red and stays there also end up sucking much of the profit away.

Roadmap

  • Write a meta-trader that spawns multiple traders with tweaked parameters to see which ones make the most money
  • Add GDAX/Coinbase Exchange API bindings
  • Add Bitfinex Exchange API bindings

Developer Info

This library is built on Python 3.6 and uses MyPy for type checking.

Check MyPy types:

env MYPYPATH=./stubs mypy example.py

Disclaimer

I'm not responsible for any money you lose from this code. The code is MIT Licensed.

More Repositories

1

wireguard-docs

๐Ÿ“– Unofficial WireGuard Documentation: Setup, Usage, Configuration, and full example setups for VPNs supporting both servers & roaming clients.
Shell
4,398
star
2

sites-using-cloudflare

๐Ÿ’” Archived list of domains using Cloudflare DNS at the time of the CloudBleed announcement.
1,911
star
3

security-growler

๐Ÿ“ก A Mac menubar app that notifies you whenever SSH, VNC, sudo, or other auth events occur.
Python
857
star
4

mesh-networking

๐ŸŒ LEGO blocks for networking, a Python library to help create and test flexible network topologies across real and simulated physical links.
JavaScript
356
star
5

wikipedia-mirror

๐ŸŒ Guide and tools to run a full offline mirror of Wikipedia.org with three different approaches: Nginx caching proxy, Kiwix + ZIM dump, and MediaWiki/XOWA + XML dump
Shell
331
star
6

WebRTCChat

๐Ÿ” Pure Browser To Browser Chat (STUN & ICE Servers optional)
JavaScript
254
star
7

mac-keyboard-brightness

๐Ÿ”† Programmatically get & set the keyboard & display backlight brightness on Macs. Flash your keyboard to the music! (only works on <2015 Macs)
C
217
star
8

bash-utils

A collection of hand-crafted bash scripts for various common tasks.
Shell
209
star
9

fish-utils

๐Ÿ”ง My utility belt of fish functions, writing these has saved me many hours in the long run... I hope...
Shell
135
star
10

spellchecker

๐Ÿ“– A spell-checker extending Peter Norvig's with multi-typo correction, hamming distance weighting, and more.
Python
96
star
11

mesh-botnet

๐Ÿ Proof-of-concept python IRC botnet for orchestrating macOS computers (harmless due to SIP & Gatekeeper)
Python
84
star
12

django-http2-middleware

โšก๏ธDjango middleware to automatically send preload headers before views runs, enabling faster HTTP2 server-push (with CSP support).
Python
67
star
13

django-concurrency-talk

๐ŸŽญ Database Integrity in Django: Safely Handling Critical Data in Distributed Systems
JavaScript
53
star
14

internet-archiving-talk

๐ŸŽญ An introduction to the Internet Archiving ecosystem, tooling, and some of the ethical dilemmas that the community faces.
JavaScript
47
star
15

gzint

โœ‚๏ธ A python3 library for efficiently storing massive integers (stands for gzipped-integer).
Python
41
star
16

macOS-global-autocomplete

๐Ÿ“ƒ System-wide autocompleting that learns what you type and works in any app! (also slightly scary maybe don't use this...)
C
40
star
17

quebec-power-grid-talk

๐ŸŽญ Quebec's 735kv power lines can survive the apocalypse, but can they run TCP?!
JavaScript
33
star
18

Cpp-Data-Structures

๐Ÿ“ C++ Implementations of data structures & algorithms from PSU course CS162/CS163
C++
23
star
19

nicksweeting.com

๐Ÿ’ป The code for my website, including the game of life and other easter eggs.
HTML
18
star
20

500.html

A nice 500.html page template to use in django/jinja2 projects.
HTML
9
star
21

experiments

โœจ Random (sometimes xkcd-inspired) Python, Haskell, and JS experiments involving data science and algorithm fun.
Python
9
star
22

inject-luxinate

๐Ÿ’‰ Inject download buttons into web pages that Luxinate is capable of downloading songs from.
Python
7
star
23

txmoderna.com

Moderna's domain name is modernatx, not txmoderna
HTML
5
star
24

china-vpn

๐Ÿ€„ Wordpress site which powers my free VPN service (with extras)
PHP
5
star
25

music-bot

โ™ฌ A facebook messenger bot that listens for music links in chats and converts them to Apple Music IDs.
JavaScript
4
star
26

squasher-browser-extension

Extension to collect all open browser tabs for a given domain into a new window (with suspender support).
JavaScript
4
star
27

pirate.github.io

Nothing to see here.
HTML
3
star
28

docker.hera

Setup for the Hera Cloudflare Argo Tunnel manager for Docker
3
star
29

throws

โ— Proposal for a new 'throws' keyword in python.
Python
3
star
30

archivebox-codespace

Codespace scratchpad for working on ArchiveBox development
EJS
2
star
31

stevesweeting

๐ŸŽถ Steve Sweeting Music
CSS
1
star