pickle is just like Shelve, I'm using Python 3.10.7 VENV environment on visual studio code
it says db_ID_1 is 0 in the terminal but when it comes to.. if db_ID_1 != '0': .. it think it isn't a 0 so it runs the wrong bit of code...
any help is much appreciated !!!
if think the problem is maybe with the string '0' or the class ID_1_db: .... i need it to be a str not a float thx.
from flask import Flask, render_template, config, request
import asyncio, json, time, websockets, requests
from web3 import Web3
import ccxt
from termcolor import colored
import numpy as np
import decimal
import os
import shelve
import threading
class ID_1_db:
def __init__(self, ID: str):
self.ID = ID
def __str__(self):
return f'{self.ID}'
# Create Bybit exchange object
exchange = ccxt.bybit({
'apiKey': '.......',
'secret': '........',
'enableRateLimit': True,
'options': {
'defaultType': 'swap',
},
})
exchange.options['recvwindow'] = 10000
symbol = 'BTCUSDT'
shib = 'SHIB1000USDT'
CRED = '\033[91m'
CEND = '\033[0m'
data: dict = {
'db_ID_1': ID_1_db('0'),
}
with shelve.open('bybitDB') as db:
db.update(data)
#----------------------------------------------------------------------------------------------------------------------------------
# checks the ID of an order to see if it is valid or if the DB needs to be reset
with shelve.open('bybitDB') as db:
db_ID_1 = db.get('db_ID_1')
print(db_ID_1)
if db_ID_1 != '0':
try:
status_order = exchange.fetch_order(id=str(db_ID_1), symbol=symbol)
if status_order['status'] != ['filled', 'open', 'new']:
data: dict = {
'db_ID_1': ID_1_db('0'),
'db_size_1': size_1_db('db_size_1', 0),
'db_TP_1': TP_1_db('db_TP_1', 0),
'db_TP_orderID_1': TP_orderID_db('db_TP_orderID_1', '0'),
'ema_orderID_db_1': ema_orderID_db('ema_orderID_db_1', '0'),
'exceed_orderID_db_1': exceed_orderID_db('exceed_orderID_db_1', '0'),
'side_1_db': side_db('side_1_db', '0'),
}
with shelve.open('bybitDB') as db:
db.update(data)
print('resetting all db values to 0')
time.sleep(1)
else:
print('there is a valid order that is filled, open, or new')
time.sleep(1)
except Exception as e:
print(CRED +" ERROR Exception, trying to reset DB :"+ CEND, e)
data: dict = {
'db_ID_1': ID_1_db('0'),
'db_size_1': size_1_db('db_size_1', 0),
'db_TP_1': TP_1_db('db_TP_1', 0),
'db_TP_orderID_1': TP_orderID_db('db_TP_orderID_1', '0'),
'ema_orderID_db_1': ema_orderID_db('ema_orderID_db_1', '0'),
'exceed_orderID_db_1': exceed_orderID_db('exceed_orderID_db_1', '0'),
'side_1_db': side_db('side_1_db', '0'),
}
with shelve.open('bybitDB') as db:
db.update(data)
else:
print('no order has been placed yet or no ID in db')
time.sleep(1)
as it is a string I needed to add str before db_ID_1... str(db_ID_1)
if str(db_ID_1) != '0':
try:
status_order = exchange.fetch_order(id=str(db_ID_1), symbol=symbol)