示例#1
0
# Hack to get relative imports - probably need to fix the dir structure instead but we need this at the minute for
# pytest to work
import os, sys, inspect
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
parentdir = os.path.dirname(currentdir)
sys.path.insert(0, parentdir)

from modules.Poloniex import Poloniex
import modules.Configuration as Config
import modules.Data as Data
from modules.Logger import Logger
import threading

Config.init('default.cfg', Data)
api = Poloniex(Config, Logger())


# def multiple_api_queries(n):
#     try:
#         for i in xrange(n):
#             print 'api_query ' + str(i + 1) + '\n'
#             thread1 = threading.Thread(target=api.return_open_loan_offers)
#             thread1.start()
#     except Exception as e:
#         assert False, 'api_query ' + str(i + 1) + ':' + e.message
# 
#
# # Test fast api calls
# def test_multiple_calls():
#     multiple_api_queries(9)
示例#2
0
# Hack to get relative imports - probably need to fix the dir structure instead but we need this at the minute for
# pytest to work
import os, sys, inspect
currentdir = os.path.dirname(
    os.path.abspath(inspect.getfile(inspect.currentframe())))
parentdir = os.path.dirname(currentdir)
sys.path.insert(0, parentdir)

from modules.MarketAnalysis import MarketAnalysis
from modules.Configuration import get_all_currencies
from modules.Poloniex import Poloniex
import modules.Configuration as Config
import modules.Data as Data

Config.init('default.cfg', Data)
api = Poloniex(Config, None)
Data.init(api, None)
MA = MarketAnalysis(Config, api)


def new_db():
    db_con = MA.create_connection(None, ':memory:')
    MA.create_rate_table(db_con, 3)
    return db_con


def random_rates():
    return lists(floats(min_value=0.00001,
                        max_value=100,
                        allow_nan=False,
                        allow_infinity=False),
    config_location = 'default.cfg'
# End handling args.

Config.init(config_location)
# Config format: Config.get(category, option, default_value=False, lower_limit=False, upper_limit=False)
# A default_value "None" means that the option is required and the bot will not run without it.
# Do not use lower or upper limit on any config options which are not numbers.
# Define the variable from the option in the module where you use it.
output_currency = Config.get('BOT', 'outputCurrency', 'BTC')
end_date = Config.get('BOT', 'endDate')
json_output_enabled = Config.has_option(
    'BOT', 'jsonfile') and Config.has_option('BOT', 'jsonlogsize')

log = Logger(Config.get('BOT', 'jsonfile', ''),
             Decimal(Config.get('BOT', 'jsonlogsize', -1)))
api = Poloniex(Config.get("API", "apikey", None),
               Config.get("API", "secret", None))
MaxToLend.init(Config, log)
Data.init(api, log)
Config.init(config_location, Data)
if Config.has_option('BOT', 'analyseCurrencies'):
    import modules.MarketAnalysis as Analysis
    Analysis.init(Config, api, Data)
else:
    Analysis = None
Lending.init(Config, api, log, Data, MaxToLend, dry_run, Analysis)

print 'Welcome to Poloniex Lending Bot'
# Configure web server

web_server_enabled = Config.getboolean('BOT', 'startWebServer')
if web_server_enabled:  # Run web server
示例#4
0
"""
import argparse
import pandas as pd

from modules.Poloniex import Poloniex, PoloniexApiError
import modules.Configuration as Config

# Fetch configuration for the API key & secret inside
parser = argparse.ArgumentParser()
parser.add_argument("-cfg", "--config", help="Custom config file")
args = parser.parse_args()
if args.config:
    config_location = args.config
else:
    config_location = 'default.cfg'
Config.init(config_location)

api = Poloniex(Config.get('API', 'apikey', None), Config.get('API', 'secret', None))
active_loans = api.return_active_loans()
active_loans_sum = pd.DataFrame.from_records(active_loans['provided']).query('currency == "BTC"')['amount'].map(lambda x: x.replace('.','')).astype('int').sum()
idle_loan_balance = api.return_available_account_balances("lending")["lending"]
# idle_loan_balance = int(idle_loan_balance.replace('.', ''))
if idle_loan_balance == []:
    idle_loan_balance = 0
else:
    idle_loan_balance = int(idle_loan_balance["BTC"].replace('.', ''))

print("Idle: {0}".format(idle_loan_balance))
print("Active: {0}".format(active_loans_sum))
print("Total satoshi: {0}".format(idle_loan_balance + active_loans_sum))