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 empty reflex project with print log of bitcoin's trade #32

Merged
merged 1 commit into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions reflex-binance/.env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
BINANCE_API_KEY=my_binance_api_key
BINANCE_API_SECRET=my_binance_api_secret
5 changes: 5 additions & 0 deletions reflex-binance/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.py[cod]
.env
.web
__pycache__/
reflex.db
9 changes: 9 additions & 0 deletions reflex-binance/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# reflex-binance
## set keys
```bash
cp .env.template .env
vim .env
```
Set the two keys in .evn file. it will not commited into git server


Binary file added reflex-binance/assets/favicon.ico
Binary file not shown.
Empty file.
49 changes: 49 additions & 0 deletions reflex-binance/reflex_binance/reflex_binance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""Welcome to Reflex! This file outlines the steps to create a basic app."""
from rxconfig import config
import os
import reflex as rx
from dotenv import load_dotenv
from binance.client import Client
load_dotenv()
API_KEY = os.environ.get('BINANCE_API_KEY')
API_SECRET = os.environ.get('BINANCE_API_SECRET')
if not API_KEY or not API_SECRET:
raise ValueError("Please set the BINANCE_API_KEY and BINANCE_API_SECRET environment variables.")
try:
client = Client(API_KEY, API_SECRET)
recent_trades = client.get_recent_trades(symbol='BTCUSDT', limit=10)

print("最近的 Bitcoin 交易:")
for trade in recent_trades:
print(f"交易ID: {trade['id']}, 價格: {trade['price']}, 數量: {trade['qty']}")
except:
print("Exception")





class State(rx.State):
"""The app state."""
pass


def index() -> rx.Component:
return rx.fragment(
rx.color_mode_button(rx.color_mode_icon(), float="right"),
rx.vstack(
rx.heading("Welcome to Reflex Binance!", font_size="2em"),
rx.text(API_KEY),
rx.text(API_SECRET)
),
spacing="1.5em",
font_size="2em",
padding_top="10%",

)


# Add state and page to the app.
app = rx.App(state=State)
app.add_page(index)
app.compile()
3 changes: 3 additions & 0 deletions reflex-binance/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
reflex==0.2.0
python-dotenv
python-binance
10 changes: 10 additions & 0 deletions reflex-binance/rxconfig.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import reflex as rx

class ReflexbinanceConfig(rx.Config):
pass

config = ReflexbinanceConfig(
app_name="reflex_binance",
db_url="sqlite:///reflex.db",
env=rx.Env.DEV,
)