def run_trades():
    price_btc = float(get_price('BTCUSDT')['price'])
    profits = 0
    total_base_currency= 0
    base_currency = 'BTC'
    for balance in balances :
        asset = balance['asset']
        if asset!= base_currency:

            symbol = f'{asset}{base_currency}'
            free_bal = balance_dict[asset]

            price = float(get_price(symbol)['price'])
            if price > price_dict[symbol]*1.05:
                profit = free_bal*price
                print(f"can place buy order for {symbol} for profit of {profit}")
                price_dict[symbol] = price
                #place_new_order_test(symbol)
                profits = profits +profit
                balance_dict[symbol] = 0

            if price < price_dict[symbol]*.95:
                profit = free_bal*price
                print(f"can place sell order for {symbol} for loss of {profit}")
                price_dict[symbol] = price
                #place_new_order_test(symbol)
                profits = profits - profit
                balance_dict[symbol] = free_bal
    print(f"total profit {profits}")
Beispiel #2
0
def getCurrentPositions():
    account_info=api_caller.get_account_info()
    account_data=pd.DataFrame(account_info['balances'],dtype=float)
    account_data=account_data[account_data.free.astype(float)>0.0]

    account_data.index=range(len(account_data))
    btc_price=float(api_caller.get_price('BTCUSDT')['price'])
    eth_price=float(api_caller.get_price('ETHUSDT')['price'])
    all_pos=[]

    for index, row  in account_data.iterrows():
        asset=row['asset']
        print(asset)

        for base_currency in ['BTC','ETH']:
            if asset==base_currency:
                continue
            symbol=asset+base_currency
            btctrades=api_caller.get_all_trades(symbol)
            if len(btctrades)<1 or ('code' in btctrades and  btctrades['code']==-1121):
                continue

            pos_data={}
            btctradesdata=pd.DataFrame(btctrades,dtype=float)
            total_buy_value=0.0
            total_quantity=0.0
            current_price=float(api_caller.get_price(symbol)['price'])
            for idx, row in btctradesdata.iterrows():
                mult= 1 if row['isBuyer']==True else -1
                total_buy_value+=float(row['price'])*float(row['qty'])*mult
                total_quantity+=float(row['qty'])*mult

            base_currency_price=(btc_price if base_currency=='BTC' else eth_price)

            avg_price=total_buy_value/total_quantity
            pos_data['base_currency']=base_currency
            pos_data['asset']=asset
            pos_data['avg_price']=avg_price
            pos_data['qty']=total_quantity
            pos_data['current_price']=current_price
            pos_data['CURR_USD_PRICE']=total_quantity*current_price*base_currency_price
            pos_data['BUY_USD_PRICE']=total_quantity*avg_price*base_currency_price
            all_pos.append(pos_data)


    return all_pos 
Beispiel #3
0
def main():
    price_eth = float(get_price('ETHUSDT')['price'])
    price_btc = float(get_price('BTCUSDT')['price'])
    accounts = get_account_info()
    balances = [acc for acc in accounts['balances'] if float(acc['free']) > 0]
    total_base_currency = 0
    base_currency = 'BTC'
    for balance in balances:
        asset = balance['asset']
        free_bal = float(balance['free'])
        if asset == base_currency:
            total_base_currency = total_base_currency + free_bal
        else:
            price = float(get_price(f'{asset}{base_currency}')['price'])
            total_base_currency = total_base_currency + free_bal * price
    print(
        f"total {base_currency} : {total_base_currency} , Total USD : {total_base_currency*price_btc}"
    )
def init_price():
    base_currency = 'BTC'
    for balance in balances:
        asset = balance['asset']
        if asset != base_currency:
            symbol = f'{asset}{base_currency}'
            price = float(get_price(symbol)['price'])
            price_dict[symbol] = price
            balance_dict[asset] = float(balance['free'])
    print("initialization done ")
def run_trades():
    symbol = 'ADABTC'
    target_price = 0.00004900
    side = 'SELL'
    quantity = 50
    price_btc = float(get_price(symbol)['price'])
    if price_btc > target_price:
        print(f"can place buy order for {symbol} for price of {price_btc}")
        #place_new_order(symbol, quantity= quantity, side=side)
    else:
        print(
            f" cann't place order yet for {target_price} current_price = {price_btc}"
        )
def calculate_total_coins(wallet):
    coins = 0
    for symbol, qty in wallet.items():
        coins = coins + float(get_price(symbol)['price']) * float(qty)
    return coins
import schedule
from binance_exchange_api.rest.api_caller import get_price
import time
import datetime as dt

binance_symbol_btc = {
    'TNBBTC': 332.66700000,
    'ADABTC': 65.93400000,
    'XRPBTC': 21.97800000
}
binance_symbol_eth = {'IOSTETH': 251.748, 'ICXETH': 3.38661000}
price_eth = float(get_price('ETHUSDT')['price'])
price_btc = float(get_price('BTCUSDT')['price'])


def calculate_total_coins(wallet):
    coins = 0
    for symbol, qty in wallet.items():
        coins = coins + float(get_price(symbol)['price']) * float(qty)
    return coins


def calculate_portfolio_value():
    eth = calculate_total_coins(binance_symbol_eth)
    btc = calculate_total_coins(binance_symbol_btc)
    total_val = price_btc * btc + price_eth * eth
    print(dt.datetime.now().strftime('%Y%d%m%H%M%S') + "," + str(total_val))


schedule.every(10).seconds.do(calculate_portfolio_value)
while True:
 def test_price(self):
     price = api_caller.get_price(self.symbol)
     print(price)