Giter Site home page Giter Site logo

btce-api's Introduction

btce-api

Build Status Coverage Status

NOTE: Due to the closure of BTC-e, this repository is no longer being maintained. I am leaving it here in case some of the code proves useful for the development of similar tools for other exchanges.

This library provides a wrapper (hopefully a convenient one) around the public and trading APIs of the BTC-e.com exchange site. So that you don't have to spend your time chasing down wacky dependencies, it depends only on the Python standard library.

NOTE: Some of the samples use matplotlib and NumPy, so you may need to install additional packages to run all the samples.

NOTE: BTC-e is not affiliated with this project; this is a completely independent implementation based on the API description. Use at your own risk.

If you find the library useful and would like to donate (and many thanks to those that have donated!), please send some coins here:

LTC LatrKXtfw66LQUURrxBzCE7cxFc9Sv8FWf
BTC 16vnh6gwFYLGneBa8JUk7NaXpEt3Qojqs1
DOGE D5jNqRjwxhDZT4hkG8yoGkseP576smjyNx

The following functions in the btceapi module access the public API and/or scrape content from the main page, and do not require any user account information:

getDepth(pair) - Retrieve the depth for the given pair.  Returns a tuple 
(asks, bids); each of these is a list of (price, volume) tuples.  See the
example usage in samples/show_depth.py.

getTicker(pair) - Retrieve the ticker information (high, low, avg, etc.)
for the given pair.  Returns a Ticker instance, which has members high, low,
avg, vol, vol_cur, last, buy, sell, updated, and server_time.

getTradeFee(pair) - Retrieve the fee (in percent) associated with trades
for a given pair.

getTradeHistory(pair) - Retrieve the trade history for the given pair.  
Returns a list of Trade instances.  Each Trade instance has members 
trade_type (either "bid" or "ask"), price, tid (transaction ID?), amount, 
and date (a datetime object).

scrapeMainPage() - Collect information from the main page and return it in
a ScraperResults object.  This object has members 'messages' (a list of 
(message ID, user, time, text) tuples representing the chat messages 
currently visible on the main page, 'bitInstantReserves' (an integer value
representing the current BitInstant reserves), and 'aurumXchangeReserves'
(an integer value representing the current AurumXchange reserves).

All of the functions above also take an optional 'connection' argument, which should be an instance of BTCEConnection. This will speed up multiple function calls, as a new connection will not have to be created for every call.

The TradeAPI class in the btceapi module accesses the trading API, and requires a KeyHandler object. The KeyHandler manages your API key and secret values (found under "API Keys" on the Profile page), stored in a text file. For instructions on creating this text file, please see step 9 here:

https://github.com/alanmcintyre/btce-bot/wiki/Getting-started

The following methods are available on a TradeAPI instance:

getInfo - Retrieves basic account information via the server getInfo 
method, and returns a TradeAccountInfo object with the following members:
    balance_[currency] - Current available balance in the given currency.
    open_orders - Number of open orders.
    server_time - Server time in a datetime object.
    transaction_count - Number of transactions. (?)
    info_rights - True if the API key has info rights.
    withdraw_rights - True if the API key has withdrawal rights.
    trade_rights - True if the API key has trading rights.
    
transHistory - Retrieves transaction history via the server TransHistory
method, and returns a list of TransactionHistoryItem objects, which have
the following members: type, amount, currency, desc, status, and timestamp
(a datetime object).

tradeHistory - Retrieves trading history via the server TradeHistory 
method, and returns a list of TradeHistoryItem objects, which have the 
following members: pair (such as "btc_usd"), type ("buy" or "sell"), 
amount, rate, order_id, is_your_order, timestamp (a datetime object).

activeOrders - Retrieves a list of orders via the server ActiveOrders 
method, and returns a list of OrderItem objects, which have the following
members:  pair (such as "btc_usd"), type ("buy" or "sell"), amount, rate, 
timestamp_created (a datetime object) and status.

trade - Place a trade order via the server Trade method, and return a 
TradeResult object, which has the following members:
    received - Immediate proceeds from the order.
    remains - Portion of the order that remains unfilled.
    order_id 
    balance_[currency] - Current available balance in the given currency.
    
cancelOrder - Cancel the specified order via the server CancelOrder method,
and return a CancelOrderResult object, which has the following members:
    order_id 
    balance_[currency] - Current available balance in the given currency.

See the API documentation (https://btc-e.com/api/documentation) for more details on arguments to these methods.

btce-api's People

Contributors

alanmcintyre avatar area avatar beer-avalanche avatar christopherpoole avatar codemonkey2841 avatar codereclaimers avatar frenchfriesketchup avatar g4nd41ph avatar hiyorimi avatar jazzer9f avatar jluttine avatar kishkin avatar lomax avatar wk8 avatar zku avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

btce-api's Issues

Attempt to fix outdated nonce

The API returns an error message that makes it possible to correct an outdated nonce (due to an application crash without saving nonces, for example), so it would be helpful to just fix it and retry the call.

Exception Caused by nonce error

I'm getting an error that is causing an unusual exception when it automatically tries to fix a nonce error. I think the error message was changed and it cannot parse this line (164) properly:

expected, actual = map(int, err_message.split()[-2:])

The error messages from btce look like this:
invalid nonce parameter; on key:xxxxx, you sent:xxxxx

decimal_places shouldn't be applied to amount

Pair's decimal_places are really about rate. Amount, as long as it's greater than the minimum, can have up to 8 decimal places regardless the pair and currency (at least in Trade method parameter and result set, but I suspect it applies everywhere). Enforcing 8 decimal places in parameter values ARE important, 9 or more places are rejected.

I failed to find a reference to 8-digit amount precision in the documentation -- maybe some other libraries have it, as there are obviously many bots buying and selling amounts like 0.01003882 BTC.

Looking at the code, I'd suggest that format_currency should be split in format_rate and format_amount (the latter doesn't really need pair information, so it's unclear in what class should in be defined). For existing code calling format_currency, it should probably be treated like format_rate to be on the safe side. Maybe I'll have some time to prepare a complete patch.

Trade response parsing error

There seems to be issues with parsing the json response received on higher/certain trade calls. It appears to be that the error occurs in the "remains" field as there's no numbers trailing the the decimal point (in this case the order was 44.000000).

Error while attempting to parse JSON response: Expecting , delimiter: line 1 column 48 (char 48)
Response: '{"success":1,"return":{"received":0,"remains":44.,"order_id":(omitted),"funds":{"usd":778.21537223,"rur":0,"eur":0,"btc":0,"ltc":0.43376503,"nmc":0,"nvc":0,"trc":0,"ppc":0}}}'

I guess it's an issue on BTC-E's part, but perhaps you can handle it accordingly in your API. Otherwise I've enjoyed working with it thus far.

withdraw coins

Hi alan, thank you for the great work.

Is it possible to withdraw coins via API? Apparently from the flag in the permission it is.. but how?

scrapeMainPage().messages updates slowly

I'm not sure what's going on here, but when I scrape the main page for messages I get the same results over and over for about 4 or 5 minutes.

I suspect this is actually a bug in btc-e, related to what sometimes happens if you switch currencies just as a new message shows up, and it disappears.

EUR/RUR is not recognized

trying to do this
pair = "eur_rur"
gives this error
btceapi.common.InvalidTradePairException: Unrecognized pair: 'eur_rur'
An error occurred: Unrecognized pair: 'eur_rur'

Best way to get around polling failure

HI Alan,

This isn't an issue with your excellent api (or at least I haven't seen it), but what's the best way to capture exceptions and retry polling when you get 403 and SSL Errors?

Right now my bot is running on a batch file (in infinite loop) so python script can restart when any exceptions are caught.

I'm new to github and haven't figured out how to email you. :(

Scraper doesn't seem to handle &apos and truncates strings

Example raw html:

<p id='msg10560425' class='chatmessage'>
<a title='30.12.13 21:43:11' style='color: #8da0b9; font-weight: bold;' 
href='javascript:void(0)' onclick='nChatMenu(88862, "andreasjva", 10560425, event)'>
andreasjva</a>: 
<span>1cryptoamin, just keep in mind, if you did 2% a day every day, at the end of the month you&apos;ll be up over 60% (compounded)</span>
</p>

as parsed by handle_data (html entity is changed to 0x0a):
1cryptoamin, just keep in mind, if you did 2% a day every day, at the end of the month you
ll be up over 60% (compounded)

After data.strip():
2013-12-30 21:43:11 andreasjva: ll be up over 60% (compounded)

BTW -- it's possible there are other html entity issues.

Redundant nonce management

You could simply build a nonce method based on time, lets say:

    # This value is used in order to generate a small nonce, 
    # because for some reason btc-e doesn't like big nonces.
    timestamp_reduce_value = 1380736931200
    return int(time.time()*1e3) - timestamp_reduce_value

XPM-BTC

Hello, Alan. Please add XPM-BTC pair.

common.formatCurrency bug?

Hi.
When making an order for sale, for example:
tapi.trade("btc_usd", "sell", 999.99, 0.109)

order for sale 0.108 btc created. It's just me or there is a bug in common.formatCurrency?

Add parameters to getTradeHistory and getDepth

It will be great if it will be possible to call getTradeHistory and getDepth functions with additional parameters. For example, I need to get just single last trade and not the whole 150, because of decreased response time and BTC-e server load. For this reason the API allows to specify, for example, optional count parameter, so it would be great if you will implement this feature in the future.

CNH

Hey, Alan. Recently BTC-e has added CNH for BTC, LTC and USD. Please add these pairs.

'order' parameter of 'transHistory' not works

At first thank you for creating such a beautiful tool.
The issue is as follows: the order parameter of transHistory method of TradeAPI object does not do any sorting. As a workaround, I'm using a lambda function, but it may be a bit slower:

trn_history = t.transHistory(count_number=3) 
trn_history.sort(key=lambda a: a.transaction_id, reverse=True)
for n in trn_history:
    print "AMNT: %s\t CUR: %s\t DESC: %s\t STAT: %s\t TIM: %s\t TID: %s\t TYP: %s" % (n.amount, n.currency, n.desc, n.status, n.timestamp, n.transaction_id, n.type)

Also, I noticed, that the next TransactionHistoryItem objects aren't returned at all: currency, desc and status. transHistory always return them as None. It would be great if you'll fix this minor bug.

Small bug in Common.py

Hey there, I noticed that sometimes an automated trader I built was bombing out when trying to make trades involving the btc_eur pair with a message about not being able to use a "none type" (I suppose that's Python's version of a null reference exception). In any case, I traced it to the fact that there is no minimum trade or max digits value set for that pair in Common.py. After adding appropriate values for these, I didn't see the error again. Please merge this change into the master if you feel it appropriate.

Add order validation

Provide functions to validate an order before submitting it, to catch things like orders that are below the minimum size, etc., without having to make the trip to the server to find out.

python-3 compatibility

/btceapi/common.py line 49 is not compatible with exceptions in python-3
I think it should change to:
except Exception as e:
print("Error while attempting to parse JSON response:", e)
print ("Response:",response)
raise e

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.