Exemplo n.º 1
0
from btsx import BTSX
from mylog import logger
import urllib2
import json
import time

if len(sys.argv) < 5:
    print "Usage:  feed.py rpcuser rpcpass port live_network"
    sys.exit(0)

user = sys.argv[1]
password = sys.argv[2]
port = int(sys.argv[3])
live = bool(sys.argv[4])

SYMBOL = ""
if live:
    SYMBOL = "BTSX"
else:
    SYMBOL = "XTS"

client = BTSX(user, password, port, "bitusd-buyer")


while True:
    remaining = client.get_balance(SYMBOL)
    bid = client.get_highest_bid("USD", SYMBOL)
    price = (float(ask["market_index"]["order_price"]["ratio"]) * 10)  - 0.0001
    print client.submit_ask(remaining / 100, SYMBOL, price, "USD")
    time.sleep(10)
Exemplo n.º 2
0
        if is_cancel : continue
        if is_market : continue 
        for l in i["ledger_entries"] :
            if( l[ "memo" ] == "yield" ) : continue ## skip yields
            asset_id            = l["amount"]["asset_id"]
            precision           = basePrecision if asset_id == baseid else quotePrecision
            amount              = l["amount"]["amount"] / precision
            matchObjA = re.match( r'^(ASK)|(BID)', l["from_account"], re.M|re.I)
            matchObjB = re.match( r'^(ASK)|(BID)', l["to_account"], re.M|re.I)
            if matchObjA or matchObjB: continue # skip market
            if l["to_account"] == name : funding[ asset_id ] += amount
            else :                       funding[ asset_id ] -= amount

    ## Get Balances ###########################################################
    last_price   = client.get_last_fill(quote, base) * (basePrecision / quotePrecision)
    balanceBase  = client.get_balance(name, base)
    balanceQuote = client.get_balance(name, quote)

    ## Adjust by open orders ##################################################
    open_orders  = client.get_all_orders(name, quote, base)
    for o in open_orders[ 1 ] :
       if   o[ "type" ] == "ask_order" : balanceBase  += float(o["state"]["balance"]) / basePrecision  # balance in base
       elif o[ "type" ] == "bid_order" : balanceQuote += float(o["state"]["balance"]) / quotePrecision # balance in quote
       else : raise Exception( "This bot only runs with a separate account name!" )

    ## Output #################################################################
    print('+'*65)
    print('Balance: %20.8f %4s = %20.8f %4s' %(balanceBase, base, balanceBase*last_price, quote))
    print('Balance: %20.8f %4s = %20.8f %4s' %(balanceQuote, quote, balanceQuote/last_price, base))
    print('-'*65)
    print('Sum:     %20.8f %4s = %20.8f %4s' %(balanceBase+balanceQuote/last_price, base, balanceBase*last_price+balanceQuote, quote))
Exemplo n.º 3
0
password = sys.argv[2]
port = int(sys.argv[3])
live = bool(sys.argv[4])

if live:
    SYMBOL = "BTSX"
else:
    SYMBOL = "XTS"

client = BTSX(user, password, port, "arbiteur")


init_price = get_true_price()
log("Init price:  %f" % init_price)
log("Init price:  %f" % (1.0 / init_price))
init_usd_balance = client.get_balance("USD")
print init_usd_balance
init_btsx_balance = client.get_balance(SYMBOL)
print init_btsx_balance

client.cancel_all_orders("USD", SYMBOL)
print init_usd_balance / init_price
print client.submit_bid(0.3*(init_usd_balance / init_price), SYMBOL, init_price * (1-SPREAD_PERCENT), "USD")
print client.submit_ask(0.3*(init_btsx_balance), SYMBOL, init_price * (1+SPREAD_PERCENT), "USD")
sec_since_update = 0
last_price = init_price
while True:
    true_usd_per_btsx = get_true_price()

    log("Price moved  -  old:  %f   new:  %f" % (last_price, true_usd_per_btsx))