Skip to content

Instantly share code, notes, and snippets.

@page1
Last active October 22, 2017 05:40
Show Gist options
  • Save page1/71f0ca20e66a496bb26f16c3951b5c3a to your computer and use it in GitHub Desktop.
Save page1/71f0ca20e66a496bb26f16c3951b5c3a to your computer and use it in GitHub Desktop.
Get Poloniex Lending Fees
#Poloniex api doesn't give the lending fees that are needed to reconcile accounts.
#Poloniex trade history export also doesn't give the lending fees
#Scraping is the only way I could get this data
#Hope this helps you, no warrenty :)
#Env Vars - POLONIEX_USER, POLONIEX_PASS, POLONIEX_OTP
#Incase you didn't catch that - POLONIEX_OTP - Is the one time password secret needed to make it through 2 factor auth
import os
from xvfbwrapper import Xvfb
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import WebDriverException
from pandas.io.html import read_html
from pyotp import TOTP
with Xvfb(width=1280, height=720) as xvfb:
driver = webdriver.Firefox()
driver.set_script_timeout(120)
driver.set_page_load_timeout(120)
driver.implicitly_wait(5)
try:
driver.get("https://poloniex.com/login")
print("Loading Login Page")
element = WebDriverWait(driver, 10).until(
EC.title_is('Poloniex - Bitcoin/Digital Asset Exchange - Sign In')
)
username = driver.find_element_by_id("username")
password = driver.find_element_by_id("password")
username.send_keys(os.getenv("POLONIEX_USER"))
password.send_keys(os.getenv("POLONIEX_PASS"))
print("Submitting Login")
driver.find_element_by_name("login").click()
element = WebDriverWait(driver, 10).until(
EC.title_is('Poloniex - Bitcoin/Digital Asset Exchange - Sign In')
)
code = driver.find_element_by_name("code")
one_time_pass = TOTP(os.getenv("POLONIEX_OTP"))
code.send_keys(one_time_pass.now())
print("Submitting OTP")
driver.find_element_by_name("login").click()
element = WebDriverWait(driver, 10).until(
EC.title_contains('Market - Poloniex Bitcoin/Digital Asset Exchange')
)
for ticker in ['XMR', 'XRP']: #just list out the markets you care about
trade_analysis_url = "https://poloniex.com/tradeHistory#analysis/" + ticker + "/BTC/all" #I'd suggest adding data limiters to the URL to avoid blowing up on large account
driver.get(trade_analysis_url)
print("Getting Trade History " + ticker)
def wait_for_table_or_no_result(driver):
return driver.find_elements(By.XPATH, r"""//*[@id="tradeHistoryTable"]/tbody/tr[1]/td[2][contains(.,'""" + ticker + r"""')]""") or \
driver.find_elements(By.XPATH, r""" //*[@id="tradeHistoryTable"]/tbody/tr/td/p[contains(.,'No Results')]""")
element = WebDriverWait(driver, 180, poll_frequency=1).until(
wait_for_table_or_no_result
)
if len(driver.find_elements(By.XPATH, r"""//*[@id="tradeHistoryTable"]/tbody/tr/td/p[contains(.,'No Results')]""")) > 0:
print("Up To Date")
continue
tradeHistory = driver.find_element_by_id("tradeHistoryTable")
table_html = tradeHistory.get_attribute('innerHTML')
print("Trade History to DataFrame")
df = read_html(table_html)[0] #This is the lending fee data
print(df)
#Do cool things with your lending fee data!
finally:
try:
driver.quit()
except WebDriverException:
pass
@page1
Copy link
Author

page1 commented Oct 22, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment