market_emulator.py 1.13 KB
Newer Older
Mikey's avatar
Mikey committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
import bittrex.bittrex as bx
import logging

class e_balance(object):
  def __init__(self,bittrex):
    self.all = {'BTC':0.500}
    self.b = bittrex
  def deduct(self,coin,amount):
    print(coin+': '+str(amount))
    self.all.setdefault(coin, 0.0)
    if amount > self.all[coin]:
      print('Error! Not enough coin!: '+coin)
    else:
      self.all[coin] -= amount
  def add(self,coin,amount):
    print(coin+': '+str(amount))
    self.all.setdefault(coin,0.0)
    self.all[coin] += amount
    
    
class e_trader(object):
  def __init__(self,bittrex,bal):
    self.b = bittrex
    self.bal = bal
    self.m_2_c = {'BTC':'USDT-BTC'}
    
  def buy_market_e(self,market,amount,ask):
    #b.get_ticker(market)['Ask']
    tt = market.split('-')
    base = tt[0]
    head = tt[1]
    am = (amount*ask)
    am = am + (am*0.0025)
    self.bal.deduct(base,am)
    self.bal.add(head,amount)
    
    self.m_2_c.setdefault(head,market)
    
  def sell_market_e(self,market,amount,ask):
    tt = market.split('-')
    base = tt[0]
    head = tt[1]
      
    am = (amount*ask)
    am = am - (am*0.0025)
    self.bal.deduct(head, amount)
    self.bal.add(base, am)