The python code is available here :
--> Python
Replace API_KEY and SECRET_KEY with your own keys
API_KEY = 'YOUR_PUBLIC_KEY'
SECRET_KEY = 'YOUR_PRIVATE_KEY'
You can run this main if you want to display all the functions. We commented createOrder and cancelOrder because it doesn't work since you need fund to make it run.
WARNING: If you rerun main() a second time, the console will display that the table already exists. Just comment 'con = sqlConnection()' and 'createCandleTable(con,"BTCUSDT","5m")' and 'createTradeTable(con,"BTCUSDT")' to avoid this.
def main():
getList()
getDepth()
getOrderBook()
con = sqlConnection()
createCandleTable(con,"BTCUSDT","5m")
refreshDataCandle()
con = sqlConnection()
createTradeTable(con,"BTCUSDT")
refreshData()
#createOrder('SELL','8300','0.1')
#uuid=333105
#cancelOrder(uuid)
>> getList()
Returns all the cryptocurrencies and their price.
>> getDepth('bid','BNBEUR')
By default, the pair is "BTCUSDT"
We created an additional function named removeKey in order to display only bid or only ask prices :
def removeKey(d, key):
r = dict(d)
del r[key]
return r
>> getOrderBook('BNBEUR')
By default, the pair is "BTCUSDT"
Create a function to read agregated trading data (candles) (Don't worry, it will display an error at the end of the console because you didn't create the sqlite table yet)
>> refreshDataCandle('BTCUSDT','5m')
con=sqlConnection()
createCandleTable(con,'BTCUSDT','5m')
See the functions in the python file, sqlConnection handle the connection to sqlite and createCandleTable create the table and names is "Binance_BTCUSDT_5m" for this example. Then you can rerun refreshDataCandle()
We adapted the refreshDataCandle() function to add datas to the base with this command:
c.executemany('INSERT INTO ' + setTableName + ' VALUES (?,?,?,?,?,?,?,?,?,?,?,?)', r.json())
You just have to rerun the function to add the data to the base. If you want to clear the db each time you rerun the function, just had the following before the previous command :
c.execute('DELETE * from ' + setTableName)
Same logic as before :
con=sqlConnection()
createTradeTable(con,'BTCUSDT')
Had to manipulate a bit the request r before adding it in the table with the following :
l=[]
for i in range(len(r.json())):
temp=[]
for valeur in r.json()[i].values():
temp.append(valeur)
l.append(temp)
Explanation : r.json() object was like a dictionnary (i.e. : '{"a":1, "b":2, etc.}') and it was impossible to add it to the table. After this, the l object contains only the values (i.e. : '{1,2,etc.}').
Will display an error since we have no fund, and the price must be close to the traded price to make the order.
>> createOrder('SELL', '8300', '0.1', 'BTCUSDT', 'LIMIT')
Need the uuid of the order to cancel it, which we don't have.
>> cancelOrder(uuid, 'BTCUSDT')