Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated for issue #1 and ExchB changes #2

Merged
merged 3 commits into from Jun 17, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions mtgox.py → api.py
Expand Up @@ -98,3 +98,18 @@ def _url(self, action, scheme="http", args={}):
''))
return url

class ExchB(MTGox):
def __init__(self,user,password):
MTGox.__init__(self,user,password)
self.server = "www.exchangebitcoins.com"
self.actions = {"_get_ticker": ("GET", "/data/ticker"),
"get_depth": ("GET", "/data/depth"),
"get_trades": ("GET", "/data/recent"),
"get_balance": ("POST", "/data/getFunds"),
"buy_btc": ("POST", "/data/buyBTC"),
"sell_btc": ("POST", "/data/sellBTC"),
"_get_orders": ("POST", "/data/getOrders"),
"_cancel_order": ("POST", "/data/cancelOrder")}



6 changes: 2 additions & 4 deletions balance.py
@@ -1,9 +1,7 @@
#!/usr/bin/env python

from mtgox import MTGox
import settings
from settings import *

mtgox = MTGox(user=settings.MTGOX_USER, password=settings.MTGOX_PASSWORD)
balance = mtgox.get_balance()
balance = exchange.get_balance()
print balance

6 changes: 2 additions & 4 deletions buy.py
Expand Up @@ -2,8 +2,7 @@

import sys

from mtgox import MTGox
import settings
from settings import *

if len(sys.argv) in (2, 3):
amount = sys.argv[1]
Expand All @@ -12,7 +11,6 @@
print "Usage: %s <amount> [bid]" % sys.argv[0]
exit(1)

mtgox = MTGox(user=settings.MTGOX_USER, password=settings.MTGOX_PASSWORD)
status = mtgox.buy_btc(amount=amount, price=bid)
status = exchange.buy_btc(amount=amount, price=bid)
print status

6 changes: 2 additions & 4 deletions cancel.py
Expand Up @@ -2,16 +2,14 @@

import sys

from mtgox import MTGox
import settings
from settings import *

if len(sys.argv) == 2:
oid = sys.argv[1]
else:
print "Usage: %s <order id>" % sys.argv[0]
exit(1)

mtgox = MTGox(user=settings.MTGOX_USER, password=settings.MTGOX_PASSWORD)
status = mtgox.cancel_order(oid=oid)
status = exchange.cancel_order(oid=oid)
print status

19 changes: 19 additions & 0 deletions defaultsettings.py
@@ -0,0 +1,19 @@
#!/usr/bin/env python

#
# Copy to settings.py, enter credentials for the
# exchange(s) you would like to connect to and uncomment
# the corresponding exchange line.
#

from api import ExchB, MTGox

EXCHB_USER = 'your_username'
EXCHB_PASSWORD = 'your_password'

MTGOX_USER = 'your_username'
MTGOX_PASSWORD = 'your_password'

# uncomment the exchange you want to use
#exchange = ExchB(user=EXCHB_USER, password=EXCHB_PASSWORD)
exchange = MTGox(user=MTGOX_USER, password=MTGOX_PASSWORD)
6 changes: 2 additions & 4 deletions depth.py
@@ -1,10 +1,8 @@
#!/usr/bin/env python

from mtgox import MTGox
import settings
from settings import *

mtgox = MTGox(user=settings.MTGOX_USER, password=settings.MTGOX_PASSWORD)
depth = mtgox.get_depth()
depth = exchange.get_depth()

bids = sorted(depth['bids'], key=lambda bid: bid[0])
asks = sorted(depth['asks'], key=lambda bid: bid[0])
Expand Down
16 changes: 9 additions & 7 deletions orders.py
Expand Up @@ -2,18 +2,20 @@

import time

from mtgox import MTGox
import settings
from settings import *

mtgox = MTGox(user=settings.MTGOX_USER, password=settings.MTGOX_PASSWORD)
orders = mtgox.get_orders()
orders = exchange.get_orders()

now = time.time()
for order in orders:
order["type_text"] = {1: "sell", 2: "buy"}[order["type"]]
order["status_text"] = {1: "active",
2: "not enough funds"}[int(order["status"])]
order["type_text"] = {1: "sell", 2: "buy", "Sell": "sell", "Buy": "buy"}[order["type"]]
if "status" in order:
order["status_text"] = {1: "active",
2: "not enough funds"}[int(order["status"])]
else:
order["status_text"] = "active"
order["ago"] = int((now - int(order["date"]))/60)
print ("%(oid)s %(type_text)s %(amount)s at %(price)s %(ago)s minutes ago, "
"%(status_text)s" % order)


6 changes: 2 additions & 4 deletions sell.py
Expand Up @@ -2,8 +2,7 @@

import sys

from mtgox import MTGox
import settings
from settings import *

if len(sys.argv) in (2, 3):
amount = sys.argv[1]
Expand All @@ -12,7 +11,6 @@
print "Usage: %s <amount> [ask]" % sys.argv[0]
exit(1)

mtgox = MTGox(user=settings.MTGOX_USER, password=settings.MTGOX_PASSWORD)
status = mtgox.sell_btc(amount=amount, price=ask)
status = exchange.sell_btc(amount=amount, price=ask)
print status

6 changes: 2 additions & 4 deletions ticker.py
@@ -1,10 +1,8 @@
#!/usr/bin/env python

from mtgox import MTGox
import settings
from settings import *

mtgox = MTGox(user=settings.MTGOX_USER, password=settings.MTGOX_PASSWORD)
ticker = mtgox.get_ticker()
ticker = exchange.get_ticker()

if ticker:
for key in ("last", "buy", "sell", "low", "high", "vol"):
Expand Down
6 changes: 2 additions & 4 deletions trades.py
Expand Up @@ -2,11 +2,9 @@

import time

from mtgox import MTGox
import settings
from settings import *

mtgox = MTGox(user=settings.MTGOX_USER, password=settings.MTGOX_PASSWORD)
trades = mtgox.get_trades()
trades = exchange.get_trades()

now = time.time()
for tr in trades:
Expand Down
9 changes: 3 additions & 6 deletions watch.py
Expand Up @@ -2,10 +2,7 @@

import time

from mtgox import MTGox
import settings

mtgox = MTGox(user=settings.MTGOX_USER, password=settings.MTGOX_PASSWORD)
from settings import *

wait = 60

Expand All @@ -14,7 +11,7 @@
last_asks = []

while True:
trades = mtgox.get_trades()
trades = exchange.get_trades()

now = time.time()
for tr in trades:
Expand All @@ -29,7 +26,7 @@
time.sleep(wait)
continue

depth = mtgox.get_depth()
depth = exchange.get_depth()

bids = sorted(depth['bids'], key=lambda bid: bid[0])
asks = sorted(depth['asks'], key=lambda bid: bid[0])
Expand Down
6 changes: 2 additions & 4 deletions withdraw.py
Expand Up @@ -2,16 +2,14 @@

import sys

from mtgox import MTGox
import settings
from settings import *

if len(sys.argv) == 3:
_, amount, address = sys.argv
else:
print "Usage: %s <amount> <BTC address>" % sys.argv[0]
exit(1)

mtgox = MTGox(user=settings.MTGOX_USER, password=settings.MTGOX_PASSWORD)
status = mtgox.withdraw(group1="BTC", btca=address, amount=amount)
status = exchange.withdraw(group1="BTC", btca=address, amount=amount)
print status