<center></center> So @strava2hive pointed me out to Beem... So I started piddling. Updated the code a little. ````html import pandas as pd import time import logging from beem import Hive from beem.account import Account from beem.market import Market from beem.transactionbuilder import TransactionBuilder # Configure logging logging.basicConfig(level=logging.INFO, filename='trading_bot.log', format='%(asctime)s - %(levelname)s - %(message)s') # Initialize Hive instance hive = Hive() def get_market_history(symbol, bucket_seconds, start, end): market = Market() return market.get_market_history(bucket_seconds, start, end) def get_signal(data): data['SMA50'] = data['close'].rolling(window=50).mean() data['SMA200'] = data['close'].rolling(window=200).mean() if data['SMA50'].iloc[-1] > data['SMA200'].iloc[-1]: return 'buy' elif data['SMA50'].iloc[-1] < data['SMA200'].iloc[-1]: return 'sell' else: return 'hold' def fetch_data(symbol, bucket_seconds, start, end): market_data = get_market_history(symbol, bucket_seconds, start, end) df = pd.DataFrame(market_data) df['date'] = pd.to_datetime(df['open'], unit='s') df.set_index('date', inplace=True) df['close'] = df['close_base'] / df['close_quote'] return df def check_transaction_status(transaction_id): tx = TransactionBuilder() try: tx.get_transaction(transaction_id) return "confirmed" except: return "unknown" def get_account_balance(account_name, symbol): account = Account(account_name) balance = account.get_balance(symbol) return balance def buy(symbol, amount, account_name): account = Account(account_name) market = Market() order = market.buy(amount, symbol, account_name=account_name) logging.info(f'Bought {amount} of {symbol} for account {account_name}') return order['transaction_id'] def sell(symbol, amount, account_name): account = Account(account_name) market = Market() order = market.sell(amount, symbol, account_name=account_name) logging.info(f'Sold {amount} of {symbol} for account {account_name}') return order['transaction_id'] def execute_trade(signal, symbol, amount, account_name): try: if signal == 'buy': transaction_id = buy(symbol, amount, account_name) elif signal == 'sell': transaction_id = sell(symbol, amount, account_name) # Check transaction status status = check_transaction_status(transaction_id) logging.info(f'Transaction status for {transaction_id}: {status}') except Exception as e: logging.error(f'Error executing trade: {e}') def run_bot(symbol, amount, account_name, bucket_seconds, interval=60): while True: try: end = int(time.time()) start = end - (bucket_seconds * 200) data = fetch_data(symbol, bucket_seconds, start, end) signal = get_signal(data) if signal != 'hold': execute_trade(signal, symbol, amount, account_name) time.sleep(interval) except Exception as e: logging.error(f'Error in run_bot loop: {e}') time.sleep(interval) # Run the bot run_bot('BEE', 10, 'alice', 86400) # Example with daily buckets (86400 seconds)
author | paulmoon410 |
---|---|
permlink | making-a-trading-bot-part |
category | hive-188262 |
json_metadata | "{"app":"ecency/3.2.0-vision","tags":["hive-188262","neoxian","pimp","thgaming","blockchaingaming","hivehustlers","palnet","waivio","ctp","lassecash","archon","ecency","ecency"],"format":"markdown+html","image":["https://images.ecency.com/DQmUzS18cvVuTV177wmSnpzXcSkBCcTxekz9BNdJ5vjgUQ8/image.png"],"thumbnails":["https://images.ecency.com/DQmUzS18cvVuTV177wmSnpzXcSkBCcTxekz9BNdJ5vjgUQ8/image.png"],"description":"Making a trading bot for hive... but I am so out of my depths.","image_ratios":["1.7820"]}" |
created | 2024-05-23 20:23:00 |
last_update | 2024-05-23 20:23:00 |
depth | 0 |
children | 4 |
last_payout | 2024-05-30 20:23:00 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.158 HBD |
curator_payout_value | 0.156 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 3,443 |
author_reputation | 40,653,574,175,519 |
root_title | "'Making A Trading Bot' Part 2- Learning to Code" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 133,881,818 |
net_rshares | 739,944,836,224 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
chrisaiki | 0 | 268,399,566,974 | 100% | ||
pixresteemer | 0 | 50,342,333,464 | 12% | ||
dejan.vuckovic | 0 | 11,621,853,681 | 15% | ||
chireerocks | 0 | 916,616,981 | 50% | ||
masoom | 0 | 3,312,031,599 | 50% | ||
ladasamara | 0 | 3,124,467,268 | 100% | ||
hivecannabis | 0 | 3,300,151,271 | 42% | ||
dannewton | 0 | 221,938,025,600 | 50% | ||
earthsea | 0 | 17,635,595,500 | 50% | ||
sodomlv | 0 | 2,605,345,687 | 50% | ||
marshmellowman | 0 | 9,370,632,865 | 55% | ||
arc7icwolf | 0 | 89,689,608,700 | 100% | ||
svanbo | 0 | 15,850,601,216 | 15% | ||
singerice | 0 | 0 | 100% | ||
waivio.welcome | 0 | 728,607,958 | 1.4% | ||
dr-animation | 0 | 1,709,005,126 | 100% | ||
nicklewis | 0 | 5,776,635,009 | 10% | ||
strava2hive | 0 | 27,846,212,788 | 100% | ||
giorgakis | 0 | 3,408,044,371 | 50% | ||
peakecoin | 0 | 1,267,338,823 | 100% | ||
pept-learn | 0 | 138,623,406 | 100% | ||
learn2code | 0 | 963,537,937 | 50% | ||
arc7icwolf.byte | 0 | 0 | 100% | ||
bbarelyseal | 0 | 0 | 100% | ||
vaultingagent | 0 | 0 | 100% | ||
gladartificial | 0 | 0 | 100% |
Curated by @arc7icwolf.byte for the #LearnToCode Community.
author | arc7icwolf |
---|---|
permlink | re-paulmoon410-2024526t223354394z |
category | hive-188262 |
json_metadata | {"tags":["hive-188262","neoxian","pimp","thgaming","blockchaingaming","hivehustlers","palnet","waivio","ctp","lassecash","archon","ecency","ecency"],"app":"ecency/3.2.0-vision","format":"markdown+html"} |
created | 2024-05-26 20:33:54 |
last_update | 2024-05-26 20:33:54 |
depth | 1 |
children | 0 |
last_payout | 2024-06-02 20:33:54 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 59 |
author_reputation | 508,055,258,566,757 |
root_title | "'Making A Trading Bot' Part 2- Learning to Code" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 133,949,832 |
net_rshares | 0 |
hahaha, I'm helpful...Yay!!! Glad I was able to assist. Yeah, I have been using beem for a little while and it really simplifies things when working with Hive.
author | strava2hive | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
permlink | sdyqxr | ||||||||||||
category | hive-188262 | ||||||||||||
json_metadata | {"app":"hiveblog/0.1"} | ||||||||||||
created | 2024-05-24 00:05:51 | ||||||||||||
last_update | 2024-05-24 00:05:51 | ||||||||||||
depth | 1 | ||||||||||||
children | 2 | ||||||||||||
last_payout | 2024-05-31 00:05:51 | ||||||||||||
cashout_time | 1969-12-31 23:59:59 | ||||||||||||
total_payout_value | 0.000 HBD | ||||||||||||
curator_payout_value | 0.000 HBD | ||||||||||||
pending_payout_value | 0.000 HBD | ||||||||||||
promoted | 0.000 HBD | ||||||||||||
body_length | 159 | ||||||||||||
author_reputation | 30,416,414,992,927 | ||||||||||||
root_title | "'Making A Trading Bot' Part 2- Learning to Code" | ||||||||||||
beneficiaries |
| ||||||||||||
max_accepted_payout | 1,000,000.000 HBD | ||||||||||||
percent_hbd | 10,000 | ||||||||||||
post_id | 133,885,423 | ||||||||||||
net_rshares | 0 |
It simplified it for me a lot
author | paulmoon410 |
---|---|
permlink | re-strava2hive-2024523t211114691z |
category | hive-188262 |
json_metadata | {"type":"comment","tags":["ecency"],"app":"ecency/3.1.0-mobile","format":"markdown+html"} |
created | 2024-05-24 01:11:15 |
last_update | 2024-05-24 01:11:15 |
depth | 2 |
children | 0 |
last_payout | 2024-05-31 01:11:15 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 29 |
author_reputation | 40,653,574,175,519 |
root_title | "'Making A Trading Bot' Part 2- Learning to Code" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 133,886,360 |
net_rshares | 0 |
Ok ok... So your ever work with Flask on Beem? To put a bot on my geocities account I have some work to do with it.
author | paulmoon410 |
---|---|
permlink | re-strava2hive-2024523t231737242z |
category | hive-188262 |
json_metadata | {"type":"comment","tags":["ecency"],"app":"ecency/3.1.0-mobile","format":"markdown+html"} |
created | 2024-05-24 03:17:39 |
last_update | 2024-05-24 03:17:39 |
depth | 2 |
children | 0 |
last_payout | 2024-05-31 03:17:39 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 115 |
author_reputation | 40,653,574,175,519 |
root_title | "'Making A Trading Bot' Part 2- Learning to Code" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 133,888,579 |
net_rshares | 0 |