-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create empty reflex project with print log of bitcoin's trade (#32
- Loading branch information
1 parent
680f9e3
commit 9296e3c
Showing
8 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
*.py[cod] | ||
.env | ||
.web | ||
__pycache__/ | ||
reflex.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
reflex==0.2.0 | ||
python-dotenv | ||
python-binance |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |