🢀 poloniex :: e799104


commit e799104044cf190543619a39977902f1efcc2ce1
Author: acidvegas <acid.vegas@acid.vegas>
Date:   Mon Jun 24 23:08:11 2019 -0400

    Initial commit

diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..69997e8
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,15 @@
+ISC License
+
+Copyright (c) 2019, acidvegas <acid.vegas@acid.vegas>
+
+Permission to use, copy, modify, and/or distribute this software for any
+purpose with or without fee is hereby granted, provided that the above
+copyright notice and this permission notice appear in all copies.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..7239046
--- /dev/null
+++ b/README.md
@@ -0,0 +1,11 @@
+###### Requirements
+* [Python](https://www.python.org/downloads/) *(**Note:** This script was developed to be used with the latest version of Python.)*
+
+###### API Documentation
+ - [Public/Trade API](https://poloniex.com/support/api/)
+
+###### Mirrors
+- [acid.vegas](https://acid.vegas/poloniex) *(main)*
+- [SuperNETs](https://git.supernets.org/pumpcoin/poloniex)
+- [GitHub](https://github.com/pumpcoin/poloniex)
+- [GitLab](https://gitlab.com/pumpcoin/poloniex)
\ No newline at end of file
diff --git a/poloniex/poloniex.py b/poloniex/poloniex.py
new file mode 100644
index 0000000..e89fac3
--- /dev/null
+++ b/poloniex/poloniex.py
@@ -0,0 +1,166 @@
+#!/usr/bin/env python
+# Poloniex API Class - Developed by acidvegas in Python (https://acid.vegas/poloniex)
+
+'''
+API Documentation:
+ * Public/Trade API (https://poloniex.com/support/api/)
+'''
+
+import hashlib
+import hmac
+import http.client
+import json
+import urllib.parse
+import time
+
+class PublicAPI:
+	def api_call(command):
+		conn = http.client.HTTPSConnection('poloniex.com', timeout=15)
+		conn.request('GET', '/public?command=' + command)
+		response = conn.getresponse().read().decode()
+		data = json.loads(response)
+		conn.close()
+		return data
+
+	def Ticker():
+		return PublicAPI.api_call('returnTicker')
+
+	def 24Volume():
+		return PublicAPI.api_call('return24Volume')
+
+	def OrderBook(currencyPair, depth=None):
+		if depth:
+			return PublicAPI.api_call(f'returnOrderBook&currencyPair={currencyPair}&depth={depth}')
+		else:
+			return PublicAPI.api_call('returnOrderBook&currencyPair=' + currencyPair)
+
+	def TradeHistory(currencyPair, start=None, end=None):
+		if start and end:
+			return PublicAPI.api_call(f'returnTradeHistory&currencyPair={currencyPair}&start={start}&end={end}')
+		else:
+			return PublicAPI.api_call('returnTradeHistory&currencyPair=' + currencyPair)
+
+	def ChartData(currencyPair, start, end, period):
+		return PublicAPI.api_call(f'returnChartData&currencyPair={currencyPair}&start={start}&end={end}&period={period}')
+
+	def Currencies():
+		return PublicAPI.api_call('returnCurrencies')
+
+	def LoanOrders(currency):
+		return PublicAPI.api_call('returnLoanOrders&currency=' + currency)
+
+class TradeAPI:
+	def __init__(self, api_key, api_secret, api_nonce):
+		self.api_key = api_key
+		self.api_secret = api_secret
+		self.api_nonce = api_nonce
+
+	def signature(self, params):
+		sig = hmac.new(self.api_secret.encode(), params.encode(), hashlib.sha512)
+		return sig.hexdigest()
+
+	def api_call(self, command, params):
+		self.api_nonce = str(time.time()).split('.')[0]
+		params['command'] = command
+		params['nonce'] = str(self.api_nonce)
+		params = urllib.parse.urlencode(params)
+		headers = {'Key':self.api_key, 'Sign':self.signature(params)}
+		conn = http.client.HTTPSConnection('poloniex.com', timeout=http_timeout)
+		conn.request('POST', '/tradingApi', params, headers)
+		response = conn.getresponse().read().decode()
+		data = json.loads(response)
+		conn.close()
+		return data
+
+	def Balances(self):
+		return self.api_call('returnBalances')
+
+	def CompleteBalances(self, all_accounts=False):
+		if all_accounts:
+			return self.api_call('returnCompleteBalances&account=all')
+		else:
+			return self.api_call('returnCompleteBalances')
+
+	def DepositAddresses(self):
+		return self.api_call('returnDepositAddresses')
+
+	def GenerateNewAddress(self, currency):
+		return self.api_call('generateNewAddress&currency=' + currency)
+
+	def DepositsWithdrawals(self, start, end):
+		return self.api_call(f'returnDepositsWithdrawals&start={start}&end={end}')
+
+	def OpenOrders(self, currencyPair):
+		return self.api_call('returnOpenOrders&currencyPair=' + currencyPair)
+
+	def TradeHistory(self, currencyPair, start=None, end=None, limit=None):
+		pass
+
+	def OrderTrades(self, orderNumber):
+		return self.api_call('returnOrderTrades&orderNumber=' + orderNumber)
+
+	def Buy(self, currencyPair, rate, amount, fillOrKill=False, immediateOrCancel=False, postOnly=False):
+		pass
+
+	def Sell(self, currencyPair, rate, amount, fillOrKill=False, immediateOrCancel=False, postOnly=False):
+		pass
+
+	def CancelOrder(self, orderNumber):
+		return self.api_call('cancelOrder*orderNumber=' + orderNumber)
+
+	def MoveOrder(self, orderNumber, rate, amount=None, postOnly=False, immediateOrCancel=False):
+		return
+
+	def Withdraw(self, currency, amount, address):
+		return self.api_call(f'withdraw&currency={currency}&amount={amount}&address={address}')
+
+	def FeeInfo(self):
+		return self.api_call('returnFeeInfo')
+
+	def AvailableAccountBalances(self, account=None):
+		if account:
+			return self.api_call('returnAvailableAccountBalances&account=' + account)
+		else:
+			return self.api_call('returnAvailableAccountBalances')
+
+	def TradableBalances(self):
+		return self.api_call('returnTradableBalances')
+
+	def TransferBalance(self, currency, amount, fromAccount, toAccount):
+		return self.api_call(f'transferBalance&currency={currency}&amount={amount}&fromAccount={fromAccount}&toAccount={toAccount}')
+
+	def returnMarginAccountSummary(self):
+		return self.api_call('returnMarginAccountSummary')
+
+	def MarginBuy(self, currencyPair, rate, amount):
+		return self.api_call(f'marginBuy&currencyPair={currencyPair}&rate={rate}&amount={amount}')
+
+	def MarginSell(self, currencyPair, rate, amount):
+		return self.api_call(f'marginSell&currencyPair={currencyPair}&rate={rate}&amount={amount}')
+
+	def GetMarginPosition(self, currencyPair='all'):
+		return self.api_call('getMarginPosition&currencyPair=' + currnecyPair)
+
+	def CloseMarginPosition(self, currencyPair):
+		return self.api_call('closeMarginPosition&currencyPair=' + currencyPair)
+
+	def CreateLoanOffer(self, currency, amount, duration, autoRenew, lendingRate):
+		return self.api_call(f'createLoanOffer&currency={currency}&amount={amount}&duration={duration}&autoRenew={autoRenew}&lendingRate={lendingRate}')
+
+	def CancelLoanOffer(self, orderNumber):
+		return self.api_call('cancelLoanOffer&orderNumber=' + orderNumber)
+
+	def OpenLoanOffers(self):
+		return self.api_call('returnOpenLoanOffers')
+
+	def ActiveLoans(self):
+		return self.api_call('returnActiveLoans')
+
+	def LendingHistory(self, start, stop, limit=None):
+		if limit:
+			return self.api_call(f'returnLendingHistory&start={start}&stop={stop}&limit={limit}')
+		else:
+			return self.api_call(f'returnLendingHistory&start={start}&stop={stop}')
+
+	def ToggleAutoRenew(self, orderNumber):
+		return self.api_call('toggleAutoRenew&orderNumber=' + orderNumber)
\ No newline at end of file