Coder Social home page Coder Social logo

stoney2759 / bitcoin-trader Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pirate/crypto-trader

0.0 1.0 0.0 7 KB

Bitcoin trading bot based on a simple exponential moving average (trading via BTCMarkets).

License: MIT License

Python 100.00%

bitcoin-trader's Introduction

Python Coinbase trading bot (BTC<>USD)

๐Ÿ’ฐ Bitcoin trading bot based on a simple exponential moving average (trading via Coinbase).

I'm trying to write a simple bot that sells bitcoin the moment it makes enough profit to pay for transaction fees, plus a small margin. It will do this thousands of times per day, and hopefully profit in the long run as long as the market is volatile and trending upwards (i.e. as long as not too many people are running bots exactly like this one).

If everyone ran bots like this the market would be flat, and no one would profit because bots would quickly equalize any fluctuations, but based on the recent press and hubub around bitcoin, I think it's volatile enough to make a small profit using a simple algorithm like this one.

The algorithm works by making a set of small initial buys (~$10), then tracking the market price in relation to the purchased price. If the price drops below the purchase price, it'll sell immediately to avoid any losses. If the price rises back above the purchase price, it'll rebuy the same amount, and sell once it goes above the min profit margin amount + transaction fees. This type of tight, risk-averse bot will only make small profits because it'll never wait for big upward trends to max out, it'll sell as soon as it goes in the green.

while bankroll > 0:
    for idx, buy in enumerate(self.buys):
        if self.get_price() > buy['price'] + market_fees + min_profit_margin:
            self.buys.pop(idx)
            self.sell(buy['amount'])    # if price rises above buy price + market fees by a certain amount, sell early and reap the tiny profits
        elif self.get_price() < buy['price'] + market_fees:
            self.buys.pop(idx)
            self.sell(buy['amount'])    # if price drops below the price it was bought at, sell immediately to minimize losses
        else:
            pass                        # do nothing until the price fluctuates enough to make more of a difference

    for idx, sell in enumerate(self.sells):
        if self.get_price() > sell['price']:
            self.sells.pop(idx)
            self.buy(sell['amount'])    # if price starts to rise above the amount we sold it for, rebuy the same amount
        else:
            # if market trends downwards we'll lose (number of transactions * (market fee per transaction + min profit margin))
            pass                        # price is below the amount we sold for, don't do anything until it's passing break-even again

The trading algorithm is nowhere near complete, it will trade REAL MONEY though, so beware if you run it.
The trader.py file is intentionally broken, to run it you much read analyze() and adapt it to your own needs.

======

TODOS:

  • Implement better ties between buys and sells (instead of just buys.pop(idx))
  • Write the initial buy code that kicks off trading each day
  • Implement a bankroll system so the bot is only ever trading with profits
  • Write a meta-trader that spawns multiple traders with tweaked parameters to see which ones make the most money
  • Switch to the Coinbase Exchange API instead of the general trading API

====== I'm not responsible for any money you lose due to my bad algorithm, bugs in the implementation of it, or fluctuations in the market.

bitcoin-trader's People

Contributors

pirate avatar

Watchers

Jared 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.