mtgox – Mt. Gox reference

MtGox support depends on ws4py (https://github.com/Lawouach/WebSocket-for-Python) and tornado (http://www.tornadoweb.org/en/stable/) so be sure to have those installed before moving forward.

Tools

pyalgotrade.mtgox.tools.download_trades_by_month(currency, year, month, csvFile, ignoreMultiCurrency=False)

Download trades for a given month.

Parameters:
  • currency (string.) – Currency in which trade was completed.
  • year (int.) – The year.
  • month (int.) – The month.
  • csvFile (string.) – The path to the CSV file to write the trades.
  • ignoreMultiCurrency (boolean.) – Ignore multi currency trades.

Note

This will take some time since Mt. Gox API returns no more than 1000 trades on each request

pyalgotrade.mtgox.tools.download_trades_by_year(currency, year, csvFile, ignoreMultiCurrency=False)

Download trades for a given year.

Parameters:
  • currency (string.) – Currency in which trade was completed.
  • year (int.) – The year.
  • csvFile (string.) – The path to the CSV file to write the trades.
  • ignoreMultiCurrency (boolean.) – Ignore multi currency trades.

Note

This will take some time since Mt. Gox API returns no more than 1000 trades on each request

Client

class pyalgotrade.mtgox.client.Client(currency, apiKey, apiSecret, ignoreMultiCurrency=False)

Bases: pyalgotrade.observer.Subject

This class is responsible for all trading interaction with MtGox.

Parameters:
  • currency (string.) – The account’s currency. Valid values are: USD, AUD, CAD, CHF, CNY, DKK, EUR, GBP, HKD, JPY, NZD, PLN, RUB, SEK, SGD, THB, NOK or CZK.
  • apiKey (string.) – Your API key. Set this to None for paper trading.
  • apiSecret (string.) – Your API secret. Set this to None for paper trading.
  • ignoreMultiCurrency (boolean.) – Ignore multi currency trades.

Note

For apiKey and apiSecret check the Application and API access section in mtgox.com.

Feeds

class pyalgotrade.mtgox.barfeed.CSVTradeFeed(timezone=None, frequency=None, maxLen=1024)

Bases: pyalgotrade.barfeed.csvfeed.BarFeed

A BarFeed that builds bars from a trades CSV file.

Parameters:
  • timezone (A pytz timezone.) – The default timezone to use to localize bars. Check pyalgotrade.marketsession.
  • frequency – Reserved for future use. Currently ignored.
  • maxLen (int.) – The maximum number of values that the pyalgotrade.dataseries.bards.BarDataSeries will hold. If not None, it must be greater than 0. Once a bounded length is full, when new items are added, a corresponding number of items are discarded from the opposite end.

Note

Note that a pyalgotrade.bar.Bar instance will be created for every trade, so open, high, low and close values will all be the same.

addBarsFromCSV(path, timezone=None)

Loads bars from a trades CSV formatted file.

Parameters:
  • path (string.) – The path to the file.
  • timezone (A pytz timezone.) – The timezone to use to localize bars. Check pyalgotrade.marketsession.

Note

Every file that you load bars from must have trades in the same currency.

class pyalgotrade.mtgox.barfeed.LiveTradeFeed(client, maxLen=1024)

Bases: pyalgotrade.barfeed.BaseBarFeed

A real-time BarFeed that builds bars from live trades.

Parameters:

Note

Note that a pyalgotrade.bar.Bar instance will be created for every trade, so open, high, low and close values will all be the same.

Brokers

class pyalgotrade.mtgox.broker.BacktestingBroker(cash, barFeed, commission=None)

Bases: pyalgotrade.broker.backtesting.Broker

A backtesting broker.

Parameters:
  • cash (int/float.) – The initial amount of cash.
  • barFeed (pyalgotrade.barfeed.BarFeed) – The bar feed that will provide the bars.
  • commission (pyalgotrade.broker.backtesting.Commission) – An object responsible for calculating order commissions. If None, a 0.6% trade commision will be used.

Note

Neither stop nor stop limit orders are supported.

Table Of Contents

Previous topic

Tutorial for Bitcoin trading through Mt. Gox

Next topic

Trading based on Twitter events

This Page