Beispiel #1
0
def Buy():
    """Buy Bitcoin a specified Dollar amount."""
    client = Client(coin_api, coin_secret)
    balance = float(client.get_account(btc_id)['native_balance']['amount'])
    amount = round((.1 * balance), 2)
    client.buy(btc_id, amount, currency='USD')
    print(f"Buy order executed in the amount of ${amount}.")
class CoinbaseHelper():
    def __init__(self, api_key, api_secret):
        self.client = Client(api_key, api_secret)

    def get_price(self, seconds):

        price = self.client.get_spot_price(currency_pair='ETH-USD')

        dollar_per_second = 0.00025
        ether_per_dollar = 1 / float(price['amount'])
        ether_price_per_second = ether_per_dollar * dollar_per_second
        final_price = ether_price_per_second * seconds

        if final_price < 0.000001:
            print("SENDING 0.000001")
            return 0.000001

        print(f"SENDING {final_price}")
        return final_price

    def send_ether(self, email, seconds):
        account = self.client.get_account("ETH")
        amount_to_send = self.get_price(seconds)
        tx = account.send_money(to=email,
                                amount=amount_to_send,
                                currency='ETH')

        print(tx)
 def __init__(self, client: Client, currency: str):
     wallet_dict = client.get_account(currency)
     self.client = client
     self.currency = currency
     self.balance = float(wallet_dict['balance']['amount'])
     self.native_currency = wallet_dict['native_balance']['currency']
     self.native_balance = float(wallet_dict['native_balance']['amount'])
Beispiel #4
0
def get_currency_amount(currency):
    """
    :param currency:
    :return:
    """

    client = Client(config['api_key'], config['api_secret'])

    if currency == "BTC":
        account = client.get_account(config["btc_wallet"])
    elif currency == "ETH":
        account = client.get_account(config["eth_wallet"])
    elif currency == "LTC":
        account = client.get_account(config["ltc_wallet"])
    elif currency == "USD":
        account = client.get_account(config["usd_wallet"])

    money = re.search(r'\d+.\d+', str(account["native_balance"]))
    return float(money.group(0))
Beispiel #5
0
class CoinBase:
    def __init__(self, config):
        self.auth_client = Client(config['API_KEY'], config['SECRET'])

    def amount(self):
        try:
            account = self.auth_client.get_account(
                "0ed05157-8cee-501a-bd7e-4fe2aa8d62b8")
            return float(account['native_balance']['amount'])
        except APIError as err:
            raise err
        except KeyError as err:
            raise err
        except ValueError as err:
            raise err
 def test_get_account(self):
     client = Client(api_key, api_secret)
     account = client.get_account('foo')
     self.assertIsInstance(account, Account)
     self.assertEqual(account, mock_item)
Beispiel #7
0
 def test_get_account(self):
   client = Client(api_key, api_secret)
   account = client.get_account('foo')
   self.assertIsInstance(account, Account)
   self.assertEqual(account, mock_item)
Beispiel #8
0
                    'ESjT9WB5rh46NMXsuUOspL8WF3nAkuB4',
                    api_version='2017-11-20')
    accounts = client.get_accounts()
    currency_code = 'GBP'  # can also use EUR, CAD, etc.

    for x in range(1):
        #Make the request
        #price = client.get_spot_price(currency=currency_code)
        #print ('Current bitcoin price in ' +  currency_code + " " +  price.amount)
        #price = client.get_buy_price(currency_pair = 'BTC-GBP')
        #print ('Current BTC BUY price in ' +  currency_code + " " +  price.amount)
        price = client.get_sell_price(currency_pair='BTC-GBP')
        print('Current BTC SELL price in ' + currency_code + " " +
              price.amount)

    account_ = client.get_account("BTC")
    balance = account_.balance
    acc_id = str(account_.id)
    print("DEBUG : account.balance " + str(balance.amount))

    #for account_ in accounts.data:
    #balance = account_.balance
    #print ("DEBUG : account.balance " + str(balance))
    #print (account.name, balance.amount, balance.currency)
    #print (account.get_transactions())

    #**********************TESTING************************
    #**********************TESTING************************
    #**********************TESTING************************
    #**********************TESTING************************
    if ('BTC' in acc.name):
        bal = acc.balance
        balance = float(bal.amount)
        accid = acc.id

###############################################################################
# get payment ID
method = "USD Wallet"
payid = -1

for pm in payment_methods.data:
    if pm.name == method:
        payid = pm.id
###############################################################################
sell_price = client.get_sell_price(currency_pair='BTC-USD')
print(sell_price.amount)

sp = float(sell_price.amount)
sell_value = 15.0
sell_amount = sell_value / sp
print(balance, sell_amount)

samount = "%f" % (sell_amount)

print(accid)

acc = client.get_account(accid)
txs = client.get_transactions(accid)

print(txs.data[0])