Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- def main():
- API_KEY = 'YOUR-API-KEY'
- SECRET = 'you-api-secret'
- DAILY_LIMIT_USD = 24000
- WITHDRAW_ADDRESS = 'your-xmr-address'
- WITHDRAW_CURRENCY = 'XMR'
- WITHDRAW_CURRENCY_NAME = 'monero'
- amount = DAILY_LIMIT_USD / usdValue(WITHDRAW_CURRENCY_NAME.lower())
- # Documentation: https://poloniex.com/support/api/
- p = poloniex(API_KEY, SECRET)
- print("Withdrawing %s" % amount)
- print(p.api_query('withdraw', {'currency': WITHDRAW_CURRENCY,
- 'amount': amount,
- 'address': WITHDRAW_ADDRESS}))
- ## -----------------------------------------------------
- import urllib
- import urllib2
- import json
- import time
- import hmac,hashlib
- def usdValue(currency):
- ret = urllib2.urlopen(urllib2.Request('https://api.coinmarketcap.com/v1/ticker/%s/?convert=USD' % currency))
- data = json.loads(ret.read())
- return float(data[0]['price_usd'])
- def createTimeStamp(datestr, format="%Y-%m-%d %H:%M:%S"):
- return time.mktime(time.strptime(datestr, format))
- class poloniex:
- def __init__(self, APIKey, Secret):
- self.APIKey = APIKey
- self.Secret = Secret
- def post_process(self, before):
- after = before
- # Add timestamps if there isnt one but is a datetime
- if('return' in after):
- if(isinstance(after['return'], list)):
- for x in xrange(0, len(after['return'])):
- if(isinstance(after['return'][x], dict)):
- if('datetime' in after['return'][x] and 'timestamp' not in after['return'][x]):
- after['return'][x]['timestamp'] = float(createTimeStamp(after['return'][x]['datetime']))
- return after
- def api_query(self, command, req={}):
- if(command == "returnTicker" or command == "return24Volume"):
- ret = urllib2.urlopen(urllib2.Request('https://poloniex.com/public?command=' + command))
- return json.loads(ret.read())
- elif(command == "returnOrderBook"):
- ret = urllib2.urlopen(urllib2.Request('https://poloniex.com/public?command=' + command + '¤cyPair=' + str(req['currencyPair'])))
- return json.loads(ret.read())
- elif(command == "returnMarketTradeHistory"):
- ret = urllib2.urlopen(urllib2.Request('https://poloniex.com/public?command=' + "returnTradeHistory" + '¤cyPair=' + str(req['currencyPair'])))
- return json.loads(ret.read())
- else:
- req['command'] = command
- req['nonce'] = int(time.time()*1000)
- post_data = urllib.urlencode(req)
- sign = hmac.new(self.Secret, post_data, hashlib.sha512).hexdigest()
- headers = {
- 'Sign': sign,
- 'Key': self.APIKey
- }
- ret = urllib2.urlopen(urllib2.Request('https://poloniex.com/tradingApi', post_data, headers))
- jsonRet = json.loads(ret.read())
- return self.post_process(jsonRet)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement