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 mm #36

Open
wants to merge 1 commit into
base: main
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
53 changes: 53 additions & 0 deletions Robots/mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import time
import numpy as np
import ccxt # A library for connecting to exchanges (example for crypto markets)

# Connect to an exchange (example for Binance)
exchange = ccxt.binance({
'apiKey': 'YOUR_API_KEY',
'secret': 'YOUR_API_SECRET',
})

# Settings for the market making strategy
symbol = 'BTC/USDT' # Trading pair
spread = 0.001 # 0.1% spread between bid and ask prices
order_size = 0.001 # Order size in BTC

def get_market_price(symbol):
ticker = exchange.fetch_ticker(symbol)
return ticker['ask'], ticker['bid']

def place_order(symbol, side, price, amount):
if side == 'buy':
order = exchange.create_limit_buy_order(symbol, amount, price)
elif side == 'sell':
order = exchange.create_limit_sell_order(symbol, amount, price)
return order

def cancel_orders(symbol):
orders = exchange.fetch_open_orders(symbol)
for order in orders:
exchange.cancel_order(order['id'], symbol)

def market_making(symbol):
while True:
# Get the current market price (ask and bid)
ask_price, bid_price = get_market_price(symbol)

# Calculate the new buy and sell prices based on the spread
buy_price = bid_price * (1 - spread)
sell_price = ask_price * (1 + spread)

# Cancel previous orders to avoid stale orders
cancel_orders(symbol)

# Place new buy and sell orders at the updated prices
print(f"Placing buy order at {buy_price}, sell order at {sell_price}")
place_order(symbol, 'buy', buy_price, order_size)
place_order(symbol, 'sell', sell_price, order_size)

# Sleep for a small period to simulate high-frequency execution
time.sleep(0.1) # Adjust the sleep time to control how fast the strategy runs

if __name__ == "__main__":
market_making(symbol)