Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
Try to solve OndroS#1

and more.
  • Loading branch information
vitorgamer58 committed Oct 8, 2019
1 parent 3fde5e1 commit 4b02dd9
Show file tree
Hide file tree
Showing 4 changed files with 179 additions and 49 deletions.
1 change: 0 additions & 1 deletion API-Demo-Python
Submodule API-Demo-Python deleted from 4e307e
159 changes: 115 additions & 44 deletions CB_bot.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,81 +2,152 @@
"cells": [
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"BETHER vs. ETH\n",
"*********************************\n",
"{'symbol': 'BETHERETH', '24hrHigh': '0.00000990', 'last': '0.00000711', '24hrVol': '21889039.72', 'ask': '0.00000782', '24hrLow': '0.00000701', 'bid': '0.00000711', '24hrAmt': '171.32539129'}\n",
"ETH vs. USDT\n",
"*********************************\n",
"{'symbol': 'ETHUSDT', '24hrHigh': '150.00', 'last': '147.71', '24hrVol': '33207.28', 'ask': '147.64', '24hrLow': '146.00', 'bid': '147.6', '24hrAmt': '4904143.22'}\n"
"UDST vs. BRL\n",
"BOT BY vitorgamer58\n",
"{'symbol': 'USDTBRL', '24hrHigh': '4.210', 'last': '4.210', '24hrVol': '119.38', 'ask': '4.31', '24hrLow': '4.210', 'bid': '4.21', '24hrAmt': '502.589'}\n"
]
}
],
"source": [
"import bot as bot\n",
"\n",
"print('BETHER vs. ETH')\n",
"print('*********************************')\n",
"print(bot.get_ticker('BETHERETH'))\n",
"print('ETH vs. USDT')\n",
"print('*********************************')\n",
"print(bot.get_ticker('ETHUSDT'))"
"print('UDST vs. BRL')\n",
"print('BOT BY vitorgamer58')\n",
"print(bot.get_ticker('USDTBRL'))"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"execution_count": 2,
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.00000747\n",
"147.71\n",
"Actual BETHER Price 0.0011033937\n",
"Actual Portfolio Price 1875.7692900000002\n",
"Desired Portfolio Price 375869.1874\n"
"4.21\n",
"Não compre\n",
"Não compre\n",
"Não compre\n",
"compre\n"
]
}
],
"source": [
"BETHERETH = bot.get_ticker('BETHERETH')\n",
"ETHUSDT = bot.get_ticker('ETHUSDT')\n",
"\n",
"\n",
"\n",
"lastBetherPrice = BETHERETH['last']\n",
"lastETHPrice = ETHUSDT['last']\n",
"\n",
"print(lastBetherPrice)\n",
"print(lastETHPrice)\n",
"\n",
"actualInUSD = float(lastBetherPrice) * float(lastETHPrice)\n",
"USDTBRL = bot.get_ticker('USDTBRL')\n",
"\n",
"portfolioAMount = 1700000\n",
"lastPrice = float(USDTBRL['last'])\n",
"print(lastPrice)\n",
"\n",
"portfolioPrice = float(portfolioAMount) * float(actualInUSD)\n",
"\n",
"print(\"Actual BETHER Price \" + str(actualInUSD))\n",
"print(\"Actual Portfolio Price \" + str(portfolioPrice))\n",
"\n",
"desiredPrice = 0.221099522\n",
"\n",
"print(\"Desired Portfolio Price \" + str(float(portfolioAMount) * float(desiredPrice)))"
"while lastPrice > 4.00:\n",
" print('Não compre')\n",
" lastPrice = lastPrice - 0.10\n",
"else:\n",
" print('compre')\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'symbol': 'USDTBRL', 'orderbook': {'bids': [{'quantity': 7.9, 'price': 4.21}, {'quantity': 1000.33, 'price': 4.16}, {'quantity': 4014.37, 'price': 3.83}, {'quantity': 4800, 'price': 3.82}, {'quantity': 4000, 'price': 3.81}, {'quantity': 41688.9, 'price': 3.15}, {'quantity': 22007.6, 'price': 2.48}, {'quantity': 15046.24, 'price': 2.18}, {'quantity': 48470.41, 'price': 2.05}], 'asks': [{'quantity': 168.03, 'price': 4.31}, {'quantity': 14957.5, 'price': 5.25}, {'quantity': 113.84, 'price': 5.316}, {'quantity': 22436.25, 'price': 5.45}, {'quantity': 22436.25, 'price': 6.25}]}, 'status': 'ok', 'timestamp': 1570504909529}\n"
]
}
],
"source": [
"print(bot.get_orderbook('USDTBRL'))"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"({'description': \"JSON parse error: Unrecognized token 'apiid': was expecting ('true', 'false' or 'null'); nested exception is com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'apiid': was expecting ('true', 'false' or 'null')\\n at [Source: java.io.PushbackInputStream@a9bbe89; line: 1, column: 7]\",\n",
" 'status': 'error',\n",
" 'timestamp': 1570505118426},\n",
" {'apiid': 'e4ded97f572ac6307616c1067657a531',\n",
" 'price': '4.01',\n",
" 'quantity': '1',\n",
" 'symbol': 'BTCUSDT',\n",
" 'type': 'sell-limit',\n",
" 'timestamp': 1570465518240,\n",
" 'sign': '674f3ad9e62337d6ee11698884f68635'},\n",
" {'Date': 'Tue, 08 Oct 2019 03:25:18 GMT', 'Content-Type': 'application/json;charset=UTF-8', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Set-Cookie': '__cfduid=d4b2b00dab667b1275e464ee68b11f7321570505118; expires=Wed, 07-Oct-20 03:25:18 GMT; path=/; domain=.coinbene.com; HttpOnly, acw_tc=0bc1a90415705051184231119e7e112455d4f2380ca37acbf12058c4a0bb98;path=/;HttpOnly;Max-Age=1800', 'X-Application-Context': 'exchange-openapi:prod:8601', 'CF-Cache-Status': 'DYNAMIC', 'Expect-CT': 'max-age=604800, report-uri=\"https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\"', 'Server': 'cloudflare', 'CF-RAY': '522501bd793e4ba3-GRU'})"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"bot.limit_order('sell', '1', '4.01', 'BTCUSDT')"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'account': 'exchange', 'apiid': 'e4ded97f572ac6307616c1067657a531', 'timestamp': 1570465581394, 'sign': '0ec9bb959dbc0af17ec8f3761e02995d'}\n"
]
},
{
"data": {
"text/plain": [
"{'description': \"JSON parse error: Unrecognized token 'account': was expecting ('true', 'false' or 'null'); nested exception is com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'account': was expecting ('true', 'false' or 'null')\\n at [Source: java.io.PushbackInputStream@42ee04a9; line: 1, column: 9]\",\n",
" 'status': 'error',\n",
" 'timestamp': 1570505181752}"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"bot.get_balance()"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"ename": "NameError",
"evalue": "name 'r' is not defined",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m<ipython-input-10-13e5847e3224>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mr\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mencoding\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[1;31mNameError\u001b[0m: name 'r' is not defined"
]
}
],
"source": []
},
{
Expand All @@ -103,7 +174,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
"version": "3.7.4"
}
},
"nbformat": 4,
Expand Down
57 changes: 57 additions & 0 deletions CB_bot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env python
# coding: utf-8

# In[1]:


import bot as bot

print('UDST vs. BRL')
print('BOT BY vitorgamer58')
print(bot.get_ticker('USDTBRL'))


# In[2]:


USDTBRL = bot.get_ticker('USDTBRL')

lastPrice = float(USDTBRL['last'])
print(lastPrice)

while lastPrice > 4.00:
print('Não compre')
lastPrice = lastPrice - 0.10
else:
print('compre')


# In[3]:


print(bot.get_orderbook('USDTBRL'))


# In[2]:


bot.limit_order('sell', '1', '4.01', 'BTCUSDT')


# In[2]:


bot.get_balance()


# In[10]:





# In[ ]:




11 changes: 7 additions & 4 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@


# API information
apiId = ''
secretId = ''
apiId = 'e4ded97f572ac6307616c1067657a531'
secretId = '08060e6f23a14d5aa5366c73412485e0'

header_dict = {"User-Agent": "Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko",\
"Content-Type":"application/json;charset=utf-8","Connection":"keep-alive"}



Expand Down Expand Up @@ -143,7 +146,7 @@ def get_balance():
print(data)

# Send POST request and saving response as response object
r = requests.post(url = API_ENDPOINT, data = data)
r = requests.post(url = API_ENDPOINT, data = data, headers=header_dict)
output = r.json()

return output
Expand Down Expand Up @@ -201,7 +204,7 @@ def limit_order(t, q, p, s):
}

# Send POST request and saving response as response object
r = requests.post(url = API_ENDPOINT, data = data)
r = requests.post(url = API_ENDPOINT, data = data, headers=header_dict)
output = r.json()

# return orderID for order tracking
Expand Down

0 comments on commit 4b02dd9

Please sign in to comment.