Algo Trading Python Code Example

 


Here is a code example of algorithm trading using Python on the upcoming coin, DeepOnion.  For more details, see this thread on bitcointalk.  .py file can be found here.

import time
import hmac
import hashlib
import base64
import requests
import json
import urllib
import sys

 

API_KEY = “xxx”
API_SECRET = “xxx”

public_set = set([ “GetCurrencies”, “GetTradePairs”, “GetMarkets”, “GetMarket”, “GetMarketHistory”, “GetMarketOrders” ])
private_set = set([ “GetBalance”, “GetDepositAddress”, “GetOpenOrders”, “GetTradeHistory”, “GetTransactions”, “SubmitTrade”, “CancelTrade”, “SubmitTip” ])

url = “https://www.cryptopia.co.nz/”

while True:

NonceTimeFactor = 3

 

def NonceValue(NonceTimeFactor):
Nonce = str( int( time.time() * NonceTimeFactor – 4361732500 ) )
return Nonce

 

def api_query( method, req = None ):
url = “https://www.cryptopia.co.nz/”
if not req:
req = {}
if method.split(‘/’)[0][0:6] == ‘Api’:
r = requests.get( url + method + ‘/’, timeout = 60 )
elif method.split(‘/’)[0][0:6] == ‘Api’:
url = “https://www.cryptopia.co.nz/” + method
nonce = NonceValue(NonceTimeFactor)
post_data = json.dumps( req );
m = hashlib.md5()
m.update(post_data)
requestContentBase64String = base64.b64encode(m.digest())
signature = API_KEY + “POST” + urllib.quote_plus( url ).lower() + nonce + requestContentBase64String
hmacsignature = base64.b64encode(hmac.new(base64.b64decode( API_SECRET ), signature, hashlib.sha256).digest())
header_value = “amx ” + API_KEY + “:” + hmacsignature + “:” + nonce
headers = { ‘Authorization’: header_value, ‘Content-Type’:’application/json; charset=utf-8′ }
r = requests.post( url, data = post_data, headers = headers, timeout = 60 )
return r.text

def api_query1( method, req = None ):
url = “https://www.cryptopia.co.nz/”
if not req:
req = {}
if method.split(‘/’)[0][0:6] == ‘A’:
r = requests.get( url + method + ‘/’, timeout = 60 )
elif method.split(‘/’)[0][0:6] == ‘Api’:
url = “https://www.cryptopia.co.nz/” + method
nonce = NonceValue(NonceTimeFactor)
post_data = json.dumps( req );
m = hashlib.md5()
m.update(post_data)
requestContentBase64String = base64.b64encode(m.digest())
signature = API_KEY + “POST” + urllib.quote_plus( url ).lower() + nonce + requestContentBase64String
hmacsignature = base64.b64encode(hmac.new(base64.b64decode( API_SECRET ), signature, hashlib.sha256).digest())
header_value = “amx ” + API_KEY + “:” + hmacsignature + “:” + nonce
headers = { ‘Authorization’: header_value, ‘Content-Type’:’application/json; charset=utf-8′ }
r = requests.post( url, data = post_data, headers = headers )
return r.text

 

#VARIABLES

buypricelimit = 0.0009
sellpricelimit = 0.0005775
sizelimit = 22835.21785463
minsizelimit = 6.28951249
maxtotalsize = 25900
searchsize = 98.1
safebuyprice = 0.000177
safesellprice = 0.0009
#SIZE

bid1 = (api_query( “Api/” + “GetMarketOrders/” + “ONION_BTC” ))
bid1 = json.loads(bid1)
bid1 = bid1[‘Data’][‘Buy’][0][‘Volume’]

bid2 = (api_query( “Api/” + “GetMarketOrders/” + “ONION_BTC” ))
bid3 = (api_query( “Api/” + “GetMarketOrders/” + “ONION_BTC” ))
bid4 = (api_query( “Api/” + “GetMarketOrders/” + “ONION_BTC” ))
bid5 = (api_query( “Api/” + “GetMarketOrders/” + “ONION_BTC” ))
bid6 = (api_query( “Api/” + “GetMarketOrders/” + “ONION_BTC” ))
bid7 = (api_query( “Api/” + “GetMarketOrders/” + “ONION_BTC” ))
bid8 = (api_query( “Api/” + “GetMarketOrders/” + “ONION_BTC” ))
bid9 = (api_query( “Api/” + “GetMarketOrders/” + “ONION_BTC” ))
bid10 = (api_query( “Api/” + “GetMarketOrders/” + “ONION_BTC” ))

bid2 = json.loads(bid2)
bid3 = json.loads(bid3)
bid4 = json.loads(bid4)
bid5 = json.loads(bid5)
bid6 = json.loads(bid6)
bid7 = json.loads(bid7)
bid8 = json.loads(bid8)
bid9 = json.loads(bid9)
bid10 = json.loads(bid10)

bid2 = bid2[‘Data’][‘Buy’][1][‘Volume’]
bid3 = bid3[‘Data’][‘Buy’][2][‘Volume’]
bid4 = bid4[‘Data’][‘Buy’][3][‘Volume’]
bid5 = bid5[‘Data’][‘Buy’][4][‘Volume’]
bid6 = bid6[‘Data’][‘Buy’][5][‘Volume’]
bid7 = bid7[‘Data’][‘Buy’][6][‘Volume’]
bid8 = bid8[‘Data’][‘Buy’][7][‘Volume’]
bid9 = bid9[‘Data’][‘Buy’][8][‘Volume’]
bid10 = bid10[‘Data’][‘Buy’][9][‘Volume’]

ask1 = (api_query( “Api/” + “GetMarketOrders/” + “ONION_BTC” ))
ask2 = (api_query( “Api/” + “GetMarketOrders/” + “ONION_BTC” ))
ask3 = (api_query( “Api/” + “GetMarketOrders/” + “ONION_BTC” ))
ask4 = (api_query( “Api/” + “GetMarketOrders/” + “ONION_BTC” ))
ask5 = (api_query( “Api/” + “GetMarketOrders/” + “ONION_BTC” ))
ask6 = (api_query( “Api/” + “GetMarketOrders/” + “ONION_BTC” ))
ask7 = (api_query( “Api/” + “GetMarketOrders/” + “ONION_BTC” ))
ask8 = (api_query( “Api/” + “GetMarketOrders/” + “ONION_BTC” ))
ask9 = (api_query( “Api/” + “GetMarketOrders/” + “ONION_BTC” ))
ask10 = (api_query( “Api/” + “GetMarketOrders/” + “ONION_BTC” ))
ask1 = json.loads(ask1)
ask2 = json.loads(ask2)
ask3 = json.loads(ask3)
ask4 = json.loads(ask4)
ask5 = json.loads(ask5)
ask6 = json.loads(ask6)
ask7 = json.loads(ask7)
ask8 = json.loads(ask8)
ask9 = json.loads(ask9)
ask10 = json.loads(ask10)
ask1 = ask1[‘Data’][‘Sell’][0][‘Volume’]
ask2 = ask2[‘Data’][‘Sell’][1][‘Volume’]
ask3 = ask3[‘Data’][‘Sell’][2][‘Volume’]
ask4 = ask4[‘Data’][‘Sell’][3][‘Volume’]
ask5 = ask5[‘Data’][‘Sell’][4][‘Volume’]
ask6 = ask6[‘Data’][‘Sell’][5][‘Volume’]
ask7 = ask7[‘Data’][‘Sell’][6][‘Volume’]
ask8 = ask8[‘Data’][‘Sell’][7][‘Volume’]
ask9 = ask9[‘Data’][‘Sell’][8][‘Volume’]
ask10 = ask10[‘Data’][‘Sell’][9][‘Volume’]

#PRICE

bprice1 = (api_query( “Api/” + “GetMarketOrders/” + “ONION_BTC” ))
bprice2 = (api_query( “Api/” + “GetMarketOrders/” + “ONION_BTC” ))
bprice3 = (api_query( “Api/” + “GetMarketOrders/” + “ONION_BTC” ))
bprice4 = (api_query( “Api/” + “GetMarketOrders/” + “ONION_BTC” ))
bprice5 = (api_query( “Api/” + “GetMarketOrders/” + “ONION_BTC” ))
bprice6 = (api_query( “Api/” + “GetMarketOrders/” + “ONION_BTC” ))
bprice7 = (api_query( “Api/” + “GetMarketOrders/” + “ONION_BTC” ))
bprice8 = (api_query( “Api/” + “GetMarketOrders/” + “ONION_BTC” ))
bprice9 = (api_query( “Api/” + “GetMarketOrders/” + “ONION_BTC” ))
bprice10 = (api_query( “Api/” + “GetMarketOrders/” + “ONION_BTC” ))
bprice1 = json.loads(bprice1)
bprice2 = json.loads(bprice2)
bprice3 = json.loads(bprice3)
bprice4 = json.loads(bprice4)
bprice5 = json.loads(bprice5)
bprice6 = json.loads(bprice6)
bprice7 = json.loads(bprice7)
bprice8 = json.loads(bprice8)
bprice9 = json.loads(bprice9)
bprice10 = json.loads(bprice10)
bprice1 = bprice1[‘Data’][‘Buy’][0][‘Price’]
bprice2 = bprice2[‘Data’][‘Buy’][1][‘Price’]
bprice3 = bprice3[‘Data’][‘Buy’][2][‘Price’]
bprice4 = bprice4[‘Data’][‘Buy’][3][‘Price’]
bprice5 = bprice5[‘Data’][‘Buy’][4][‘Price’]
bprice6 = bprice6[‘Data’][‘Buy’][5][‘Price’]
bprice7 = bprice7[‘Data’][‘Buy’][6][‘Price’]
bprice8 = bprice8[‘Data’][‘Buy’][7][‘Price’]
bprice9 = bprice9[‘Data’][‘Buy’][8][‘Price’]
bprice10 = bprice10[‘Data’][‘Buy’][9][‘Price’]
aprice1 = (api_query( “Api/” + “GetMarketOrders/” + “ONION_BTC” ))
aprice2 = (api_query( “Api/” + “GetMarketOrders/” + “ONION_BTC” ))
aprice3 = (api_query( “Api/” + “GetMarketOrders/” + “ONION_BTC” ))
aprice4 = (api_query( “Api/” + “GetMarketOrders/” + “ONION_BTC” ))
aprice5 = (api_query( “Api/” + “GetMarketOrders/” + “ONION_BTC” ))
aprice6 = (api_query( “Api/” + “GetMarketOrders/” + “ONION_BTC” ))
aprice7 = (api_query( “Api/” + “GetMarketOrders/” + “ONION_BTC” ))
aprice8 = (api_query( “Api/” + “GetMarketOrders/” + “ONION_BTC” ))
aprice9 = (api_query( “Api/” + “GetMarketOrders/” + “ONION_BTC” ))
aprice10 = (api_query( “Api/” + “GetMarketOrders/” + “ONION_BTC” ))
aprice1 = json.loads(aprice1)
aprice2 = json.loads(aprice2)
aprice3 = json.loads(aprice3)
aprice4 = json.loads(aprice4)
aprice5 = json.loads(aprice5)
aprice6 = json.loads(aprice6)
aprice7 = json.loads(aprice7)
aprice8 = json.loads(aprice8)
aprice9 = json.loads(aprice9)
aprice10 = json.loads(aprice10)
aprice1 = aprice1[‘Data’][‘Sell’][0][‘Price’]
aprice2 = aprice2[‘Data’][‘Sell’][1][‘Price’]
aprice3 = aprice3[‘Data’][‘Sell’][2][‘Price’]
aprice4 = aprice4[‘Data’][‘Sell’][3][‘Price’]
aprice5 = aprice5[‘Data’][‘Sell’][4][‘Price’]
aprice6 = aprice6[‘Data’][‘Sell’][5][‘Price’]
aprice7 = aprice7[‘Data’][‘Sell’][6][‘Price’]
aprice8 = aprice8[‘Data’][‘Sell’][7][‘Price’]
aprice9 = aprice9[‘Data’][‘Sell’][8][‘Price’]
aprice10 = aprice10[‘Data’][‘Sell’][9][‘Price’]

#MY ORDERS AND BALANCES

totalbalance = (api_query1( “Api/” + “GetBalance/”, {‘Currency’:’ONION’} ))
totalbalance = json.loads(totalbalance)
totalbalance = totalbalance[‘Data’][0][‘Total’]

time.sleep(3)

availbalance = (api_query1( “Api/” + “GetBalance/”, {‘Currency’:’ONION’} ))
availbalance = json.loads(availbalance)
availbalance = availbalance[‘Data’][0][‘Available’]

time.sleep(3)

balancebtc = (api_query1( “Api/” + “GetBalance/”, {‘Currency’:’BTC’} ))
balancebtc = json.loads(balancebtc)
balancebtc = balancebtc[‘Data’][0][‘Available’]

time.sleep(3)

firstorder = (api_query1( “Api/” + “GetOpenOrders/”, {‘Market’:’ONION/BTC’} ))
time.sleep(3)
secondorder = (api_query1( “Api/” + “GetOpenOrders/”, {‘Market’:’ONION/BTC’} ))
time.sleep(3)
firstorder = json.loads(firstorder)
secondorder = json.loads(secondorder)
try:
firstorder = firstorder[‘Data’][0][‘Rate’]
except IndexError:
firstorder = ‘0’

try:
secondorder = secondorder[‘Data’][1][‘Rate’]
except IndexError:
secondorder = ‘0’

 

firstid = (api_query1( “Api/” + “GetOpenOrders/”, {‘Market’:’ONION/BTC’} ))
time.sleep(3)
secondid = (api_query1( “Api/” + “GetOpenOrders/”, {‘Market’:’ONION/BTC’} ))
time.sleep(3)
firstid = json.loads(firstid)
secondid = json.loads(secondid)
try:
firstid = firstid[‘Data’][0][‘OrderId’]
except IndexError:
firstid = ‘0’
try:
secondid = secondid[‘Data’][1][‘OrderId’]
except IndexError:
secondid = ‘0’

firstside = (api_query1( “Api/” + “GetOpenOrders/”, {‘Market’:’ONION/BTC’} ))
time.sleep(3)
secondside = (api_query1( “Api/” + “GetOpenOrders/”, {‘Market’:’ONION/BTC’} ))
time.sleep(3)
firstside = json.loads(firstside)
secondside = json.loads(secondside)
try:
firstside = firstside[‘Data’][0][‘Type’]
except IndexError:
firstside = ‘0’
try:
secondside = secondside[‘Data’][1][‘Type’]
except IndexError:
secondside = ‘0’

mybidprice = float(bprice1) + 0.00000001
mybidsize = 0
myasksize = 0
mybidsize = ((float(balancebtc) – 0.0000221) / float(mybidprice) ) – 5
myasksize = (float(availbalance) – 0.1)
if float(mybidsize) > float(sizelimit):
mybidsize = float(sizelimit)

#Search size

if float(bid1) > searchsize:
mybidprice = float(bprice1) + 0.00000001
elif (float(bid1) + float(bid2)) > searchsize:
mybidprice = float(bprice2) + 0.00000001
elif (float(bid1) + float(bid2) + float(bid3)) > searchsize:
mybidprice = float(bprice3) + 0.00000001
elif (float(bid1) + float(bid2) + float(bid3) + float(bid4)) > searchsize:
mybidprice = float(bprice4) + 0.00000001
elif (float(bid1) + float(bid2) + float(bid3) + float(bid4) + float(bid5)) > searchsize:
mybidprice = float(bprice5) + 0.00000001
elif (float(bid1) + float(bid2) + float(bid3) + float(bid4) + float(bid5) + float(bid6)) > searchsize:
mybidprice = float(bprice6) + 0.00000001
elif (float(bid1) + float(bid2) + float(bid3) + float(bid4) + float(bid5) + float(bid6) + float(bid7)) > searchsize:
mybidprice = float(bprice7) + 0.00000001
elif (float(bid1) + float(bid2) + float(bid3) + float(bid4) + float(bid5) + float(bid6) + float(bid7) + float(bid8)) > searchsize:
mybidprice = float(bprice8) + 0.00000001
elif (float(bid1) + float(bid2) + float(bid3) + float(bid4) + float(bid5) + float(bid6) + float(bid7) + float(bid8) + float(bid9)) > searchsize:
mybidprice = float(bprice9) + 0.00000001
elif (float(bid1) + float(bid2) + float(bid3) + float(bid4) + float(bid5) + float(bid6) + float(bid7) + float(bid8) + float(bid9) + float(bid10)) > searchsize:
mybidprice = float(bprice10) + 0.00000001
else:
mybidprice = float(bprice10) + 0.00000001
if float(mybidprice) > float(buypricelimit):
mybidprice = float(buypricelimit)

myaskprice = float(aprice1) – 0.00000001
if float(ask1) > searchsize:
myaskprice = float(aprice1) – 0.00000001
elif (float(ask1) + float(ask2)) > searchsize:
myaskprice = float(aprice2) – 0.00000001
elif (float(ask1) + float(ask2) + float(ask3)) > searchsize:
myaskprice = float(aprice3) – 0.00000001
elif (float(ask1) + float(ask2) + float(ask3) + float(ask4)) > searchsize:
myaskprice = float(aprice4) – 0.00000001
elif (float(ask1) + float(ask2) + float(ask3) + float(ask4) + float(ask5)) > searchsize:
myaskprice = float(aprice5) – 0.00000001
elif (float(ask1) + float(ask2) + float(ask3) + float(ask4) + float(ask5) + float(ask6)) > searchsize:
myaskprice = float(aprice6) – 0.00000001
elif (float(ask1) + float(ask2) + float(ask3) + float(ask4) + float(ask5) + float(ask6) + float(ask7)) > searchsize:
myaskprice = float(aprice7) – 0.00000001
elif (float(ask1) + float(ask2) + float(ask3) + float(ask4) + float(ask5) + float(ask6) + float(ask7) + float(ask8)) > searchsize:
myaskprice = float(aprice8) – 0.00000001
elif (float(ask1) + float(ask2) + float(ask3) + float(ask4) + float(ask5) + float(ask6) + float(ask7) + float(ask8) + float(ask9)) > searchsize:
myaskprice = float(aprice9) – 0.00000001
elif (float(ask1) + float(ask2) + float(ask3) + float(ask4) + float(ask5) + float(ask6) + float(ask7) + float(ask8) + float(ask9) + float(ask10)) > searchsize:
myaskprice = float(aprice10) – 0.00000001
else:
myaskprice = float(aprice10) – 0.00000001

if float(myaskprice) < float(sellpricelimit):
myaskprice = float(sellpricelimit)

checkfirstbuy = 1
checksecondbuy = 1
checkfirstsell = 1
checksecondsell = 1

if firstside in [“Buy”] and float(firstorder) > 0:
try:
checkfirstbuy = 1
except IndexError:
checkfirstbuy = 0
else:
checkfirstbuy = 0
if secondside in [“Buy”] and float(secondorder) > 0:
try:
checksecondbuy = 1
except IndexError:
checksecondbuy = 0
else:
checksecondbuy = 0
if firstside in [“Sell”] and float(firstorder) > 0:
try:
checkfirstsell = 1
except IndexError:
checkfirstsell = 0
else:
checkfirstsell = 0
if secondside in [“Sell”] and float(secondorder) > 0:
try:
checksecondsell = 1
except IndexError:
checksecondsell = 0
else:
checksecondsell = 0

if (float(firstorder) <= float(safebuyprice)):
checkfirstbuy = 0

if (float(secondorder) <= float(safebuyprice)):
checksecondbuy = 0

if (float(firstorder) >= float(safesellprice)):
checkfirstsell = 0

if (float(secondorder) >= float(safesellprice)):
checksecondsell = 0

 

def getbalance():
balancebtc = (api_query1( “Api/” + “GetBalance/”, {‘Currency’:’BTC’} ))
time.sleep(3)
balancebtc = json.loads(balancebtc)
balancebtc = balancebtc[‘Data’][0][‘Available’]
return float(balancebtc)

def getbidprice():
mybidprice = float(bprice1) + 0.00000001
if float(bid1) – float(mybidsize) > searchsize:
mybidprice = float(bprice1) + 0.00000001
elif (float(bid1) + float(bid2) – float(mybidsize)) > searchsize:
mybidprice = float(bprice2) + 0.00000001
elif (float(bid1) + float(bid2) + float(bid3) – float(mybidsize)) > searchsize:
mybidprice = float(bprice3) + 0.00000001
elif (float(bid1) + float(bid2) + float(bid3) + float(bid4) – float(mybidsize)) > searchsize:
mybidprice = float(bprice4) + 0.00000001
elif (float(bid1) + float(bid2) + float(bid3) + float(bid4) + float(bid5) – float(mybidsize)) > searchsize:
mybidprice = float(bprice5) + 0.00000001
elif (float(bid1) + float(bid2) + float(bid3) + float(bid4) + float(bid5) + float(bid6) – float(mybidsize)) > searchsize:
mybidprice = float(bprice6) + 0.00000001
elif (float(bid1) + float(bid2) + float(bid3) + float(bid4) + float(bid5) + float(bid6) + float(bid7) – float(mybidsize)) > searchsize:
mybidprice = float(bprice7) + 0.00000001
elif (float(bid1) + float(bid2) + float(bid3) + float(bid4) + float(bid5) + float(bid6) + float(bid7) + float(bid8) – float(mybidsize)) > searchsize:
mybidprice = float(bprice8) + 0.00000001
elif (float(bid1) + float(bid2) + float(bid3) + float(bid4) + float(bid5) + float(bid6) + float(bid7) + float(bid8) + float(bid9) – float(mybidsize)) > searchsize:
mybidprice = float(bprice9) + 0.00000001
elif (float(bid1) + float(bid2) + float(bid3) + float(bid4) + float(bid5) + float(bid6) + float(bid7) + float(bid8) + float(bid9) + float(bid10) – float(mybidsize)) > searchsize:
mybidprice = float(bprice10) + 0.00000001
else:
mybidprice = float(bprice10) + 0.00000001
if float(mybidprice) > float(buypricelimit):
mybidprice = float(buypricelimit)
return(mybidprice)

def getaskprice():
myaskprice = float(aprice1) – 0.00000001
if float(ask1) – float(myasksize) > searchsize:
myaskprice = float(aprice1) – 0.00000001
elif (float(ask1) + float(ask2) – float(myasksize)) > searchsize:
myaskprice = float(aprice2) – 0.00000001
elif (float(ask1) + float(ask2) + float(ask3) – float(myasksize)) > searchsize:
myaskprice = float(aprice3) – 0.00000001
elif (float(ask1) + float(ask2) + float(ask3) + float(ask4) – float(myasksize)) > searchsize:
myaskprice = float(aprice4) – 0.00000001
elif (float(ask1) + float(ask2) + float(ask3) + float(ask4) + float(ask5) – float(myasksize)) > searchsize:
myaskprice = float(aprice5) – 0.00000001
elif (float(ask1) + float(ask2) + float(ask3) + float(ask4) + float(ask5) + float(ask6) – float(myasksize)) > searchsize:
myaskprice = float(aprice6) – 0.00000001
elif (float(ask1) + float(ask2) + float(ask3) + float(ask4) + float(ask5) + float(ask6) + float(ask7) – float(myasksize)) > searchsize:
myaskprice = float(aprice7) – 0.00000001
elif (float(ask1) + float(ask2) + float(ask3) + float(ask4) + float(ask5) + float(ask6) + float(ask7) + float(ask8) – float(myasksize)) > searchsize:
myaskprice = float(aprice8) – 0.00000001
elif (float(ask1) + float(ask2) + float(ask3) + float(ask4) + float(ask5) + float(ask6) + float(ask7) + float(ask8) + float(ask9) – float(myasksize)) > searchsize:
myaskprice = float(aprice9) – 0.00000001
elif (float(ask1) + float(ask2) + float(ask3) + float(ask4) + float(ask5) + float(ask6) + float(ask7) + float(ask8) + float(ask9) + float(ask10) – float(myasksize)) > searchsize:
myaskprice = float(aprice10) – 0.00000001
else:
myaskprice = float(aprice10) – 0.00000001
if float(myaskprice) < float(sellpricelimit):
myaskprice = float(sellpricelimit)
return(myaskprice)

 

def getbidsize():
mybidsize = ((getbalance() – 0.0000221) / getbidprice()) – 5
if float(mybidsize) > float(sizelimit):
mybidsize = float(sizelimit)
return float(mybidsize)

#INIT ORDERS

time.sleep(3)
if ((float(mybidsize) > float(minsizelimit)) and (float(totalbalance) < float(maxtotalsize)) and (int(checkfirstbuy) < 1) and (int(checksecondbuy) < 1)):
print(api_query1( “Api/” + “SubmitTrade/”, { ‘Market’: “ONION/BTC”, ‘Type’: “BUY”, ‘Rate’: float(mybidprice), ‘Amount’: float(mybidsize) } ) + ‘\n’ + ‘\n’ + “NEW BUY ORDER” + ‘\n’)
time.sleep(3)
if ((float(myasksize) > float(minsizelimit)) and (int(checkfirstsell) < 1) and (int(checksecondsell) < 1)):
print(api_query1( “Api/” + “SubmitTrade/”, { ‘Market’: “ONION/BTC”, ‘Type’: “SELL”, ‘Rate’: float(myaskprice), ‘Amount’: float(myasksize) } ) + ‘\n’ + ‘\n’ + “NEW SELL ORDER” + ‘\n’)

time.sleep(3)

#SHAVE

time.sleep(3)
if (firstside in [“Buy”] and (float(firstorder) != getbidprice()) and (float(firstorder) > float(safebuyprice)) and (int(checkfirstbuy) == 1)):
if float(firstorder) < float(bprice1):
api_query1( “Api/” + “CancelTrade/”, { ‘Type’: “Trade”, ‘OrderId’: str(firstid) } )
time.sleep(3)
print(api_query1( “Api/” + “SubmitTrade/”, { ‘Market’: “ONION/BTC”, ‘Type’: “BUY”, ‘Rate’: getbidprice(), ‘Amount’: getbidsize() } ) + ‘\n’ + ‘\n’ + “CFO BUY ORDER” + ‘\n’)

if (secondside in [“Buy”] and (float(secondorder) != getbidprice()) and (float(secondorder) > float(safebuyprice)) and (int(checksecondbuy) == 1)):
if float(secondorder) < float(bprice1):
api_query1( “Api/” + “CancelTrade/”, { ‘Type’: “Trade”, ‘OrderId’: str(secondid) } )
time.sleep(3)
print(api_query1( “Api/” + “SubmitTrade/”, { ‘Market’: “ONION/BTC”, ‘Type’: “BUY”, ‘Rate’: getbidprice(), ‘Amount’: getbidsize() } ) + ‘\n’ + ‘\n’ + “CFO BUY ORDER” + ‘\n’)
time.sleep(3)
if (firstside in [“Sell”] and (float(firstorder) != getaskprice()) and (float(firstorder) < float(safesellprice)) and (int(checkfirstsell) == 1)):
if float(firstorder) > float(aprice1):
api_query1( “Api/” + “CancelTrade/”, { ‘Type’: “Trade”, ‘OrderId’: str(firstid) } )
time.sleep(3)
availbalance = (api_query1( “Api/” + “GetBalance/”, {‘Currency’:’ONION’} ))
time.sleep(3)
availbalance = json.loads(availbalance)
availbalance = availbalance[‘Data’][0][‘Available’]
myasksize = (float(availbalance) – 0.1)
print(api_query1( “Api/” + “SubmitTrade/”, { ‘Market’: “ONION/BTC”, ‘Type’: “SELL”, ‘Rate’: getaskprice(), ‘Amount’: float(myasksize) } ) + ‘\n’ + ‘\n’ + “CFO SELL ORDER” + ‘\n’)
time.sleep(3)
if (secondside in [“Sell”] and (float(secondorder) != getaskprice()) and (float(secondorder) < float(safesellprice)) and (int(checksecondsell) == 1)):
if float(secondorder) > float(aprice1):
api_query1( “Api/” + “CancelTrade/”, { ‘Type’: “Trade”, ‘OrderId’: str(secondid) } )
time.sleep(3)
availbalance = (api_query1( “Api/” + “GetBalance/”, {‘Currency’:’ONION’} ))
time.sleep(3)
availbalance = json.loads(availbalance)
availbalance = availbalance[‘Data’][0][‘Available’]
myasksize = (float(availbalance) – 0.1)
print(api_query1( “Api/” + “SubmitTrade/”, { ‘Market’: “ONION/BTC”, ‘Type’: “SELL”, ‘Rate’: getaskprice(), ‘Amount’: float(myasksize) } ) + ‘\n’ + ‘\n’ + “CFO SELL ORDER” + ‘\n’)
time.sleep(3)

continue

 

Leave a Reply

Your email address will not be published. Required fields are marked *