Exemplo n.º 1
0
 def test_get_payment_methods(self):
   client = Client(api_key, api_secret)
   payment_methods = client.get_payment_methods()
   self.assertIsInstance(payment_methods, APIObject)
   self.assertEqual(payment_methods.data, mock_collection)
   for payment_method in payment_methods.data:
     self.assertIsInstance(payment_method, PaymentMethod)
Exemplo n.º 2
0
 def test_get_payment_methods(self):
     client = Client(api_key, api_secret)
     payment_methods = client.get_payment_methods()
     self.assertIsInstance(payment_methods, APIObject)
     self.assertEqual(payment_methods.data, mock_collection)
     for payment_method in payment_methods.data:
         self.assertIsInstance(payment_method, PaymentMethod)
Exemplo n.º 3
0
def buy_btc(amount, addr):
  client = Client(api_key,api_secret)
  account = client.get_primary_account()
  payment_method = client.get_payment_methods()[0]
  buy_price  = client.get_buy_price(currency='USD')
  buy = account.buy(amount=amount/(buy_price*1.1),
                    currency="BTC",
                    payment_method=payment_method.id)
  tx = account.send_money(to=addr,
                                amount=amount/(buy_price*1.1),
                                currency='BTC')
Exemplo n.º 4
0
class Coinbase():
    def __init__(self):
        self.client = Client(os.environ['COINBASE_API_KEY'],
                             os.environ['COINBASE_API_SECRET'],
                             api_version='2020-12-08')
        self.payment_methods = self.client.get_payment_methods()
        self.account = self.client.get_primary_account()
        self.payment_method = self.client.get_payment_methods()[0]

    def get_price(self, date, currency):
        return self.client.get_spot_price(currency_pair=f'{currency}-EUR',
                                          date=date)

    def get_portfolio(self):
        pass

    def buy(self, amount):
        pass

    def sell(self, amount):
        pass
Exemplo n.º 5
0
def buy_coins(order: BuyOrder):
    coins = sat_to_coins(order.satoshis)

    client = Client("4Mf2j413XB7qNl3V", "0e1wuPN2MaDDPTQdZUQMonxLaJ3zSael")

    pms = client.get_payment_methods()

    buy = client.buy('2bbf394c-193b-5b2a-9155-3b4732659ede',
                     amount=coins,
                     currency="BTC",
                     payment_method=pms)

    tx = client.send_money('2bbf394c-193b-5b2a-9155-3b4732659ede',
                           to=order.address,
                           amount=coins,
                           currency='BTC',
                           idem='9316dd16-0c05')
Exemplo n.º 6
0
def go():
    print 'start'

    client = Client(config.COINBASE_KEY,
                    config.COINBASE_SECRET,
                    api_version='2017-04-13')

    account = client.get_primary_account()
    payment_methods = client.get_payment_methods().data
    if (len(payment_methods) < 1):
        print 'No payment methods.'
        return
    payment_method = payment_methods[0].id

    # (Right now .001 BTC is about equal to 3.65 USD.)
    # Buy .001 BTC if we can do so for 3 USD or less.
    buyParams = {
        'client': client,
        'payment_method': payment_method,
        'source_currency_symbol': 'USD',
        'source_currency_max_buy_price': 3,
        'target_currency_symbol': 'BTC',
        'target_currency_amount_to_buy': '.001'
    }
    # print buyParams
    buyResult = offerBuy(buyParams)
    print buyResult

    # (Right now .001 BTC is about equal to 3.65 USD.)
    # Sell .001 BTC if we can get at least 5 USD for doing so.
    sellParams = {
        'client': client,
        'payment_method': payment_method,
        'source_currency_symbol': 'BTC',
        'source_currency_amount_to_sell': '.001',
        'target_currency_symbol': 'USD',
        'target_currency_min_aquisition_amount': 5,
    }
    sellResult = offerSell(sellParams)
    print sellResult
Exemplo n.º 7
0
    help=
    "How much of the desired Crypto would you like to buy for the previously defined amount to invest? e.g. 23"
)
args = vars(parser.parse_args())

api_key = args["key"]
api_secret = args["secret"]
targetPaymentMethod = args["paymentMethod"]
targetCurrency = args["currencyToBuy"]
targetBuyCurrencyWallet = args["accountWallet"]
investMoney = float(args["invest"])
targetAmountToBuy = args["buy"]

client = Client(api_key, api_secret)
accounts = client.get_accounts()
pms = client.get_payment_methods()

for method in pms.data:
    if method['name'] == targetPaymentMethod:
        paymentID = method['id']

for account in accounts.data:
    if account['name'] == targetBuyCurrencyWallet:
        accountID = account['id']

buy = client.buy(accountID,
                 commit="false",
                 amount=targetAmountToBuy,
                 currency=targetCurrency,
                 payment_method=paymentID,
                 quote="true")
Exemplo n.º 8
0
accounts_response = client.get_accounts()
print(term.format(accounts_response, term.Color.BLUE))
account_id = json.loads(accounts_response)["data"][0]["id"]

# check real time bitcoin price (total USD to buy one bitcoin)
print(term.format("Check Bitcoin Price\n", term.Attr.BOLD))
bitcoin_price_response = client.get_buy_price(currency_pair='BTC-USD')
print(term.format(bitcoin_price_response, term.Color.BLUE))
bitcoin_price = float(json.loads(bitcoin_price_response)["data"]["amount"])

# convert USD amount to bitcoin
bitcoin_amount = str(usd_amount / bitcoin_price)

# fetch default payment method ID from your coinbase account
print(term.format("Fetch Payment Method\n", term.Attr.BOLD))
payment_methods_response = client.get_payment_methods()
print(term.format(payment_methods_response, term.Color.BLUE))
payment_method_id = json.loads(payment_methods_response)["data"][0]["id"]

# buy bitcoin and commit order immediately
print(term.format("Purchase Bitcoin\n", term.Attr.BOLD))
buy_response = client.buy(account_id,
                          amount=bitcoin_amount,
                          currency="BTC",
                          commit=True,
                          payment_method=payment_method_id)
print(term.format(buy_response, term.Color.BLUE))

# verify purchase time
buy_time = json.loads(buy_response)["data"]["payout_at"]
print(term.format("Purchased Bitcoin at " + buy_time + "\n", term.Attr.BOLD))
Exemplo n.º 9
0
print(' .(-._. ~Coinbase Failsafe~ ._.-). ')
print('###################################')
print('')
sleep(1)
print('[*] Wait time is set to %s seconds.' % (time_delay))
print('[*] Acceptable relative loss from maximum is set to %s %%.' % (margin))
print('[*] The currency code chosen is %s.' % (currency_code))
print('[*] Connecting to Coinbase..')

# Connects to Coinbase
client = Client(api_key, api_secret, api_version=version)
# Gets primary account
account = client.get_primary_account()
price = client.get_spot_price(currency=currency_code)
# DA GUARDARE MEGLIO
payment_method = client.get_payment_methods()[2]
print('[*] Connected. You currently have %s. Starting..' % (account.balance))
print('')

# Defines starting maximum value
max_price = float(price.amount)
# Defines starting acceptable loss
margin_value = (1 - float(margin) / 100) * max_price
sleep(5)

# Main code
while True:

    try:
        account = client.get_primary_account()
        # Updates data
Exemplo n.º 10
0
from coinbase.wallet.client import Client

from config import coinbase_api_key, coinbase_api_secret

SANDBOX_URL = 'https://api.sandbox.coinbase.com'

client = Client(
    coinbase_api_key(),
    coinbase_api_secret(),
    base_api_uri=SANDBOX_URL)

payment_methods = client.get_payment_methods()

account = client.get_primary_account()
payment_method = client.get_payment_methods()[0]

buy_price_threshold = 200
sell_price_threshold = 500

buy_price = client.get_buy_price(currency='USD')
sell_price = client.get_sell_price(currency='USD')

if float(sell_price.amount) <= sell_price_threshold:
  sell = account.sell(amount='1',
                      currency="BTC",
                      payment_method=payment_method.id)

if float(buy_price.amount) <= buy_price_threshold:
  buy = account.buy(amount='1',
                    currency="BTC",
                    payment_method=payment_method.id)