Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create vectar #500

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions vectar
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import ccxt
import pandas as pd
import time

# Replace these with your actual API keys
api_key = 'YOUR_API_KEY'
api_secret = 'YOUR_API_SECRET'

# Initialize the exchange
exchange = ccxt.binance({
'apiKey': api_key,
'secret': api_secret,
})

# Define the trading parameters
symbol = 'BTC/USDT'
timeframe = '1h'
limit = 100
sma_period = 20

def fetch_data():
# Fetch historical data
ohlcv = exchange.fetch_ohlcv(symbol, timeframe, limit=limit)
df = pd.DataFrame(ohlcv, columns=['timestamp', 'open', 'high', 'low', 'close', 'volume'])
df['timestamp'] = pd.to_datetime(df['timestamp'], unit='ms')
df.set_index('timestamp', inplace=True)
return df

def calculate_sma(df):
df['sma'] = df['close'].rolling(window=sma_period).mean()
return df

def trade_logic(df):
last_row = df.iloc[-1]
if last_row['close'] > last_row['sma']:
return 'buy'
elif last_row['close'] < last_row['sma']:
return 'sell'
return 'hold'

def execute_trade(signal):
if signal == 'buy':
print("Placing buy order")
exchange.create_market_buy_order(symbol, 0.001) # Adjust the amount as needed
elif signal == 'sell':
print("Placing sell order")
exchange.create_market_sell_order(symbol, 0.001) # Adjust the amount as needed

def main():
while True:
df = fetch_data()
df = calculate_sma(df)
signal = trade_logic(df)
execute_trade(signal)
time.sleep(60 * 60) # Sleep for an hour before running again

if __name__ == "__main__":
main()