4

I'm interested in automatic trading but I don't know how to get started.

  • For market-making or for arbitrage between BTC-E and other exchanges? Also, just BTC or for what currencies? – Stephen Gornick Dec 9 '12 at 4:04
  • Namecoin to BTC and BTC/USD – quitmyjob Dec 9 '12 at 16:44
4

You can write your own bot in any modern programming language using the BTC-e API. Also MtGox, Bitstamp, Bitcoin-24 and probably more popular exchanges support this.

These API's mostly give you the possibility to track the price, the market depth and place orders, making easy for you to implement your own trading bot.

  • How big is MtGox compared to BTCe? – Pacerier Apr 19 '13 at 7:23
  • You can see a list of all markets sorted by trading volume on bitcoincharts.com/markets – Steven Roose Apr 21 '13 at 18:23
0

Here is a starting point I found for Btc-e using Pastebin, source here http://pastebin.com/Xu64wH1e:

# BTC-e trade module takes options, pair the pair being traded eg. ltc_usd, ltc_btc,
# btc_usd. type the type of transaction buy or sell, rate the price you are buying or selling
# at with leading zero if decimal (0.025 not .025), and amount the amount to buy or sell.
#  Usage ./trade.py ltc_btc sell 0.0075 568
# Based on the already existing sample code placed on this site with my additions to make
# a working example.

import sys
import httplib
import urllib
import json
import hashlib
import hmac

# Replace these with your own API key data when generating the key be sure to check the trade
# box.
BTC_api_key = "your-api-key-here"
BTC_api_secret = "your-api-secret-here"

# Reading file to get nonce last used then increment and store for next use.
# You must create the file nonce.txt if first time using the trade api put the number 1 in it.
# It must be in the current directory as you are running the .py file in or change to correct
# path in the open(....).

with open('nonce.txt') as f:
n = int(f.read()) + 1
f.close()
with open('nonce.txt', 'w') as f:
f.write(str(n))
f.close()
nonce = n

# method name, options and nonce go into the POST parameters
params = {"method":"Trade",
      "pair" : sys.argv[1] ,
      "type" : sys.argv[2] ,
      "rate" : sys.argv[3] ,
      "amount" : sys.argv[4] ,
      "nonce": nonce}
params = urllib.urlencode(params)

# Hash the params string to produce the Sign header value
H = hmac.new(BTC_api_secret, digestmod=hashlib.sha512)
H.update(params)
sign = H.hexdigest()

headers = {"Content-type": "application/x-www-form-urlencoded",
               "Key":BTC_api_key,
               "Sign":sign}
conn = httplib.HTTPSConnection("btc-e.com")
conn.request("POST", "/tapi", params, headers)
response = conn.getresponse()

print response.status, response.reason
print json.load(response)

conn.close()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.