Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.40 KB | None | 0 0
  1. entrySpread = 2.05
  2. exitSpread = -1.68
  3. lotSize = 0.2
  4. ###############################################
  5. ##########################################################
  6. ######################################################
  7.  
  8.  
  9. bitFinexAccount = BitFinexAccount(bitFinexCore)
  10. BitFinexHistoricalData = BitFinexHistoricalData(bitFinexCore)
  11. PublicEndpoints = bitfinex_client.PublicEndpoints()
  12. bitFinexOrders = bitfinex_client.BitFinexOrders(bitFinexCore)
  13.  
  14. #print publicClient.getProductOrderBook(level=2)
  15. finexTicker = PublicEndpoints.tickers('tLTCUSD')
  16. bitfinexBid = float(finexTicker['BID'])
  17. bitfinexAsk = float(finexTicker['ASK'])
  18.  
  19. #print authClient.getAccounts()
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33. #print publicClient.getProductOrderBook(level=2)['asks']
  34.  
  35.  
  36.  
  37.  
  38. def GDAXbidDepth(x):
  39. depth =0
  40. GDAXbidBook = publicClient.getProductOrderBook(level=2)['bids']
  41. for orders in GDAXbidBook:
  42. if float(orders[0]) > float(x):
  43. depth = float(orders[1]) + float(depth)
  44. #print "bid", orders[1]
  45. #print depth
  46. print depth
  47. return depth
  48.  
  49. def GDAXaskDepth(x):
  50. depth = 0
  51. GDAXaskBook = publicClient.getProductOrderBook(level=2)['asks']
  52. for orders in GDAXaskBook:
  53. if float(orders[0]) < float(x):
  54. depth = float(orders[1]) + float(depth)
  55. #print "ask", orders[1]
  56. #print depth
  57. print depth
  58. return depth
  59.  
  60. def BFXbidDepth(x):
  61. depth =0
  62. BFXbids = PublicEndpoints.books("LTCUSD")['bids']
  63. for orders in BFXbids:
  64. if float(orders['price']) > float(x):
  65. depth = float(orders['amount']) + float(depth)
  66. #print "bid", orders[1]
  67. #print depth
  68. print depth
  69. return depth
  70.  
  71. def BFXaskDepth(x):
  72. depth = 0
  73. BFXasks = PublicEndpoints.books("LTCUSD")['asks']
  74. for orders in BFXasks:
  75. if float(orders['price']) < float(x):
  76. depth = float(orders['amount']) + float(depth)
  77. #print "ask", orders[1]
  78. #print depth
  79. print depth
  80. return depth
  81.  
  82. def BFXfindBid(x):
  83. depth =0
  84. global BFXleanBid
  85. BFXbids = PublicEndpoints.books("LTCUSD")['bids']
  86. for orders in BFXbids:
  87. if depth < float(x):
  88. depth = float(orders['amount']) + float(depth)
  89. BFXleanBid = orders['price']
  90. #print "bid", orders[1]
  91. #print depth
  92. #print BFXleanBid
  93. #print depth
  94. return float(BFXleanBid)
  95.  
  96. def BFXfindAsk(x):
  97. depth =0
  98. global BFXleanAsk
  99. BFXbids = PublicEndpoints.books("LTCUSD")['asks']
  100. for orders in BFXbids:
  101. if depth < float(x):
  102. depth = float(orders['amount']) + float(depth)
  103. BFXleanAsk = orders['price']
  104. #print "bid", orders[1]
  105. #print depth
  106. #print BFXleanAsk
  107. #print depth
  108. return float(BFXleanAsk)
  109.  
  110. def GDAXfindBid(x):
  111. depth =0
  112. global GDAXleanBid
  113. GDAXbidBook = publicClient.getProductOrderBook(level=2)['bids']
  114. for orders in GDAXbidBook:
  115. if depth < float(x):
  116. depth = float(orders[1]) + float(depth)
  117. GDAXleanBid = orders[0]
  118. #print "bid", orders[1]
  119. #print depth
  120. #print BFXleanBid
  121. #print depth
  122. return float(GDAXleanBid)
  123.  
  124. def GDAXfindAsk(x):
  125. depth =0
  126. global GDAXleanAsk
  127. GDAXaskBook = publicClient.getProductOrderBook(level=2)['asks']
  128. for orders in GDAXaskBook:
  129. if depth < float(x):
  130. depth = float(orders[1]) + float(depth)
  131. GDAXleanAsk = orders[0]
  132. #print "bid", orders[1]
  133. #print depth
  134. #print BFXleanBid
  135. #print depth
  136. return float(GDAXleanAsk)
  137.  
  138.  
  139. print GDAXfindBid(500)
  140. print GDAXfindAsk(500)
  141. print BFXfindBid(500)
  142. print BFXfindAsk(500)
  143. GDAXusd = authClient.getAccount("56ad7ec2-d1d8-4864-bd33-17a93df99001")['available']
  144. GDAXltc = authClient.getAccount("671c3517-deb8-48f8-b3a4-21eadf2ae403")['available']
  145. BFXltc = bitFinexAccount.wallet_balance()[9]['available'] #available btc balance
  146. BFXusd = bitFinexAccount.wallet_balance()[10]['available']#available usd balance
  147. spreads = 35
  148. while True:
  149. try:
  150. print BFXusd, BFXltc, GDAXusd, GDAXltc
  151. time.sleep(3)
  152. BFXgetBid = float(BFXfindBid(10))
  153. BFXgetAsk = float(BFXfindAsk(10))
  154. GDAXgetBid= float(GDAXfindBid(10))
  155. GDAXgetAsk = float(GDAXfindAsk(10))
  156. print (float(GDAXgetBid) - float(BFXgetAsk))
  157. print (float(BFXgetBid) - float(GDAXgetAsk))
  158. if float(GDAXgetBid) - float(BFXgetAsk) > float(entrySpread) and float(GDAXltc) > float(1) and float(BFXusd) > float(BFXgetAsk):
  159. sellParams = {
  160. 'price': "%.2f"%float(GDAXfindBid(100)), #USD
  161. 'size': str(lotSize), #BTC
  162. "product_id": "LTC-USD",
  163. "time_in_force": "GTT",
  164. "cancel_after" : 'min',
  165. #product_id not needed if default is desired
  166. }
  167. print authClient.sell(sellParams)
  168. print bitFinexOrders.new_order("LTCUSD", str(lotSize), '0.01', "buy", 'exchange market', 'bitfinex', False, True, 0, False, False)
  169. spreads = spreads + 1
  170. print "buy, Buy buy buy buy"
  171. print "buy, Buy buy buy buy"
  172. print "buy, Buy buy buy buy"
  173. print "buy, Buy buy buy buy"
  174. print "buy, Buy buy buy buy"
  175. print "buy, Buy buy buy buy"
  176. print "buy, Buy buy buy buy"
  177. print "buy, Buy buy buy buy"
  178. print "buy, Buy buy buy buy"
  179. print "buy, Buy buy buy buy"
  180. GDAXusd = authClient.getAccount("56ad7ec2-d1d8-4864-bd33-17a93df99001")['available']
  181. GDAXltc = authClient.getAccount("671c3517-deb8-48f8-b3a4-21eadf2ae403")['available']
  182. BFXltc = bitFinexAccount.wallet_balance()[9]['available'] #available btc balance
  183. BFXusd = bitFinexAccount.wallet_balance()[10]['available']#available usd balance
  184. if spreads > 0 and float(BFXgetBid) - float(GDAXgetAsk) > float(exitSpread) and float(BFXltc) > float(1) and float(GDAXusd) > float(GDAXgetAsk):
  185. buyParams = {
  186. 'price': "%.2f"%float(GDAXfindAsk(100)), #USD
  187. 'size': str(lotSize), #BTC
  188. "product_id": "LTC-USD",
  189. "time_in_force": "GTT",
  190. "cancel_after" : 'min',
  191. #product_id not needed if default is desired
  192. }
  193. print authClient.buy(buyParams)
  194. print bitFinexOrders.new_order("LTCUSD", str(lotSize), '0.01', "sell", 'exchange market', 'bitfinex', False, True, 0, False, False)
  195. print GDAXltc, BFXusd
  196. spreads = spreads -1
  197. print "SELL, SELL, SELL"
  198. print "SELL, SELL, SELL"
  199. print "SELL, SELL, SELL"
  200. print "SELL, SELL, SELL"
  201. print "SELL, SELL, SELL"
  202. print "SELL, SELL, SELL"
  203. print "SELL, SELL, SELL"
  204. print "SELL, SELL, SELL"
  205. print "SELL, SELL, SELL"
  206. GDAXusd = authClient.getAccount("56ad7ec2-d1d8-4864-bd33-17a93df99001")['available']
  207. GDAXltc = authClient.getAccount("671c3517-deb8-48f8-b3a4-21eadf2ae403")['available']
  208. BFXltc = bitFinexAccount.wallet_balance()[9]['available'] #available btc balance
  209. BFXusd = bitFinexAccount.wallet_balance()[10]['available']#available usd balance
  210. except:
  211. print "error"
  212. pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement